Hi
I am almost getting close to finishing the programming for my final year Project at University. I am making a Wireless winch controller that will hopefully operate multiple winches on an offroad vehicle. I am using two Arduino Uno boards that are linked together via an RF link,
Transmitt board has got a input from 4 push to make switched and are coded to send A, B, C etc over the serial link, the coding for this board is as follows;
const int FWinchIn = 2; // Number of Pin for Front Winch In
const int FWinchOut = 3; // Number of pin for Front Winch Out
const int RWinchIn = 4; //Number of Pin for Rear Winch In
const int RWinchOut = 5; //Number of Pin for Rear Winch Out
int FWIN = 0; //Variable input from Front Winch In
int FWOUT = 0; //Variable input from Front Winch Out
int RWIN = 0; //Variable input from Rear Winch In
int RWOUT = 0; //Variable input from Rear Winch Out
void setup() {
Serial.begin(9600);
pinMode(FWinchIn, INPUT); // Setting Front Winch In as an input
digitalWrite(FWinchIn, HIGH); //Sets Front Winch In as High
pinMode(FWinchOut, INPUT); // Setting Front Winch Out as an input
digitalWrite(FWinchOut, HIGH); // Sets Front Winch Out as High
pinMode(RWinchIn, INPUT); // Setting Rear Winch In as an input
digitalWrite(RWinchIn, HIGH); //Sets Rear Winch In as High
pinMode(RWinchOut, INPUT); // Setting Rear Winch Out as an input
digitalWrite(RWinchOut, HIGH); // Sets Rear Winch Out as High
}
void loop(){
FWIN = digitalRead(FWinchIn); // Reads whether Front Winch In is high or low
FWOUT= digitalRead(FWinchOut); // Reads whether Front Winch Out is high or low
RWIN = digitalRead(RWinchIn); // Reads whether Rear Winch In is high or low
RWOUT= digitalRead(RWinchOut); // Reads whether Rear Winch Out is high or low
if (FWIN == LOW) {
Serial.println("A"); // if Front Winch In is pressed outputs A
}
else {
Serial.println("B"); // if Front Winch In is not pressed outputs B
}
if (FWOUT == LOW) {
Serial.println("C"); // if Front Winch Out is pressed outputs C
}
else{
Serial.println("D"); // if Front Winch Out is not pressed 0utputs D
}
if (RWIN == LOW) {
Serial.println("E"); // if Rear Winch In is pressed outputs E
}
else {
Serial.println("F"); // if Rear Winch In is not pressed outputs F
}
if (RWOUT == LOW) {
Serial.println("G"); // if Rear Winch Out is pressed outputs G
}
else{
Serial.println("H"); // if Rear Winch Out is not pressed 0utputs H
}
}
The receive board has got the output to the winches on pin 3 + 4, 6 +7 (winch in / out). on pins 2 and 5 there are a reed switch that senses the direction of the winch drum and count the number of turns of rope on the drum, the programme then stops with winch operating if there is too many or too few turns of rope on the drum. I have then got an LCD display which displays the battery voltage from pin A0 and the number of turns of rope on the drum,
#include <LiquidCrystal.h>
const int FReedSwitch = 2; //Front Reed Switch, Input Pin 2
const int FIn = 3; //Front Winch In, Output pin 3
const int FOut = 4; //Front winch Out, Output pin 4
int FReedSw = 0; //Variable of Front Reed Switch
int FTurncount = 20; //Number of Turns of Rope, front
int FPrevReedSw = LOW; //State change of Front reed switch
unsigned long FLastReedSw = 0; //Duration Front Reed sw has been made
const int RReedSwitch = 5; //Front Reed Switch, Input Pin 5
const int RIn = 6; //Rear Winch In, Output pin 6
const int ROut = 7; //Rear winch Out, Output pin 7
int RReedSw = 0; //Variable of Rear Reed Switch
int RTurncount = 20; //Number of Turns of Rope, Rear
int RPrevReedSw = LOW; //State change of Rear reed switch
unsigned long RLastReedSw = 0; //Duration Rear Reed sw has been made
int transInt = 50; // transition time between bounces
int variable = 0; //Variable is 0 unless data recieved
const int analogPin = A0; // pin that the Potential divider is attached to
LiquidCrystal lcd (13, 12, 11, 10, 9, 8); //LCD setup
void setup() {
Serial.begin(9600);
pinMode(FReedSwitch, INPUT); //Sets pin as an input
digitalWrite(FReedSwitch, HIGH); //Pin 4 High unless Switched
pinMode(FIn, OUTPUT); //Sets pin as an ouput
digitalWrite(FIn, LOW); //Pin 5 LOW
pinMode(FOut, OUTPUT); //Sets pin as an output
digitalWrite(FOut, LOW); //Pin 6 LOW
pinMode(RReedSwitch, INPUT); //Sets pin as an input
digitalWrite(RReedSwitch, HIGH); //Pin 5 High unless Switched
pinMode(RIn, OUTPUT); //Sets pin as an ouput
digitalWrite(RIn, LOW); //Pin 6 LOW
pinMode(ROut, OUTPUT); //Sets pin as an output
digitalWrite(ROut, LOW); //Pin 7 LOW
char variable; //Variable is a character
lcd.begin (16,4); //number of lines on LCD
lcd.print("Batt Volt=");
}
void loop(){
FReedSw = digitalRead(FReedSwitch);
RReedSw = digitalRead(RReedSwitch);
int analogValue = analogRead(analogPin);
if( Serial.available() >0 ){
variable = Serial.read(); //Read available Serial
if (variable == 'A' && FReedSw == LOW && FPrevReedSw == LOW){
if(millis() - FLastReedSw > transInt)
{
FTurncount ++; //If Front Reed Sw and Front Winch in are made for longer
} //than the transition time, Count Up
FLastReedSw = millis(); //duration of Front Reed Sw in Milliseconds
}
if (variable == 'C' && FReedSw == LOW && FPrevReedSw == LOW){
if(millis() - FLastReedSw > transInt)
{
FTurncount --; //If Front Reed Sw and Front Winch out are made for longer
} //than the transition time, Count Down
FLastReedSw = millis(); //duration of Front Reed Sw in Milliseconds
}
if (variable == 'E' && RReedSw == LOW && RPrevReedSw == LOW){
if(millis() - RLastReedSw > transInt)
{
RTurncount ++; //If Rear Reed Sw and Rear Winch in are made for longer
} //than the transition time, Count Up
RLastReedSw = millis(); //duration of Rear Reed Sw in Milliseconds
}
if (variable == 'G' && RReedSw == LOW && RPrevReedSw == LOW){
if(millis() - RLastReedSw > transInt)
{
RTurncount --; //If Rear Reed Sw and Rear Winch out are made for longer
} //than the transition time, Count Down
RLastReedSw = millis(); //duration of Rear Reed Sw in Milliseconds
}
if(variable == 'A' && FTurncount <=30){
digitalWrite(3, HIGH); //If A received and Turns of rope is less
} //than or equal to 30 turns, Front Winch In
else{
digitalWrite(3, LOW);
}
if(variable == 'C' && FTurncount >=10){
digitalWrite(4, HIGH); //If C received and Turns of rope is more
} //than or equal to 10 turns, Front Winch Out
else{
digitalWrite(4, LOW);
}
if(variable == 'E' && RTurncount <=30){
digitalWrite(6, HIGH); //If E received and Turns of rope is less
} //than or equal to 30 turns, Rear Winch In
else{
digitalWrite(6, LOW);
}
if(variable == 'G' && RTurncount >=10){
digitalWrite(7, HIGH); //If G received and Turns of rope is more
} //than or equal to 10 turns, Rear Winch Out
else{
digitalWrite(7, LOW);
}
}
lcd.setCursor(10, 0);
lcd.print(analogValue*0.01566);
lcd.setCursor(16,0);
lcd.print("Front Turns = ");
lcd.setCursor(30,0);
lcd.print(FTurncount);
lcd.setCursor(16,1);
lcd.print("Rear Turns = ");
lcd.setCursor(30,1);
lcd.print(RTurncount);
}
The problem that i have got is that as soon as i try writing anything to the LCD display there seems to be a delay in the circuit, what happens is the outputs seem to flash irregularly when the corresponding switch is pressed and there is a delay of about half a second between pressing the switch and the output operating.
Has anyone got any ideas of what would be causing this problem?
Sorry for the long post but i have tired to include as much detail as possible
Many thanks
Tris