Hi guys, I'm new to arduino, and I was wondering how can I, if it's possible, write an analog output using Python.
So far I've got:
connected = False
usbport = 'COM3'
com = serial.Serial(usbport,9600,timeout=1)
while not connected:
serin = com.read()
for digital outputs, I just type com.write('PinNumber'), but I can't find anything for PWM.
What code are you running on the Arduino?
I just set the outputs and begin the serial tx,
The basic idea is to get my pc screen avg color , and send it to a RBG strip via an arduino.
So you need to write code at both ends. Start by looking at the communications examples in the IDE.
You sent commands from Python down the serial port and you pick them up on the Arduino and then action them. These commands can be anything you want from a single letter to many words, you make them up. The command on the Arduino for PWM is the analogWrite function call. It only works on certain pins, they are marked on the Arduino with a ~ symbol.
Thanks for all the help so far!
I've just read the dimm example, and let me see if i got it right.
From python I should send the byte (com.write(ColorNumber)) that I have to read in Arduino (serial.Read()), is that correct? In that case, how do I send/receive 3 different bytes each time?
Does it all stay in a Stack or a Buffer?
Yes that is right. To send three bytes just send them one after the other and then catch them at the other end.
Remember not to read more bytes than have arrived in the input buffer, use the serial available call to check all the bytes have been received before reading them.
Thank you for your help!
This Python - Arduino demo (http://forum.arduino.cc/index.php?topic=225329.msg1810764#msg1810764) may be useful.