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.
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
Jumpers on the HAT are set to short B
, similar to the photos but shorting the B
terminals instead.
/dev/serial0
! However, writing to this returns an empty response. I connected the HAT headers to the Raspberry Pi Zero W's GPIO pins.