[*] Bibliotheken: adafruit-blinka , busio , adaFruit-ssd1306
Schritte ausgeführt (mit Befehls- und Code-Snippets)
[*] Verifiziert i2c-Gerät wurde festgestellt. 0x3c , nicht der Standardbus 1 .Code: Select all
thalia@SKI:~/smartgoogles $ sudo i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- --
...
70: -- -- -- -- -- -- -- --
thalia@SKI:~/smartgoogles $ sudo i2cdetect -y 13
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: 08 09 0a 0b 0c 0d 0e 0f
...
30: 30 -- -- -- -- -- -- 37 38 39 3a 3b 3c 3d 3e 3f
...
70: 70 71 72 73 74 75 76 77
Code: Select all
thalia@SKI:~/smartgoogles $ sudo BLINKA_I2C=13 python3 gpsdisplaytest.py
Traceback (most recent call last):
File "/usr/local/lib/python3.11/dist-packages/adafruit_bus_device/i2c_device.py", line 168, in __probe_for_device
self.i2c.writeto(self.device_address, b"")
...
ValueError: No I2C device at address: 0x3c
Code: Select all
import time
import Adafruit_PureIO.smbus as smbus
import adafruit_ssd1306
import gps
import os
# Define the OLED screen parameters
WIDTH = 128
HEIGHT = 64
# Simple I2C class that wraps smbus to be compatible with adafruit_ssd1306.
class I2C(object):
def __init__(self, bus):
self.bus = smbus.SMBus(bus)
def writeto(self, address, buffer, *, start=True, stop=True, **kwargs):
self.bus.write_bytes(address, buffer)
def readfrom_into(self, address, buffer, *, start=True, stop=True, **kwargs):
read_data = self.bus.read_bytes(address, len(buffer))
for i, byte in enumerate(read_data):
buffer[i] = byte
def try_lock(self):
return True
def unlock(self):
pass
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
pass
# The i2cdetect command showed the device is on bus 13.
i2c = I2C(13)
oled = adafruit_ssd1306.SSD1306_I2C(WIDTH, HEIGHT, i2c, addr=0x3c)
# Clear the OLED display initially
oled.fill(0)
oled.show()
# Connect to the gpsd daemon
session = gps.gps(mode=gps.WATCH_ENABLE)
def display_message(message):
oled.fill(0)
oled.text(message, 0, 0, 1)
oled.show()
def get_gps_data():
display_message("Waiting for GPS...")
for report in session:
if report['class'] == 'TPV':
if report.mode >= 2:
latitude = report.lat if 'lat' in report else "n/a"
longitude = report.lon if 'lon' in report else "n/a"
altitude = report.alt if 'alt' in report else "n/a"
oled.fill(0)
oled.text("Lat: {:.4f}".format(latitude), 0, 0, 1)
oled.text("Lon: {:.4f}".format(longitude), 0, 16, 1)
oled.text("Alt: {}m".format(altitude), 0, 32, 1)
oled.show()
else:
display_message("Waiting for GPS...")
if __name__ == '__main__':
try:
get_gps_data()
except KeyboardInterrupt:
print("\nExiting script.")
finally:
oled.fill(0)
oled.show()
session.close()