AyoubDimitri Kokkonis
Published

Using GNSS of Sony Spresense in Simple Python with Zerynth

This project shows you how to take advantage of GNSS connectivity of Sony Spresense board with Zerynth.

IntermediateProtip960
Using GNSS of Sony Spresense in Simple Python with Zerynth

Things used in this project

Hardware components

Spresense boards (main & extension)
Sony Spresense boards (main & extension)
×1

Software apps and online services

Zerynth Studio
Zerynth Studio
Jupyter Notebook
Jupyter Notebook

Story

Read more

Code

gnss_1.py

Python
import gc
import streams
from sony.cxd5602gnss import gnss

# dictionary to convert from satellite type to string
sattype2string = {
gnss.SAT_GPS: "GPS",
gnss.SAT_GLONASS: "GLONASS",
gnss.SAT_SBAS: "SBAS",
gnss.SAT_QZ_L1CA: "QZ_L1CA",
gnss.SAT_IMES: "IMES",
gnss.SAT_QZ_L1S: "QZ_L1S",
gnss.SAT_BEIDOU: "BEIDOU",
gnss.SAT_GALILEO: "GALILEO"
}

streams.serial()

print("> GNSS init")

gnss.init()

while True:
gnss.wait()
# filter data to keep only position, datetime and satellites' info
data = gnss.read(read_filter=(gnss.FILTER_RECEIVER_POSITION | gnss.FILTER_RECEIVER_DATETIME | gnss.FILTER_SATS_DATA))

if data.receiver.position.pos_dataexist:
print("> POSITION:")
print(">> latitude:", data.receiver.position.latitude)
print(">> longitude:", data.receiver.position.longitude)
print(">> altitude:", data.receiver.position.altitude)
else:
print("> POSITION not available")
    print("> DATETIME:")
    print(">> date.year:", data.receiver.datetime.date.year)
    print(">> date.month:", data.receiver.datetime.date.month)
    print(">> date.day:", data.receiver.datetime.date.day)
    print(">> time.hour:", data.receiver.datetime.time.hour)
    print(">> time.minute:", data.receiver.datetime.time.minute)
    print(">> time.sec:", data.receiver.datetime.time.sec)
    print(">> time.usec:", data.receiver.datetime.time.usec)

if data.sats:
# at least one satellite available
print("> SATS:")
for sat_i, sat in enumerate(data.sats):
print(">> sat[%i].type:" % sat_i, sattype2string[sat.type])
print(">> sat[%i].siglevel:" % sat_i, sat.siglevel)

gnss_2.py

Python
import streams
import json
from sony.cxd5602gnss import gnss

sattype2string = {
gnss.SAT_GPS: "GPS",
gnss.SAT_GLONASS: "GLONASS",
gnss.SAT_SBAS: "SBAS",
gnss.SAT_QZ_L1CA: "QZ_L1CA",
gnss.SAT_IMES: "IMES",
gnss.SAT_QZ_L1S: "QZ_L1S",
gnss.SAT_BEIDOU: "BEIDOU",
gnss.SAT_GALILEO: "GALILEO"
}

data_ch = streams.serial(SERIAL0)

gnss.init()

while True:
gnss.wait()
gnss_data = gnss.read(read_filter=(gnss.FILTER_TIMESTAMP | gnss.FILTER_RECEIVER_POSITION_PRECISION |
gnss.FILTER_RECEIVER_DATETIME | gnss.FILTER_SATS_DATA | gnss.FILTER_RECEIVER_SATS))
data = {}
if gnss_data.sats:
data['sats'] = {}
for sat in gnss_data.sats:
#print("> sat type:", sat.type)
sat_string = sattype2string[sat.type]
if sat_string in data['sats']:
data['sats'][sat_string] += 1
else:
data['sats'][sat_string] = 1

 if gnss_data.receiver.position.pos_dataexist:
data['lat'] = gnss_data.receiver.position.latitude
data['lon'] = gnss_data.receiver.position.longitude

 data_ch.write(json.dumps(data))
data_ch.write("\n")

jupyter_gnss.py

Python
import json
from serial import Serial
from IPython.display import clear_output

spresense_ch = Serial("/dev/tty.SLAB_USBtoUART", 115200)

while True:
gnss_data = json.loads(spresense_ch.readline())
clear_output(wait=True)

if 'sats' in gnss_data:
print("\n> Visible satellites")
for sat_type, sat_num in gnss_data['sats'].items():
print("> %s: %i" % (sat_type, sat_num))

if 'lat' in gnss_data:
spresense_position_mark = gmaps.Marker((gnss_data['lat'], gnss_data['lon']), info_box_content='Zerynth Spresense')
map_drawing.features = [spresense_position_mark]

Credits

Ayoub

Ayoub

5 projects • 5 followers
Embedded Software Engineer
Dimitri Kokkonis

Dimitri Kokkonis

5 projects • 5 followers
EE/CS student majoring in Embedded Systems at Polytech Sorbonne, Paris.

Comments