![]() |
Serial Python and Arduino - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Serial Python and Arduino (/thread-2495.html) |
Serial Python and Arduino - delfar - Mar-21-2017 Hello, I am trying to write a base program that will connect to an Arduino, Via Serial, and will send and receive data. For some reason though, I can't seem to get Python to connect with the Arduino Uno. Here is the code I have, and the error that I get. If anyone knows a possible solution, any help would be great! import serial connected = False ser = serial.Serial("COM3", 19200) while not connected: serin = ser.read() connected = True myStr = "1" asBytes = str.encode(myStr) ser.write(asBytes) while ser.read() =='1': ser.read() ser.close
RE: Serial Python and Arduino - wavic - Mar-22-2017 Hello! Try to run the script with administrative privileges. See the bottom line of the error message. RE: Serial Python and Arduino - j.crater - Mar-22-2017 Another possibility is you have Serial monitor opened in Arduino IDE on same port. Then your Python program can't use this port at same time, so you should close the Serial monitor first. RE: Serial Python and Arduino - Larz60+ - Mar-22-2017 Getting a serial port to work for you can take some time in the beginning. Once working you forget about it as the reliability factor is high. The handshaking must be correct. I use putty (http://www.putty.org/) to get it right in the beginning. You can play with the various protocol like baud rate, parity, word length, number of stop bits etc. without having to rewrite code, Once you get it right, write your code. RE: Serial Python and Arduino - delfar - Mar-22-2017 (Mar-22-2017, 12:58 PM)Larz60+ Wrote: Getting a serial port to work for you can take some time This is helpful, but do you know of any good documentation on how to use the software? (Mar-22-2017, 12:07 AM)wavic Wrote: Hello! Suggestions on code that would run it with permissions? RE: Serial Python and Arduino - Larz60+ - Mar-22-2017 Putty user manual: https://the.earth.li/~sgtatham/putty/0.63/htmldoc/ Another thing that I noticed you are trying to open com3. Usually the first com port is number 1, you normally only use com3 if you actually have more that two com ports (two is common, 3 is not unheard of). Make sure that you actually have a com3. One way to find out is to look at your device drivers. And while doing do, if you have a com3, test the driver (there is an option in the drivers menu) RE: Serial Python and Arduino - delfar - Mar-22-2017 (Mar-22-2017, 07:50 PM)Larz60+ Wrote: Putty user manual: https://the.earth.li/~sgtatham/putty/0.63/htmldoc/ Thank you for the manual, The Arduino board is listed under COM3 and I have another connected to COM7 RE: Serial Python and Arduino - Larz60+ - Mar-23-2017 With putty, you should within seconds be able to see if you can talk to the device on the other side. Only seconds (1 hour = 3600 sceonds) |