Go Down

Topic: [Help] Writing analog outputs with Python (Read 671 times) previous topic - next topic

nonitus

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()
    connected= True


for digital outputs, I just type com.write('PinNumber'), but I can't find anything for PWM.

Thanks!

Grumpy_Mike

What code are you running on the Arduino?

nonitus

I just set the outputs and begin the serial tx,

Serial.begin(9600);

The basic idea is to get my pc screen avg color , and send it to a RBG strip via an arduino.

Grumpy_Mike

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.

nonitus

#4
Sep 11, 2015, 06:34 am Last Edit: Sep 11, 2015, 06:37 am by nonitus
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?

Grumpy_Mike

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.

nonitus


Robin2

Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up