Hi, I found a library that allows a teensy to comunicate with an sbus receiver. I need to pass the data received (an array of integers) to another board with I2C. I can see things happening on the board connected to the SBUS receiver but nothing on the board that's supposed to receive the array of data via I2C. Hope that makes sense.
I've also other i2c devices connected to the same bus (don't know if that can cause problems).
Here are the 2 programs:
Transmitter:
Receiver:
I've also other i2c devices connected to the same bus (don't know if that can cause problems).
Here are the 2 programs:
Transmitter:
Code:
#include "sbus.h"
#include <Wire.h>
/* SBUS object, reading SBUS */
bfs::SbusRx sbus_rx(&Serial2);
bfs::SbusData data;
const int channelNumber = 16;
int channels[channelNumber];
void setup() {
/* Serial to display data */
Serial.begin(115200);
while (!Serial);
sbus_rx.Begin();
Wire.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++) {
channels[i] = data.ch[i];
Serial.print(data.ch[i]);
Serial.print("\t");
}
Serial.println();
}
Wire.beginTransmission(8);
for(int i = 0; i < channelNumber; i++){
Wire.write(channels[i]);
}
Wire.endTransmission();
}
Receiver:
Code:
#include<Wire.h>
const int channelNumber = 16;
int receiverChannels[channelNumber];
void setup() {
Wire.begin(8);
Wire.onReceive(receiveEvent);
Serial.begin(115200);
while(!Serial);
}
void loop() {
}
void receiveEvent(int byteCount){
if(Wire.available()){
byte b = 0;
for(int i = 0; i < channelNumber; i++){
b = Wire.read();
receiverChannels[i] = b;
Serial.print(receiverChannels[i]); Serial.print(" ");
}
Serial.println();
}
}
Last edited: