I am controlling some LEDs via the USB serial port using a Tkinter/Python3x script to debug what I suspect is a hardware problem.
from tkinter import * import serial usbport = 'COM3' ser = serial.Serial(usbport, 9600, timeout=1) def init(): print("Started") class App: def __init__(self, master): frame = Frame(master) frame.pack() self.scale1 = Scale(master, from_=0, to=255, command=lambda ev: self.getBright(1), bd=5, bigincrement=2, length=360, width=30, label='RED') self.scale1.set(128) self.scale1.pack(side=LEFT) self.scale2 = Scale(master, from_=0, to=255, command=lambda ev: self.getBright(2), bd=5, bigincrement=2, length=360, width=30, label='GREEN') self.scale2.set(128) self.scale2.pack(side=LEFT) self.scale3 = Scale(master, from_=0, to=255, command=lambda ev: self.getBright(3), bd=5, bigincrement=2, length=360, width=30, label='BLUE') self.scale3.set(128) self.scale3.pack(side=LEFT) self.centre = Button(frame, text="Centre All", command=self.centre) self.centre.pack(side=TOP) def getBright(self, slider): if slider==1: brt = self.scale1.get() if slider==2: brt = self.scale2.get() if slider==3: brt = self.scale3.get() ser.write(255) ser.write(slider) ser.write(brt) def centre(self): for LED in range(0, 4): ser.write(255) ser.write(LED) ser.write(128) self.scale1.set(128) self.scale2.set(128) self.scale3.set(128) init() root = Tk() app = App(root) root.mainloop() On the Arduino Mega 2560 side I read in from serial a start byte, LED label & a brightness value...
int user_input[3]; int start_byte; int LED; // which LED to pulse? r=1 g=2 b=3 int brightness; int i; // LED pins #define REDPIN 7 #define GREENPIN 8 #define BLUEPIN 9 void setup() { // LED outputs pinMode(REDPIN, OUTPUT); pinMode(GREENPIN, OUTPUT); pinMode(BLUEPIN, OUTPUT); Serial.begin(9600); } void loop() { if (Serial.available() > 2) { start_byte = Serial.read(); if (start_byte == 255) { for (i = 0; i < 2 ; i++) { user_input[i] = Serial.read(); } LED = userInput[0]; brightness = user_input[1]; switch (LED) { case 1: analogWrite(REDPIN, brightness); break; case 2: analogWrite(GREENPIN, brightness); break; case 3: analogWrite(BLUEPIN, brightness); break; } } } } Now I would like to see what is actually being sent via the serial port to the Arduino using the serial monitor (yes I know I can just print the values in the Python terminal that's not what I'm asking).
The problem is that the Arduino Serial Monitor is locked out. I'm guessing this is a Windows thing (Win10 x64)? Has anybody here come across this?