fulvio
Posts: 17
Joined: Tue Sep 25, 2012 5:29 am

Sending serial packets from UART breakout board.

Sun Oct 21, 2012 10:49 pm

I purchased the following breakout board from ModMyPi:

https://www.modmypi.com/shop/slice-of-p ... akout-boad

I can't seem to be able to send serial packets to an Arduino using /dev/ttyAMA0 on this breakout (if that's even correct since there's no real documentation on how to actually send the packets. Prior I have used an Xbee module on /dev/ttyUSB0 and am able to send packets to an Arduino with an Xbee shield just fine from my Raspberry Pi) so I thought I'd use the following tutorial to free UART:

I just followed this tutorial to free UART on my Raspberry Pi:

http://learn.adafruit.com/adafruit-nfc- ... -on-the-pi

I made all these changes and after the reboot I'm getting the following
errors:

Code: Select all

VFS: Unable to mount root fs via NFS, trying floppy
VFS: Cannot open root device "(null)" or unknown-block(2,0)
Please append a correct "root=" boot option: here are the available
partitions:
Kernel panic - not syncinc: VFS: Unable to mount root fs on
unknown-block(2,0)
...
It sits there with these errors and doesn't display a login prompt.

These are the only changes I made to free UART:

From the command prompt enter the following command:

Code: Select all

$ sudo nano /boot/cmdline.txt
And changed:

Code: Select all

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200
console=tty1 $
to:

Code: Select all

dwc_otg.lpm_enable=0 console=tty1 $
Step Two: Edit /etc/inittab

From the command prompt enter the following command:

Code: Select all

$ sudo nano /etc/inittab
And changed:

Code: Select all

#Spawn a getty on Raspberry Pi serial line
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
to:

Code: Select all

#Spawn a getty on Raspberry Pi serial line
#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
Step Three: Reboot your Pi.

The problem is that now that I have this slice of pi breakout board and I'm not sure what TTY device to use.

This is the current python code I was using:

Code: Select all

import socket
import RPi.GPIO as GPIO
import wiringpi

device = "/dev/ttyUSB0"
message = "hello world"

serial = wiringpi.Serial(ttyDevice, 9600)
serial.puts(message)
I wasn't sure what device to set while using the Slice of Pi breakout instead.

Is it /dev/ttyAMA0?

According to this tutorial that's what they were using:

http://www.doctormonk.com/2012/06/raspb ... ensor.html

User avatar
BillyBag2
Posts: 32
Joined: Fri Jun 15, 2012 7:11 am
Contact: Website

Re: Sending serial packets from UART breakout board.

Sun Oct 21, 2012 11:24 pm

What you say you have done looks correct. If the other end is 5V you must add some level shifting drivers. I think you can add LEDs with resistors to the uart lines as though they were GPIOs. You should be able to se them flicker. The TX should just work and you can redirect stuff straight to the device on the command line. "ls > /dev/tty....". obviously an oscilloscope would be a lot better.

Actually another test come to mind where you loopback by just connecting the TX to the RX. not quite sure how to test this but you could search for it.
Pi N Chips - pinchips.blogspot.co.uk

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: Sending serial packets from UART breakout board.

Sun Oct 21, 2012 11:25 pm

Just to be sure, another way to read the instructions on editing the /boot/cmdline.txt, is:

remove:

Code: Select all

console=ttyAMA0,115200 kgdboc=ttyAMA0,115200
from the (full) line:

Code: Select all

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
So /boot/cmdline.txt now reads:

Code: Select all

dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
And in your python code, you're writing to /dev/ttyUSB0. That's when you have an Arduino or other USB to serial device plugged in a USB port. To send and receive serial data on the Raspberry Pi GPIO pins 14 and 15 using wiringPi for example, yes, that's /dev/ttyAMA0.

fulvio
Posts: 17
Joined: Tue Sep 25, 2012 5:29 am

Re: Sending serial packets from UART breakout board.

Sun Oct 21, 2012 11:36 pm

panik wrote:And in your python code, you're writing to /dev/ttyUSB0. That's when you have an Arduino or other USB to serial device plugged in a USB port. To send and receive serial data on the Raspberry Pi GPIO pins 14 and 15 using wiringPi for example, yes, that's /dev/ttyAMA0.
Yes, that was mentioning that the "current" code was using /dev/ttyUSB0 and I should've mentioned that changing it to /dev/ttyAMA0 didn't actually work, hence why I wanted to try to free UART using that tutorial, which resulted in getting those errors when rebooting.

Fantastic, thanks for the clarification on using /dev/ttyAMA0. So I won't be able to send serial packets from /dev/ttyAMA0 until I've freed up the UART successfully and rebooted?

I'll give those modifications a go and let you know whether it works. Thank you very much for your reply.

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: Sending serial packets from UART breakout board.

Sun Oct 21, 2012 11:42 pm

fulvio wrote:So I won't be able to send serial packets from /dev/ttyAMA0 until I've freed up the UART successfully and rebooted?
Correct. It's also sending kernel messages to the serial port. That'll interfere with what you're sending.

And I think your Raspberry Pi currently isn't booting, because it cant find the partition on the SD card. Be sure to keep everything in /boot/cmdline.txt on a single line.
Microcontroller addon boards and software for Raspberry Pi A+/B+/Pi2:
- ARMinARM: ARM Cortex-M3 (STM32)
- AVRPi: ATmega32U4 & ATmega328 ("Arduino")
http://www.onandoffables.com

fulvio
Posts: 17
Joined: Tue Sep 25, 2012 5:29 am

Re: Sending serial packets from UART breakout board.

Mon Oct 22, 2012 3:53 am

panik wrote:And I think your Raspberry Pi currently isn't booting, because it cant find the partition on the SD card. Be sure to keep everything in /boot/cmdline.txt on a single line.
Okay, those modifications to /boot/cmdline.txt seemed to work after a reboot!

I have written python and ruby code to send a serial packet to the Arduino. I can see the serial
response come through to the Arduino, however it's in strange characters:

Expected:

{power,tv}

Actual:

·Á½ÝÉtv}

Just to confirm, I am sending at 9600 and receiving at 9600 baud with 8N1.

The same code using the USB Breakout instead of the ModMyPi Breakout was sending and receiving with the same settings and coming through correctly.

I might give this a shot as a few people in the comments are talking about dropped or strange characters from Pi -> Arduino:

http://www.andremiller.net/content/rasp ... -gpio-uart

fulvio
Posts: 17
Joined: Tue Sep 25, 2012 5:29 am

Re: Sending serial packets from UART breakout board.

Mon Oct 22, 2012 10:37 pm

Okay, no luck with the strange character issues. I've tried all sorts of different baud rates (both slower and faster).

One thing I haven't tried is with a power supply - I've only tried with a USB connection to power the Pi. Could it be a power issue maybe?

philpoore
Posts: 6
Joined: Tue Feb 12, 2013 5:10 pm

Re: Sending serial packets from UART breakout board.

Tue Feb 12, 2013 9:58 pm

I'm having the same issue with weird chars being dumped from serial link...

"h,���e���l�" should be "hello"

did you have any luck sorting this out...??

Return to “General programming discussion”