Hi everyone, sorry to start like this,::::ai fixed a bug for me!! - So my intention is to help another ai save yours or you save yours. however - I wanted to write it in git directly, but since the project is archived, I could not create an issue. So now have fun reading a good structured and readable text (not from me, but I read it):
Hi everyone,
If you are using the Pimoroni Skywriter (either the full-sized Skywriter Breakout or the Skywriter HAT) on modern Raspberry Pi OS (Bookworm / Trixie / Kernel 6.x with Python 3.11 - 3.13) and find that:
- i2cdetect -y 1 successfully detects the sensor on address 0x42
- But in Python (skywriter package v0.0.8), no gestures, moves, or touches are ever received
…it is NOT your wiring or a broken sensor. The official Python library (skywriter-0.0.8) suffers from three critical bugs on modern systems:
Bug 1: Worker thread dies immediately (falsy check on todo())
In AsyncWorker.run() in skywriter/init.py:
while not self.stop_event.is_set():
if not self.todo():
self.stop_event.set()
break
Because the polling function _do_poll() returns None on idle cycles, Python evaluates “not None” as True. The thread sets its stop event and terminates on the very first tick (after ~1 millisecond)!
Fix: Change to “if self.todo() is False:”.
Bug 2: Commented-out packet headers break byte alignment
In _do_poll():
# d_size = data.pop(0)
# d_flags = data.pop(0)
# d_seq = data.pop(0)
d_ident = data.pop(0)
On modern Linux kernels and SMBus implementations, read_i2c_block_data(0x42, 0x00, 26) returns the complete 26-byte frame starting at offset 0 (size, flags, seq, and then ident at index 3).
Because the first three pops were commented out, d_ident receives 0x1a (the packet size), meaning the condition “if d_ident == 0x91:” is NEVER met and all sensor data is discarded.
Fix: Uncomment d_size, d_flags, d_seq. Also uncomment “d_timestamp = data.pop(0)” inside _handle_sensor_data().
Bug 3: Disabled Auto-Calibration leads to ADC Clipping
In setup():
“_enable_auto_calibration = False” is set by default, causing runtime parameter 0x80 to be sent, disabling the MGC3130’s internal background calibration.
As a result, Bit 5 in SystemInfo (“Clipping”) remains permanently active, and the analog front-end saturates.
Fix: Change the default to “_enable_auto_calibration = True”.
Quick Patch / Diff
Apply this patch to /usr/local/lib/python3.x/dist-packages/skywriter/init.py:
-– skywriter/init.py
+++ skywriter/init.py
@@ -52,1 +52,1 @@
-_enable_auto_calibration = False
+_enable_auto_calibration = True
@@ -134,2 +134,2 @@
-
if not self.todo(): -
if self.todo() is False: self.stop_event.set() break
@@ -142,1 +142,1 @@
-
d_timestamp = data.pop(0) # 200hz, 8-bit counter, max ~1.25sec
-
d_timestamp = data.pop(0) # 200hz, 8-bit counter, max ~1.25sec
@@ -324,3 +324,3 @@ -
# d_size = data.pop(0) -
# d_flags = data.pop(0) -
# d_seq = data.pop(0) -
d_size = data.pop(0) -
d_flags = data.pop(0) -
d_seq = data.pop(0)
Hardware Tip for the Breakout version:
If you are using the standalone Breakout (with loose wires), connect VCC to Pin 2 or 4 (5V), not Pin 1 (3.3V). The breakout board contains an onboard 3.3V LDO regulator and level shifters (VCC: 3.3 - 5V). When powering with 3.3V through longer cables, voltage drop across the wire and LDO drops internal voltage below 3.0V, leaving the MGC3130 charge pump underpowered. Supplying 5V solves this completely.
Hope this saves others many hours of debugging!