Hello! and Help! I have been working on this project all day and I cant get it to work.... Fully. I will explain...
So I have a RC car. it is equipped with a flysky FS-IA6B.
and a flysky FS-I6X. I am installing lights, a voltage sensor, and a temperature sensor (for the motor).
I already have the lights working. and the voltage sensor. and I know how I am going to do the temperature sensor.
but I am trying to transmit the sensor data over IBUS. there is some library's for it. Like iBUSTelemetry by adis1313
and IBusBM by bmellink. but I cant get any to work. I am using a arduino nano on a small 170 tie breadboard.
and I just want to know HOW to get the IBUS sensor working. This forum post steams to have worked Flysky IBUS Sensor But I just cant get it to work myself! here is my code:
#include <AverageValue.h>
#include <MyDelay.h>
float voltage;
double avgthrottle;
double avgstearing;
double avgswitch1;
double avgswitch2;
const long MAX_VALUES_NUM_THROTTLE = 10;
const long MAX_VALUES_NUM_STEARING = 10;
const long MAX_VALUES_NUM_SWITCH1 = 2;
const long MAX_VALUES_NUM_SWITCH2 = 2;
const long MAX_VALUES_NUM_VOLTAGE = 40;
const int reverselight = A0;
const int rearright = A1;
const int rearleft = A2;
const int frontright = A3;
const int frontleft = A4;
const int VoltPin = A5;
const int highbeams = 6;
const int lowbeams = 7;
const int ledbrightness = 150;
const int reverselightbrightness = 255;
int braking1 = 0;
int braking2 = 0;
int ch3 = 0;
int ch4 = 0;
int ch5 = 0;
int ch6 = 0;
int throttle = 1;
int stearing = 1;
int switch1 = 1;
int switch2 = 1;
int stearingstate = 1;
float sensorValue = 0;
uint16_t avgvoltage = 0;
const int ch3read = 2;
const int ch4read = 3;
const int ch5read = 4;
const int ch6read = 5;
AverageValue<long> averagethrottle(MAX_VALUES_NUM_THROTTLE);
AverageValue<long> averagestearing(MAX_VALUES_NUM_STEARING);
AverageValue<long> averageswitch1(MAX_VALUES_NUM_SWITCH1);
AverageValue<long> averageswitch2(MAX_VALUES_NUM_SWITCH2);
AverageValue<long> averagevoltage(MAX_VALUES_NUM_VOLTAGE);
void ledBlink();
MyDelay BlinkTime(500, ledBlink);
int ledState = 0;
void brakecheck();
MyDelay CheckTime(15, brakecheck);
int isbraking = 0;
void ledBlink()
{
if (ledState == 0)
ledState = ledbrightness;
else
ledState = 0;
}
void brakecheck()
{
braking2 = throttle;
}
void setup() {
pinMode(reverselight, OUTPUT);
pinMode(rearleft, OUTPUT);
pinMode(rearright, OUTPUT);
pinMode(frontleft, OUTPUT);
pinMode(frontright, OUTPUT);
pinMode(highbeams, OUTPUT);
pinMode(lowbeams, OUTPUT);
pinMode(VoltPin, INPUT);
pinMode(ch3read, INPUT);
pinMode(ch4read, INPUT);
pinMode(ch5read, INPUT);
pinMode(ch6read, INPUT);
BlinkTime.start();
CheckTime.start();
}
void loop()
{
if (stearingstate == 1) {
ledState = ledbrightness;
BlinkTime.start();
analogWrite(frontright, 0);
analogWrite(frontleft, 0);
}
else if (stearingstate == 2) {
BlinkTime.update();
analogWrite(frontleft, ledState);
analogWrite(rearleft, ledState);
analogWrite(frontright, 0);
}
else if (stearingstate == 0) {
BlinkTime.update();
analogWrite(frontright, ledState);
analogWrite(rearright, ledState);
analogWrite(frontleft, 0);
}
sensorValue = analogRead(VoltPin);
avgvoltage = sensorValue * (5 / 1024.0);
avgvoltage = avgvoltage + avgvoltage;
CheckTime.update();
avgthrottle = pulseIn(ch3read, HIGH);
avgstearing = pulseIn(ch4read, HIGH);
avgswitch1 = pulseIn(ch5read, HIGH);
avgswitch2 = pulseIn(ch6read, HIGH);
averagethrottle.push(avgthrottle);
averagestearing.push(avgstearing);
averageswitch1.push(avgswitch1);
averageswitch2.push(avgswitch2);
averagevoltage.push(sensorValue);
throttle = averagethrottle.average();
stearing = averagestearing.average();
switch1 = averageswitch1.average();
switch2 = averageswitch2.average();
avgvoltage = averagevoltage.average();
braking1 = throttle;
braking1 = braking1 + 3;
if (braking1 < braking2)
isbraking = 1;
else if (braking1 > braking2)
isbraking = 0;
if (isbraking == 1)
{
analogWrite(rearright, ledbrightness);
analogWrite(rearleft, ledbrightness);
}
else
{
analogWrite(rearleft, 0);
analogWrite(rearright, 0);
}
if (throttle < 1486)
{
analogWrite(reverselight, reverselightbrightness);
}
else
{
analogWrite(reverselight, 0);
}
if (stearing > 1602) {
stearingstate = 2;
}
else if (stearing < 1450) {
stearingstate = 0;
}
else
{
stearingstate = 1;
}
if (switch1 < 1000 && switch2 < 1500)
{
digitalWrite(highbeams, HIGH);
digitalWrite(lowbeams, HIGH);
}
else if (switch1 > 1400 && switch1 < 1500 && switch2 < 1500)
{
digitalWrite(highbeams, HIGH);
digitalWrite(lowbeams, LOW);
}
else if (switch1 > 1900 && switch2 < 1500)
{
digitalWrite(lowbeams, HIGH);
digitalWrite(highbeams, LOW);
}
else if (switch2 > 1500)
{
digitalWrite(lowbeams, LOW);
digitalWrite(highbeams, LOW);
}
}