iBus Serial Data and Interrupt

Hi,

This is what I am trying to do.

I am developing code for Quadcopter flight controller. The code takes data from receiver, Gyro and Accelerometer and calculates PID. For collecting data from receiver, I am using iBusBM library (IBusBM - Arduino Reference).

What I need?

It seems I can collect data each time the loop is repeated. I need the receiver data updated to variables whenever there is new data, not wait for the loop to complete. To me it sounds like hardware interrupt, but I don't know how I can implement interrupt with this library.

Following is simple Sketch for collecting 10 channel receiver data. How can I modify this Sketch so that whenever there is a new data, variables are updated and doesn't wait for rest of the Sketch to complete. (there is no rest of the Sketch in the sample code, but will be in actual Quadcopter flight controller once I build it). I am going through each stages.

#include <IBusBM.h>
IBusBM IBus;    // IBus object
void setup() {
  IBus.begin(Serial);    // iBUS object connected to serial0 RX pin
  Serial.begin(115200);
}

void loop() {
  int val[9];
  for (int i=0; i<10; i++){
    val[i] = IBus.readChannel(i); // get latest value for 10 servo channel 
  Serial.print("Ch ");
  Serial.print(i);
  Serial.print(" = ");
  Serial.print(val[i]);
  Serial.print(" ; ");  
  }
  Serial.println(" ");
  delay(20);
}
1 Like

How would you determine that?

Anyway, there isn't any wait for the rest of your sketch in your code as it is now. Just don't add one.

Also, if you collect data, and save it for later processing which is slow, new data will overwrite the old data, would it not? Does not the rest of your sketch have to keep pace with the incoming data? If so, why would there be any wait if you just get data and process, get data and process, etc etc. ?

It is the same problem with using an interrupt. The interrupt can obtain data almost instantly, but if your main program can only poll the interrupt results slowly, you have not gained any response advantage.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.