jimmybobby
Posts: 29
Joined: Wed Feb 20, 2013 9:53 pm

Serial Communication between Pis

Tue Mar 31, 2015 5:39 pm

Hi, I have two Model B rev 2 Pis, and I would like then to communicate between the GPIO. I assume that the best way to do this is through Serial (GPIO pins 8 and 10 [UART TXD and UART RXD] according to some pin out that I have).

The ideas situation is to ssh into both, and to see a string appear on both, from a python script.

Is it possible? I have already tried this: http://stackoverflow.com/questions/2186 ... spberry-pi

I would basically like a serial receiver for the Pi, is there any way to go about doing this?
It's fair to say I like obsolete/old technology. :)
A Level Comp Sci Student

User avatar
joan
Posts: 14885
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Serial Communication between Pis

Tue Mar 31, 2015 5:50 pm

Yes, it is possible, you can send messages between Pis using the serial link. Connect one ends TX to the other ends RX and vice versa. Also connect the Pi grounds.

jimmybobby
Posts: 29
Joined: Wed Feb 20, 2013 9:53 pm

Re: Serial Communication between Pis

Tue Mar 31, 2015 6:04 pm

joan wrote:Yes, it is possible, you can send messages between Pis using the serial link. Connect one ends TX to the other ends RX and vice versa. Also connect the Pi grounds.
TX > RX
RX >TX
makes sense - crossed connection.

Why the grounds, and do they have to be the same grounds?
It's fair to say I like obsolete/old technology. :)
A Level Comp Sci Student

User avatar
jojopi
Posts: 3230
Joined: Tue Oct 11, 2011 8:38 pm

Re: Serial Communication between Pis

Tue Mar 31, 2015 6:18 pm

jimmybobby wrote:The ideas situation is to ssh into both, and to see a string appear on both, from a python script.
What do you mean about seeing a string appear on both?

If you can ssh to both Pies, that suggests that they are connected to the same network. In that case the more Linuxy thing may be to have the Python programs communicate over the network instead.

Networking takes a bit more code than Serial to get started, but it is more flexible. You can have multiple programs using the network at the same time, and the kernel keeps track of the connections and which data to send where. Serial is just a sequence of bytes and you can only use it for one thing at a time. It is better suited for talking to single-task computers like Arduino.

User avatar
PeterO
Posts: 5828
Joined: Sun Jul 22, 2012 4:14 pm

Re: Serial Communication between Pis

Tue Mar 31, 2015 6:21 pm

jimmybobby wrote: Why the grounds, and do they have to be the same grounds?
Yes they both need the same "GND" as that is the reference that the RX signals are compared against to decide if they are at "1" or "0".
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

jimmybobby
Posts: 29
Joined: Wed Feb 20, 2013 9:53 pm

Re: Serial Communication between Pis

Tue Mar 31, 2015 6:26 pm

PeterO wrote:
jimmybobby wrote: Why the grounds, and do they have to be the same grounds?
Yes they both need the same "GND" as that is the reference that the RX signals are compared against to decide if they are at "1" or "0".
PeterO
Ah ok that makes sense.

So... how would I go about this?

I'd like "pi1" to transmit, and "pi2" to recieve.

I know it's kinda pointless, because I can ssh, but nothing else (afaik) is using serial on either, but at the moment I can't get anything to work, I can confirm GND > GND and TX > RX, and RX >TX are connected.
It's fair to say I like obsolete/old technology. :)
A Level Comp Sci Student

User avatar
joan
Posts: 14885
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Serial Communication between Pis

Tue Mar 31, 2015 6:52 pm

Make sure you have disabled the system's use of the serial link, raspi-config gives an option.

sudo raspi-config

Make sure the baud rate (speed) is the same on both Pis.

stty -F /dev/ttyAMA0 19200 # on both Pis

On the receiver

cat </dev/ttyAMA0

On the transmitter

echo "Hello" >/dev/ttyAMA0

jimmybobby
Posts: 29
Joined: Wed Feb 20, 2013 9:53 pm

Re: Serial Communication between Pis

Tue Mar 31, 2015 6:58 pm

joan wrote:Make sure you have disabled the system's use of the serial link, raspi-config gives an option.

sudo raspi-config

Make sure the baud rate (speed) is the same on both Pis.

stty -F /dev/ttyAMA0 19200 # on both Pis

On the receiver

cat </dev/ttyAMA0

On the transmitter

echo "Hello" >/dev/ttyAMA0
I get permission denied, even when running as sudo
It's fair to say I like obsolete/old technology. :)
A Level Comp Sci Student

User avatar
DougieLawson
Posts: 38854
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Serial Communication between Pis

Tue Mar 31, 2015 7:03 pm

Add your userid to the dialout group

sudo adduser pi dialout
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

jimmybobby
Posts: 29
Joined: Wed Feb 20, 2013 9:53 pm

Re: Serial Communication between Pis

Tue Mar 31, 2015 7:05 pm

DougieLawson wrote:Add your userid to the dialout group

sudo adduser pi dialout
It says it already is

EDIT: never mind, a reboot was needed
It's fair to say I like obsolete/old technology. :)
A Level Comp Sci Student

Return to “Automation, sensing and robotics”