-1

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

4
  • Your question lacks detail to answer, BUT those ports are connected to Bluetooth.
    – Milliways
    Sep 3, 2018 at 0:01
  • @Milliways Thank you for the feedback, what additional details should I include to help us troubleshoot the problem?
    – Nyxynyx
    Sep 3, 2018 at 14:59
  • You haven't told us WHAT YOU DID! Did you enable serial? What connections are used?
    – Milliways
    Sep 4, 2018 at 0:02
  • @Milliways I did not enable serial, but after enabling it (post updated), I now see /dev/serial0! However, writing to this returns an empty response. I connected the HAT headers to the Raspberry Pi Zero W's GPIO pins.
    – Nyxynyx
    Sep 5, 2018 at 4:45

3 Answers 3

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)
0

This is a board from a company called Waveshare. I just bought the same one. Here is the documentation I found about it https://www.waveshare.com/w/upload/4/4a/GSM_GPRS_GNSS_HAT_User_Manual_EN.pdf

I also spent quite some time trying to make it run. The solution is really simple though :) You have to use stable source of voltage, not the usb port from your laptop! And you have to connect the usb cable (with the voltage) to the hat, not to the Pi! Only then it will keep running. Otherwise it keeps shutting down, because of under voltage.

When you have two leds permanently ON, and another one blinking, then it's running. And will respond to your commands.

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.