Wonderful. Today I stopped having to reboot my raspberry pi. Bonus, Codium AI took over(without me asking) and optimized the code for performance, exception handling and best practices.
Simple, but i thought would be useful. I was work at electronic company, but dont know any programming language yet. Lately learn Python as it community base good, and lot of module. Glad to know that i can use Python also on electronics (even i hear lot people python has slow performance, but stil its good for starter)
Holy smokes - this is what I've been seeking for about the last two weeks .. thank you ! Some disgruntled idiot at work decided to leave the company with his HW & SW (python) in a complete clusterfucked state of fubar. No commenting whatsoever .. what a special kind of prick, right ? Well this tutorial got me back making progress with this diaper-change of a task. Thank you again ..
Hi there, I can find only USB serial CH340 in device manager port (which is connected to COM 3. I can't find Arduino UNO in the device manager port which is why I am getting an error "'SerialException: could not open port 'COM3': PermissionError(13, 'Access is denied.', None, 5)"' . Could you please tell me how to add arduino in port ?
when i run that code i commit the error =UnboundLocalError: local variable 'commPort' referenced before assignment. your question is similar to mine. have you got solution recently my brother tell me if you got please!!!
interesting video. I tried this without changing code but when I run it the following error is found. Cell In[4], line 17 connectPort=findArduino(foundPorts) Cell In[4], line 15 in findArduino return commPort UnboundLocalError: local variable 'commPort' referenced before assignment ****how could it be resolved tell me please!!!!!!!
I'm on a mac and the USB devices are read differently. How could one modify this code to use the USB's Manufacturer information to automate finding the Arduino? The following code seems to do the trick, but how can one have python double-check the connection? Thank you for your help! import serial.tools.list_ports def findArduino(manufacturer): for pinfo in serial.tools.list_ports.comports(): if pinfo.manufacturer == manufacturer: return serial.Serial(pinfo.device) raise IOError("Could not find an arduino - is it plugged in?") ser = findArduino(manufacturer='Arduino (www.arduino.cc)')
HELLO @WaveShapePlay PLEASE TELL ME HOW TO FIX THE ERROR: "typeerror 'generator' object is not subscriptable" AT LINE 18: port= foundports[i] please reply
@@Priyanka-hf2qm I know it's a little late, but perhaps if you cast it with list(foundports)[i] it might work. The other thing is possibly if it didn't find any ports, it might throw that error (just a guess).
if they were different types you could do if 'Arduino Uno' if 'Genuino' etc... if they were the same type, i am not sure. posibly it would be Aduino (1) and adiuno (2)
i was just looking for the exact video but i dident know what to type in to search for it and it appeared on my screen when i logged into utub. THANK YOU but in Linux or Ubuntu it displays its port in arduino.
@@WaveShapePlay hey quick question, on my device manager my arduino is just showing up as USB serial device but in the IDE the board is recognised. I’m on windows 10, I can’t find any quick fixes online. Do you know how to sort this? Thanks :) I’ll be using pyserial on a bunch of PCs and trying to automate stuff so it would be nice if the port is named as “COM3 (Arduino Uno)” or whatever.
That is Interesting. I did find a Arduino forum thread that is trying to solve that exact issue here: forum.arduino.cc/t/device-description-under-device-manager-windows/73011/7 It looks like the .INF file in the arduino drivers helps define how windows defines the device. I have not personally tried this solution yet, but it is worth a try!
Any suggestion group of people work with these kind arduino n python stuff to join, this library kind a least update, im not to familiar with javascript or johhny5, thank u, my appologize if my text seem worst
HI, excellent video. When i try to run the code i get this error: ModuleNotFoundError: No module named 'serial.tools', I have installed the PySerial library but the error keeps showing up. Has it happened to anyone ? Thanks.
@@annikenkvalsund5393 My problem was in the python version. At first I installed the latest version of python, but then I found that the version was not compatible with w10, so I went looking for a compatible version, then I reinstalled everything including the Pyserial packages again.
why you need to parse some output of __str__ if you can directly access list_ports_common.ListPortInfo fields? Your "code reuse" just obscures real meaning of what that function does def find_port_by_description(substring): port: list_ports_common.ListPortInfo for i, port in enumerate(list_ports.comports()): if substring in port.description: return port.device return None that would be much cleaner solution in my opinion
I use the following function which will find genuine Arduino boards and clones using the CH340 and CP210 USB to serial chips. def find_arduino(): ports_found = serial.tools.list_ports.comports() port = 'None' look_for = ["Arduino", "CH340", "CP210"] type = None for l in look_for: for p in ports_found: str_port = str(p) if l in str_port: type = l port = str_port.split(' ')[0] break if port != "None": break return port, type
you created very nice function !! let me ask you, after executing this function how can you access the port found? or, how can I incoporate your function to the code=ser= serial.Serial( ,9600)? I am waiting to your response please tell me!!!
@@SolomonTeklehaimanot-d8f Hi. I assume you realise that you need to load the arduino with a sketch that can receive commands and return data via its serial port. In the python program, my function looks for ports that could be connected to an arduino or clone. It returns a tuple, where the first element is a string with the port name found, i.e. "CH340". If the name is "None", no port was found. The second element in the tuple is the port name, i.e. "Com 4". You use this in your pyserial com port open command. Hope this helps.
Wonderful. Today I stopped having to reboot my raspberry pi. Bonus, Codium AI took over(without me asking) and optimized the code for performance, exception handling and best practices.
Simple, but i thought would be useful. I was work at electronic company, but dont know any programming language yet. Lately learn Python as it community base good, and lot of module. Glad to know that i can use Python also on electronics (even i hear lot people python has slow performance, but stil its good for starter)
Hello from India... Thank you very much for this easy to understand and very helpful video.
Hello my friend, thank you for watching!
Its refreshing to realize Im getting good enough to troubleshoot the program if something isn't going right
Holy smokes - this is what I've been seeking for about the last two weeks .. thank you !
Some disgruntled idiot at work decided to leave the company with his HW & SW (python) in a complete clusterfucked state of fubar. No commenting whatsoever .. what a special kind of prick, right ?
Well this tutorial got me back making progress with this diaper-change of a task. Thank you again ..
This is my favorite comment of all time! Glad you found it useful my friend.
AT LINE 18: port= foundports[i] should be replace by portsfound[i]
EXACTLY WHAT I WAS SEARCHING FOR!!!!
Thank you Hetal! I'm glad to hear!
Hi there, I can find only USB serial CH340 in device manager port (which is connected to COM 3. I can't find Arduino UNO in the device manager port which is why I am getting an error "'SerialException: could not open port 'COM3': PermissionError(13, 'Access is denied.', None, 5)"' . Could you please tell me how to add arduino in port ?
Hi! I have the same problem, Have you found a solution?
when i run that code i commit the error =UnboundLocalError: local variable 'commPort' referenced before assignment. your question is similar to mine. have you got solution recently my brother tell me if you got please!!!
Thanks ...very much
your simple code
to be easy learn and correct program
interesting video.
I tried this without changing code but when I run it the following error is found.
Cell In[4], line 17
connectPort=findArduino(foundPorts)
Cell In[4], line 15 in findArduino
return commPort
UnboundLocalError: local variable 'commPort' referenced before assignment
****how could it be resolved tell me please!!!!!!!
I'm on a mac and the USB devices are read differently. How could one modify this code to use the USB's Manufacturer information to automate finding the Arduino? The following code seems to do the trick, but how can one have python double-check the connection? Thank you for your help!
import serial.tools.list_ports
def findArduino(manufacturer):
for pinfo in serial.tools.list_ports.comports():
if pinfo.manufacturer == manufacturer:
return serial.Serial(pinfo.device)
raise IOError("Could not find an arduino - is it plugged in?")
ser = findArduino(manufacturer='Arduino (www.arduino.cc)')
HELLO @WaveShapePlay
PLEASE TELL ME HOW TO FIX THE ERROR: "typeerror 'generator' object is not subscriptable" AT LINE 18: port= foundports[i]
please reply
anyone there??, please reply, I am in need.
@@Priyanka-hf2qm I know it's a little late, but perhaps if you cast it with list(foundports)[i] it might work. The other thing is possibly if it didn't find any ports, it might throw that error (just a guess).
@@TechnoTinker i ran into the same problem but this works indeed
Replace the statment 'port = foundPorts[i]' by 'port = portsFound[i]'
Hi, thanks for the good videos!
Do you have an idea how I can identify multiple Arduinos on the same Host and connect do a defined Arduino?
if they were different types you could do
if 'Arduino Uno'
if 'Genuino'
etc...
if they were the same type, i am not sure. posibly it would be Aduino (1) and adiuno (2)
i was just looking for the exact video but i dident know what to type in to search for it and it appeared on my screen when i logged into utub. THANK YOU but in Linux or Ubuntu it displays its port in arduino.
Is there a way to have this work on either mac or windows devices?
This list ports function is hidden in the documentation, thanks for sharing this!
Thank you for watching!
@@WaveShapePlay hey quick question, on my device manager my arduino is just showing up as USB serial device but in the IDE the board is recognised. I’m on windows 10, I can’t find any quick fixes online. Do you know how to sort this? Thanks :)
I’ll be using pyserial on a bunch of PCs and trying to automate stuff so it would be nice if the port is named as “COM3 (Arduino Uno)” or whatever.
That is Interesting. I did find a Arduino forum thread that is trying to solve that exact issue here:
forum.arduino.cc/t/device-description-under-device-manager-windows/73011/7
It looks like the .INF file in the arduino drivers helps define how windows defines the device. I have not personally tried this solution yet, but it is worth a try!
@@WaveShapePlay thank you!!!
excellent, great work!
i am getting empty list like [ ], how to solve this
Any suggestion group of people work with these kind arduino n python stuff to join, this library kind a least update, im not to familiar with javascript or johhny5, thank u, my appologize if my text seem worst
HI, excellent video. When i try to run the code i get this error: ModuleNotFoundError: No module named 'serial.tools', I have installed the PySerial library but the error keeps showing up. Has it happened to anyone ? Thanks.
That happens to me too! Did you find any solution?
@@annikenkvalsund5393 My problem was in the python version.
At first I installed the latest version of python, but then I found that the version was not compatible with w10, so I went looking for a compatible version, then I reinstalled everything including the Pyserial packages again.
@@Mecatronicgarage Thanks! I reinstalled python and every package, too, that seemed to do the deal
Excellent buddy!
What is the problem here? AttributeError: module 'serial' has no attribute 'Serial' ??????
Helped a Lot
Goat
Thanks a lot. Please leave a link to the program code in another video.
You got it! Here is the link for convenience: github.com/WaveShapePlay/ArduinoPyserialComConnect
thanks good script i'll use it for make my own arduino serial monitor
Glad to hear!
Do you arduino code for the arduino in this video.?
why you need to parse some output of __str__ if you can directly access list_ports_common.ListPortInfo fields?
Your "code reuse" just obscures real meaning of what that function does
def find_port_by_description(substring):
port: list_ports_common.ListPortInfo
for i, port in enumerate(list_ports.comports()):
if substring in port.description:
return port.device
return None
that would be much cleaner solution in my opinion
I use the following function which will find genuine Arduino boards and clones using the CH340 and CP210 USB to serial chips.
def find_arduino():
ports_found = serial.tools.list_ports.comports()
port = 'None'
look_for = ["Arduino", "CH340", "CP210"]
type = None
for l in look_for:
for p in ports_found:
str_port = str(p)
if l in str_port:
type = l
port = str_port.split(' ')[0]
break
if port != "None":
break
return port, type
you created very nice function !! let me ask you, after executing this function how can you access the port found? or, how can I incoporate your function to the code=ser= serial.Serial( ,9600)? I am waiting to your response please tell me!!!
@@SolomonTeklehaimanot-d8f Hi. I assume you realise that you need to load the arduino with a sketch that can receive commands and return data via its serial port. In the python program, my function looks for ports that could be connected to an arduino or clone. It returns a tuple, where the first element is a string with the port name found, i.e. "CH340". If the name is "None", no port was found.
The second element in the tuple is the port name, i.e. "Com 4". You use this in your pyserial com port open command. Hope this helps.
Спасибо за этот гайд !
Пожалуйста
I LOVE U, MAN
Love goes both ways my friend!
In line 21 change 'Arduino' to 'CH340' for chines clone boards.
I have added a 'if else' block that first looks for 'Arduino' then CH340 and finally 'CP210X'.
thanks man