0

I have attached a GPS HAT to a Raspberry Pi Zero W running RASPBIAN STRETCH WITH DESKTOP. When I SSH in to run a simple Python script that writes to the HAT serial port, nothing happens and I am not returned back to the bash shell until I hit Ctrl + c.

Tried the following ports but they all gave the same behavoir

  • /dev/serial1
  • /dev/ttyAMA0

Did I get the serial port wrong? If not, what may be the problem?

I still require the Raspberry Pi's Bluetooth function to work along with the GPS HAT.

Thank you!

app.py

import serial
import RPi.GPIO as GPIO    

GPIO.setmode(GPIO.BOARD)   
port = serial.Serial("/dev/serial1", baudrate=115200, timeout=1)

port.write('AT'+'\r\n')            
rcv = port.read(100)
print rcv
time.sleep(.1)

Output of ls /dev

autofs           fd         loop1             mmcblk0             ram0   ram5     stderr  tty15  tty25  tty35  tty45  tty55  tty8       vcs1   vcsa4
block            full       loop2             mmcblk0p1           ram1   ram6     stdin   tty16  tty26  tty36  tty46  tty56  tty9       vcs2   vcsa5
btrfs-control    fuse       loop3             mmcblk0p2           ram10  ram7     stdout  tty17  tty27  tty37  tty47  tty57  ttyAMA0    vcs3   vcsa6
bus              gpiochip0  loop4             mqueue              ram11  ram8     tty     tty18  tty28  tty38  tty48  tty58  ttyprintk  vcs4   vcsa7
cachefiles       gpiomem    loop5             net                 ram12  ram9     tty0    tty19  tty29  tty39  tty49  tty59  uhid       vcs5   vcsm
char             hwrng      loop6             network_latency     ram13  random   tty1    tty2   tty3   tty4   tty5   tty6   uinput     vcs6   vhci
console          initctl    loop7             network_throughput  ram14  raw      tty10   tty20  tty30  tty40  tty50  tty60  urandom    vcs7   watchdog
cpu_dma_latency  input      loop-control      null                ram15  rfkill   tty11   tty21  tty31  tty41  tty51  tty61  vchiq      vcsa   watchdog0
cuse             kmsg       mapper            ppp                 ram2   serial1  tty12   tty22  tty32  tty42  tty52  tty62  vcio       vcsa1  zero
disk             log        mem               ptmx                ram3   shm      tty13   tty23  tty33  tty43  tty53  tty63  vc-mem     vcsa2
fb0              loop0      memory_bandwidth  pts                 ram4   snd      tty14   tty24  tty34  tty44  tty54  tty7   vcs        vcsa3

Update

Connections: Raspberry Pi Zero W is connected to a mini usb cable for power, and connected to the GPS HAT through the GPIO headers.

Enabled serial port by setting enable_uart=1 in /boot/config.txt then rebooting. ls /dev now shows serial0 and ttys0.

autofs           fd         loop1             mmcblk0             ram0   ram5     snd     tty14  tty24  tty34  tty44  tty54  tty7       vc-mem  vcsa2
block            full       loop2             mmcblk0p1           ram1   ram6     stderr  tty15  tty25  tty35  tty45  tty55  tty8       vcs     vcsa3
btrfs-control    fuse       loop3             mmcblk0p2           ram10  ram7     stdin   tty16  tty26  tty36  tty46  tty56  tty9       vcs1    vcsa4
bus              gpiochip0  loop4             mqueue              ram11  ram8     stdout  tty17  tty27  tty37  tty47  tty57  ttyAMA0    vcs2    vcsa5
cachefiles       gpiomem    loop5             net                 ram12  ram9     tty     tty18  tty28  tty38  tty48  tty58  ttyprintk  vcs3    vcsa6
char             hwrng      loop6             network_latency     ram13  random   tty0    tty19  tty29  tty39  tty49  tty59  ttyS0      vcs4    vcsa7
console          initctl    loop7             network_throughput  ram14  raw      tty1    tty2   tty3   tty4   tty5   tty6   uhid       vcs5    vcsm
cpu_dma_latency  input      loop-control      null                ram15  rfkill   tty10   tty20  tty30  tty40  tty50  tty60  uinput     vcs6    vhci
cuse             kmsg       mapper            ppp                 ram2   serial0  tty11   tty21  tty31  tty41  tty51  tty61  urandom    vcs7    watchdog
disk             log        mem               ptmx                ram3   serial1  tty12   tty22  tty32  tty42  tty52  tty62  vchiq      vcsa    watchdog0
fb0              loop0      memory_bandwidth  pts                 ram4   shm      tty13   tty23  tty33  tty43  tty53  tty63  vcio       vcsa1   zero

When using /dev/serial0 in my Python script, it now returns a empty `` response. Why is it not returning OK? Is this still the wrong port?

Sending AT using minicom -D /dev/serial0 also gave no OK response, just an empty response.

enter image description here

Also tried the following commands based on Jan Hus suggestion,

stty -F /dev/serial0 raw 9600 cs8 clocal -stop
cat /dev/serial0

and also a buad rate of 115200 like in the Python script and minicom

stty -F /dev/serial0 raw 115200 cs8 clocal -cstopb
cat /dev/serial0

but it returned nothing

enter image description here

Jumpers on the HAT are set to short B, similar to the photos but shorting the B terminals instead.

enter image description here

  • Which HAT exactly? If possible provide a link to some documentation. Please update your question with these details – Dirk Sep 2 '18 at 0:13
  • @Dirk Thank you, just updated question with the link to the HAT amazon.com/gp/product/B076CPX4NN/… – Nyxynyx Sep 2 '18 at 5:26
  • Your question lacks detail to answer, BUT those ports are connected to Bluetooth. – Milliways Sep 3 '18 at 0:01
  • @Milliways Thank you for the feedback, what additional details should I include to help us troubleshoot the problem? – Nyxynyx Sep 3 '18 at 14:59
  • You haven't told us WHAT YOU DID! Did you enable serial? What connections are used? – Milliways Sep 4 '18 at 0:02
0

Double check your serial configuration ( raspi-config) first and check if you indeed have correct wiring to selected port.

Then try some of the basic tests to make sure you are communicating with GPS.

https://learn.adafruit.com/adafruit-ultimate-gps-hat-for-raspberry-pi/basic-test

I do not do python - but in general you have to have some delay or monitoring before the replay comes back or is valid.

0

From Pi zero under Linux Raspbian in Phyton programming :

import serial, time 

com = serial.Serial( port='/devttyAMA0',baudrate=115200, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=1) 

com.open 

Then send command ("AT\r") response must be OK.

If not verify connection :

  • TX modem to RX terminal
  • RX modem to TX terminal
  • Ground to ground.
  • insert : time.sleep(0.2) before reading the port (import time)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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