MicroPython on Mini SAM M4

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.
User avatar
andypiper
Posts: 25
Joined: Wed Feb 02, 2022 12:17 pm
Location: Kingston upon Thames, UK
Contact:

MicroPython on Mini SAM M4

Post by andypiper » Tue Jul 26, 2022 7:10 pm

There's a build of MicroPython for the very cool / cute Mini SAM M4 board (it is shaped like a minifigure).

I can (and have) run CircuitPython on it, but I wanted to dig in on the MicroPython side of things.

- installed 1.19.1 .uf2 and restarted board
- unable to connect using Thonny (raised an issue)
- can (usually) connect using mpremote, but sometimes I need to Ctrl-D soft reboot to get into the REPL (this could also be Mac serial weirdness, not sure)
- noticed that the help for the SAMD port has some challenges... it is very succinct, and links to non-existent docs (I'll raise this as an issue)
- the `os` module doesn't seem to support things I would expect such as `uname`, but there are no docs so I don't know if this is expected or not.

Is anyone else using this board with MicroPython at all? Or any of the other M4 boards, since the help and other things will be similar...

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: MicroPython on Mini SAM M4

Post by Roberthh » Wed Jul 27, 2022 6:17 am

I spent a few weeks to extend the SAMD port. There is a PR open for both the firmware and a documentation.

Firmware PR: https://github.com/micropython/micropython/pull/8704
DOC PR: https://github.com/micropython/micropython/pull/8798

I have also a branch which extends the firmware a little bit more, which is not committed yet, at https://github.com/robert-hh/micropytho ... samd_xtend. About uos.uname(). That#s not enabled (yet) in the PR, but that is an easy thing, if required.

The downside is at the moment, that with just the PR you have to build the firmware yourself. I can do that for you, if you want to avoid the effort. It i intersting for me, if the port works on your board, especially the Pin configuration.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: MicroPython on Mini SAM M4

Post by Roberthh » Wed Jul 27, 2022 6:50 am

I placed a firmware for MINISAM M4 here: https://github.com/robert-hh/Shared-Stu ... SAM_M4.uf2

User avatar
andypiper
Posts: 25
Joined: Wed Feb 02, 2022 12:17 pm
Location: Kingston upon Thames, UK
Contact:

Re: MicroPython on Mini SAM M4

Post by andypiper » Wed Jul 27, 2022 6:08 pm

Thanks for sharing, Robert! I will definitely check this out in the next few days.

(also worth noting that I hadn't read your responses this morning, but, I did mention that I'd had some issues with the Mini SAM board with v1.19.1 during the monthly MicroPython meetup today, and it seemed to catch Damien's attention, so maybe I'll have a play with your PR and build and see if there's interest in merging things!) :ugeek:

User avatar
andypiper
Posts: 25
Joined: Wed Feb 02, 2022 12:17 pm
Location: Kingston upon Thames, UK
Contact:

Re: MicroPython on Mini SAM M4

Post by andypiper » Wed Aug 10, 2022 12:45 pm

I commented on GitHub that things seem good, which they do - installation of the binary .uf2 is fine and general REPL access, IDE connection, etc.

I'm looking through your GitHub forks, and I'm not sure where the dotstar library is being added for this board? I'm not able to import it:

Code: Select all

MicroPython v1.19.1-282-g0440032bf on 2022-07-27; Mini SAM M4 with SAMD51G19A
Type "help()" for more information.
>> 
>>> help('modules')
__main__          math              uhashlib          ure
_boot             micropython       uheapq            uselect
_onewire          samd              uio               ustruct
_uasyncio         uarray            ujson             usys
builtins          ubinascii         umachine          utime
dotstar           ucollections      uos               uzlib
framebuf          uctypes           upysh
gc                uerrno            urandom
Plus any modules on the filesystem
>>> import dotstar
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "dotstar.py", line 2, in <module>
ValueError: invalid pin
I'm only seeing it referenced in ESP32 board manifests in the repo. The UM boards seem to add it - looks like Matt's port. I might give his library a play directly, and also try building the firmware for myself as well.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: MicroPython on Mini SAM M4

Post by Roberthh » Wed Aug 10, 2022 1:04 pm

dotstar.py is located in my local modules directory and therefore frozen in the build I make here. Same with upysh. dotstar is used in my test environment for the adafruit itsybitsy boards.And I switch it off since it is so bright that I gets hard read the pin labels. It fails on the mini same because the Pin numbers are wrong. This is the code of dotstar.py. Pretty simple.

Code: Select all

from machine import SoftSPI, Pin
spi=SoftSPI(sck=Pin(25), mosi=Pin(26), miso=Pin(14))

def write(red, green, blue):
    spi.write(b"\x00\x00\x00\x00\xff")
    spi.write(bytearray((blue, green, red)))
    spi.write(b"\xff\xff\xff")

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: MicroPython on Mini SAM M4

Post by Roberthh » Wed Aug 10, 2022 1:39 pm

There is also a PR for documentation of the port: https://github.com/micropython/micropython/pull/8798

User avatar
andypiper
Posts: 25
Joined: Wed Feb 02, 2022 12:17 pm
Location: Kingston upon Thames, UK
Contact:

Re: MicroPython on Mini SAM M4

Post by andypiper » Wed Aug 10, 2022 2:38 pm

Cool, thanks. I did wonder whether it *was* Matt's code since the line number with pin refs would have been wrong.

I might update the Mini SAM M4 board definition to pull in his micropython_dotstar library and setup a helper library and function (similar to what the UM boards are doing in ESP32 land).

This works fine as a quick test:

Code: Select all

from micropython_dotstar import DotStar
from machine import Pin, SoftSPI

# setup the RGB LED on the left leg
spi = SoftSPI(sck=Pin(20), mosi=Pin(19), miso=Pin(17)) # PIN_PB03,DOTSTAR_DATA; PIN_PB02,DOTSTAR_CLK; PIN_PB23,MISO
dot = DotStar(spi, 1) # single LED (DotStar supports multiple)

dot[0] = (25, 128, 210, 0.1) # light the LED blue
Now playing with the button and built-in LED...

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: MicroPython on Mini SAM M4

Post by Roberthh » Wed Aug 10, 2022 2:56 pm

You can as well write:

spi = SoftSPI(sck=Pin("DOTSTAR_CLK"), mosi=Pin("DOTSTAR_DATA"), miso=Pin(17)) # PIN_PB23,MISO

For miso you can use any otherwise not required pin. It is a pity that SoftSPI does not allow setting e.g. miso to None. Maybe it's worth a check for a PR..

User avatar
andypiper
Posts: 25
Joined: Wed Feb 02, 2022 12:17 pm
Location: Kingston upon Thames, UK
Contact:

Re: MicroPython on Mini SAM M4

Post by andypiper » Wed Aug 10, 2022 5:05 pm


Post Reply