Initial check-in
This commit is contained in:
3
App/GetState.bat
Normal file
3
App/GetState.bat
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
@echo off
|
||||||
|
.\USBCaseControl.py -c "GETSTATE"
|
||||||
|
pause
|
||||||
3
App/MasterOff.bat
Normal file
3
App/MasterOff.bat
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
@echo off
|
||||||
|
.\USBCaseControl.py -c "MASTER=OFF"
|
||||||
|
pause
|
||||||
3
App/MasterOn.bat
Normal file
3
App/MasterOn.bat
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
@echo off
|
||||||
|
.\USBCaseControl.py -c "MASTER=ON"
|
||||||
|
pause
|
||||||
33
App/USBCaseControl.py
Normal file
33
App/USBCaseControl.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import serial.tools.list_ports
|
||||||
|
import sys, getopt
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
def main(argv):
|
||||||
|
cmd = 'GETSTATE'
|
||||||
|
print("USBCaseControl starting up...")
|
||||||
|
try:
|
||||||
|
opts, args = getopt.getopt(argv,"hc:",["cmd="])
|
||||||
|
except getopt.GetoptError as err:
|
||||||
|
print(err)
|
||||||
|
sys.exit(2)
|
||||||
|
for opt, arg in opts:
|
||||||
|
if opt == '-h':
|
||||||
|
print("USBCaseControl.py --cmd <command>")
|
||||||
|
sys.exit()
|
||||||
|
elif opt in ("-c", "--cmd"):
|
||||||
|
cmd = arg
|
||||||
|
ports = serial.tools.list_ports.comports()
|
||||||
|
for port, desc, hwid in sorted(ports):
|
||||||
|
if "Arduino Leonardo" in desc:
|
||||||
|
print("{}: {} [{}]".format(port, desc, hwid))
|
||||||
|
finalport=port
|
||||||
|
ser = serial.Serial(finalport, 9600, timeout=0,parity=serial.PARITY_EVEN, rtscts=1)
|
||||||
|
print("Calling command: {} on Port {}".format(cmd,port))
|
||||||
|
ser.write(cmd.encode('utf_8'))
|
||||||
|
time.sleep(2)
|
||||||
|
out = ser.read(100)
|
||||||
|
print("Command return: {}".format(out.decode(encoding="utf_8", errors="ignore")))
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main(sys.argv[1:])
|
||||||
100
Firmware/RelayBoardOnMicro.ino
Normal file
100
Firmware/RelayBoardOnMicro.ino
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
Serial Call and Response in ASCII
|
||||||
|
Language: Wiring/Arduino
|
||||||
|
|
||||||
|
This program sends an ASCII A (byte of value 65) on startup and repeats that
|
||||||
|
until it gets some data in. Then it waits for a byte in the serial port, and
|
||||||
|
sends three ASCII-encoded, comma-separated sensor values, truncated by a
|
||||||
|
linefeed and carriage return, whenever it gets a byte in.
|
||||||
|
|
||||||
|
The circuit:
|
||||||
|
- potentiometers attached to analog inputs 0 and 1
|
||||||
|
- pushbutton attached to digital I/O 2
|
||||||
|
|
||||||
|
created 26 Sep 2005
|
||||||
|
by Tom Igoe
|
||||||
|
modified 24 Apr 2012
|
||||||
|
by Tom Igoe and Scott Fitzgerald
|
||||||
|
Thanks to Greg Shakar and Scott Fitzgerald for the improvements
|
||||||
|
|
||||||
|
This example code is in the public domain.
|
||||||
|
|
||||||
|
http://www.arduino.cc/en/Tutorial/SerialCallResponseASCII
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define MASTER 6
|
||||||
|
#define CIRCUIT1 7
|
||||||
|
#define CIRCUIT2 8
|
||||||
|
#define CIRCUIT3 9
|
||||||
|
|
||||||
|
String inString;
|
||||||
|
int MasterState = 0;
|
||||||
|
int Circuit1State = 0;
|
||||||
|
int Circuit2State = 0;
|
||||||
|
int Circuit3State = 0;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// start serial port at 9600 bps and wait for port to open:
|
||||||
|
Serial.begin(9600);
|
||||||
|
while (!Serial) {
|
||||||
|
; // wait for serial port to connect. Needed for native USB port only
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pinMode(MASTER, OUTPUT);
|
||||||
|
pinMode(CIRCUIT1, OUTPUT);
|
||||||
|
pinMode(CIRCUIT2, OUTPUT);
|
||||||
|
pinMode(CIRCUIT3, OUTPUT);
|
||||||
|
|
||||||
|
digitalWrite(MASTER, HIGH);
|
||||||
|
digitalWrite(CIRCUIT1, HIGH);
|
||||||
|
digitalWrite(CIRCUIT2, HIGH);
|
||||||
|
digitalWrite(CIRCUIT3, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
int setState(String cmd, String ref,int pin,int state,int store){
|
||||||
|
if (cmd.indexOf(ref) >= 0){
|
||||||
|
digitalWrite(pin,state);
|
||||||
|
Serial.print("Pin ");
|
||||||
|
Serial.print(pin);
|
||||||
|
Serial.print(" was set to: ");
|
||||||
|
Serial.println(state);
|
||||||
|
return !state;
|
||||||
|
}
|
||||||
|
return store;
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// if we get a valid byte, read analog ins:
|
||||||
|
|
||||||
|
if (Serial.available() > 0) {
|
||||||
|
// get incoming byte:
|
||||||
|
inString = Serial.readString();
|
||||||
|
Serial.print("Command received: ");
|
||||||
|
Serial.println(inString);
|
||||||
|
|
||||||
|
MasterState = setState(inString,"MASTER=ON",MASTER,LOW,MasterState);
|
||||||
|
MasterState = setState(inString,"MASTER=OFF",MASTER,HIGH,MasterState);
|
||||||
|
|
||||||
|
Circuit1State = setState(inString,"CIRCUIT1=ON",CIRCUIT1,LOW,Circuit1State);
|
||||||
|
Circuit1State = setState(inString,"CIRCUIT1=OFF",CIRCUIT1,HIGH,Circuit1State);
|
||||||
|
|
||||||
|
Circuit2State = setState(inString,"CIRCUIT2=ON",CIRCUIT2,LOW,Circuit2State);
|
||||||
|
Circuit2State = setState(inString,"CIRCUIT2=OFF",CIRCUIT2,HIGH,Circuit2State);
|
||||||
|
|
||||||
|
Circuit3State = setState(inString,"CIRCUIT3=ON",CIRCUIT3,LOW,Circuit3State);
|
||||||
|
Circuit3State = setState(inString,"CIRCUIT3=OFF",CIRCUIT3,HIGH,Circuit3State);
|
||||||
|
|
||||||
|
if (inString.indexOf("GETSTATE") >= 0){
|
||||||
|
Serial.print("MASTER=");
|
||||||
|
Serial.println(MasterState);
|
||||||
|
Serial.print("CIRCUIT1=");
|
||||||
|
Serial.println(Circuit1State);
|
||||||
|
Serial.print("CIRCUIT2=");
|
||||||
|
Serial.println(Circuit2State);
|
||||||
|
Serial.print("CIRCUIT3=");
|
||||||
|
Serial.println(Circuit3State);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
10
readme.md
Normal file
10
readme.md
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# USB Base Control
|
||||||
|
|
||||||
|
This is a small project to enable the switch of several relays on a 4 relay board connected to an Arduino Board which is connected to a PC via USB cable.
|
||||||
|
So switch the different relays and the master power a python script is provided aswell.
|
||||||
|
|
||||||
|
## App
|
||||||
|
Contains the pyhton script and a couple of batch files to be used under windows.
|
||||||
|
|
||||||
|
## Firmware
|
||||||
|
Contains the Arduino IDE sketch to switch the relays based on TTY over USB cable connection.
|
||||||
Reference in New Issue
Block a user