zitman
Posts: 20
Joined: Wed Jul 18, 2012 11:02 am

GPIO, UART, Python and an Arduino

Sun Nov 11, 2012 7:05 pm

Hi all,

Having got my I2C project working well I decided to make the Pi talk to an Arduino via serial. I have connected the UART pins on the Pi (14 & 15) via a level shifter to the Arduino and modified /etc/inittab to exclude /dev/ttyAMA0 and also /boot/cmdline.txt so the Pi is not writing boot up info out to /dev/ttyAMA0. And then rebooted.

This all worked fine. I have written a simple Arduino sketch to listen for incoming serial data and print it out. The problem I am getting is when I runthe following Python code:

Code: Select all

#! /usr/bin/python

import serial

serialport = serial.Serial("/dev/ttyAMA0", 9600, timeout=0.5);
serialport.write("LED\n\n");
I get "'ÿ¦ED" out at the Arduino end. My first thought is one of baud rate so I was wondering how can I configure the baud rate of /dev/ttyAMA0 ?

Thanks
Z

User avatar
TonyD
Posts: 450
Joined: Thu Sep 08, 2011 10:58 am
Location: Newcastle, UK
Contact: Website

Re: GPIO, UART, Python and an Arduino

Sun Nov 11, 2012 7:47 pm

Have you tried different baud rates on your Arduino, starting from 115,200 baud and working down to 9600?
Last edited by TonyD on Sun Nov 11, 2012 7:49 pm, edited 1 time in total.
Tony

BlackJack
Posts: 288
Joined: Sat Aug 04, 2012 8:28 am
Contact: Website

Re: GPIO, UART, Python and an Arduino

Sun Nov 11, 2012 7:48 pm

@zitman: That's the 9600 in your example.

Code: Select all

while not self.asleep():
    sheep += 1

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

Re: GPIO, UART, Python and an Arduino

Sun Nov 11, 2012 7:58 pm

To set baud rate

stty -F /dev/ttyAMA0 baudrate

To check settings

stty -F /dev/ttyAMA0

For help

man stty

cutmore32
Posts: 3
Joined: Thu Oct 18, 2012 8:36 pm

Re: GPIO, UART, Python and an Arduino

Tue Nov 13, 2012 8:41 pm

Looks like a synchronisation issue, perhaps..... As if it were wrong baud it might not be able to receive any of the characters.

I haven't tried communication with my Arduino yet, could be great excuse to start :)

zitman
Posts: 20
Joined: Wed Jul 18, 2012 11:02 am

Re: GPIO, UART, Python and an Arduino

Wed Nov 14, 2012 8:06 pm

Originally when I had the problems I s using an Arduino UNO and NewSoftSerial. I have how tried it again using an Arduino Mega 2560 (which has four hardware serial poets) and it works ok so a little more research into NewSoftSerial is required I think.

Thanks for your comments and will post any further info as I uncover it

Z

geurt
Posts: 5
Joined: Sun Dec 30, 2012 3:47 pm

Re: GPIO, UART, Python and an Arduino

Sun Dec 30, 2012 3:51 pm

I had the same problem, using a cheap 5v power supply most of my "packets" recieved bad. Try hooking up a 5 v battery power supply.

toxibunny
Posts: 1382
Joined: Thu Aug 18, 2011 9:21 pm

Re: GPIO, UART, Python and an Arduino

Sun Dec 30, 2012 11:40 pm

Make sure your pi and the arduino share a ground.
note: I may or may not know what I'm talking about...

Return to “Python”