readysteadi
Active member
Hey Everybody, I've been delving into Sbus control for a brushless gimbal using the Bolderflight Sbus library. There were not a lot of examples to follow but I thought I had a handle on the code. I made a simple sketch to control one channel (channel 1) using a potentiometer to control the value. I tested the gimbal using sbus output before hand just to make sure it was reading sbus properly. The sketch compiles and uploads fine and I can see my pot values respond but I get no movement from the gimbal. Gimbal is connected to Pin1 (tx serial1) and ground. Any advice would be much appreciated. I know Brian who created the library has been pretty active on this forum.
Code:
#include "sbus.h"
#define NUM_OF_CHANNEL 8
/* SBUS object, writing SBUS */
bfs::SbusTx sbus_tx(&Serial1);
/* SBUS data */
bfs::SbusData data;
const int potentiometerPin = A0; // Analog pin for the potentiometer
void setup() {
Serial.begin(115200);
while (!Serial) {}
sbus_tx.Begin();
}
void loop() {
// Read the value of the potentiometer
int potValue = analogRead(potentiometerPin);
// Map the potentiometer value to the SBUS range
int sbusValue = map(potValue, 0, 1023, 0, 2047);
// Initialize SBUS data
data = bfs::SbusData();
// Set the SBUS value to the mapped potentiometer value
data.ch[1] = sbusValue; // Assuming control on channel 0
// Display the potentiometer value (for debugging)
Serial.println(potValue);
Serial.println(sbusValue);
// Write the SBUS data to the servos
sbus_tx.data(data);
sbus_tx.Write();
delay(20); // Adjust delay based on your requirements
}