Hello,
I’m trying to send data between a Particle Photon and a Rapsberry Pi 3 B+ with UART.
I’ve enabled GPIO and changed the UART linked to the GPIO pins on the Raspberry in order to have a regulare baud rate (9600 with Serial0 -> ttyAMA0).
On the Photon I’m using Serial1.
I’ve tested to loopback Rx and Tx on each device (sending and receiving on the same device) to test my code and configuration and it worked for both.
But when I connect the Particle-Rx to the Rasperry-Tx i can’t receive the sended data. Instead I receive some empty or random char:
For the other direction (Particle to Raspberry), I receive nothing.
Can someone help me please ? I’m probably missing something obvious
Here is my code:
- Particle Photon
int counter = 0;
void setup() {
Serial1.begin(9600);
}
void loop() {
Serial1.println("Particle "+String(counter));
if(Serial1.available())
{
String tmp = "";
for(int i = 0; !tmp.endsWith("\n") && Serial1.available(); i++)
{
tmp += (char)Serial1.read();
}
if (Particle.connected() == false) {
Particle.connect();
}
Particle.publish("Testing UART", "{\"Value readed\":\""+tmp+"\"}");
}
delay(1000);
counter++;
}
- Raspberry Pi
import serial
serialPort = serial.Serial("/dev/ttyAMA0", 9600, timeout = 3)
def main():
counter = 0
try:
while 1:
serialPort.write(("Raspberry %d\n" % counter).encode())
messageReaded = serialPort.readline()
print(messageReaded.decode())
counter = counter + 1
except KeyboardInterrupt:
serialPort.close()
if __name__ == '__main__':
main()