Particle to Raspberry with UART


#1

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:
Particle_Raspberry_UART

For the other direction (Particle to Raspberry), I receive nothing.

Can someone help me please ? I’m probably missing something obvious :confused:

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()

#2

I’ve made other tests and by connecting Particle-Rx to Raspberry-Tx and Particle-Tx to Raspberry-Rx, i’ve got noting on the Raspberry side, but for the Particle side i’ve got the following :
Particle_Raspberry_UART2

Receiving Particle and Raspberry messages makes me wonder … is it possible, that the Photon uses a too high tension for the Raspberry ? :thinking:


#3

I’ve made it work!
I was powering the Particle form a battery (3.7V). Now it’s powered by the 3.3V pin of the Raspberry.
At first I was surprised because the Raspberry rebooted after that I pluged the last cable (3.3V).
I double checked that my wiring was good and now it still reboot if I unplug and replug the Particle.
Does someone know why ? :thinking:


#4

This suggest you didn’t have a common ground for both devices before. If so, having a common GND level is paramount for that kind of communication.