The AROS Archives(anonymous IP: 216.73.216.105,401) 
 HomeRecentStatsSearchSubmitUploadsMirrorsContactInfoDisclaimerConfigAdmin
 Menu

 Features
   Markdown composer
 

 Categories

   o Audio (128)
   o Datatype (18)
   o Demo (66)
   o Development (270)
   o Document (70)
   o Driver (20)
   o Emulation (71)
   o Game (626)
   o Graphics (240)
   o Library (24)
   o Network (87)
   o Office (24)
   o Utility (336)
   o Video (22)

Total files: 2002

Full index file
Recent index file

Part of AROS World
 Readme for:  Development » Language » micropython.aarch64-aros.lha

micropython

Description: micropython ported to Rasberry Pi
Download: micropython.aarch64-aros.lha       (TIPS: Use the right click menu if your browser takes you back here all the time)
Size: 254kb
Version: 1.29.0-r1
Date: 05 Dec 26
Author: tennis74
Submitter: tennis74
Homepage: https://github.com/tenko/aros-micropython/
Requirements: Rasberry Pi400, Pi4, Pi3, Zero
Category: development/language
License: BSD
Distribute: yes
FileID: 3663
 
Comments: 0
Snapshots: 0
Videos: 0
Downloads: 8  (Current version)
8  (Accumulated)
Votes: 0 (0/0)  (30 days/7 days)

[Show comments] [Show snapshots] [Show videos] [Show content] [Replace file] 

aros-micropython

Micropython port to AROS with support for Rasberry Pi hardware peripherals (GPIO, UART, I2C, SPI, PWM). This is based on the standalone port to Rasberry Pi here : micropython-raspberrypi

How to build

wget https://github.com/micropython/micropython/archive/refs/tags/v1.29.0.tar.gz
tar -xaf v1.29.0.tar.gz
git clone https://github.com/tenko/aros-micropython.git
patch -p0 < aros-micropython/vfs_posix_file.patch
cd aros-micropython
make

The build was performed with help of aros-compiler-docker

This is tested on Pi400 and Rasberry Pi4 and older version should work. The Pi5 is not supported as it has a completely different architecture which is currently not well documented.

How to use

The pinout of the 40 pin connector is found in the official documentation for the raspberry-pi.

Be careful with the 5V pins as the GPIO pins does are only 3V3 tolerant.

The pins are fragile and can only sink or supply 50mA. Using a LED or similar must therefore use a current limit resistor. The size of the resistor is dependent on the forward voltage of the particular LED.

I use the "Adafruit T-Cobbler Plus" which allows the 40 pin connector to be used with a standard bread board and the pins are clearly marked.

GPIO Example:

# Example blinking LED on GPIO21 (pin 40)
# Stop loop with Ctrl+C on the keyboard
import time
from machine import Pin
pin = Pin(21, Pin.OUT)
while True:
  time.sleep_ms(500)
  pin.toggle()

UART Example:

UART has no clock signal, so the parameters needs to be matched. The RPi UART can only change the baudrate.

Other parameters:

  • Databits : 8
  • Parity : None
  • Stop bits: 1
  • Flow control : None

TX pin is on GPIO14 (pin 8) and RX pin is on GPIO15 (pin 10).

When connecting to other device the TX/RX pair must be crossed.

# Example uart echo server
# Stop loop with Ctrl+C on the keyboard
import time
from machine import UART

uart = UART(0, baudrate = 9600)

while True:
  if uart.any():
    ch = uart.read(1)
    print(chr(ch[0]), end = "")
    uart.write(ch)
  time.sleep_ms(10)

I2C Example:

The I2C bus is half-duplex serial type bus which can interface a lot of interresting devices like sensors and memory chips.

The I2C1 support on the RPi has to be enable in the "boot.txt" by adding the following text:

# Enable I2C
dtparam=i2c_arm=on

I2C1 device SDA signal is on GPIO2 (pin 3) and SCL signal is on GPIO3 (pin 5). Additional I2C devices can be defined in the "boot.txt" file if needed.

Pull-up resistors are automatic activated on the pins when the I2C port is enables.

# I2C example with Sparkfun LIS331 sensor
from machine import I2C, Pin
import struct
import time

ADDR        = const(0x19)
WHO_AM_I    = const(0x0F)
CTRL_REG1   = const(0x20)
OUT_X_L     = const(0x28)

i2c = I2C(1, freq = 400_000)

chip = i2c.readfrom_mem(ADDR, WHO_AM_I, 1)
print("chip = ", chip)

i2c.writeto_mem(ADDR, CTRL_REG1, bytes([0x27]))
time.sleep_ms(50)

while True:
    data = i2c.readfrom_mem(0x19, 0x80 | OUT_X_L, 6)
    x, y, z = struct.unpack("<hhh", data)
    print("x,y,z:", x >> 4, y >> 4, z >> 4)
    time.sleep_ms(100)

SPI Example:

The SPI bus is full-duplex serial type bus which use more pins the I2C, but is much faster.

The SPI0 support on the RPi has to be enable in the "boot.txt" by adding the following text:

# Enable SPI
dtparam=spi=on

SPI0 device SCLK signal is on GPI11 (pin 23), MOSI signal is on GPI10 (pin 19) and MISO signal is on GPI9 (pin 21).

In addition a CS signal is needed from a normal GPIO pin for chip select function.

Additional SPI devices can be defined in the "boot.txt" file if needed.

# SPI example with Sparkfun LIS331 sensor
# GPIO21 is used as CS pin.
import struct
import time
from machine import Pin, SPI

REG_WHO_AM_I    = const(0x0F)
REG_CTRL_REG1   = const(0x20)
REG_OUT_X_L     = const(0x28)

spi = SPI(0, baudrate = 1_000_000, polarity = 1, phase = 1)
cs = Pin(21, Pin.OUT, value = 1)

def read_reg(reg, nbytes = 1):
    cmd = 0x80 | (0x40 if nbytes > 1 else 0x00) | (reg & 0x3F)
    cs.value(0)
    spi.write(bytes([cmd]))
    data = spi.read(nbytes)
    cs.value(1)
    return data                                                                         

def write_reg(reg, val):
    cmd = reg & 0x3F
    cs.value(0)
    spi.write(bytes([cmd, val & 0xFF]))
    cs.value(1)

chip = read_reg(REG_WHO_AM_I, 1)[0]
print("chip = ", chip)

write_reg(REG_CTRL_REG1, 0x27)
time.sleep_ms(20)

while True:
    raw = read_reg(REG_OUT_X_L, 6)
    x, y, z = struct.unpack("<hhh", raw)
    print("z, y, z:", x >> 4, y >> 4, z >> 4)
    time.sleep_ms(200)

Status

Currently the port is working fine for the examples above and is usable for my use. Only Pi400 has been tested yet. Probably Pi4 and Pi3 devices should work without problems.

TODO

  • Onewire not supported yet as RPi does not have proper open drain on GPIO.
  • Open with icon not handled. Probably implementation can be copied from lua port.
  • Direct use of peripherals probably should be use the AROS api where available.
  • RPi5 not supported.
  • Threading not enabled.
  • Soft timer device is missing. Can probably be copied from the SDL3 port with separate running thread.
  • Networking not enabled (socket module needed)
Copyright © 2005 - 2026 The AROS Archives All Rights Reserved