title: Problem with Arduino and pySerial
body: <p>I got a problem. I recently bought an <a href="http://arduino.cc/en/Main/ArduinoBoardUno" rel="nofollow">Arduino Uno</a> board. I tried to make something funny like controlling an input from my computer. I used Python with <a href="http://pyserial.sourceforge.net/" rel="nofollow">pySerial</a> and the program is the following:</p>
  
  <pre><code>arduino = serial.Serial(portaCOM, 9600, timeout = 1)
  ... in loop -&gt;
  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"
  </code></pre>
  
  <p>The write value should send the value to my board though USB.
  The program loaded on board is:</p>
  
  <pre><code> 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 the brightness
           delay(10);
       }
   }
  </code></pre>
  
  <p>My LED is working properly. I tried with the Fade example provided by Arduino and it's working..</p>
  
  <p>I checked if the program is sending properly the data. Yes, it is. It returns the same thing I sent before.</p>
  
  <p>It should retrieve the value sent and set <code>analaogWriter(pin, VALUE)</code>, but something is wrong or not working.</p>
  
  <p>How can I fix this problem?</p>
  
  <p><strong>Solution</strong></p>
  
  <p>The Arduino code</p>
  
  <pre><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);
      }
  }
  </code></pre>
  
  <p>Python script code:</p>
  
  <pre><code>pos = self.slider.GetValue()
  arduino.write(chr(pos))
  </code></pre>
  
  <p>Thank you to everybody!! :)</p>