Photon to Arduino serial data false

Hi all, I’m using my Photon and Arduino board with tx/rx. What I’m trying to do is get my photon to send potentiometer data to my Arduino uno via tx/rx… I have a logic level shifter to shift the signals ( https://learn.sparkfun.com/tutorials/bi-directional-logic-level-converter-hookup-guide)and I run tx and rx through it; while I connect the ground. For some reason this will not work. The strange thing is it will work on Photon’s even when one is 3.3, and the other 5v while I use the same logic level converter; the data makes sense, so this must be the Arduino messing with me because it works when I do this with my photons. My goal is to get the data from the Photon to print in my Arduino’s serial monitor. This has been confusing me for a while now…

Photon code:

void setup() {
Serial1.begin(9600);


}

void loop() {
int data = analogRead(A0)/ 4;

delay(400);
Serial1.println("Hello World, this is my value");
delay(400);
Serial1.println(data);
}

Arduino code:

int incomingByte = 0;   

void setup() {
        Serial.begin(9600);     
}
void loop() {

        if (Serial.available() > 0) {
                // read the incoming byte:
                incomingByte = Serial.read();

                Serial.print("received, ");
                Serial.println(incomingByte, DEC);
        }
}

If anyone would like me to clarify I would be happy to do so. My goal is to get the data from the Photon to print in my Arduino’s serial monitor

Jack

@JackD12, the code on the arduino seems to be receiving on Serial and then printing to Serial (back to Photon). Is this what you intended?

Um no but that’s a good point @peekay123

I meant for that data to printed in Arduino’s serial monitor

@JackD12, you can’t do both! You can have the serial monitor connected but need a second serial port to communicate with the Photon. You may want to consider using SoftwareSerial for connecting to the Photon.

Would that explain the false data? @peekay123

@JackD12, what do you mean by “false data”? From what I understand, you can do Photon to Photon even with the level shifter, correct? For the Arduino are the TX and RX lines crossed going to the Arduino TX and RX lines?

Using the serial monitor while being connected to the Photon may cause problems. This is why I suggest using SoftwareSerial to create a second serial port. That way you can keep the serial monitor on the USB and have software serial create a new port for the Photon which will not interfere.

By false data I mean the numbers that show up in Arduino’s serial monitor; but I know its false because it’s absolutely crazy! And yes I double checked my connections for tx/rx. Do you mean Software Serial on arduino or Photon (Sorry I’m not very good with the SoftwareSerial library :joy: )

@JackD12, trying to use the Serial monitor and the RX/TX lines on the Arduino at the same time could produce that false data. SoftwareSerial is a standard Arduino library that allows you create a serial port from 2 GPIO pins you designate. It is very easy to use. It creates a serial port that you could use much like Photon’s Serial1 port.

So on the Arduino side, you would read from the SoftwareSerial port you created and send it to the Serial port for display on the serial monitor.

Ok, so instead of putting the tx and rx pins from the photon I would put them on whatever pins I designate and allowed for SoftwareSerial, then take the value from the designated pin(s) and print it in the Arduino serial monitor. Correct @peekay123 ?

And my Arduino code above would no longer be needed i could just use the Arduino example “Two Port Receive”

@JackD12, yup. Without looking at the “two port receive” example, I can’t confirm but I think you’re on the right track. :wink:

Thanks @peekay123 it’s starting to work a heck of a lot better!!! :grinning:
The data finally makes sense!

1 Like

@JackD12, don’t you love it when a plan comes together!

Absolutely, I never would’ve figured that one out on my own! :laughing:

1 Like