Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/pcf8591 #814

Merged
merged 1 commit into from
Apr 24, 2022
Merged

Feature/pcf8591 #814

merged 1 commit into from
Apr 24, 2022

Conversation

gen2thomas
Copy link
Collaborator

@gen2thomas gen2thomas commented Mar 26, 2022

this PR will cover the issue #813

Adds in detail

  • possibility to use AnalogSensorDriver for scaling values to float64
  • add possibility to switch off polling with given 0s as polling intervall, although Start() is called
  • add generic TemperatureSensorDriver which supports nonlinear NTC, PT100, PTC and other linear sensors
  • adjust grove temperatur sensor to the generic one, add tests for correct scaling the NTC with B=3975, R25=10k, Rs=10k
  • introduce the AnalogWriter interface
  • introduce AnalogActuatorDriver which uses the new interface
  • add driver for PCF8591 to cover support for PCF8591 8-bit 4xADC 1xDAC i2c #813
  • add driver for YL-40 module which contains the PCF8591, temperature sensor (B=3950, R25=10k, Rs=1k, invers), brightness sensor, potentiometer, free analog input, one analog output, use all previously added features
  • examples for PCF8591 and YL-40 module provided
  • most features practically tested with tinkerboard

Notes for NTC scaling

  • the scaling can be done by T0, R0, B or also by T0, R0, T1, R1 --> B will be calculated at initialization
  • thermistor is typically connected with an series resistor between reference voltage and ground, both directions are supported (normal, inverse)
  • all NTC test expectations were calculated by an LibreOffice table

Notes for the PCF8591 chip and the driver

The IC PCF8591 only supports 100 kHz (basic 100 kbit/s mode), see section 14.4 Dynamic characteristics at page 20 of NXP specification. Running the PCF8591 in 400 kbit fast mode, which seems to be the default of most platforms now, leads to some instability (tested with 5 devices at ~370 kbit/s on tinkerboard):

  1. the control byte is not recognized on first write (on 4 devices, ~30% of calls)
  2. the read value is to small when immediately read after write (all devices, 100% of calls)
  3. the read value is still the old one after more than one reads (all devices, ~99% of calls)
  4. the read value is still the old one after more than two reads (4 devices, ~50% of calls)

strategies to overcome problems with 400 kbit:
for 1.: do "full double reading" (write control register and read, done in most other drivers) fix the problem for 3 tested devices, ~95% good calls
for 3,4.: multiple write don't stabilize this enough (only reduce to ~75%), multiple reading to an buffer and after some relaxation a single read is quite sufficient to reduce it to 5% wrong reads (for one device the problem is gone completely)
for 2.: for long conversion time, write also don't do anything for stabilization, it will be covered by the strategy above

driver:

  • all modes are supported (single, 2-/3- differential, mixed) - most other drivers (python, cpp) don't do that
  • auto increment is not supported yet
  • 400 kbit stabilizing strategies are part of the driver (default is 2x write, 3x buffered read, wait, 1x read)

Notes for YL-40 module driver

Because the supply voltage of i2c bus on tinkerboard seems to be 3.3V and both LED's are shining very bright, I would suggest to not run this board with 5V. Therefor some scaler are prepared for 3.3V as default. This can be changed by a with-function to each scaler function you want.

@gen2thomas gen2thomas marked this pull request as draft March 29, 2022 17:56
@gen2thomas gen2thomas force-pushed the feature/pcf8591 branch 2 times, most recently from ced9f4a to 0480720 Compare April 3, 2022 15:35
@gen2thomas gen2thomas marked this pull request as ready for review April 3, 2022 16:19
@gen2thomas gen2thomas marked this pull request as draft April 8, 2022 09:15
@gen2thomas gen2thomas marked this pull request as ready for review April 8, 2022 17:45
…91 (with 400kbit stabilization), driver for YL-40
@deadprogram
Copy link
Member

Another massive PR, you have me in awe @gen2thomas

Merging 🎆

@deadprogram deadprogram merged commit 3b3ad4d into hybridgroup:dev Apr 24, 2022
@gen2thomas gen2thomas deleted the feature/pcf8591 branch April 24, 2022 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants