35

I am not very skilled with the C Language and I was wondering if there is a way in which python could be used to program an Arduino. This would most likely require a different IDE in order to be able to debug the scripts them self.

  • 2
    There are couple alternatives for programming Arduino, one of them is BitLash and there is a basic interpreter. There are couple options when you search the Internet, but learning C/C++ will pay off in the end. – jippie Feb 12 '14 at 17:06
  • Thanks, I am actually getting a bit better at C, just not as good as I am with Python. – JVarhol Feb 12 '14 at 17:07
  • 2
    related, more general question: "Arduino programming options other than C++" – David Cary Feb 15 '14 at 4:15
  • Is a raspberry PI an option? – Paul May 21 '15 at 12:12
26

It's going to be extremely difficult to get any kind of Python script running directly on the Arduino. The reason is that it's an interpreted language, so you would need the interpreter on-board in addition to the plain text script. There's probably not going to be enough memory for all of that.

Your best bet would probably be finding a way to compile a Python script to native machine code (which is how C/C++ works). I believe there are projects around to do something like that for other platforms, but (as far as I know) none which does it successfully for Arduino yet.

You might find some more useful information on this question at Stack Overflow: Is there a way to "compile" Python code onto an Arduino (Uno).

15

Yes, it is (somewhat) possible to program the Arduino using Python. One such project on Github is the Python Arduino Prototyping API v2. It provides very basic functionality such as digital I/O and analog I/O.

This can be used for very simple projects.


*This project is a bit of a hack at "programming" the board using the serial connection. It passes the commands over the serial connection to a sketch running on the board which then "executes" the Python command.

  • So the board has to be plugged into a computer in order to actually run the code? – JVarhol Feb 12 '14 at 16:19
  • @JVarhol Oddly, yes. – asheeshr Feb 12 '14 at 16:23
  • 1
    Well, that pretty crappy. It would be easier to use a Raspberry Pi. – JVarhol Feb 12 '14 at 16:25
8

There is a project which brings a Python virtual machine to micro-controllers, including the Arduino Mega.

Here's a quote from the Ardunio Mega README, which gives a feel for what this could be like (though, I've not tested this!):

The following is an example session using ipm::

ipm> import avr, sys
ipm> avr.ddrA(0xff)
ipm> avr.portA(0)       # Pins 22-29 all at 0 V
ipm> avr.portA(0xa5)
ipm> sys.heap()
(2622, 7424)
3

I have used pyserial with great success in controlling the pins on the arduino. Your workstation (laptop, etc) runs a python script that then communicates in real time to the arduino.

It's not quite the same as running the script directly on the arduino but I was doing quite a bit more than I thought the arduino could handle (some music analysis, hitting a REST api, etc).

3

Another option to consider is the Arduino Yun. In addition to the AVR chip which most Arduinos have, it also includes a MIPS chip running Linux. Since it's linux, you can easily run python code, and any pure-python package can be easily installed.

However, all the interesting input/output capability is on the AVR chip, not on the MIPS chip. Projects such as Autobahn and LininoIO solve this problem by running a special program on the AVR chip which performs I/O operations under instruction from the MIPS chip.

0

We know this is an open issue in Arduino programming and in the embedded world in general. There are various solutions available on the market like MicroPython but most of them are dedicated to specific boards and don't allow to keep the system real-time. We are working on a solution! VIPER is a Python Virtual Machine for Arduino DUE and all ARM 32 bit architectures that runs on top of a real-time operating system. This means that you can develop Python scripts that can be exexuted by Arduino DUE, UDOO, Spark (all boards) and also on the new ST nucleo boards. Moreover if you need high performances and you re skilled in C you can develop real-time modules for VIPER that can be called and managed by the Python scripts.

You can see VIPER in action here http://bit.ly/kickviper

  • It’s not an open issue. python is a horrible indentation language. – user2497 Jun 23 '18 at 19:57
-1

Yes. Python can be used to program an Arduino, simply by importing pyfirmata, which can interface the arduino with Python.

  • True. But that isn't what the OP is asking for. – sempaiscuba Jun 8 '18 at 2:40
-8

I'm affraid Arduino IDE doesn't use C/C++ language. It's derived from Processing IDE and has quite simplified C/Java-like syntax.

  • 8
    The Arduino IDE is C++: it does some minimal preprocessing (prepends “#include <Arduino.h>” and declarations for the function you have defined), then calls a regular C++ compiler (GNU g++). – Edgar Bonet May 21 '15 at 8:42
  • It's the IDE itself rather than the programming language which is derived from Processing. – Peter Bloomfield May 21 '15 at 8:55
  • Virtually nobody cares about implementing the IDE on the Arduino. The point is to be able to write Python which executes efficiently on the Arduino. – wallyk Jan 22 '16 at 19:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.