title: Arduino serial communication and Python
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1618141/pyserial-problem-with-arduino-works-with-the-python-shell-but-not-in-a-program">Pyserial problem with Arduino - works with the Python shell but not in a program</a>  </p>
  </blockquote>
  
  
  
  <p>So I just got myself an <a href="http://arduino.cc/en/Main/ArduinoBoardUno" rel="nofollow noreferrer">Arduino Uno</a>, and now I'm trying to communicate with it using <a href="http://en.wikipedia.org/wiki/Universal_Serial_Bus" rel="nofollow noreferrer">USB</a>. I've got it working with the Serial Monitor provided by the Arduino IDE, and now I'm testing it with <a href="http://en.wikipedia.org/wiki/Python_%28programming_language%29" rel="nofollow noreferrer">Python</a>.</p>
  
  <p>The program should make a LED on the board blink when it read data from the USB.</p>
  
  <p>The way I do it is:</p>
  
  <pre><code>#!/usr/bin/env python
  import serial
  
  ser = serial.Serial("/dev/ttyACM0", 9600)
  ser.write("something")
  </code></pre>
  
  <p>This doesn't work, but doing each step in the interactive shell works:</p>
  
  <pre><code>&gt;&gt;&gt; import serial
  &gt;&gt;&gt; ser = serial.Serial("/dev/ttyACM0", 9600)
  &gt;&gt;&gt; ser.write("something")
  </code></pre>
  
  <p>I've tried using a timeout in the script before closing, but that didn't help. What am I doing wrong?</p>