Simple program for communicating with u-blox M8 series GNSS modules over I2C
Run this code on the target:
gcc i2c_stream.c -o i2c_stream
Many Raspberry Pi's, including the Raspberry Pi zero W, don't support clock stretching on their hardware I2C bus.
You can add the following to /boot/config.txt
activate a bit-banged I2C bus on GPIO pins 23 and 24 at /dev/i2c-3
[all]
dtoverlay=i2c-gpio,bus=3,i2c_gpio_sda=23,i2c_gpio_scl=24
u-blox pin | Raspberry Pi pin |
---|---|
3v3 | 3v3 |
GND | GND |
SDA | GPIO23 |
SCL | GPIO24 |
You can test your connection to the module with the following command:
$ ./i2c_stream
Usage: ./i2c_stream <bus> <addr> <poll_sleep_ms> <poll_error_sleep_ms>
$ ./i2c_stream /dev/i2c-3 42 100 1000
See __main__.py for a complete example
from ublox_m8_i2c import open_async
reader, writer = await open_async(
bus="/dev/i2c-3",
address=0x42,
)
await writer.write(b"Hello World!\n")
line = await reader.readline()
print(line)