My Latest project is a DC control panel for my radio shack, it has 300W solar panel and 40A MPPT controller. It also has PC control via serial to an Arduino with a relay board, the control software is written in python.
|
Master DC Control Panel |
|
WS2812B 24 LED RGB Ring apx 8cm for status signal |
|
Software running on desktop and android |
The python code
#!/usr/bin/python3
#
-
# Python Ver 3
# Linux Systems
# Author Mark 'POCKETS' Clohesy
-
#
################################################################################################################
#
# This is a linux CLI program sends serial commands to the an arduino that switches a
# radio shack control panel via a relay control board.
#
# It uses the letters A-F. Uppercase turns the relay on while lowercase turns it off the panel
# has 6 swirches and relays hence A-F. A CLI program was choosen over a GUI as the code can be modified
# with pygame to have a GUI or broken down in to small parts and modules that would allow control with
# things like cron or ifttt makers channel in the future.
#
# These are the devices that are being controlled
#
# A- Radio 1 FT8900
# B- Radio 2 IC2200
# C- Radio 3 FT 991
# D- Diesel Heater
# E- Accessories
# F- Not Used (Spare)
#
################################################################################################################
#
# Import Modules
import curses
from os import system, name
import serial
import time
import sys
#
#Setup Serial Port
serA = sys.argv[1]
ser = serial.Serial(
port=('/dev/ttyUSB'+serA),
baudrate = 9600,
stopbits=1,
bytesize=8,
timeout=1
)
#
#Start Main Code
def main(win):
win.nodelay(True)
key=""
win.clear()
#
# Display Main Screen showing options for the contorl panel
win.addstr("\n")
win.addstr("Twistedshack DC Control\n")
win.addstr("Menu Choices\n")
win.addstr("This program sends serial commands to the radio shack control panel\n")
win.addstr("It uses Letters A to F : Uppercase will turn the Device on and lowercase will turn it off\n")
win.addstr("There is no need to press enter after a keypress it is automatic \n")
win.addstr("A- Radio 1 FT8900\n")
win.addstr("B- Radio 2 IC2200\n")
win.addstr("C- Radio 3 FT 991\n")
win.addstr("D- Diesel Heater Warning: Make Sure it has completed the shutdwdown procedure\n")
win.addstr("E- Accessories\n")
win.addstr("F- Not Used (Spare)\n")
win.addstr("\n")
win.addstr("Key Selected:")
#Loop waiting for keypress and if valid sending it to the serial port
while 1:
try:
key = win.getkey()
win.clear()
win.addstr("\n")
win.addstr("Twistedshack DC Control\n")
win.addstr("Menu Choices\n")
win.addstr("This program sends serial commands to the radio shack control panel\n")
win.addstr("It uses Letters A to E : Uppercase will turn the Device on and lowercase will turn it off\n")
win.addstr("There is no need to press enter after a keypress it is automatic \n")
win.addstr("A- Radio 1 FT8900\n")
win.addstr("B- Radio 2 IC2200\n")
win.addstr("C- Radio 3 FT 991\n")
win.addstr("D- Diesel Heater Warning: Make Sure it has completed the shutdwdown procedure\n")
win.addstr("E- Accessories\n")
win.addstr("F- Not Used (Spare)\n")
win.addstr("\n")
win.addstr("Key Selected:")
win.addstr(str(key))
if key == "A":
ser.write(("A").encode('ascii'))
if key == "a":
ser.write(("a").encode('ascii'))
if key == "B":
ser.write(("B").encode('ascii'))
if key == "b":
ser.write(("b").encode('ascii'))
if key == "C":
ser.write(("C").encode('ascii'))
if key == "c":
ser.write(("c").encode('ascii'))
if key == "D":
ser.write(("D").encode('ascii'))
if key == "d":
ser.write(("d").encode('ascii'))
if key == "E":
ser.write(("E").encode('ascii'))
if key == "e":
ser.write(("e").encode('ascii'))
if key == "F":
ser.write(("F").encode('ascii'))
if key == "f":
ser.write(("f").encode('ascii'))
if key == os.linesep:
break
except Exception as e:
# No input
pass
curses.wrapper(main)
#EOF
No comments:
Post a Comment