7

I currently working on a project where an Arduino has to communicate with a pi. Since the pi is running out of USB ports, I am forced to use the ux/tx ports on the Arduino and pi.

The communication in between those to consist of writing and reading from rostopic, meaning that rosserial is establising the serial communication.

I have only tested this using USB and between a pc and arduino, which works well, but haven tested on those pins and are bit unsure on a few things.

Do I need to use certain pins? And should they be setup for serial communication? in that case how?

I guess I would need a logic level converter. It should be easily made using a voltage divider. But should both have separate ones, or is just one enough?

Spencer H
  • 149
  • 5
J.Down
  • 171
  • 1
  • 2
  • Hello and welcome. Check these http://raspberrypi.stackexchange.com/questions/553/gpio-uart-to-arduino-communication and http://raspberrypi.stackexchange.com/questions/26219/arduino-to-rpi-serial-communication to get a first idea. – Ghanima Oct 09 '16 at 13:17

2 Answers2

1

I guess i would need a logic level converter

Yes. I don't think there is any arrangement of voltage divider you can use for the Pi's TX -> Arduino RX. So you need at least a 2 channel shifter that's either bidirectional or has a channel going each way.

I use a shifter like the one shown and described here. Although that's a question about "Arduino devices" I mostly do it directly with the Arduino itself.

The relationship is very reliable at the Arduino's max baud rate (115200) in my experience. The thing you have to watch out for is state management -- you should have a means of resetting the Arduino to a predictable state. This is usually pretty easy as it would be hard to create a situation where simply pushing "reset" doesn't work, since even if the content of information sent at that point is unknown, the format should not be (e.g., a set of 3 2-byte unsigned integers constitutes one message or whatever).

If you need to do that remotely you can connect a GPIO to the Arduino's reset pin then you just need to pull it low momentarily and leave it high for normal operation. This also needs to pass through the level shifter, so if you think you want that you need at least 3 channels. The four channel ones are very common and cheap anyway.

goldilocks
  • 58,859
  • 17
  • 112
  • 227
  • Thanks for that. My next stop, once getting the Arduinos to talk to each other, is to include the Rpi3. I may yet use I2C for that, now that @Joan has upgraded the gpgio package to include it. I am new to all this but am positive I can make things work, once I know their parameters. – SDsolar Dec 03 '16 at 00:58
1

You should not need to shift the RPI Tx ---> Arduino RX The Arduino will be able to read the 3.3V logic produced by the pi, so you can use a simple voltage divider to shift Arduino TX ---> RPI RX

The RPI3 does have a different setup for the UART, there are actually 2 that can be used (not at the same time) One is always tied to the Bluetooth unit(i think) The default is the better(more stable) of the two is used for bluetooth and the other is tied to the UART pins on the GPIO. So make sure to look into that. If you list out the /dev directory, you will see the linked device at Serial1 (which will always point to the actual UART being used) But if you have any performance issues you can switch which internal UART is tied the GPIO

Here is some reading on the UARTS on the pi

Chad G
  • 1,043
  • 1
  • 7
  • 14