bolderflight / sbus

Arduino and CMake library for communicating with SBUS receivers and servos.
MIT License
374 stars 132 forks source link

Arduino Mega: hang on setReadCal #27

Closed rwalte25 closed 3 years ago

rwalte25 commented 4 years ago

Thank you bolderflight for making this library--been very useful.

I am using a RadioLink R7FG to control an RC car through the Arduino Mega (hope to move to Micro later). However, when attempting to call setReadCal, the program seems to hang... most of the time. About 10% of the time it will setReadCal properly and it seems to be boot dependent (shutting the Mega off/ on might fix it sometimes, random). When it does work, it might do so on a channel or two before hanging. Adding delays() before/ after setReadCal() or additional print statements does not change anything.

I've attached the code that's been giving me a hard time, using one of the examples as guidance. Commenting out the setReadCal in the for loop allows the visualization to work, just not on the bounds I need (standard PWM [1000,2000]).

` // channel, fail safe, and lost frames data //uint8_t channels[16]; //for my_sbus.read() float channels[16]; float cal[2] = {500, 1500}; uint8_t l = 2; bool failSafe; bool lostFrame;

void setup() { // begin the SBUS communication my_sbus.begin();

// set channel range 1000-2000 for (uint8_t i = 0; i < ch_num; i++) { my_sbus.setReadCal(i, cal, l); //##############hangs here################## } // begin serial monitor/ plotter if active Serial.begin(115200); while (!Serial) { //wait for serial to properly begin ; } }

void loop() { // look for a good SBUS packet from the receiver if (my_sbus.readCal(&channels[0], &failSafe, &lostFrame)) { Serial.println(mode); for (int i = 0; i < 4; i++) { Serial.print(channels[i]); int bar_len = floor(channels[i] / 50); for (int j = 0; j <= bar_len; j++) { Serial.print("#"); } Serial.println(); } Serial.println("~~~~~~~~~~"); } `

flybrianfly commented 3 years ago

We no longer are supporting calibrated read / write methods.