Thursday, May 7, 2020

DC Control Panel

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

  1. #!/usr/bin/python3
  2. #
  3. # Python Ver 3
  4. # Linux Systems
  5. # Author Mark 'POCKETS' Clohesy
  6. #
  7. ################################################################################################################
  8. #
  9. # This is a linux CLI program sends serial commands to the an arduino that switches a
  10. # radio shack control panel via a relay control board.
  11. #
  12. # It uses the letters A-F. Uppercase turns the relay on while lowercase turns it off the panel
  13. # has 6 swirches and relays hence A-F. A CLI program was choosen over a GUI as the code can be modified
  14. # with pygame to have a GUI or broken down in  to small parts and modules that would allow control with
  15. # things like cron or ifttt makers channel in the future.
  16. #
  17. # These are the devices that are being controlled
  18. #
  19. # A- Radio 1 FT8900
  20. # B- Radio 2 IC2200
  21. # C- Radio 3 FT 991
  22. # D- Diesel Heater
  23. # E- Accessories
  24. # F- Not Used (Spare)
  25. #
  26. ################################################################################################################
  27. #
  28. # Import Modules
  29. import curses
  30. from os import system, name
  31. import serial
  32. import time
  33. import sys
  34. #
  35. #Setup Serial Port
  36. serA = sys.argv[1]
  37. ser = serial.Serial(
  38.     port=('/dev/ttyUSB'+serA),
  39.     baudrate = 9600,
  40.     stopbits=1,
  41.     bytesize=8,
  42.     timeout=1
  43. )
  44. #
  45. #Start Main Code
  46. def main(win):
  47.     win.nodelay(True)
  48.     key=""
  49.     win.clear()
  50. #
  51. # Display Main Screen showing options for the contorl panel
  52.     win.addstr("\n")
  53.     win.addstr("Twistedshack DC Control\n")
  54.     win.addstr("Menu Choices\n")
  55.     win.addstr("This program sends serial commands to the radio shack control panel\n")
  56.     win.addstr("It uses Letters A to F : Uppercase will turn the Device on and lowercase will turn it off\n")
  57.     win.addstr("There is no need to press enter after a keypress it is automatic \n")
  58.     win.addstr("A- Radio 1 FT8900\n")
  59.     win.addstr("B- Radio 2 IC2200\n")
  60.     win.addstr("C- Radio 3 FT 991\n")
  61.     win.addstr("D- Diesel Heater Warning: Make Sure it has completed the shutdwdown procedure\n")
  62.     win.addstr("E- Accessories\n")
  63.     win.addstr("F- Not Used (Spare)\n")
  64.     win.addstr("\n")
  65.     win.addstr("Key Selected:")
  66. #Loop waiting for keypress and if valid sending it to the serial port
  67.     while 1:
  68.         try:
  69.            key = win.getkey()
  70.            win.clear()
  71.            win.addstr("\n")
  72.            win.addstr("Twistedshack DC Control\n")
  73.            win.addstr("Menu Choices\n")
  74.            win.addstr("This program sends serial commands to the radio shack control panel\n")
  75.            win.addstr("It uses Letters A to E : Uppercase will turn the Device on and lowercase will turn it off\n")
  76.            win.addstr("There is no need to press enter after a keypress it is automatic \n")
  77.            win.addstr("A- Radio 1 FT8900\n")
  78.            win.addstr("B- Radio 2 IC2200\n")
  79.            win.addstr("C- Radio 3 FT 991\n")
  80.            win.addstr("D- Diesel Heater Warning: Make Sure it has completed the shutdwdown procedure\n")
  81.            win.addstr("E- Accessories\n")
  82.            win.addstr("F- Not Used (Spare)\n")
  83.            win.addstr("\n")
  84.            win.addstr("Key Selected:")
  85.            win.addstr(str(key))
  86.            if key == "A":
  87.              ser.write(("A").encode('ascii'))
  88.            if key == "a":
  89.              ser.write(("a").encode('ascii'))
  90.            if key == "B":
  91.              ser.write(("B").encode('ascii'))
  92.            if key == "b":
  93.              ser.write(("b").encode('ascii'))
  94.            if key == "C":
  95.              ser.write(("C").encode('ascii'))
  96.            if key == "c":
  97.              ser.write(("c").encode('ascii'))
  98.            if key == "D":
  99.              ser.write(("D").encode('ascii'))
  100.            if key == "d":
  101.              ser.write(("d").encode('ascii'))
  102.            if key == "E":
  103.              ser.write(("E").encode('ascii'))
  104.            if key == "e":
  105.              ser.write(("e").encode('ascii'))
  106.            if key == "F":
  107.              ser.write(("F").encode('ascii'))
  108.            if key == "f":
  109.              ser.write(("f").encode('ascii'))
  110.            if key == os.linesep:
  111.               break
  112.         except Exception as e:
  113.            # No input
  114.            pass
  115. curses.wrapper(main)
  116. #EOF