PySense library on Extension Board 3.1
-
I'm trying to read the battery voltage with the PySense/pycoproc library function
read_battery_voltage()
, however the board detection fails with the error message below. Is there no support for the Extension Board 3.1?rst:0x7 (TG0WDT_SYS_RESET),boot:0x12 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0xee clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:DIO, clock div:1 load:0x3fff8020,len:8 load:0x3fff8028,len:2140 ho 0 tail 12 room 4 load:0x4009fa00,len:19760 entry 0x400a05bc Smart Provisioning started in the background See https://docs.pycom.io/smart for details Traceback (most recent call last): File "main.py", line 15, in <module> File "/flash/lib/pysense.py", line 20, in __init__ File "/flash/lib/pycoproc.py", line 115, in __init__ File "/flash/lib/pycoproc.py", line 115, in __init__ Exception: Board not detected: I2C bus error Pycom MicroPython 1.20.2.rc6 [v1.11-01f49f7] on 2020-02-28; LoPy4 with ESP32 Pybytes Version: 1.3.1 Type "help()" for more information. >>>
-
@aparcar On expansion Boards you can determine the battery voltage with the internal ADC on Pin P16. There is a voltage divider between the battery an P16, which divides the battery voltage by 2 or by 3.05, depending on the board. So you can use the ADC class (see https://docs.pycom.io/tutorials/all/adc/) with 11dB attenuation to read the input voltage and scale that by the divider. E.g. if the ADC tells 1.9V, and the divider is 2, the the battery voltage is 3.8V. Since the ADC is noisy, you may have to calculate an average over say 100 values taken. If you have an voltage meter, you should take that to obtain the proper scaling value.