python - Problem with Arduino and pySerial -


i got problem. bought arduino uno board. tried make funny controlling input computer. used python pyserial , program following:

arduino = serial.serial(portacom, 9600, timeout = 1) ... in loop -> arduino.write(value)     def sliderupdate(self, event):         pos = self.slider.getvalue()         arduino.write(pos)         time.sleep(.1)         print arduino.readline()  try:     arduino = serial.serial(portacom, 9600, timeout = 1) except:     print "errore di connessione alla porta seriale" 

the write value should send value board though usb. program loaded on board is:

 const int ledpin = 11;  byte brightness;   void setup(){      serial.begin(9600);      pinmode(ledpin, output);  }   void loop(){      while(serial.available()){          brightness = serial.read();          serial.print(brightness);          analogwrite(ledpin, brightness); //led doesn't refresh brightness          delay(10);      }  } 

my led working properly. tried fade example provided arduino , it's working..

i checked if program sending data. yes, is. returns same thing sent before.

it should retrieve value sent , set analaogwriter(pin, value), wrong or not working.

how can fix problem?

solution

the arduino code

const int ledpin = 11; byte valoreled;  void setup(){     serial.begin(9600);     pinmode(ledpin, output); }  void loop(){     while(serial.available()){         valoreled = serial.read();         analogwrite(ledpin, valoreled);         delay(20);     } } 

python script code:

pos = self.slider.getvalue() arduino.write(chr(pos)) 

thank everybody!! :)

  1. first of all, make sure led connected. anode (longer pin) pwm 11 port , cathode (shorter pin) ground, may need add resistor between cathode , ground depending on led.
  2. make sure you're writing right port python (that ftdi cable associated in os).
  3. if you're not using ftdi cable usb connector, make sure of pins connected right inputs.
  4. what value of value in example? try arduino.write(chr(0xff)), led stay lit?

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -