Quantcast
Viewing all articles
Browse latest Browse all 36

Serial communication between Raspberry Pi and Arduino

I want to communicate between my Raspberry Pi and Arduino via Serial line (UART). Why? The RPI cost less than a Arduino Ethernet Shield and has more power. And because I can…

The main problem is, the RPI operates at 3.3V while Arduino operate at 5V. So you cannot connect the two devices together without voltage level shifter, right? Wrong! Seeedstudio’s Arduino clone Seeeduino can switch between 5V and 3.3V IO voltage, so you don’t need a voltage level shifter.

There are two options how to connect the two devices:

  • Arduino USB connector
  • UART

I dont want to use the USB option, because it adds the USB latency.

Perpare the RPI
I use the 2012-12-16-wheezy-raspbian image on my Model B RPI with 512mb.

This image use the UART port as a serial console. As I want to control the serial port myself I want to get rid of the serial console. Edit the file /boot/cmdline.txt and remove those

1
console=ttyAMA0,115200 kgdboc=ttyAMA0,115200

entries. Now open the file /etc/inittab and comment out the following line:

1
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

Credit for this procedure: http://www.irrational.net. Now connect the GPIO line 14 (TX) and 15 (RX) and fire up minicom:

1
minicom -b 115200 -o -D /dev/ttyAMA0

To verify everything works fine, just type some characters into the terminal and the should them in the terminal.

As next step, install the tool ser2net a “Serial to Network Proxy”. The RPI contains an old release of ser2net, so I compiled the latest version (v2.8-rc3) myself (./configure && make && make install). The config file of ser2net contains:

1
5333:raw:500:/dev/ttyAMA0:115200 8DATABITS NONE 1STOPBIT

Listen on port 5333, disconnect TCP session after 500s inactivity.

The init script didn’t work, so I started ser2net manually:

1
2
$ sudo ser2net -n -d
Error on line 1, Unable to create TCP socket

I did some research and found out, that this might be a code error. I inserted the IPv6 module

1
$ sudo modprobe ipv6

and ser2net worked! I also reported the bug to the ser2net project.

Edit 30.01.2013:
The ser2net bug is already fixed in the head version (or any version older than version 2.8-rc3).

Connect Arduino and Raspberry Pi
I connected 4 Cables between the two devices:

1
2
3
4
5
RPI            Arduino
5V (Pin 2)     5V
GND (Pin 6)    GND
TX (Pin 8)     RX
RX (Pin 10)    TX

So I power the Arduino with the RPI.

Image may be NSFW.
Clik here to view.
RPI-Arduino

The next steps are, performance calculations! Have fun!


Viewing all articles
Browse latest Browse all 36

Trending Articles