stocyr / SourdoughMonitor

Sourdough monitoring system with an ESP32 devboard, a ToF distance sensor, temperature sensors and an eInk display.
Other
5 stars 0 forks source link

Issues with TMF8821 #1

Closed mplnck closed 8 months ago

mplnck commented 1 year ago

Hello,

I've got some issues with the TMF8821. In the main project I get the message cannot read from TMF8821 and with the serial debugging, I won't get a suitable answer. When I want to calibrate the sensor, I comment line 47 and uncomment line 45. The code just runs smooth until we get to line 75. There I got the following error: Zurückverfolgung (jüngste Aufforderung zuletzt): Datei "code.py", Zeile 78, in Datei "lib/tmf8821/adafruit_tmf8821.py", Zeile 533, in load_factory_calibration AssertionError: Calibration size doesn't match 0xBC

I tried to fill the 3x3_normal_mode_short with all different kinds of options but unsuccessfully. May you provide a sample calibration file to recheck?

BR Mario

stocyr commented 1 year ago

Hi Mario

L48 prints the configuration data in hexadecimal string format. I used some not checked-in code in the running interpreter to convert this format to a pure binary encoding. I then use this pure binary encoding to write to the configuration file and read from there (for maximum storage size efficiency).

stocyr commented 1 year ago

Here is my calibration file: 3x3_normal_mode_short.zip

The reason code4.py doesn't write the calibration file to storage is that during running of this file, the CIRCUITPYTHON drive is in read-only mode, so copying from the console print-out and later manually storing to the drive is the workaround I chose. The following code will convert the hex display print-out to a byte array and store it to a file D:\3x3_normal_mode_short:

# your string looks like this: calibration_data = "0x0 0x1 0x1 0x0 0x1 0xff 0x51 0xf..."
byte_array = bytes(int(b, base=16) for b in calibration_data.split(' '))
with open(Path('D:\3x3_normal_mode_short'), 'wb') as f:
    f.write(byte_array)
mplnck commented 8 months ago

This worked well!