I want to send data from RaspberryPi to Arduino UNO using UART. I tried sending my data 10 times to Arduino but it received it once. It reads as follows.

Connected to PC
pi: ÿpi: ÿpi: ÿ

1) I modified two files:

boot/cmdline.txt: to

dwc_otg.lpm_enable=0 console=ttyAMA0,9600 kgdboc=ttyAMA0,9600 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait

etc/inittab: to

T0:23:respawn:/sbin/getty -L ttyAMA0 9600 vt10

2) I connected Arduino to my PC using USB UART and to Rpi

pin 10(Arduino) to pin 8(Raspberry)

pin 11(Arduino) to pin 10(Raspberry)

This is my Arduino code to receive data over UART:

 Connects Arduino to Raspberry Pi
 Arduino: SoftSerial
 Raspberry Pi: GPIO UART 
 Just connect pin 10(Arduino) to pin 8(Raspberry)  
              pin 11(Arduino) to pin 10(Raspberry)  
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX

void setup()  
   while (!Serial) {

  Serial.println("Connected to PC");

void loop() 
  // If data is available on Raspberry Pi, print it to PC
  if (mySerial.available()){
      Serial.print("pi: ");

3) On Raspberry i use python:

import RPi.GPIO as GPIO ## Import GPIO Library 
import time ## Import 'time' library.  Allows us to use 'sleep' 
import sys, getopt
import serial

print('Dang thuc thi')

port = serial.Serial("/dev/ttyAMA0", baudrate=9600,timeout=1)
#port.write("\r\n" + args[0])
a = 0;
while a<10:
    port.write('data ' + str(a))
    print('times: '+ str(a))

Where am I going wrong?


First of all, you need to disable serial console on Rpi which is on by default. If you're running a new version of raspbian. Run sudo raspi-config, go to 8. Advanced options, Go to Serial and select disable. It will disable your serial console. You will have to reboot to make it effective.

If you don't want to make changes using raspi-config way.

  1. Like you said, change your /boot/cmdline.txt to look like follow. Ie, remove any reference to /dev/ttyAMA0.

    dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait
  2. Open /etc/inittab and comment out (insert # at the very beginning) following line to make it look like as below.

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

Second point, Rpi is a 3v3 device while Arduino is 5v device. So while connecting both of them, you must use a level shifter to convert 5v logic to 3v3 logic else it can damage your RPi.

Here is a connection circuit for your reference.

enter image description here

Hope it helps.

  • I also send data from Raspberry PI to Arduion. (Is it possiple when only connect RX (Arduino) with TX (Raspberry PI) ?) Jul 2 '15 at 10:52
  • @user3326893 Yes, ideally it is. In that case, it would be simplex communication ie, one way. Jul 2 '15 at 10:55
  • @user3326893 Make sure that you have disabled serial console as mentioned in my answer. Jul 2 '15 at 11:06
  • i remember I tried your way. but it doesn't work. I will try again! Jul 2 '15 at 11:07
  • I just try! when i connect RX (Arduino) with TX (Raspberry PI) . On arduino display ÿpi: ÿpi: ÿpi: ÿpi: ÿpi: ÿpi: ÿpi:pi: ÿpi: ÿpi: ÿpi: ÿpi: Çpi: ÿpi: ópi: ÿpi: ƒpi: pi: ÿpi: Ã very long! always receive data! Jul 2 '15 at 11:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.