adafruit / Adafruit_Wippersnapper_Arduino

WipperSnapper is a firmware for creating no-code IoT electronics projects.
https://io.adafruit.com/welcome
MIT License
29 stars 44 forks source link

Analog Input values are incredibly low on PICOW #609

Closed tyeth closed 1 month ago

tyeth commented 2 months ago

A user reported to IO Support that their values for a 2.25v source on any analog input pin on the pico was minimal / unexpectedly small (0.3v).

Testing locally I see a value between 2 and 1023 being detected, and then scaled incorrectly. It returns 0.00 to 0.05.

Changing these lines to include setting a native resolution and scaleAnalogRead here appears to fix the issue (now 2 represents 0.006v and 1023 = 3.287v): src/components/analogIO/Wippersnapper_AnalogIO.cpp#L84

I added to this if block along with a load of logging in branch https://github.com/adafruit/Adafruit_Wippersnapper_Arduino/tree/analogIO-scaling-picow:

#if defined(ARDUINO_ARCH_SAMD)
  analogReadResolution(16);
  _nativeResolution = 12;
#elif defined(ARDUINO_ARCH_ESP32)
  scaleAnalogRead = true;
  _nativeResolution = 13;
#elif defined(ARDUINO_ARCH_RP2040)
  scaleAnalogRead = true;
  _nativeResolution = 10;
#else
  scaleAnalogRead = true;
  _nativeResolution = 10;
#endif

Tagging @brentru who has more of a grasp on this.

Also worth of note is the possibly related older issue #403

tyeth commented 2 months ago

Added PR #610 to test the change

brentru commented 2 months ago

@tyeth another forum user is having issues with analog read on pico w - https://forums.adafruit.com/viewtopic.php?t=212531

tyeth commented 1 month ago

Closing this as appears to have been solved and released. Feel free to reopen or create a new issue if this still affects you