Afternoon All,
Been trying to build a linear drive unit from a Radio Control input for a project I’m working on.
Had a search on here but could find want i looking for but sorry if it’s already been asked.
Not sure if the IBT 2 is damaged or if it something in the code.
the unit powered of a 6v battery and then 5 v from the arduino.
here is the basic’s of the project.
#include <EnableInterrupt.h>
#define SERIAL_PORT_SPEED 57600
#define RC_NUM_CHANNELS 1
#define RC_CH1 0
#define RC_CH1_INPUT A0
#define EE 2 // enable pin on ibt 2 forward
#define EF 4// enable pin on ibt 2 reverse
#define ME 3 //motor forward
#define MF 5 // motor reverse
#define LE 6 //limit switch empty currently not used
#define LF 7 //limit switch full
uint16_t rc_values[RC_NUM_CHANNELS];
uint32_t rc_start[RC_NUM_CHANNELS];
volatile uint16_t rc_shared[RC_NUM_CHANNELS];
//------------------------------------------------------------
void rc_read_values() {
noInterrupts();
memcpy(rc_values, (const void *)rc_shared, sizeof(rc_shared));
interrupts();
}
void calc_input(uint8_t channel, uint8_t input_pin) {
if (digitalRead(input_pin) == HIGH) {
rc_start[channel] = micros();
} else {
uint16_t rc_compare = (uint16_t)(micros() - rc_start[channel]);
rc_shared[channel] = rc_compare;
}
}
void calc_ch1() {
calc_input(RC_CH1, RC_CH1_INPUT);
}
void setup() {
Serial.begin(SERIAL_PORT_SPEED);
pinMode(RC_CH1_INPUT, INPUT); // rc input
enableInterrupt(RC_CH1_INPUT, calc_ch1, CHANGE);
// pinMode(LE, INPUT_PULLUP);
// pinMode (LF,INPUT_PULLUP);
pinMode(EE, OUTPUT);
pinMode(EF, OUTPUT);
pinMode(ME, OUTPUT);
pinMode(MF, OUTPUT);
pinMode(LE, INPUT);
pinMode(LF, INPUT);
}
void loop() {
rc_read_values();
{
if (rc_values[RC_CH1] < 1350) //// Tank Empty
analogWrite(ME, 255);
analogWrite(MF, 0);
digitalWrite(EF, LOW);
digitalWrite(EE, HIGH);
}
{
if ((rc_values[RC_CH1] > 1300) && (rc_values[RC_CH1] < 1750))// Stop Tank
analogWrite(ME, 0);
analogWrite(MF, 0);
digitalWrite(EF, LOW);
digitalWrite(EE, LOW);
}
{
if (rc_values[RC_CH1] > 1800) //Fill tank
analogWrite(MF, 255);
analogWrite(ME, 0);
digitalWrite(EF, HIGH);
digitalWrite(EE, LOW);
}
}
many thanks