- My goal is: [To Know How to use c /c++ library in mongoose os and therein how to upload it to esp32 with a valid example]
- My actions are: [i want to read a pin whic is connected to a battery and pin when read should give me voltage level.i tried usig GPIO.read(pin] but it only gives me 1 or 0 value and same pin if i read using arduino based programme i get proper voltage values. i also tried using ADC.read(pin) but when i do this esp32 freezes .
- The result I see is: [The result i get by GPIO.read(pin) is 1 or 0 and if i write ADC.read(pin) then i seee my programme doesnt run]
- My expectation & question is: [to read the value from pin and get the voltage level to monitor battery voltage and i am using esp32 board]
- Add the adc library to your
mos.yml
libs:
- origin: https://github.com/mongoose-os-libs/adc
- Example
main.c
#include "mgos.h"
#include "mgos_adc.h"
/*
* ADC_PIN must be in the range 32-39
*/
#define ADC_PIN 32
static void timer_cb(void *arg) {
int mV = int mgos_adc_read_voltage(ADC_PIN);
LOG(LL_INFO, ("voltage: %d mV", mV));
(void) arg;
}
enum mgos_app_init_result mgos_app_init(void) {
// enable ADC on pin ADC_PIN
// by default the attenuation is set to 11dB, which means the maximum voltage
// that can be applied is about 2600 mV
mgos_adc_enable(ADC_PIN);
mgos_set_timer(10000 /* ms */, MGOS_TIMER_REPEAT, timer_cb, NULL);
return MGOS_APP_INIT_SUCCESS;
}
Thank You For Your Kind Reply
But Here s the Problem i am facing ,it fails to build with following error
volumes/latest/apps/app5/esp32/build_contexts/build_ctx_927577934/build/objs/lwip/port/esp32/netif/wlanif.o
CC /data/fwbuild-volumes/latest/apps/app5/esp32/build_contexts/build_ctx_927577934/build/objs/lwip/port/esp32/netif/dhcp_state.o
CC /data/fwbuild-volumes/latest/apps/app5/esp32/build_contexts/build_ctx_927577934/build/objs/lwip/port/esp32/netif/ethernetif.o
CC /data/fwbuild-volumes/latest/apps/app5/esp32/build_contexts/build_ctx_927577934/build/objs/lwip/port/esp32/debug/lwip_debug.o
AR /data/fwbuild-volumes/latest/apps/app5/esp32/build_contexts/build_ctx_927577934/build/objs/lwip/liblwip.a
make[1]: Leaving directory '/data/fwbuild-volumes/latest/apps/app5/esp32/build_contexts/build_ctx_927577934/build/objs/lwip'
AR /data/fwbuild-volumes/latest/apps/app5/esp32/build_contexts/build_ctx_927577934/build/objs/nvs_flash/libnvs_flash.a
make[1]: Leaving directory '/data/fwbuild-volumes/latest/apps/app5/esp32/build_contexts/build_ctx_927577934/build/objs/nvs_flash'
make: Leaving directory '/app'
Error: exit status 2
/src/cli/build_local.go:697:
/src/cli/build_local.go:684:
/src/cli/build_local.go:449:
/src/cli/build.go:270:
/src/cli/build.go:213:
/src/cli/main.go:198: build failed
Error: /src/cli/build_remote.go:333: build failed
/src/cli/build.go:270:
/src/cli/build.go:213:
/src/cli/main.go:198: build failed
I don’t see the actual error in the snippet you posted. It must be somewhere earliear in the build log.
The complete log is here
https://drive.google.com/file/d/1EYJnUB8P6lUr1NZ3_AwjOE12PRbU7dS0/view?usp=sharing
The actual error is
/data/fwbuild-volumes/latest/apps/app5/esp32/build_contexts/build_ctx_927577934/src/main.c:10:12: error: expected expression before 'int'
int mV = int mgos_adc_read_voltage(ADC_PIN);
^~~
Sorry, there was an error in my code.
Modify that line to read:
int mV = mgos_adc_read_voltage(ADC_PIN);