Arduino development in Python

Hello folks,
My name is Prasad and i am a developer from Bangalore, India. I have been working with Arduino for almost 2 years now. I do my most of the programming work in Python and IronPython (.NET version). So, obviously i was looking for Python based solutions to use with Arduino ;D . Then i had an Idea.

I have worked with cross-compilers. I have successfully converted all the basic expressions of python into C++ code using Python itself. So, my question is, would it be useful if i write an IDE where user can write code in Python, it gets converted to Arduino code and gets uploaded to Arduino ? So user doesn't have to learn comparatively difficult Arduino Language (now, Python is used to teach programming everywhere 'cause it's easy)..

Think it could be useful,

Are your Cross-compilers open source?

Can you give some examples of Python code and the generated C++?

I would certainly be interested to see this as long as it works on Linux (and without Wine or Mono).
If it is written in Python it should.

How do you get around the fact that Python does not require variables to be typed before use?

...R

The absence of necessity of variable declaration is really quite a problem. But i used first time initialize of the variable for its type detection, and in the end, the "dynamically typed" feature of python is lost, which really doesn't matter in case of Arduino, since the target language is required to be statically typed.
The examples as you asked,The C++ source is completely generated by the Python script i wrote. (return type of function main() is considered implicitly as integer assuming that the function is expected to be the "main" function of any C/C++ program)
Python source:

limit = 900
def inc(x = 0):
y = x
temp = 0
if y < limit:
inc(y+1)
else:
print("Ended at ",limit)

def main():
y = 0
print("Staring at x = ",y)
inc(0)

=========================================================
the equivalent C++ Code:

/*************************************************************

  • Generated by Py2CPP
  • A python utility for converting python code to pure C++
  • Py2CPP is developed by Shivaprasad Bhat
  • Code formatting done by Astyle

  • Source File : ../sample_recursive.py
  • Date and Time : Sun Jan 5 23:15:25 2014
    *************************************************************/

/* Preprocessors and namespaces */
#include "iostream"
using namespace std;

/* Gobal declarations */
int limit = 900;

void inc(int x=0){
int y = x;
int temp = 0;
if(y<limit){
inc(y+1);
}else{
cout << "Ended at " << limit << endl;
}
}

int main(){
int y = 0;
cout << "Staring at x = " << y << endl;
inc(0);
return 0;
}

If the aim of your project is for Arduino development why not make your Python code produce standard Arduino code with setup() and loop() and Serial.print() etc. That way it can be compiled and uploaded using the Arduino IDE and the C++ code could be directly tweaked, if necessary, by someone who was only familiar with the Arduino way of C++ coding.

I don't see how, in your Python example, the user could specify whether a variable type should be a byte, char, int, unsigned long etc

Using nothing but integers is not practical.

And I have to say I don't immediately see the benefit of using Python - much as I like Python. The whole point of Python is dynamically typed variables. But they are quite impractical in an Arduino.

...R

sprasadbhat:
Hello folks,
My name is Prasad and i am a developer from Bangalore, India. I have been working with Arduino for almost 2 years now. I do my most of the programming work in Python and IronPython (.NET version). So, obviously i was looking for Python based solutions to use with Arduino ;D . Then i had an Idea.

I have worked with cross-compilers. I have successfully converted all the basic expressions of python into C++ code using Python itself. So, my question is, would it be useful if i write an IDE where user can write code in Python, it gets converted to Arduino code and gets uploaded to Arduino ? So user doesn't have to learn comparatively difficult Arduino Language (now, Python is used to teach programming everywhere 'cause it's easy)..

Instead of reinventing the wheel and building a new IDE, have you considered adding Python to the existing Arduino IDE stack? It is open-source as you probably know. Python for Arduino is a cool idea, I think a lot of developers and hobbists will love it. However personally I think you should try to maintain the current ecosystem, that way you have the most reach and perhaps also a healthy development life cycle.

That last remark is aimed at the integration you will have to provide and the effort it will take to maintain your software. E.g. new Arduino features come out and you need to patch your IDE to be compatible with the latest Arduino version.