How to Connect and Control an Arduino From Python!

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 พ.ย. 2023
  • Check out my follow up video 'How to Make GUIs in Python for Arduino' Here! • How to Make GUIs in Py...
    Controlling an Arduino from Python could be super useful for a wide variety of applications and using the serial control method we can easily do this in just a few lines of code! All code in both python and the Arduino IDE needed are here: github.com/plemaster01/PyDuino
    And don't forget to leave a like, subscribe to the channel, and comment what you want to see next!
    Consider becoming a super supporter of the channel at my Patreon as well!
    / lemastertech
    Thanks for watching and goodluck with your projects!!
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 67

  • @seanmcelwee5034
    @seanmcelwee5034 6 หลายเดือนก่อน +6

    Thanks for making this tutorial. This is a great generic parser to implement for most projects to easily add microcontroller sensors to l your python program

    • @lemastertech
      @lemastertech  6 หลายเดือนก่อน

      Thanks for watching! That was my hope in making it for sure!

  • @oladunk9986
    @oladunk9986 8 วันที่ผ่านมา +1

    Thank you very much for sharing this video.Very useful and just what I needed for some future projects using Raspberry Pi , Arduino, ESP32.Never done serial port programming in Python before.

    • @lemastertech
      @lemastertech  7 วันที่ผ่านมา

      You’re very welcome thank you for watching!

  • @thedarthcader7055
    @thedarthcader7055 4 วันที่ผ่านมา +1

    Thanks for making this tutorial! It was super helpful and well explained!

    • @lemastertech
      @lemastertech  3 วันที่ผ่านมา

      You’re welcome thank you so much for watching!!

  • @whitenoise3120
    @whitenoise3120 2 หลายเดือนก่อน +1

    Thank you for your time and dedication to making this video. For me it was excellent, fast and direct. Your video helps me with a project that I want to do in which I use a muscle sensor in which if the muscle sensor is activated it turns on a green LED. and when it stops receiving signal it turns off. Hopefully you can make an example of what I intend to do. Thanks for help and time.

    • @lemastertech
      @lemastertech  2 หลายเดือนก่อน

      Hi that’s an interesting application! Do you have a specific muscle sensor already specified and picked out yet? If it outputs a digital on/off signal it should be pretty easy to do but it will depend on the sensor!

  • @maciejbalawejder
    @maciejbalawejder 5 หลายเดือนก่อน +4

    Really helpful. Thanks a lot! :)

    • @lemastertech
      @lemastertech  5 หลายเดือนก่อน +1

      You're super welcome, thanks for watching!!

  • @user-rt7hc1mg2t
    @user-rt7hc1mg2t 6 หลายเดือนก่อน +1

    bro your so cool i will tell about you to all my programmer friends

    • @lemastertech
      @lemastertech  6 หลายเดือนก่อน

      Hey thank you so much haha!

  • @viniciusvieira9160
    @viniciusvieira9160 8 วันที่ผ่านมา +2

    Thanks so much bro!

    • @lemastertech
      @lemastertech  7 วันที่ผ่านมา

      You’re welcome thank you for watching!

  • @TheMadManPlace
    @TheMadManPlace 2 หลายเดือนก่อน +3

    Hi
    Bit late to the party but I only just found your channel.
    NEVER used Python but I hear that it is rather powerful so I will be going "hermit" to test it out and learn it.
    Have a few questions about both Python (and Arduino running GRBL but that is for later)
    1) Can Python run on "old" 32 bit Windows systems? - eg. WinXP, Win7 32bit.
    2) Can Python use the USB port to connect to the Arduino?
    3) Would it be possible to retrieve a file from a storage device? eg. A G-Code command list file from a HDD or memory stick.
    4) I assume that parsing strings is an easy standard function so parsing the input should be easy (in PHP it was VERY EASY)
    5) Then can I forward the commands to the Arduino so that GRBL can do its thing?
    6) Would Python be able to receive and handle returns from the GRBL on the Arduino and branch accordingly?
    I am assuming that the answer to all these things is probably a resounding YES.
    Now why am I asking?
    I need to control a CNC Router and the only PC I have is AT BEST an OLD HP Notepad that is happy with XP but can handle Win7-32bit with a LOT of coaxing.
    My aim is to write my own 32bit friendly version of GCodeSender that runs well on really old 32bit Windows machines because the only available versions that will INSTALL EASILY are all 64bit.
    To run 32bit it needs libraries that Microsoft no longer gives you and when you go to alternative source web sites my Anti-Virus has heart attacks. (I listen to my Anti-Virus software)
    And just by the way, there are A LOT of people out there with the same problem that I have - ESPECIALLY us pensioners.
    So, its off to install Python for me and I hope you had a good Easter weekend.

    • @lemastertech
      @lemastertech  2 หลายเดือนก่อน

      Hi this is a really cool project idea and the answer is definitely yes to all the questions but honestly 1-4 seem easy, but it’s 5 and 6 I’m not certain on as I haven’t done that specifically myself but doesn’t seem crazy!

  • @skjcreation24
    @skjcreation24 5 วันที่ผ่านมา +1

    Thank you so much

    • @lemastertech
      @lemastertech  3 วันที่ผ่านมา

      You’re super welcome thanks for watching!

  • @user-ed4yp6eq5k
    @user-ed4yp6eq5k 12 วันที่ผ่านมา +1

    So should I buy a arduino uno dev board and a light; can I use it with roboflow objects detection im new sorry?

    • @lemastertech
      @lemastertech  11 วันที่ผ่านมา

      That’s a good idea for a cool
      Project! You can use any Python packages you want and just send data back and forth from the arduino when you need to control the light or read sensors in!

    • @user-ed4yp6eq5k
      @user-ed4yp6eq5k 11 วันที่ผ่านมา

      @lemastertech 🤣 chief i have no clue how to do that im only good at mechanic . I'm searching yt for a code like that tho

  • @flioink
    @flioink 6 หลายเดือนก่อน +1

    As far as I know both C++ & Python are used for Arduino.
    My guess would be that C++ gets the speed advantage but for prototypes it probably doesn't matter.

    • @lemastertech
      @lemastertech  6 หลายเดือนก่อน +1

      I don’t believe the arduino IDE natively supports Python programming unless I’m not aware of that setting!! I thought generally you had to do base level setup on your arduino in their C++ format?

    • @flioink
      @flioink 6 หลายเดือนก่อน +1

      @@lemastertech Yea, I think you're right.
      There's like a translation layer from what I understood.
      Because of many Python Arduino projects here I thought the connection is "official".
      Nowadays everything except my fridge can run Python ;)

  • @rezahassani2335
    @rezahassani2335 หลายเดือนก่อน +1

    hi great tutorial.I want to make a project that is controlled with python and arduino.basically the arduino talks to python to do something and then after finishing the job the python programs talks to arduino via serial to do something and after arduino job is done the arduino sends a word via serial to python and the loop continues.this requires 2way communication between python and arduino.would you give me some tips how to do this.thank you

    • @lemastertech
      @lemastertech  หลายเดือนก่อน

      I think a read and write tutorial would be very useful between Python and arduino I can for sure try making one soon thanks for the suggestion!

  • @naivedyasharma4512
    @naivedyasharma4512 5 หลายเดือนก่อน +2

    hey loved the video! but i am getting this error can you help me out?
    this error has come due to .open() function
    self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    FileNotFoundError: [Errno 2] No such file or directory: 'COM14201'
    During handling of the above exception, another exception occurred:

    • @lemastertech
      @lemastertech  5 หลายเดือนก่อน

      Hi sorry I have not seen this before - are you using a Mac? I did mine on a PC maybe there’s an OS difference is hitting com ports??

    • @naivedyasharma4512
      @naivedyasharma4512 5 หลายเดือนก่อน

      thanks! yeah i am using a Mac@@lemastertech any suggestions how to fix it?
      raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
      serial.serialutil.SerialException: [Errno 2] could not open port COM14201: [Errno 2] No such file or directory: 'COM14201'
      why is it treating COM14201 as a file? maybe thats the problem?
      btw the best video on this topic thanks man
      appreciation it!!You have gotten a new sub

  • @dracodavidius3583
    @dracodavidius3583 16 ชั่วโมงที่ผ่านมา +1

    How to command the Arduino to read a connected sensor and send the information back to the Python program???

    • @lemastertech
      @lemastertech  14 ชั่วโมงที่ผ่านมา

      Hi that’s just reading serial data! You use serial.print() commands in your arduino IDE and then your python program just needs to listen for serial data!

  • @slslimee
    @slslimee 3 หลายเดือนก่อน +1

    Hey, Can you turn this into a GUI. For example using Tkinter? And also can you make a tutorial out of it if possible? Thanks!

    • @lemastertech
      @lemastertech  3 หลายเดือนก่อน +1

      Yes you can and I am working on a tutorial on that right now and will likely have it out this week on the channel! I’ll probably use PyGame but it would work the same using tkinter just a little difference syntax!

    • @slslimee
      @slslimee 3 หลายเดือนก่อน

      @@lemastertech Ohh okay... but is it possible to send data input from arduino to python? for example, i want to send photoresistor value on python and use the value to do certain things in the app?

  • @pzare1
    @pzare1 หลายเดือนก่อน +1

    how the program upload to arduino board?

    • @lemastertech
      @lemastertech  หลายเดือนก่อน

      Hi, how to program what to an arduino? Using relays you can just program an arduino like any other program!

  • @superpayaseria
    @superpayaseria 2 หลายเดือนก่อน +3

    Yeah but can u program an entire humanoid robot just using the arduino? With 10's of thousands of selections and options off of just one loop alone?? Like robocop?? And also anyone that wants to build robocop with me hit this up if you can code or want to be part of the team. Thx!

    • @lemastertech
      @lemastertech  2 หลายเดือนก่อน +1

      lol this is easily one of the best comments I’ve ever gotten on a TH-cam video and I can honestly say I don’t have the time or knowledge to help you build robocop but I sincerely wish you all the best 😂

  • @byteforcebuilds8213
    @byteforcebuilds8213 3 หลายเดือนก่อน +1

    Getting an "access is denied error". Any idea what could be causing that?

    • @lemastertech
      @lemastertech  3 หลายเดือนก่อน +1

      Almost certainly this is because you still have the arduino ide open! Can’t connect to two sources at once :)

  • @SeussmanCT
    @SeussmanCT หลายเดือนก่อน +1

    Weird situation, it appears when I run from arduino, both LED's immediately just turn on from start. This occurs from coding it myself and using your github Pyduino code...
    only difference is that I made the Python portion first before the Arduino...

    • @lemastertech
      @lemastertech  หลายเดือนก่อน

      Hi, this could be resolved probably by just writing LOW to both LED pins in the setup code? Is it when the arduino first powers on or when the python program first connects to the board?

  • @fineidontknowwhat8218
    @fineidontknowwhat8218 5 หลายเดือนก่อน +1

    Awesome video but is there a way you send information from Arduino to python?

    • @lemastertech
      @lemastertech  5 หลายเดือนก่อน

      Hi yes there is! The difference is just basically serial.read versus serial.write - the difference is using either transmit or receive from the arduino but it’s capable of doing both!

  • @manolo_21
    @manolo_21 6 หลายเดือนก่อน +1

    Can you do something with raspberry pi or with a game engine?

    • @lemastertech
      @lemastertech  6 หลายเดือนก่อน

      Hi! Sure I can do you have a project in mind or a preferred game engine?

  • @mohammedalyafeai7283
    @mohammedalyafeai7283 7 วันที่ผ่านมา

    I am lost Idk where should I connect each cabel and resistor

    • @lemastertech
      @lemastertech  7 วันที่ผ่านมา +1

      You make an arduino project like normal then use a serial cable to connect a regular computer to your arduino board. Don’t think you need to do anything special with a resistor

    • @mohammedalyafeai7283
      @mohammedalyafeai7283 7 วันที่ผ่านมา

      @@lemastertech yes that's clear, my issue where should I plug each cable and light, ad I'm very beginner, if you can share a picture of how they should look like I would appreciate it, because the picture that was in the video is not clear for me

  • @blueraventy
    @blueraventy 2 หลายเดือนก่อน +1

    how to apply this on ANPR system?

    • @lemastertech
      @lemastertech  2 หลายเดือนก่อน

      High are you talking about a plate recognition algorithm?? It depends on the output of data you get from that system, it might just be simple serial data but it might be more complicated than that!

    • @blueraventy
      @blueraventy 2 หลายเดือนก่อน

      @@lemastertech Yes I was talking about plate recognition. Can you please explain more on that?

  • @unknown-vq8so
    @unknown-vq8so 3 หลายเดือนก่อน +1

    How to create simple GUI with Arduino uno and python?

    • @straightforward8928
      @straightforward8928 3 หลายเดือนก่อน +1

      Man I was going to ask the same

    • @lemastertech
      @lemastertech  3 หลายเดือนก่อน +1

      This is a great question and I’d recommend using a simple PyGame or tkinter gui and then the same backing code as this video shows - I can make a video on it soon!

    • @straightforward8928
      @straightforward8928 3 หลายเดือนก่อน

      @@lemastertech please brother, actually I tried doing it by myself for 2 quiz buzzers but it isn't detecting the COM and showing the result in GUI

  • @carstenseifert2478
    @carstenseifert2478 4 หลายเดือนก่อน

    Why do you not use micropython??

    • @lemastertech
      @lemastertech  4 หลายเดือนก่อน +1

      It took 20 lines of code to do from scratch and is very useful to know how to control stuff via serial!

  • @JoqsanCastellanos
    @JoqsanCastellanos 3 หลายเดือนก่อน +2

    My Arduino resets instead of reading the serial port.

    • @lemastertech
      @lemastertech  3 หลายเดือนก่อน +1

      You mean when you run the python program it never populates you with options for serial ports, or once you select your port it never reads data?

    • @JoqsanCastellanos
      @JoqsanCastellanos 3 หลายเดือนก่อน +1

      @@lemastertech I mean when I send the data to the serial port with Python, my Arduino resets. It just doesn't work but I guess my device has some issue.

  • @SalisburyKing
    @SalisburyKing 22 วันที่ผ่านมา +1

    I think I will stick with Arduino it's easier.

    • @lemastertech
      @lemastertech  22 วันที่ผ่านมา

      I actually think arduino memory is the main reason you’d want to be able to write a python script though, you’ll find large projects or complicated functionality can’t run very well on the limited memory that comes with arduino so writing computer based scripts for more advanced functionality is very useful!

  • @sarvar_abd
    @sarvar_abd หลายเดือนก่อน +2

    I found this a bit hard tbh

    • @lemastertech
      @lemastertech  หลายเดือนก่อน

      Was it because I didn’t explain it well or just a confusing concept in your opinion??

    • @sarvar_abd
      @sarvar_abd หลายเดือนก่อน

      I reckon it has to do with my understanding of the concept, need more time maybe, but still could u go even further and make oversimplified guide on this with more details on each element maybe 😅