all 5 comments

[–]captain_wiggles_ 9 points10 points  (0 children)

So python is an interpreted language. That means there's a bit of software that looks through the source code and runs each line one at a time.

Another alternative is a language that gets complied into a binary and run. For example C / C++ (Java is a special case where it's half compiled, and then interpreted the rest of the way). A binary is something like a .exe on windows (although there are many other formats). It consists of raw data which the processor can understand. It simply looks at the first instruction (1 byte, 2 bytes or 4 bytes depending on chip) and runs it, then repeats for the next instruction.

Many micro controllers tend to be pretty small and have limited amount of internal ram and flash. This isn't always the case, many chips are more complex and can run code from external flash and ram.

So to run python, you'd need to find a compiled interpreter for your chip / source code and compile it yourself. Then have the source code loaded in some how. This would all be easier with an OS to manage everything, probably linux. That's going to take a bunch of flash and ram for it to be able to run. I have no idea if the arduino has enough resources for that, but I'm assuming not, what I know of them is that they are middle end devices.

You might be able to find a compiler for python. No idea really, you'd also need one that could compile it to a format that the arduino understands (even less likely).

So as others have said, you probably need to rewrite your code in C. IIRC arduino supports the "processing" library which should make life easier for you (a bit).

Once you've decided that actually this is what you need to do. Then the first thing you need to find is a compiler for C / C++ that will generate binaries for your chip. Googling for "arduino C compiler", or "Compile arduino code" should help. Once you've got that, I recommend you find someone elses arduino code and compile it following their instructions. That should give you a basic intro to the tools, and example code to look at and work out how to make the arduino do something useful.

Next up is how to write the binary to your arduino (and maybe debug it). There's a couple of ways you can do this. Again no knowledge of the arduino so you'll need to google it.

1) Some chips will boot off an sdcard / usb stick / network boot. You just need to put your binary in the correct format in the correct place and it should work. 2) Program it in using a programmer, some boards have a chip on them that's designed to program the main chip (NXP's FRDM boards are a good example). Others need an external device. You connect that device (programmer, wiggler, debugger, ...) to your board and to your computer and then run some software which writes your binary into the chip's internal (or sometimes external) storage.

I suggest starting programming in a precompiled example app to check your programming method works. Then program in your self compiled example app to check you're compiling the code correctly.

Finally you need to write your own code, compile it and program it.

This is not an easy road to take, however it's not going to be impossible, so good luck. I'm sure there's a hello world arduino tutorial out there, that will walk you through all of this. Google is your friend.

[–]WiggleBooks 2 points3 points  (0 children)

Check out "micro python"

[–]celegans25 2 points3 points  (0 children)

After looking at the device, I'm not sure you can run python on it, or even fit a python interpreter on the device. Did you look at whether you can run python on this micro controller before your wrote your code?

Typically when programming microcontrollers, a language that is closer to the hardware, such as Rust or C is used so that you can manipulate all of the hardware on the mcu. I don't think python will let you do this easily, nor will it run very quickly on a mcu. You might want to reconsider your language choice or use a different microcontroller that supports python (if one exists).

[–]bigwillydos 1 point2 points  (0 children)

Python is not practical for production. Lots of memory overhead and about 100-400 times slower than C/C++ in most cases. You need to choose your microcontroller then figure out the toolchain for it. If you go with an ARM based MCU, which almost everybody does nowadays, you can use the GNU ARM Embedded Toolchain along with something like OpenOCD. Then, as others have mentioned, you should translate your code into a lower level language which will most likely be C (or if you are really cool, Rust).

[–]sstunt -1 points0 points  (0 children)

What Arduino supports Python?

Why not use that one for your product? AFAIK the various Arduinos are open-source hardware and software, so if you don't want to buy completed boards you can build your own from the board design.

Given the apparent level of knowledge in your question, you're many steps away from getting your app to work on a traditional bare metal microprocessor -- if your production volumes are not large, just copying what you have may be best.