I am trying to integrate custom sensors (DHT11 and SGP30) to the robot’s wrist expansion header. Following the tutorial tutorial_data_transfer, I wrote a function to get values from the sensors which was called by stepWaccController_1000Hz() in Wacc.cpp. When testing, I found that the libraries from Adafruit (DHT sensor library and Adafruit SGP30 Library) used delay() to set the sensors ready for data transaction, and since stepWaccController_1000Hz() was in ISR, delay() caused the cpu to stall. I tried to remove all the delays but it seemed that sensors depended on them to init properly.
Thank you for your post. Could you share your code or email us at support@hello-robot.com, if you wish to keep it private, for better context? Thank you.
You can easily implement a non-blocking delay by skipping the read from your sensors until a specific time interval has passed:
unsigned long previousMillis = 0;
const long interval = 1000; // interval at which to do something (milliseconds) - this is the same value as your delay()
void read_from_sensors() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// Perform the read from sensor action
previousMillis = currentMillis;
}
}