NoriAbe
Posts: 12
Joined: Sat Sep 19, 2020 1:45 am

[solved]RasPi 4B GPIO serial communication

Sat Sep 19, 2020 12:04 pm

Hello, my name is NoriAbe from Japan. This is my first post.

I'm planning to get NMEA messages from a GNSS sensor, made by
ADVANCED NAVIGATION, via GPIO 15 (RxD). I use RasPi 4B, OS Rasbian Buster.

This GNSS sensor has 2 types of data output method.

(1)RS232
(2)GPIO

I already established the method to get NMEA messages via RS232, which let
me use USB-serial cable and use USB port on my RasPi. I can read the incoming
data by using the command show below.

> cat /dev/ttyUSB0

In this post I want to ask the method about above (2).

Currently I can see the behavior shown below on my RasPi.

1. current behavior
(1)can NOT see any text on /dev/ttyAMA0 by using the command below
 > cat /dev/ttyAMA0
I assume my RasPi starts GPIO communication with the /etc/rc.local
setting shown below.

(2)can see corrupted texts after starting GPIO communication using the
command below
 > sudo cu -s 9600 -l /dev/ttyAMA0

 I can see the corrupted texts shown below.
−−−−−
pi@raspberrypi:~ $ cu -s 9600 -l /dev/ttyAMA0
Connected.
[׵u����������������������������������[׵u����������������������������������[׵u����������������������������������[׵u����������������������������������[׵u����������������������������������[׵u�������������������������������w��[׵u�������������������������������y��[׵u����������������������������������~[׵u����������������������������������.
Disconnected.
−−−−−

(3)can see unexpected texts after running Python script
<Python script>
−−−−−
import serial
from time import sleep

ser = serial.Serial ("/dev/ttyAMA0", 9600) #Open port with baud rate

while True:
received_data = ser.read() #read serial port
sleep(0.03)
data_left = ser.inWaiting() #check for remaining byte
received_data += ser.read(data_left)

print (received_data) #print received data
−−−−−

<outputs>
−−−−−
pi@raspberrypi:~/Documents/Project/NGD01/Source $ python3 test.py
b'[\xd7\xb5u\xf5\x9d\x9f\x9f\x9f\x9b\x95\x9f\xa3\x9d\x93\x9d\xa7\x9d\x8d\xa7\x9f\x8d\xa7\x9b\x9f\x9b\x9f\xa7\x9f\x9f\xa7\x9f\x9f\xab\x95\x93\xe5\xeb\x00'
b'[\xd7\xb5u\xf5\x9d\x9f\x9f\x9f\x9b\x95\x9d\xa3\x9d\x93\x9d\xa7\x9d\x8d\xa7\x9f\x8d\xa7\x9b\x9f\x9b\x9f\xa7\x9f\x9f\xa7\x9f\x9f\xab\x95\x91\xe5\xeb\x00'
b'[\xd7\xb5u\xf5\x9d\x9f\x9f\x9f\x9b\x95\x9b\xa3\x9d\x93\x9d\xa7\x9d\x8d\xa7\x9f\x8d\xa7\x9b\x9f\x9b\x9f\xa7\x9f\x9f\xa7\x9f\x9f\xab\x95\x97\xe5\xeb\x00'
b'[\xd7\xb5u\xf5\x9d\x9f\x9f\x9f\x9b\x95\x99\xa3\x9d\x93\x9d\xa7\x9d\x8d\xa7\x9f\x8d\xa7\x9b\x9f\x9b\x9f\xa7\x9f\x9f\xa7\x9f\x9f\xab\x95\x95\xe5\xeb\x00'
−−−−−


I can show you my configurations, setting files.

2. setting files
(1)/etc/rc.local
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi

# Open /dev/ttyAMA0
stty -F /dev/ttyAMA0 9600

# Start GPS daemon
systemctl start gpsd
exit 0

(2)/boot/config.txt
[pi4]
# Enable DRM VC4 V3D driver on top of the dispmanx display stack
dtoverlay=vc4-fkms-v3d
max_framebuffers=2

# PPS signal for NTP synchronization
dtoverlay=pps-gpio,gpiopin=18

dtoverlay=pi3-disable-bt
enable_uart=1
dtoverlay=disable-bt

3. その他
(1)GNSS sensor outputs
GNSS sensor outputs may change. I'll ask GNSS sensor supplier by chance.

(2)disable serial console
I've already disabled Linux serial console following some information found
on web pages.

I'm new on RasPi GPIO serial communication. Please advise me!!
Last edited by NoriAbe on Mon Sep 21, 2020 3:33 am, edited 1 time in total.

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

Re: RasPi 4B GPIO serial communication

Sat Sep 19, 2020 2:34 pm

The default baud rate for GPS is 4800 (not 9600).

cleverca22
Posts: 1284
Joined: Sat Aug 18, 2012 2:33 pm

Re: RasPi 4B GPIO serial communication

Sat Sep 19, 2020 11:21 pm

/dev/ttyAMA0 is routed to the bluetooth by default

if you set enable_uart=1 only then you should be using /dev/ttyS0

if you set `dtoverlay=disable-bt` + `enable_uart=1` or `dtoverlay=miniuart-bt` + `enable_uart=1`, then ttyAMA0 gets routed to the gpio header

NoriAbe
Posts: 12
Joined: Sat Sep 19, 2020 1:45 am

Re: RasPi 4B GPIO serial communication

Sun Sep 20, 2020 4:50 am

Hi, joan and cleverca22! Thank you for your reply.
The default baud rate for GPS is 4800 (not 9600).
I tried the GNSS sensor to send NMEA messages at the rate of 4800 baud. (By the way,
I can change the transmission rate.) And I also tried several reception rate on my RasPi.
But the behavior was the same as before.
if you set enable_uart=1 only then you should be using /dev/ttyS0
if you set `dtoverlay=disable-bt` + `enable_uart=1` or `dtoverlay=miniuart-bt` + `enable_uart=1`, then ttyAMA0 gets routed to the gpio header
As I stated in my original post, I set "enable_uart=1" + "dtoverlay=disable-bt". So it means
ttyAMA0 shall correctly got routed to GPIO header. Am I right?

How about the order of those statements. Is it OK to state "enable_uart=1" first, then
"dtoverlay=disable-bt"?

Thank you,

NoriAbe
Posts: 12
Joined: Sat Sep 19, 2020 1:45 am

Re: RasPi 4B GPIO serial communication

Sun Sep 20, 2020 5:12 am

I'm wondering if GNSS sensor output signal is correctly shifted to RasPi GPIO signal.
Attached is the captured image of RasPi GPIO input. Originally GNSS sensor output
signal is around 5.5V high.
NGD01_200920_1.jpg
NGD01_200920_1.jpg (76.08 KiB) Viewed 497 times

High level is around 3.3V, should be OK. Low level is -1.05V. I'm not quite sure if it's
OK or not. I remember RasPi GPIO recognizes the voltage below 0.7V(?) as low. If
so -1.05V should be OK.

Vpp is too big?

If anything you realize, please let me know.

cleverca22
Posts: 1284
Joined: Sat Aug 18, 2012 2:33 pm

Re: RasPi 4B GPIO serial communication

Sun Sep 20, 2020 5:45 am

main problem i see in that image, is that it looks inverted
the serial line should idle at 3.3v when nothing is happening, but yours is idling at -1.05v!

User avatar
bensimmo
Posts: 4809
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: RasPi 4B GPIO serial communication

Sun Sep 20, 2020 6:50 am

Start from basics, with a fresh as card if you have another handy).

Use Raspi-config to disable the serial console and enable the serial port
and reboot. (in the interface serial section in rasp-config or desktop RPi setupings)

then use dev/serial0 as your serial port location.

cat /dev/serial0
should get the stream
is you have gpsd & gpsd tools installed, the try gpsmon too.


You don't normally need anything in rc.local (never seen anyone put anything in there).

you don't normally need to disable or switch BT.
Check your pin wires are the right way around
tx-rx and rx-tx .

It is usually dead easy.

NoriAbe
Posts: 12
Joined: Sat Sep 19, 2020 1:45 am

Re: RasPi 4B GPIO serial communication

Sun Sep 20, 2020 10:21 am

Hi, cleverca22 , thank you for your advice.
main problem i see in that image, is that it looks inverted
the serial line should idle at 3.3v when nothing is happening, but yours is idling at -1.05v!

Now I did it! I can get NMEA messages from GNSS sensor!! I really appreciate it.
NGD01_200920_2.jpg
NGD01_200920_2.jpg (99.84 KiB) Viewed 420 times

This is the GNSS sensor signal currently my RasPi receives. As you stated I inverted
original signal. The IC which inverted the signal also corrected the low level voltage
level. Now I can get almost 0V Vmin.

By the way how do I know idle level shall be 3.3v. If possible could you tell me what
document should I refer to.

Thank you,
Last edited by NoriAbe on Sun Sep 20, 2020 10:24 am, edited 1 time in total.

NoriAbe
Posts: 12
Joined: Sat Sep 19, 2020 1:45 am

Re: RasPi 4B GPIO serial communication

Sun Sep 20, 2020 10:23 am

Hi, bensimmo,

Thank you for your advice. I will double check my setting.

Thank you,

cleverca22
Posts: 1284
Joined: Sat Aug 18, 2012 2:33 pm

Re: RasPi 4B GPIO serial communication

Sun Sep 20, 2020 10:35 am

NoriAbe wrote:
Sun Sep 20, 2020 10:21 am
By the way how do I know idle level shall be 3.3v. If possible could you tell me what
document should I refer to.

Thank you,
the pi serial is always 3.3v, so it always idles at 3.3v and goes to 0v when sending 0 bits

other (non-pi) TTL serial stuff may idle at 5v instead, and go to 0v when sending 0 bits

the only real exception to the rule of $VCC & $GND is when your using rs232, that idles at anywhere from -3 to -15volts!!! and will swing up to anything from +3 to +15 volts when sending a 0, so its both inverted, way higher voltages, and never stays at 0v

more reading:
https://en.wikipedia.org/wiki/RS-232#Voltage_levels
https://www.fpga4fun.com/SerialInterface1.html

NoriAbe
Posts: 12
Joined: Sat Sep 19, 2020 1:45 am

Re: RasPi 4B GPIO serial communication

Sun Sep 20, 2020 10:18 pm

Hi, cleverca22.

Thanks!
Now my issue is closed. How can I close this post?

cleverca22
Posts: 1284
Joined: Sat Aug 18, 2012 2:33 pm

Re: RasPi 4B GPIO serial communication

Mon Sep 21, 2020 2:55 am

NoriAbe wrote:
Sun Sep 20, 2020 10:18 pm
Hi, cleverca22.

Thanks!
Now my issue is closed. How can I close this post?
just edit the 1st post in the thread and add [solved] to the title

emma1997
Posts: 972
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: RasPi 4B GPIO serial communication

Mon Sep 21, 2020 8:45 pm

joan wrote:
Sat Sep 19, 2020 2:34 pm
The default baud rate for GPS is 4800 (not 9600).
IME not correct for most modern low cost GPS modules. 9600 is the standard for the majority of off-the-shelf units like ubiquitous Globalsat Neo6 or Neo7 and their re-branded ilk.

Originally when Rockwell and Magellan reigned supreme the default was 2400. Then in the early days of integrated modules like Mediatek switched to 4800. However soon after they went to 9600 which has been GPS standard for decades now.

NoriAbe
Posts: 12
Joined: Sat Sep 19, 2020 1:45 am

Re: [solved]RasPi 4B GPIO serial communication

Tue Sep 22, 2020 2:50 am

Thanks! emma1997.

Return to “Device Tree”