2

I have a problem with using the UART on RPi2.

I tried every program found on the internet but nothing works. I checked every baud rate of my two BT modules but whatever code I use I've got errors like this:

Error 1:

Traceback (most recent call last):   File "Serial2.py", line 6, in
<module>
    serial_line = ser.readline()   File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 449, in
read
    buf = os.read(self.fd, size-len(read)) OSError: [Errno 11] Resource temporarily unavailable

Error 2:

Traceback (most recent call last):
  File "Serial2.py", line 6, in <module>
    serial_line = ser.readline()
  File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 449, in read
    buf = os.read(self.fd, size-len(read))
OSError: [Errno 11] Resource temporarily unavailable

Error 3:

Traceback (most recent call last):   File "Serial.py", line 7, in
<module>
    rcv = port.read()   File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 456, in
read
    raise SerialException('device reports readiness to read but returned no data (device disconnected?)')
serial.serialutil.SerialException: device reports readiness to read
but returned no data (device disconnected?)

Err1 code:

import serial

    port = serial.Serial("/dev/ttyAMA0", baudrate=115200, timeout=3.0)

    while True:
        port.write("\r\nSay something:")
        rcv = port.read()
        port.write("\r\nYou sent:" + rcv)

Err2&3 code:

import serial, time

ser = serial.Serial('/dev/ttyAMA0', 9600)

while 1:
    serial_line = ser.readline()

    print(serial_line)
    time.sleep(300)
ser.close()

I'm using ArduinoRC app (Terminal) to send data.

Would you help me and/or send a link to a good command list please ?

12
  • You want to communicate between a Raspberry Pi and an Arduino using serial data. You have a cable to connect the Pi and Arduino. To what do you connect the Pi end of the cable? To what do you connect the Arduino end of the cable?
    – joan
    Commented Jul 30, 2015 at 10:11
  • No! I want to communicate between smartphone>>>bluetooth>>>RPi using BT module on serial in RPi.
    – Nicolas
    Commented Jul 30, 2015 at 11:19
  • It's working with Arduino but not with BTM222 module.
    – Nicolas
    Commented Jul 30, 2015 at 11:24
  • And it stopped working with Ardu... :/
    – Nicolas
    Commented Jul 31, 2015 at 10:02
  • What do you think ? Is it a problem with RPi UART lanes ?
    – Nicolas
    Commented Jul 31, 2015 at 10:03

2 Answers 2

1

I also had a lot of problems with it... But today I found a solution from this site: http://m.instructables.com/id/Read-and-write-from-serial-port-with-Raspberry-Pi/

#!/usr/bin/env python

import time 
import serial 

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

while 1: 
    x=ser.readline() 
    print x

And the code worked, only you need to change the

/dev/ttyUSB0

To:

/dev/ttyAMA0

Like this (this is the code that worked):

EDIT: reformatted the code:

#!/usr/bin/env python

import serial
import time

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

while 1:
    x=ser.readline()
    print x

Ps: I used an HC-06 module, also be sure you have disabled the boot sequence on the serial port: open terminal, sudo raspi-config

And then go to advanced options and there will be something like boot on serial, you need to disable that.

Kind regards Michielvk

2
  • Can you reformat the code - there is some indentation missing which I think python will regard as significant and thus will not run properly without.
    – SlySven
    Commented Dec 27, 2015 at 22:49
  • I reformatted the code.
    – Michielvk
    Commented Dec 28, 2015 at 11:08
0

According to http://download.chip45.com/BTM222_DataSheet.pdf the factory settings of the UART are as follows

Baud rate: 19200 bps
Data bit: 8
Parity: none
Stop bit: 1
1
  • So what ? I programmed the same baudrate in my newest python script and BT module. With arduino everything is working (Ardu&Bluetooth, Pi&Arduino) but I can't force Pi to work with Bluetooth.
    – Nicolas
    Commented Jul 31, 2015 at 7:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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