Raspberry Pi and Arduino Serial Communication

Setup and Connections

  1. Connect the output of the Arduino TX pin to a voltage divider.  The output of the voltage divider is then connected to the RPi GPIO pin # 10 (GPIO 15).  The voltage divider drops Arduino TX voltage from 5V to 3.3V.  In my case, I used 2 10K resistors connected in parallel and 1 10K resistor attached to ground (See schematic below).Raspberry Pi and Arduino Serial Communication
  2. The RPi TX GPIO pin #8 is attached to the base of an NPN transistor while the Arduino RX pin is attached to the collector (See schematic below).  The transistor takes the input signal from the RPi and increases the output voltage to 5V.
  1. Connect a wire from Arduino GND to RPi GPIO pin # 6.
  2. Remove console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 from /boot/cmdline.txt on the RPi.
  3. Comment out #T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100 in /etc/inittab on the RPi.

he Software – Raspberry Pi

I have seen a lot of examples of serial communication using Python and it seems VERY simple and straight forward.  However, since I happened to have spent WAY too much time coding a C program last year that did just that.  This program sends a byte of data to the Arduino setting the brightness of an LED.

Raspberry Pi and Arduino Serial Communication Raspberry Pi and Arduino Serial Communication schematic

In order to confirm that the receiving circuit is working OK, the Arduino sends the brightness back to the program and is displayed in the terminal.

To compile this program, simply enter the following at a command prompt:
gcc serial_set_led_brightness.c -o serial_set_led_brightness

The Software – Arduino

The Dimmer sketch can be found in the “Examples” folder.

 

For more detail: Raspberry Pi and Arduino Serial Communication

Scroll to Top