bolderflight / pwm

PWM actuator library.
MIT License
5 stars 2 forks source link

Arduino MEGA #2

Closed flightblog closed 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() {

  Serial.println("Begin SBUS...");
  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

flightblog commented 1 year ago

Posted in incorrect repo.