Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><a href="http://pyserial.sourceforge.net/" rel="nofollow">pySerial</a> may or may not be built in to Python. Regardless, if it's not, pySerial is the library to download and install.</p> <p>And since you already know the Arduino is on COM3, just use this:</p> <pre><code>import serial ser = serial.Serial("COM3", 19200, timeout=1) ser.write("Whatever") </code></pre> <p>For a Linux box, it's relatively easy to find out what serial port your Arduino is using:</p> <pre><code>dmesg | grep tty </code></pre> <p>This will give you some output similar to this: <code>[ 7.944654] usb 1-1.6: FTDI USB Serial Device converter now attached to ttyUSB0</code></p> <p>So my Arduino is on ttyUSB0. This means you can use the following code to talk to the Arduino on a Linux box:</p> <pre><code>import serial ser = serial.Serial("/dev/ttyUSB0", 19200, timeout=1) ser.write("Whatever") </code></pre> <p>Note: If you use a baud rate of 9600 on the Arduino, as most people do, you can simply use <code>serial.Serial("COM3")</code> or <code>serial.Serial("/dev/ttyUSB0")</code> without any other parameters.</p> <p>EDIT: You should also keep in mind that in the real world, it may take a second to actually open the port and get it ready for transmitting data. This means that performing a write IMMEDIATELY after the serial.Serial() call may not actually do anything. So the code I would use is as follows:</p> <pre><code>import serial import time ser = serial.Serial("/dev/ttyUSB0", 19200, timeout=1) time.sleep(1.5) ser.write("Whatever") </code></pre> <p>Kind of a hack, but it's the only way I know how to get it to work on my system.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload