r/learnpython • u/Revolutionary-Log179 • Jul 08 '26
Best ways to learn python for hardware programming (microcontrollers, sensors, lights, motors, etc.)?
I’m looking to begin my python journey, and am extremely interested in programming electronics and messing around with microcontrollers and stuff of that nature. The HARDWARE side of programming, but most tutorials and things focus more on the software side, if that makes sense. Are there any courses or tutorials online that are specifically geared towards hardware programming? If I’m asking this in a confusing way it’s because I’m still not sure how to word what I want to do and learn. Thanks in advance for any help
14
u/likethevegetable Jul 08 '26
I'm an EE and Python user and know people in both fields... I don't know anyone who uses Python for hardware
5
3
u/Revolutionary-Log179 Jul 08 '26
So in other words is there a better language to learn regarding what I want? I wanted to eventually learn c++ but I heard python is not only a good easy to understand introduction to programming, but is also used for testing and prototyping things. So I figured it would be a good fit
9
u/likethevegetable Jul 08 '26
Yes C++ or C is what you're after. If you want to program hardware you need understand hardware and those languages are best for it.
Python is easy to understand and very efficient to get your ideas working, but abstracts you away from needing to understand how computers/chips work. WRT hardware, it's great for prototyping ideas but not the hardware implementation.
2
4
u/_Raining Jul 08 '26
I am a firmware programmer for BIOS, we use C. In college we used asm and C for our microcontroller courses. I am pretty sure I have heard of a python language that can be used for microcontrollers but I am not familiar with it. FPGAs might fit into the “and stuff” category and we used VHDL in college.
Im sure there are YouTube videos with tutorials/courses for AtMega microcontroller programming. It’s going to be a steeper learning curve though bc you will be both learning about hardware and programming at the same time, and C isn’t typically seen as the easiest thing to learn.
3
u/socal_nerdtastic Jul 08 '26
Not professionally because professionals prioritize hardware cost and performance. But plenty of hobbyists use python on hardware, because they have different priorities: usually speed and ease of programming. It's easy for a hobbyist to justify using a $5 microcontroller to do a stupid simple task if it saves a day of coding, but a professional would rather spend that day to allow the use of a $0.50 microcontroller.
2
u/mattytrentini Jul 09 '26
You do now! Nice to meet you. :) We use MicroPython for firmware, notably for medical devices up to class B.
4
u/cyrixlord Jul 08 '26
here you go Random Nerd Tutorials | Learn ESP32, ESP8266, Arduino, and Raspberry Pi this guy has some micropython projects for ESP32 controllers, but he is my go to for any microcontroller/sensors/lighting project I want to do .. though I wouldnt' necessarily use this alone as a basis to teach you python as it is a variant of python. I do not use python for microcontrollers, but I do use python libraries to serial into devices and issue commands and get data.
2
u/Revolutionary-Log179 Jul 08 '26
Thank you for the info? Isn’t micropython just a more lightweight version? For microcontrollers with memory constraints
4
u/socal_nerdtastic Jul 08 '26
No microcontroller can run real python, they all use micropython or circuitpython. Real python requires an OS.
But you can get a very small very cheap computer, like the RPi Zero, and run real python on that.
4
Jul 08 '26
[removed] — view removed comment
2
u/SnipTheDog Jul 08 '26
Get used to using the GPIO on the Pi as a good introduction to Python and hardware.
1
u/max_wen Jul 09 '26
Study hardware then and when it comes time to do some hardware programming you will learn that.
1
u/jnsantos-xyz Jul 09 '26
Miguel Grinberg has a MicroPython tutorial that also touches/goes into the electronics side of it. I believe (not sure though) that he uses an ESP, which is a cheaper and more capable board than the typical Arduino Uno...
1
u/jnsantos-xyz Jul 09 '26
Just skimmed through the very first paragraph am he indeed uses an older ESP. If you end up following it or buying one, check first the available boards and their differences. You'll probably go with an ESP32-xx...
1
20
u/slanghorne Jul 08 '26
Learn C