bolderflight / sbus

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

Trouble with an Arduino Mega #68

Open flightblog opened 1 year ago

flightblog commented 1 year ago

I'm not having any luck with an Arduino Mega and the sample code. I'm using an inverter that has worked with an MKR1010 and I'm have RX pinned to 17 (RX2).

#include "sbus.h"

/* SBUS object, reading SBUS */
bfs::SbusRx sbus_rx(&Serial2);
/* SBUS object, writing SBUS */
bfs::SbusTx sbus_tx(&Serial2);
/* SBUS data */
bfs::SbusData data;

void setup() {
  /* Serial to display data */
  Serial.begin(115200);
  while (!Serial) {}

  delay(2000);

  /* Begin the SBUS communication */
  Serial.println("Begin SBUS...");
  sbus_rx.Begin();
  sbus_tx.Begin();
}

void loop() {

  if (sbus_rx.Read()) {
    /* Grab the received data */
    data = sbus_rx.data();
    /* Display the received data */
    for (int8_t i = 0; i < data.NUM_CH; i++) {
      Serial.print(data.ch[i]);
      Serial.print("\t");
    }

    /* Display lost frames and failsafe data */
    Serial.print(data.lost_frame);
    Serial.print("\t");
    Serial.println(data.failsafe);
    /* Set the SBUS TX data to the received data */
    sbus_tx.data(data);
    /* Write the data to the servos */
    sbus_tx.Write();
  }
}

Occasionally I will receive data from sbus_rx.Read()

sbus-data

flybrianfly commented 1 year ago

Hard to say, even the posted data looks kind of garbage. I'll have to dig around to see if I have a Mega to test with.

Witty-Wizard commented 6 days ago

The Arduino Mega does not support baudrate of 100000, better change to a 32bit microcontroller