-
Notifications
You must be signed in to change notification settings - Fork 313
Open
Description
Hello.
I used ads1115 and esp32 for my project. I have a need for clocking stepper motors even with i2c issues. For these purposes, I have written the following code.
#include <Adafruit_ADS1X15.h>
Adafruit_ADS1115 ads;
uint16_t geom_ads_ch0_val = 0;
uint16_t geom_ads_ch1_val = 0;
uint8_t ch_in_reading = 0;
uint64_t lst_geom_update_time = 0;
// ----------------------!
#define TASK_FILAMENT_SENSOR_TIMEOUT 10
void geom_ads_request(){
ads.startADCReading(MUX_BY_CHANNEL[ch_in_reading], /*continuous=*/false);
}
// This function is called in setup()
void geom_setup(){
if (!ads.begin(0x49)){
Serial.println("ADS1115 NOT INITED");
}
Wire.setTimeout(1);
Wire1.setTimeout(1);
geom_ads_request();
}
// This function is called in loop() with a period of TASK_FILAMENT_SENSOR_TIMEOUT of milliseconds
void task_filament_sensor_handler(){
// static uint8_t ch_in_reading = 0;
if(ads.conversionComplete()){
if(ch_in_reading == 0){
geom_ads_ch0_val = ads.getLastConversionResults();
} else if(ch_in_reading == 1){
geom_ads_ch1_val = ads.getLastConversionResults();
}
ch_in_reading++;
if(ch_in_reading > 1){
ch_in_reading = 0;
}
lst_geom_update_time = millis();
geom_ads_request();
}
}
But there is a problem: the conversionComplete() function, before giving up, tries to communicate for a whole second, blocking the flow.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels