zendes / SBUS

Arduino library for the Futaba SBUS protocol
GNU General Public License v2.0
127 stars 63 forks source link

NANO V3 #7

Open ghost opened 6 years ago

ghost commented 6 years ago

Hy, it uses fine on Mega, on UNO but seems stucked on NANO V3 (ATmega328p), is it not possible ? I have add Softawre serial to be able to readsome debugs which work on UNO but no possibility to see anything on Arduino Nano. On a program I am making for rc model lighting using SBUS from channel 9, I get running on UNO but not on Nano. Nothing happens. I am trying since a week now and a good advice if NANO yes or no would be nice. Otherwise it is a perfect library. Thanks for reply, André

voroshkov commented 5 years ago

Doesn't work reliably on Pro Mini as well. Initializes once in 50 resets.

voroshkov commented 5 years ago

Found a workaround which seems to work reliably on Pro Mini: It merely reboots Arduino until it starts capturing valid packets. Surprisingly enough this code works pretty good and fast.

#define SBUS_WARM_UP_TIME_MS 100

void(* resetArduino) (void) = 0; //declare reset function at address 0

void setup() {
    sbus.begin(false);

    uint32_t ms = millis();
    while(millis() - ms < SBUS_WARM_UP_TIME_MS) {
        sbus.process();
    }

    if (sbus.getGoodFrames() == 0) {
        resetArduino();
    }
    ...
eskaflon commented 5 years ago

How do you get it to work on nano? @voroshkov did it not work at all for you at first ? when you used pro mini

voroshkov commented 5 years ago

@eskaflon, yes - didn't work on Pro Mini until I implemented the "hack" described above. Tried 2 ProMinis with the same result. At the same time didn't notice an issue on Uno board. That's weird because both have ATMega328p chip, 16MHz oscillator and 5V voltage

eskaflon commented 5 years ago

@voroshkov Weird how it doesnt work on these boards, thanks for the hack. Is this how you used it ?

#include <SBUS.h>
#define SBUS_WARM_UP_TIME_MS 100
SBUS sbus(Serial);

void(* resetArduino) (void) = 0; //declare reset function at address 0

void setup()
{
  sbus.begin(false);

  uint32_t ms = millis();
  while(millis() - ms < SBUS_WARM_UP_TIME_MS) {
      sbus.process();
  }

  if (sbus.getGoodFrames() == 0) {
      resetArduino();
  }
  sbus.begin();
  Serial.begin(115200);
  Serial.println("SBUS Status");
}

// this is timer2, which triggers ever 1ms and processes the incoming SBUS datastream
ISR(TIMER2_COMPA_vect)
{
  sbus.process();
}
...
voroshkov commented 5 years ago

@eskaflon, no. On proMini you cannot use sbus & Serial, because Serial is used for sbus. Not sure about timer ISR - didn't try that.

My code is as follows:

...
void setup() {
    sbus.begin(false);
    uint32_t ms = millis();
    while(millis() - ms < SBUS_WARM_UP_TIME_MS) {
        sbus.process();
    }
    if (sbus.getGoodFrames() == 0) {
        resetArduino();
    }
    // also setup pins and other stuff as usual...
    ...
}

void loop() {
    sbus.process();
    ...
    // and the loop should not be long to avoid sbus losing packets
}
jasin755 commented 5 years ago

What about Arduino micro?