Python + Arduino =?

Hi
I have took a decision to learn python and started it.So i already know that raspberry pi uses python and have done some before too... :sweat_smile:
So today my question is how to code arduino in python? Is it possible to code arduino in python? And if its possible should I add a new software or use the same arduino IDE ?
Thats for today and thanks ! :grinning:

That depends on what you mean by "arduino". Which board do you have in mind to use ? In any case you cannot use the Arduino IDE to code in Python

My RPis mostly use C and C++

It's much easier to write programs in python on a computer, and send commands to arduino via Serial or Firmata.
You can read the manual here Arduino With Python: How to Get Started

2 Likes

Uno and nano

Neither support running Python due not least to the limited memory available

???
What does that mean?

It means that you cannot run Python on them. However, as has been suggested, you could connect to them with Python running on a PC and use the Arduino to collect data for processing in Python

If you really want to run Python on a microcontroller then get something like an ESP32 or a Raspberry Pi Pico

Look at the Adafruit site - they have some devices that run MicroPython.

In general:

  1. Python requires at least a 32bit processor (Due, Zero, etc)

  2. Python requires significant flash space for the interpreter.

  3. Python requires significant RAM available at run-time.

  4. Python requires additional storage space for the libraries it uses, meaning some sort of file system in flash, and enough "extra" flash to hold significant content.

To implement this, the Adafruit boards (they are very big on "Circuit Python") use at least a SAMD ARM chip, PLUS an additional external flash memory chip. A "faster" ARM chip with more RAM, like the SAMD51 or RP2040, is desireable.

Python will also run on ESP8266 or ESP32 boards, and some others, but you CAN NOT run Python programs on the popular AVR-Based Arduinos like the Uno and Nano.

Programming languages are tools. Just like other tools not every task can be done using the same tool with the same efficiency. Some tools are better at one thing than others.

This is a good chance for you to learn a second programming language and discover what they have in common and what makes them different. Learning your third or fourth programming language will become even easier. :slight_smile: And there will be reasons to do so in your future.

Arduinos are programmed in C/C++ and you can do a lot with just a few basic C/C++ programming constructs. A lot of the work has been done for you by the Arduino team. C/C++ are low level programming languages and are better suited for the typical applications covered by microcontrollers. They require little memory and processor cycles on top of the applications code itself.

On a Raspberry Pi or PC, you can afford to waste a few million processor cycles and a few MB of RAM to get Python running. In return you can be a bit lazier while programming and if you do something stupid there is always an operating system to save you. It is a bit like the matrix.

Arduino C/C++ is the real world. Do you want the blue or the red pill? :slight_smile:

wait a sec!!!
does taht mean i can not code with python but one user @Boffin said it is possible!
im getting really confused, :thinking: :thinking: :thinking:

Python + Arduino scheme.
In any case, you must upload C ++ sketch to Arduino. There are a very large number of ready-made sketches in the Arduino IDE examples and on the net.
This sketch:

  • receives commands from the computer using the Serial protocol and controls the Arduino pins.
  • Receives data from Arduino sensors and transmits them to the computer through the Serial.

The advantage of this scheme is that you write the main program in your favorite Python.
The disadvantage is that the Arduino must always be connected to the computer.

Where did he/she say that ?

umm....
the 3rd reply?

That says no such thing