Copyright © https://mongoose-os.com

Mongoose OS Forum

frame
ATTENTION! This forum has moved to:

https://community.mongoose-os.com

Do not post any new messages.

How to read ADC from sensor javscript?

CipanXCipanX Malaysia
edited October 2018 in Mongoose OS

Im using ESP32 DevKit V1 with mos tool version 1.18. I already connected my sensor to produce analog voltage. The pin connected to the ADC0 pin on my ESP32. But I failed to get any reading from any pin. It just constant value with 258. This is my coding using the javascript.

// Load Mongoose OS API
load('api_grove.js');
load('api_gpio.js');
load('api_sys.js');
load("api_adc.js");

ADC.enable(0);
ADC.enable(1);



// Configure LED
let led = 23;// ffi('int get_led_gpio_pin()')();  // Get built-in LED GPIO pin
GPIO.set_mode(led, GPIO.MODE_OUTPUT);

Grove.Button.attach(0, function() {
  print('Analog Output 1: ', ADC.read(0));
  print('Analog Output 2: ', ADC.read(1));

  GPIO.toggle(23);
 });

This is the result :

[Oct 10 15:28:21.472] [0;31mE (2619416) RTC_MODULE: /opt/Espressif/esp-idf/components/driver/./rtc_module.c:952 (adc1_get_raw):ADC Channel Err[0m
[Oct 10 15:28:21.475] Analog Output 1:  258 
[Oct 10 15:28:21.488] [0;31mE (2619436) RTC_MODULE: /opt/Espressif/esp-idf/components/driver/./rtc_module.c:952 (adc1_get_raw):ADC Channel Err[0m
[Oct 10 15:28:21.493] Analog Output 2:  258 

PinOut:

1.PNG 431.4K

Comments

Sign In or Register to comment.