-
Notifications
You must be signed in to change notification settings - Fork 220
esp32/modesp.c: Added hall_sensor() function to esp module #211
Conversation
This functionality might find a better home in the ADC class as a special channel (eg the 8th channel), something like: import machine
hall = machine.ADC(8)
hall.read() |
Yeah, maybe. The hall sensor, and the low-noise-preamp (LNA) mode which
uses the SENS_VN and SENS_VP pins, are a special case not fully
supported by ESP-IDF just yet. I'm following up with Espressif ...
|
I added it to the esp module because hall sensor is esp specific functionality, similar to #192 ... |
Tried it, and it works. Might want to return a signed integer. With no magnet, I get 110-ish. With a small strong neodymium, I can get around 1500, but flipping the other way I got 4294965952, which works out to about -1500 w/ two's complement. |
Confirmed. According to Eric's comment, I changed the last line of the function to:
The base level here is is in the 30's, and the reading is quite noisy, and dose not change with the orientation of the board. Flipping an external magnet changes the sign. |
OK so there's something interesting about the Hall Effect Sensor:
there's a differential "Low Noise Amplifier" in the ESP32, switchable
onto the same pins as ADC0 and ADC3, which should allow much greater
accuracy in hall effect sensor readings. I think it'll likely allow
external differential input too (eg: for strain gauges and stuff).
There's some hardware registers documented which can switch the LNA on
and off and so on, but the details are pretty unclear.
But the hall_sensor_read function in the current ESP-IDF doesn't
currently use the LNA, and that feature is still in development at
Espressif. The current version is somewhat of a hack, reading ADC0 and
ADC3 separately and subtracting one from the other. The API is unlikely
to change much but the range and resolution may.
In short: this is a worthy addition, and the PR is appreciated but I
think it'd be wise to hold it here until the situation clarifies,
and we also need to think about the API for accessing the LNA for
other purposes.
|
( @hcharan and @robert-hh : Sorry for the delay, I'm continuing to follow this up with Espressif and hope we'll see a better |
@nickzoic Hi, any progress with a better hall_sensor_read()? Specifically with using LNA for the Hall sensor input? Eagerly waiting for it. |
Support for reading the hall sensor was added upstream as |
ADC1 needed to be configured for 12 bit output before calling the IDF's hall sensor function. It works, only issue might be ambiguity with machine module's ADC implementation.
Board - WEMOS Lolin32 V1.0.
It would be great if someone tests and reviews it.