Closed pacmac closed 7 years ago
Use: machine.ADC(machine.Pin('GP36')).
Thanks but that results in:
machine.Pin('GP36')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't convert str to int
machine.ADC(machine.Pin('GP36')) gives the same error ?!
Sorry, you'll need to use integers for pins, eg: machine.Pin(36).
Thanks, that works:
import machine
adc = machine.ADC(machine.Pin(36))
print(adc.read())
>> 4095
Another question on same topic, is it possible to internally read the VCC on the ESP32 as it is with the ESP8266 ??
I can't see anything mentioned about this in the esp-idf docs ($ESP_IDF/docs/api/peripherals/adc.rst) ... although there's an internal Hall Effect sensor which is pretty weird (and not yet supported by MicroPython).
The ADC input pins have a range of 0-1 volt so you'd need to add a voltage divider between VCC (or V_BATT) and an ADC pin and sample it that way.
Thanks, I just checked the datasheet and could not see it mentioned, but I am sure I read it somewhere on a forum, pretty sure it was an arduino forum.
Interesting thing I just noticed in the datasheet is there is an internal temperature sensor, it would be nice to be able to access that.
esp8266 had a VCC option on the ADC but I dunno, it wasn't all that useful unless you had Vcc == Vbatt. The docs do say:
ESP32 integrates two 12-bit SAR ("Successive Approximation Register") ADCs [...] The ADC driver API currently only supports ADC1 (9 channels, attached to GPIOs 32-39).
So it is possible that the alleged ADC2 might have some such connection but there's no mention of it in the esp-idf docs at this point.
Hi, what about adding ADC2 support? Arduino libs seem to have implemented ADC2 support: https://www.esp32.com/viewtopic.php?t=955
Hi, what about adding ADC2 support?
It's currently not recommended to expose ADC2 to the user because it's used for low-level control of the wifi and BT, see: https://github.com/espressif/esp-idf/issues/461
ESP32 has an internal Temperature sensor, How it can be read?
There was a PR for that here: https://github.com/micropython/micropython-esp32/pull/192/files
with some discussions, whether it is useful or not.
Edit 1:
See also this link on reading the internal temp sensor directly: https://github.com/espressif/esp-idf/blob/master/components/esp32/test/test_tsens.c
You replace the print statement by a line returning res as a MP object, like:
return mp_obj_new_int(res);
This code is also used by the pycom variant. The value returned is probably °F.
Edit 2:
Whether it's useful or not is to be discussed. It returns the internal temp of the ESP32, which is only to al little extend related to the ambient temperature, and due to the low power dissipation the device is not subject to overheat.
Thank you
ESP-IDF offers atten() function to change the voltage range measurable. 11dB makes 0 to 3.3V possible. Is that going to be built into Micropython?
I think it should already be there, something like:
adc = machine.ADC(machine.Pin(35)) adc.atten(machine.ADC_ATTN_11DB)
Awesome! Thank you.
Christian
On Feb 18, 2018 8:35 PM, "Nick Moore" notifications@github.com wrote:
I think it should already be there, something like:
adc = machine.ADC(machine.Pin(35)) adc.atten(machine.ADC_ATTN_11DB)
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/micropython/micropython-esp32/issues/33#issuecomment-366575106, or mute the thread https://github.com/notifications/unsubscribe-auth/AQBjGf0ERpyhXx6SeRhDzaxLr8fIMjWXks5tWN4MgaJpZM4MN_kJ .
The correct attenuation is below. Note the period instead of underscore.
adc = machine.ADC(machine.Pin(35)) adc.atten(machine.ADC.ATTN_11DB)
I can't seem to initiate the ADC, all of the following result in the same 'expecting a pin' error: