that exactly is my meaning by "advice" I feel I am learning how to write with 3 different "SBUS" libraries and I'm not sure which is best for my application.. i.e. I'm messing with this code that says it's for "Futaba" SBUS but it works... I want to try the Boulder.SBUS library but I'm not sure how to indicate the separate channel write functions.. I have read the "readme" on so many libraries at this point that I get things twisted when I am trying to write.. I'll use a function from one library not in the other. and it's just messy. The code below is what I have as of now... I get the tracks to move.. very slowly.. I believe it has something to do with serial monitor is reading values from -86 to 86 and should give me values from 900's-1800's.. not really sure why, how to fix, or if it's just how Futaba uses Sbus that's messing with it... I am sending the receiver through a amplifying inverter.. 10k resistor on the Sbus TX 5k resistor on the 5v power pin to the 4444 transistor...
yes I have a license, I'm a junior in college for Aerospace Engineering.. hope your day gets better buddy...
#include <SBUS.h>
SBUS sbus(Serial1);
#define motorLeft_IN1 4
#define motorLeft_IN2 5
#define motorRight_IN1 6
#define motorRight_IN2 7
int ch2, ch3, ch6, ch8 = 0;
int motorSpeed, steeringValue, leftMotorSpeed, rightMotorSpeed = 0;
void setup()
{
sbus.begin();
Serial.begin(115200);
Serial.println("SBUS Status");
// DC motors control - set them stationary
// Left track
digitalWrite(motorLeft_IN1, LOW); // PWM value
digitalWrite(motorLeft_IN2, LOW); // Forward
// Right track
digitalWrite(motorRight_IN1, LOW); // PWM value
digitalWrite(motorRight_IN2, LOW); // Forward
}
// this is timer2, which triggers ever 1ms and processes the incoming SBUS datastream
ISR(TIMER2_COMPA_vect)
{
sbus.process();
}
void loop()
{
ch2 = sbus.getChannel(2); // ch0 - left and right;
ch3 = sbus.getChannel(3); // ch1 - forward and backward;
// convert the incoming date into suitable PWM value
steeringValue = map(ch2, 1000, 2000, -185, 185); // 0 to 185 range because then I add +70 in order to avoid low PWM values as to motors won't start if so
motorSpeed = map(ch3, 500, 1500, -100, 100);
motorSpeed = abs(motorSpeed);
leftMotorSpeed = 70 + motorSpeed + steeringValue; // 70 + (0-185) + (0 - 185 ) = 70 - 255 so this range from 70 to 255 is used as PWM value
rightMotorSpeed = 70 + motorSpeed - steeringValue;
leftMotorSpeed = constrain(leftMotorSpeed, 0, 255); // constrain the PWM value from 0 to 255
rightMotorSpeed = constrain(rightMotorSpeed, 0, 255);
// if PWM is lower than -10, set PWM value to 0
if (leftMotorSpeed < -10) {
leftMotorSpeed = 0;
}
if (rightMotorSpeed < 10) {
rightMotorSpeed = 0;
}
// if right joystick up > forward
if (ch3 > 10 && ch3 < 90) {
analogWrite(motorLeft_IN1, leftMotorSpeed); // PWM input
digitalWrite(motorLeft_IN2, LOW); // Direction - Forward
analogWrite(motorRight_IN1, rightMotorSpeed); // PWM input
digitalWrite(motorRight_IN2, LOW); // Direction - Forward
}
// if right joystick down > backward
if (ch3 > -90 && ch3 < -10) {
digitalWrite(motorLeft_IN1, LOW); // Direction - Backward
analogWrite(motorLeft_IN2, leftMotorSpeed); // PWM input
digitalWrite(motorRight_IN1, LOW); // Direction - Backward
analogWrite(motorRight_IN2, rightMotorSpeed); // PWM input
}
// if right joystick middle, don't move
if (ch3 > -10 && ch3 < 10) {
if (leftMotorSpeed < 75 && rightMotorSpeed < 75) {
digitalWrite(motorLeft_IN1, LOW);
digitalWrite(motorLeft_IN2, LOW);
digitalWrite(motorRight_IN1, LOW);
digitalWrite(motorRight_IN2, LOW);
}
// if right joystick move just left or right, without going up or down, move the tank left or right (only 1 motor move)
else {
analogWrite(motorLeft_IN1, leftMotorSpeed); // PWM input
digitalWrite(motorLeft_IN2, LOW); // Direction - Forward
analogWrite(motorRight_IN1, rightMotorSpeed); // PWM input
digitalWrite(motorRight_IN2, LOW); // Direction - Forward
}
}
delay(500);
printSBUSStatus();
}
void printSBUSStatus()
{
Serial.print("Ch1 ");
Serial.println(sbus.getNormalizedChannel(1));
Serial.print("Ch2 ");
Serial.println(sbus.getNormalizedChannel(2));
Serial.print("Ch3 ");
Serial.println(sbus.getNormalizedChannel(3));
Serial.print("Ch4 ");
Serial.println(sbus.getNormalizedChannel(4));
Serial.print("Ch5 ");
Serial.println(sbus.getNormalizedChannel(5));
Serial.print("Ch6 ");
Serial.println(sbus.getNormalizedChannel(6));
Serial.print("Ch7 ");
Serial.println(sbus.getNormalizedChannel(7));
Serial.print("Ch8 ");
Serial.println(sbus.getNormalizedChannel(8));
Serial.print("Ch9 ");
Serial.println(sbus.getNormalizedChannel(9));
Serial.print("Ch10 ");
Serial.println(sbus.getNormalizedChannel(10));
Serial.print("Ch11 ");
Serial.println(sbus.getNormalizedChannel(11));
Serial.print("Ch12 ");
Serial.println(sbus.getNormalizedChannel(12));
Serial.print("Ch13 ");
Serial.println(sbus.getNormalizedChannel(13));
Serial.print("Ch14 ");
Serial.println(sbus.getNormalizedChannel(14));
Serial.print("Ch15 ");
Serial.println(sbus.getNormalizedChannel(15));
Serial.print("Ch16 ");
Serial.println(sbus.getNormalizedChannel(16));
Serial.println();
Serial.print("Failsafe: ");
if (sbus.getFailsafeStatus() == SBUS_FAILSAFE_ACTIVE) {
Serial.println("Active");
}
if (sbus.getFailsafeStatus() == SBUS_FAILSAFE_INACTIVE) {
Serial.println("Not Active");
}
Serial.print("Data loss on connection: ");
Serial.print(sbus.getFrameLoss());
Serial.println("%");
Serial.print("Frames: ");
Serial.print(sbus.getGoodFrames());
Serial.print(" / ");
Serial.print(sbus.getLostFrames());
Serial.print(" / ");
Serial.println(sbus.getDecoderErrorFrames());
Serial.print("Time diff: ");
}