dgordon42
Posts: 764
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: Pi 3 Serial Issues

Tue May 15, 2018 9:53 pm

@marciokoko,
Nice try, but no.

The Pi uses one of it's serial ports to communicate with the Bluetooth Controller chip. It sends and receives low level data and instructions to/from the chip. Unfortunately, you can't just fire data at the chip and expect it to communicate it to another device over Bluetooth.

It should be possible to establish a connection over Bluetooth to another device using the Linux Bluetooth software on the Pi, but it is something I have never done. Perhaps someone with Bluetooth knowledge (Douglas6?) might be able to show you how.

Dave.

User avatar
Douglas6
Posts: 4783
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Pi 3 Serial Issues

Tue May 15, 2018 10:08 pm

Dgordon42, thanks for all your help. I'm working with marciokoko in another thread.

anshumantech
Posts: 51
Joined: Fri Aug 05, 2016 5:20 am

Re: Pi 3 Serial Issues

Fri Sep 07, 2018 9:02 am

I am working on GPS module connected to Raspberry pi 3 via serial pins Tx, Rx with coding in Python 3.5.3 but i got following errors while i was trying to execute the code:
1. when i gave command as print (rcv.decode('ascii')) then i got error as “unicodedecodeerror:'ascii' codec can't decode the byte 0xff in position 0:ordinal not in range(128)” but when i gave command as print(rcv.decode('ascii','ignore')) then no error but it didn't print expected NMEA sentence data of GPS module.
2. if i removed the decode command then it gives the output in binary as given in doc file below.
I have attached pictures of errors and the code this code is working on Python 2.7 well but on python 3.5.3 it is not working. Please suggest any solution.
Attachments
2018-08-31-142254_640x480_scrot.png
2018-08-31-142254_640x480_scrot.png (79.19 KiB) Viewed 615 times
2018-09-06-134849_640x480_scrot.png
2018-09-06-134849_640x480_scrot.png (53.69 KiB) Viewed 617 times
2018-09-06-134847_640x480_scrot.png
2018-09-06-134847_640x480_scrot.png (35.87 KiB) Viewed 617 times

dgordon42
Posts: 764
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: Pi 3 Serial Issues

Fri Sep 07, 2018 1:17 pm

Python2 and Python3 handle ASCII and Unicode characters differently.
After the line:

Code: Select all

rcv = port.read(400)
in your code, add the line:

Code: Select all

rcv.encode('utf-8')
and see what happens.

Good Luck,
Dave.

anshumantech
Posts: 51
Joined: Fri Aug 05, 2016 5:20 am

Re: Pi 3 Serial Issues

Mon Sep 10, 2018 5:51 am

I have checked with the command rcv.decode('utf-8') after rcv = port.read() but it was giving error as "bytes object has no attribute as encode".

dgordon42
Posts: 764
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: Pi 3 Serial Issues

Mon Sep 10, 2018 10:26 am

anshumantech wrote:I have checked with the command rcv.decode('utf-8') after rcv = port.read() but it was giving error as "bytes object has no attribute as encode".
That is why I wanted you to try encode. Python2 will print bytes as ASCII characters, but Python3 will not. You need to encode the bytes into UTF-8 characters for Python3 to print them. That is what the "b'" characters in your output is trying to tell you, Python3's print function is not sure what to do with a byte, so it just prints "b". encode should change the bytes into UTF-8 characters so Python3 can print them.

Good Luck.
Dave.

Return to “General discussion”