Connect the GlobalSat BU-353 USB GPS to a Raspberry Pi


There isn't much to say in this post. Following the previous one here about connecting NMEA-0183 devices to a Raspberry Pi, you should plug in the BU-353 S4 USB GPS and get its USB address. Then, change the address in the following script to start receiving info. For my purposes, I only need the RMC sentence. I don't really care about any of the other ones.

As with my previous post with fault protection, if it doesn't receive an RMC sentence for 10 seconds, it starts printing out to the UDP port an XDR sentence saying it has failed an needs to be reset. How to reset it? Well, that would probably just involve turning off and on the whole Raspberry Pi. An example of that:

$IIXDR,GPS_FAIL,.3*4A

meaning it has failed for .3 minutes.
I won't be updating this pasted code here, so check the github page for the most recent script here.

The gps.py script:

 import sys  
 import serial  
 import math  
 import operator  
 import time  
 import socket  
   
 GPS_IP = "127.0.0.3"  
 GPS_PORT = 5005  
   
 t_gps = 0  
 t_fail = 0.0  
 t_print = time.time()  
   
 ser = serial.Serial('/dev/ttyUSB1', 4800, timeout=1)  
   
 while True:  
   
   hack = time.time()  
   
   gps_raw = ser.readline()  
   if "*" in gps_raw:  
     gps_split = gps_raw.split('*')  
     gps_sentence = gps_split[0].strip('$')  
     cs0 = gps_split[1][:-2]  
     cs1 = format(reduce(operator.xor,map(ord,gps_sentence),0),'X')  
     if len(cs1) == 1:  
       cs1 = "0" + cs1  
     if cs0 == cs1:  
   
       gps_vars = gps_sentence.split(',')  
       title = gps_vars[0]  
   
       if title == "GPRMC":  
         t_fail = 0.0  
         t_gps = hack  
         sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  
         sock.sendto(gps_raw, (GPS_IP, GPS_PORT))  
   
   if (hack - t_gps) > 10.0:  
     if (hack - t_print) > 1.0:  
       t_fail += 1.0  
       gps_sentence = "IIXDR,GPS_FAIL," + str(round(t_fail / 60, 1))  
       cs = format(reduce(operator.xor,map(ord,gps_sentence),0),'X')  
       if len(cs) == 1:  
         cs = "0" + cs  
       gps_sentence = "$" + gps_sentence + "*" + cs  
       sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  
       sock.sendto(gps_sentence, (GPS_IP, GPS_PORT))  
       t_gps = hack  
   

Comments

  1. This content is written very well. Your use of formatting when making your points makes your observations very clear and easy to understand. Thank you.
    USB名入れ

    ReplyDelete
    Replies
    1. Thanks! I think that's one of the shortcomings of most technical tutorials out there today.

      Delete
  2. Lightweight plane pilots utilize the logged sign to confirm their landing in turn focuses in rivalries. Minimal effort GPS recipients are regularly joined with PDAs, PDAs, auto PCs, or vehicle following frameworks.https://biobigdata.ucsd.edu/members/1939/blog/2016/09/garmin-camper-660lmt-the-latest-navigator-you-need-to-have

    ReplyDelete

Post a Comment

Popular Posts