3

I am trying to send and receive radio signals using my Raspberry, but I am already stuck at the first step :)

My Radio module uses UART for communication but I have failed to set up my serial communication correctly. I found out Bluetooth is somehow interfering, so I disabled it. Now my program is at least able to step over read and write functions of my python script. Jippie :)

To test if UART works I connected Pin 14 and 15 (RX and TX) with each other and would now expect that when I send something, I will receive the same string?!? That should be right, shouldn't it? But on the receiving end I never get something... readline() return with no string.

I would be very very thankful if somebody could shed some light for me :) Or even a hint to a working tutorial. I already followed that tutorial: http://www.briandorey.com/post/Raspberry-Pi-3-UART-Boot-Overlay-Part-Two but it didn't get me much further... :(

Btw.: I am using Raspbian Version May 2016 (2016-05-10).

Here's my sample code:

#!/usr/bin/env python
import serial

ser = serial.Serial(
  port='/dev/ttyAMA0',
  baudrate = 9600,
  parity=serial.PARITY_NONE,
  stopbits=serial.STOPBITS_ONE,
  bytesize=serial.EIGHTBITS,
  timeout=1
)

print "Serial is open: " + str(ser.isOpen())

print "Now Writing"
ser.write("This is a test")

print "Did write, now read"
x = ser.readline()
print "got '" + x + "'"

ser.close()
Georg
  • 193
  • 1
  • 3
  • 7

5 Answers5

2

port='/dev/ttyAMA0'

I believe the default device node on the Pi 3 is different. Try:

port='/dev/ttyS0'


You may also need to disable the serial console. The easiest way to do this is via raspi-config under Advanced Options -> Enable/Disable shell and kernel messages on the serial connection.

If you don't have raspi-config, it doesn't work, and/or you want to double check, first look in /boot/cmdline.txt. If you see:

 console=/dev/ttyS0,115200 

Or:

 console=/dev/serial0,115200 

Or anything involving console= that isn't console=tty1, remove it. Make sure not to accidentally add a line break to that file, it should remain all one line with spaces between the options, but no spaces around any =.

The other aspect is the login started by the init system. On Raspbian jessie, check:

ls /etc/systemd/system/getty.target.wants

If you see that serial device node (ttyS0) mentioned, disable this service:

systemctl disable serial-getty@ttyS0.service

You will have to reboot for these things to take effect.

goldilocks
  • 60,325
  • 17
  • 117
  • 234
1

If you're using Raspberry Pi desktop you have to enable Serial in its configuration I think...

  1. Click on the small RPi icon on upper left
  2. Click on preferences
  3. Then click on Rasp. Config
  4. Go to Interface
  5. Enable Serial
Jacobm001
  • 11,904
  • 7
  • 47
  • 58
Azrideus
  • 11
  • 1
0

/dev/ttyAMA0 is now used for Bluetooth, and the default has problems with varying clock rates. See How-do-i-make-serial-work-on-the-raspberry-pi3

NOTE This was done on previous version of Raspbian, as I haven't had a chance to test the latest but should still apply.

Milliways
  • 62,573
  • 32
  • 113
  • 225
0

I had the same problem on my RPi3 (Jessie after 18th March 2016 release) and solved it by changing enable_uart=0 to enable_uart=1 and adding dtoverlay=pi3-miniuart-bt (disable the bluetooth on the UART) at the end of /boot/config.txt. I use pin 8 and 10 (TX and RX).

0

I don't know how Raspbian Python handles the serial timeout, but if I were coding it, I would still start out putting a delay of at least a couple of milliseconds between the transmit code and the receive code (I'd start with 5 ms). Your receiver can't flag the first received byte until the data has shifted 10 bits completely out of the transmitter and into the receiver. That is a delay of approximately 1 millisecond. Once that works, you can back out the delay to see how the timeout handles it. Of course, this may not be related to the real problem, but it removes one unknown.

Aurora0001
  • 6,357
  • 3
  • 25
  • 39