The 'machine' module on Raspberry 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.
Post Reply
ProudPagan
Posts: 35
Joined: Fri Apr 12, 2019 8:55 am

The 'machine' module on Raspberry Pi

Post by ProudPagan » Tue Apr 23, 2019 3:37 pm

Hi,

Does anyone know how to build the 'machine' module on a Raspberry Pi running Raspbian or Buildroot?
I know boochow has a bare metal version with SPI and I2C, but I need MicroPython to run inside Buildroot.

Thanks

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

Re: The 'machine' module on Raspberry Pi

Post by pythoncoder » Tue Apr 23, 2019 5:40 pm

As I understand it buildroot has the option of installing a Linux kernel, filesystem and bootloader. If you plan to use it in that mode I'd try the official Unix build. However this does not support machine. Otherwise I guess you'll need to skip the Linux OS options and build one of the baremetal ports.

I think the options of accessing hardware directly and having an underlying Linux OS are mutually exclusive.
Peter Hinch
Index to my micropython libraries.

ProudPagan
Posts: 35
Joined: Fri Apr 12, 2019 8:55 am

Re: The 'machine' module on Raspberry Pi

Post by ProudPagan » Fri Apr 26, 2019 2:23 pm

There's a low level RPi C library at http://www.airspayce.com/mikem/bcm2835/index.html
I could not find anything like the Python RPi.GPIO modules so I am trying to get a MicroPython wrapper working on top of this:
https://github.com/hacksterous/micropyt ... /mpbcm2835

I have tested simple GPIO writes, and it seems to work

Code: Select all

import mpbcm2835
mpbcm2835.init()

#select GPIO17 (RPi-2 pin-P1-11) as output
mpbcm2835.fsel(17, 1)

#write '1'
mpbcm2835.write(17, 1)
#delay of 1000 milliseconds
mpbcm2835.delay(1000)
#write '0'
mpbcm2835.write(17, 0)
Feel free to use.

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

Re: The 'machine' module on Raspberry Pi

Post by jimmo » Sat Apr 27, 2019 1:11 pm

Not sure if this is useful or not (or even a good idea), but depending on what you need from `machine` (e.g. just basic pin control), can you get by with filesystem access to sysfs-gpio? (Write the pin number to `/sys/class/gpio/export` then access `/sys/class/gpio/gpioN/value` )

(But the `mpbcm2835` module linked above looks heaps better :D )

Turbinenreiter
Posts: 288
Joined: Sun May 04, 2014 8:54 am

Re: The 'machine' module on Raspberry Pi

Post by Turbinenreiter » Sat Apr 27, 2019 5:34 pm

The CircuitPython HAL works on Raspberry Pi with Linux, its using CPython tough.

https://learn.adafruit.com/circuitpytho ... x/overview

Having the machine module on Raspberry Pi is definitely possible, but nobody wrote it yet.

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: The 'machine' module on Raspberry Pi

Post by pfalcon » Tue Apr 30, 2019 7:58 pm

"machine" module for Unix port was written 3 years ago: https://github.com/pfalcon/micropython- ... ne/machine . Obviously, the amount of the code written so far is based on the needs of people who contributed to the module.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: The 'machine' module on Raspberry Pi

Post by kevinkk525 » Wed May 08, 2019 3:55 pm

ProudPagan wrote:
Fri Apr 26, 2019 2:23 pm
There's a low level RPi C library at http://www.airspayce.com/mikem/bcm2835/index.html
I could not find anything like the Python RPi.GPIO modules so I am trying to get a MicroPython wrapper working on top of this:
https://github.com/hacksterous/micropyt ... /mpbcm2835

I have tested simple GPIO writes, and it seems to work

Code: Select all

import mpbcm2835
mpbcm2835.init()

#select GPIO17 (RPi-2 pin-P1-11) as output
mpbcm2835.fsel(17, 1)

#write '1'
mpbcm2835.write(17, 1)
#delay of 1000 milliseconds
mpbcm2835.delay(1000)
#write '0'
mpbcm2835.write(17, 0)
Feel free to use.
This looks very promising and recent. But it doesn't conform to the typical machine.Pin interface so needs another wrapper around it to be compatible.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

Post Reply