I am all but finished my long and drawn out program that lets me press a GUI button in Python/Tkinter and have it latch a relay using an Arduino Mega 2560 board. Actually there are 14 separate commands to latch and unlatch 7 different relays. That works fine but........what code is needed so I can take the info from the Arduino board (voltage present at a digital output pin because the relay is latched) and send that fact back to the Python program to maybe do something like change the color of the button that was pressed to get that relay to latch. I need some kind of feedback on the GUI screen that confirms that a relay has changed state.
Below are my programs for the Python and the Arduino. I know they are stoneage but they do work. I just need help sending Arduino data back to the GUI to confirm an action has taken place.
THIS IS THE PROGRAM IN ARDUINO:
char serialData;
int sim1Pin = 51;
int sim2Pin = 22;
int sim3Pin = 23;
int sim4Pin = 24;
int sim5Pin = 25;
int sim6Pin = 26;
int sim7Pin = 27;
int sim1analogPin = 1;
int sim2analogPin = 2;
int sim3analogPin = 3;
int sim4analogPin = 4;
int sim5analogPin = 5;
int sim6analogPin = 6;
int sim7analogPin = 7;
int pin31 = 31;
int pin32 = 32;
int pin33 = 33;
int pin34 = 34;
int pin35 = 35;
int pin36 = 36;
int pin37 = 37;
int pin41 = 41;
int pin42 = 42;
int pin43 = 43;
int pin44 = 44;
int pin45 = 45;
int pin46 = 46;
int pin47 = 47;
int threshold = 300;
void setup() {
pinMode(sim1Pin, OUTPUT);
pinMode(sim2Pin, OUTPUT);
pinMode(sim3Pin, OUTPUT);
pinMode(sim4Pin, OUTPUT);
pinMode(sim5Pin, OUTPUT);
pinMode(sim6Pin, OUTPUT);
pinMode(sim7Pin, OUTPUT);
pinMode(sim1analogPin, INPUT);
pinMode(sim2analogPin, INPUT);
pinMode(sim3analogPin, INPUT);
pinMode(sim4analogPin, INPUT);
pinMode(sim5analogPin, INPUT);
pinMode(sim6analogPin, INPUT);
pinMode(sim7analogPin, INPUT);
pinMode(pin31, OUTPUT);
pinMode(pin32, OUTPUT);
pinMode(pin33, OUTPUT);
pinMode(pin34, OUTPUT);
pinMode(pin35, OUTPUT);
pinMode(pin36, OUTPUT);
pinMode(pin37, OUTPUT);
pinMode(pin41, OUTPUT);
pinMode(pin42, OUTPUT);
pinMode(pin43, OUTPUT);
pinMode(pin44, OUTPUT);
pinMode(pin45, OUTPUT);
pinMode(pin46, OUTPUT);
pinMode(pin47, OUTPUT);
Serial.begin(9600);
// put your setup code here, to run once:
}
void loop() {
int analog1Value = analogRead(sim1analogPin);
int analog2Value = analogRead(sim2analogPin);
int analog3Value = analogRead(sim3analogPin);
int analog4Value = analogRead(sim4analogPin);
int analog5Value = analogRead(sim5analogPin);
int analog6Value = analogRead(sim6analogPin);
int analog7Value = analogRead(sim7analogPin);
if (Serial.available() > 0){
serialData = Serial.read();
Serial.print(serialData);
if (serialData =='2'){
digitalWrite(pin31, HIGH);}
delay(100);
digitalWrite(pin31, LOW);
if ((analog1Value > threshold) and (serialData =='2')){
digitalWrite(sim1Pin, HIGH);}
else
digitalWrite(sim1Pin, LOW);
if (serialData =='3'){
digitalWrite(pin41, HIGH);}
delay(100);
digitalWrite(pin41, LOW);
if (serialData =='4'){
digitalWrite(pin32, HIGH);}
delay(100);
digitalWrite(pin32, LOW);
if ((analog2Value > threshold) and (serialData =='4')){
digitalWrite(sim2Pin, HIGH);
}
else
digitalWrite(sim2Pin, LOW);
if (serialData =='5'){
digitalWrite(pin42, HIGH);}
delay(100);
digitalWrite(pin42, LOW);
if (serialData =='6'){
digitalWrite(pin33, HIGH);}
delay(100);
digitalWrite(pin33, LOW);
if ((analog3Value > threshold) and (serialData =='6')){
digitalWrite(sim3Pin, HIGH);
}
else
digitalWrite(sim3Pin, LOW);
if (serialData =='7'){
digitalWrite(pin43, HIGH);}
delay(100);
digitalWrite(pin43, LOW);
if (serialData =='8'){
digitalWrite(pin34, HIGH);}
delay(100);
digitalWrite(pin34, LOW);
if ((analog4Value > threshold) and (serialData =='8')){
digitalWrite(sim4Pin, HIGH);
}
else
digitalWrite(sim4Pin, LOW);
if (serialData =='9'){
digitalWrite(pin44, HIGH);}
delay(100);
digitalWrite(pin44, LOW);}
if (serialData =='A'){
digitalWrite(pin35, HIGH);}
delay(100);
digitalWrite(pin35, LOW);
if ((analog5Value > threshold) and (serialData =='A')){
digitalWrite(sim5Pin, HIGH);
}
else
digitalWrite(sim5Pin, LOW);
if (serialData =='B'){
digitalWrite(pin45, HIGH);}
delay(100);
digitalWrite(pin45, LOW);
if (serialData =='C'){
digitalWrite(pin36, HIGH);}
delay(100);
digitalWrite(pin36, LOW);
if ((analog6Value > threshold) and (serialData =='C')){
digitalWrite(sim6Pin, HIGH);
}
else
digitalWrite(sim6Pin, LOW);
if (serialData =='D'){
digitalWrite(pin46, HIGH);}
delay(100);
digitalWrite(pin46, LOW);
if (serialData =='E'){
digitalWrite(pin37, HIGH);}
delay(100);
digitalWrite(pin37, LOW);
if ((analog7Value > threshold) and (serialData =='E')){
digitalWrite(sim7Pin, HIGH);
}
else
digitalWrite(sim7Pin, LOW);
if (serialData =='F'){
digitalWrite(pin47, HIGH);}
delay(100);
digitalWrite(pin47, LOW);
}