Python Forum
Controlling an Arduino with Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Controlling an Arduino with Python
#1
So while looking for some arduino assistance lastnight, i ran across some videos showing how to control an ardunio with python code..
All the videos i found where mostly showing you how to import the libraries into python to communicate with the board..

BUT i couldn't find anything specific to what the board needs in order to work.

I have done plenty of projects with arduinos and all my projects were coded in the arduino sketches..

So my question is, does the board still require a sketch to be uploaded to the board? and if so, what purpose would python play in communicating with the board?

I guess i just need to know if i need to build my whole project code in the sketch and upload to the board and then python is just used to get that data out easier and do something with it?

Just trying to wrap my head around the purpose of python with arduino..

Im not looking for any examples or help getting this to work.. just a simple explanation as to how or why i would want or need to use python with any of my arduino projects.
Reply
#2
which board? I use ESP8266's quite a bit. It comes setup to use Arduino.
I burn micro-python onto the flash memory and use thonny for development.
Works great.
Reply
#3
(Mar-18-2022, 10:25 PM)Larz60+ Wrote: which board? I use ESP8266's quite a bit. It comes setup to use Arduino.
I burn micro-python onto the flash memory and use thonny for development.
Works great.


So do you control and write everything in python?
Reply
#4
yes,
here's a typical program to simply light four RGB Leds using GPIO port 5, all to a different color:
This is from https://RandomNerdTutorials.com
import machine, neopixel

n = 4
p = 5

np = neopixel.NeoPixel(machine.Pin(p), n)

np[0] = (255, 0, 0)
np[1] = (125, 204, 223)
np[7] = (120, 153, 23)
np[10] = (255, 0, 153)
np.write()
Reply
#5
(Mar-18-2022, 01:40 PM)cubangt Wrote: So while looking for some Arduino assistance last night, I ran across some videos showing how to control an Arduino with python code.
All the videos I found where mostly showing you how to import the libraries into python to communicate with the board.

One way is to control the Microcontroller with Python, where your PC is the Master and the Arduino is the slave, which is controlled.

pyFirmata


Quote:BUT i couldn't find anything specific to what the board needs in order to work.
Quote:So my question is, does the board still require a sketch to be uploaded to the board?
Yes.
Follow these instructions: http://firmata.org/wiki/Main_Page
You need to put the Arduino Firmata Sketch on your Arduino.

If you want to use Python directly on a Microcontroller, the Arduino is too small. It has not enough memory and flash.

MicroPython is a Python implementation for Microcontrollers like the PyBoard, ESP32, ESP8266, STM32 and many more. The benefit of the ESP32 and ESP8266 controllers is the 2.4GHz WiFi connectivity. You can get this modules below 10$. This week I bought 3 new modules for 24 €.

@no referer link, in your region you'll find maybe better prices
https://www.amazon.de/dp/B074RGW2VQ/

You should also buy jumper wires and a breadboard.
The boards are supplied with 5V over USB. You can also supply the board with a rechargeable LiPo-Battery.
All GPIO are using 3.3V. 5V on a GPIO will kill the board. This difference is critical, if you use for example 5V sensors. In this case, you have to reduce the signal voltage to 3.3V. Otherwise, you need a new microcontroller.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#6
yea so i watched a few videos this weekend on firmata and think i understand now..So the videos i watched showed how to setup everything and it seems that the only thing once the firmata sketch was loaded on the uno, the rest of the code was writting within python on the guys computer and he was sending/executing commands from his .py file to set pins high and low.. and never once did he upload another sketch..

Is that correct to say that once you load the basic firmata sketch onto the board, the code and logic can all be done within the python file/script and run it from there since you already have the serial com setup and communicating?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  ARDUINO via Python: Dissapointing ironfelix717 1 1,650 May-02-2020, 06:55 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020