Is it possible to execute a micropython code on Rasperry Pi ?

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
zaord
Posts: 96
Joined: Fri Jan 31, 2020 3:56 pm

Is it possible to execute a micropython code on Rasperry Pi ?

Post by zaord » Sat Nov 07, 2020 11:01 am

Hi here,
I would like to know if it's possible to execute a micropython code with I2C / Spi access on raspebbry Pi, maybe with Unix port?

Is it possible ?

Or should I need to adapt my code to work with normal python (3.7) ?

Best Regards


zaord
Posts: 96
Joined: Fri Jan 31, 2020 3:56 pm

Re: Is it possible to execute a micropython code on Rasperry Pi ?

Post by zaord » Sun Nov 08, 2020 9:09 pm

I looked into this post before post, but i don't know how to use spi and i2c with this script.
I need to mix some python code with micropython so maybe i should rewrite all in normal python code ?

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Is it possible to execute a micropython code on Rasperry Pi ?

Post by jimmo » Mon Nov 09, 2020 7:14 am

zaord wrote:
Sun Nov 08, 2020 9:09 pm
I looked into this post before post, but i don't know how to use spi and i2c with this script.
That script provides a way to use /dev/i2c from MicroPython. It's called SMBus but that's (mostly) just another name for I2C.

But really, on a Raspberry Pi, you might just be better off using regular Python.

stijn
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

Re: Is it possible to execute a micropython code on Rasperry Pi ?

Post by stijn » Mon Nov 09, 2020 7:19 am

The i2c.py from the link should just work as-is with MicroPython.
There doesn's eem to be a readily available SPI implementation.

But yes if you just use CPython everything works out of the box..

User avatar
rcolistete
Posts: 352
Joined: Thu Dec 31, 2015 3:12 pm
Location: Brazil
Contact:

Re: Is it possible to execute a micropython code on Rasperry Pi ?

Post by rcolistete » Mon Nov 09, 2020 9:14 pm

CircuitPython runs on Raspberry Pi, via Blinka :
https://learn.adafruit.com/circuitpytho ... spberry-pi
My "MicroPython Samples". My "MicroPython Firmwares" with many options (double precision, ulab, etc).

User avatar
scruss
Posts: 360
Joined: Sat Aug 12, 2017 2:27 pm
Location: Toronto, Canada
Contact:

Re: Is it possible to execute a micropython code on Rasperry Pi ?

Post by scruss » Thu Nov 12, 2020 2:49 am

rcolistete wrote:
Mon Nov 09, 2020 9:14 pm
CircuitPython runs on Raspberry Pi, via Blinka
Seeing recent queries on the Raspberry Pi bulletin board, I'm not convinced this is a great idea. All of Adafruit's device drivers are being moved over to Blinka, so you basically have to install Blinka (and all of its many, many dependencies) in order to access one sensor from Python. Adafruit have moved old, working code out of their main repos so many tutorials just don't work any more.

I'm also seeing people getting confused why CP code for Adafruit devices like the Circuit Playground Express doesn't run on a Raspberry Pi. They're in a "move fast and break stuff" phase.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Is it possible to execute a micropython code on Rasperry Pi ?

Post by pythoncoder » Thu Nov 12, 2020 11:01 am

CPython 3.8, CircuitPython and MicroPython all run on the Pi. Where they differ is in their hardware support and their support for asynchronous programming.
  • MicroPython has minimal hardware support. It's fine for socket/internet programming but not for I/O.
  • CircuitPython has fairly new hardware support.
  • CPython has official Pi libraries offering hardware support which have had years of development.
This alone would bias me towards CPython for hardware projects.

The killer (for me) is asyncio support which is excellent in CPython and MicroPython but non-existent in CircuitPython. It is difficult to write non-trivial firmware applications using synchronous code.

There is a baremetal MicroPython port which could be a real game changer except that I believe its hardware support is minimal.

Much as I love MicroPython on other platforms, on the Pi I would use CPython with the Pi official libraries.
Peter Hinch
Index to my micropython libraries.

tannewt
Posts: 51
Joined: Thu Aug 25, 2016 2:43 am

Re: Is it possible to execute a micropython code on Rasperry Pi ?

Post by tannewt » Tue Nov 17, 2020 12:58 am

scruss wrote:
Thu Nov 12, 2020 2:49 am
rcolistete wrote:
Mon Nov 09, 2020 9:14 pm
CircuitPython runs on Raspberry Pi, via Blinka
Seeing recent queries on the Raspberry Pi bulletin board, I'm not convinced this is a great idea. All of Adafruit's device drivers are being moved over to Blinka, so you basically have to install Blinka (and all of its many, many dependencies) in order to access one sensor from Python. Adafruit have moved old, working code out of their main repos so many tutorials just don't work any more.

I'm also seeing people getting confused why CP code for Adafruit devices like the Circuit Playground Express doesn't run on a Raspberry Pi. They're in a "move fast and break stuff" phase.
*CircuitPython libraries* run on Raspberry Pi in CPython. This is not the unix port.

Thanks for the Raspberry Pi board mention. I'll add it to my weekly rounds. (I work on CircuitPython for Adafruit and try and check other forums once a week.) Our overall goal is to have a single hardware API (CircuitPython's) across all platforms. That is why we're moving away from the older libraries.
pythoncoder wrote:
Thu Nov 12, 2020 11:01 am
The killer (for me) is asyncio support which is excellent in CPython and MicroPython but non-existent in CircuitPython. It is difficult to write non-trivial firmware applications using synchronous code.
Take a look at the latest CP. We haven't advertised it, but `async` and `await` is now turned on by default. It was enabled in: https://github.com/adafruit/circuitpython/pull/3540 Note that the API is changed from MicroPython to be closer to CPython and that it's based on MicroPython <1.13.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Is it possible to execute a micropython code on Rasperry Pi ?

Post by pythoncoder » Tue Nov 17, 2020 6:02 am

tannewt wrote:
Tue Nov 17, 2020 12:58 am
...
Take a look at the latest CP. We haven't advertised it, but `async` and `await` is now turned on by default. It was enabled in: https://github.com/adafruit/circuitpython/pull/3540 Note that the API is changed from MicroPython to be closer to CPython and that it's based on MicroPython <1.13.
That's a big improvement.

It seems a pity that it's based on V < 1.13 as V1.13 has an entirely new version of uasyncio (V3) which has much better CPython compatibility. Had you based on that, you might not have seen a need to write your own scheduler. One of the quoted reasons for doing this is to remove the need to use the event loop. Under V3 it is possible (and recommended) to write code without any reference to the event loop. Your example

Code: Select all

tasko.schedule(hz=10,  coroutine_function=read_sensor)
tasko.schedule(hz=10,  coroutine_function=animate_beach_ball)
tasko.schedule(hz=5,   corouting_function=read_from_3d_printer)  # Note the typo here!!!
tasko.schedule(hz=100, coroutine_function=rotary.loop)

# And let tasko do while True
tasko.run()
would look like this under V3:

Code: Select all

import uasyncio as asyncio
# code omitted
async def main():
    asyncio.create_task(read_sensor())
    asyncio.create_task(animate_beach_ball())
    asyncio.create_task(read_from_3d_printer())
    await(rotary.loop())  # Run forever

asyncio.run(main())
To me this is equally clear, is CPython compatible and removes the arbitrary frequencies, letting uasyncio do its job.

I should add that, in my opinion, uasyncio V3 is exceptionally well written and minimal. I strongly recommend you take a look at it, if you haven't already.
Peter Hinch
Index to my micropython libraries.

Post Reply