SBUS re-router buddy box project

Status
Not open for further replies.

MMESSITER

Active member
Hi

I am trying to create a trivial program for Teensy 4.0 that reads the SBUS output from two R/C receivers, and then routes one only of these to a single serial output, chosen according to the value on a PWM pin on the master receiver.

This is to support SBUS buddy boxing for training new model flyers. The very brief code is below. The part that reads a PWM value is working fine. The part that reads SBUS input seems to work too.

But so far it fails to produce any valid SBUS output, and I'm really hoping someone can tell me why! :)


(In this short bit of code I want only to read the SBUS input (on Serial1) and then simply output it (to Serial2). Once this much works, I can add another input port and the switch logic of course.)


volatile long int pulse_time;
byte incomingByte;

#define CHANNEL_7_PIN 2

volatile unsigned long timer_start;
volatile int last_interrupt_time;

void setup() {
timer_start = 0;
attachInterrupt(CHANNEL_7_PIN, ReadPWMvalue, CHANGE);
Serial.begin(115200);
Serial1.begin(100000);
Serial2.begin(100000);
}

void loop(){
while (Serial1.available()) {
incomingByte = Serial1.read();
Serial2.write(incomingByte);
}
}

void ReadPWMvalue(){ // Interrupt handler to read PWM value on pin
last_interrupt_time = micros();if(digitalRead(CHANNEL_7_PIN) == HIGH) {timer_start = micros();}else
{if(timer_start != 0){pulse_time = ((volatile int)micros()-timer_start);timer_start = 0;}}
}
 
I think I’ve found the answer! Brian Taylor’s SBUS library can read as well as write.
A packet at a time. I think that’ll work. I’ll try it...

Malcolm
 
Its WORKING NOW! :eek:


Code:
#include <SBUS.h>

SBUS SbusMASTER (Serial1);        //  PIN  0
SBUS SbusBUDDY  (Serial2);        //  PIN  7
SBUS SbusMODEL  (Serial3);        //  PIN 14

uint16_t channels[20];
bool failSafe;
bool lostFrame;


void setup() {
    SbusMASTER.begin();
    SbusBUDDY.begin();
    SbusMODEL.begin();  
}  
 
void loop(){ 
    if(SbusMASTER.read(&channels[0], &failSafe, &lostFrame)){
                  if (channels[11]<200) {SbusMODEL.write(&channels[0]);}else{           // Channel 12 is the switch
                            if(SbusBUDDY.read(&channels[0], &failSafe, &lostFrame)){
                                        SbusMODEL.write(&channels[0]);
                            }               
                    }           
          } 
}
 
Last edited by a moderator:
A better buddy box method

Although the method I suggested the other day works fine, it does require two receivers in the model which is a pity. So I now have a new method:

The extra receiver will be part of the transmitter so that it can receive from the buddy and the transmitter can decide which of the channels if any to forward to the model. When this code is working I will post it!

Malcolm
 
Status
Not open for further replies.
Back
Top