Micropython on the buspirate 5 works

Receiving my Buspirate I was curious how difficult it would be to install Micropython on it.
As for why, I feel Micropyhton could be an interesting alternative to the current firmware, if Buspirate features are implemented as Micropython modules. That would give people the possibility to use a programming language for debugging and testing.

It is surprisingly easy to switch between Micropython and the Buspirate firmware.
All one has to do:

Install Micropython:

  • Get a copy of Micropython for the RP pico, readily available here:
    https://micropython.org/download/RPI_PICO/
  • Keep the small rear-side button on the Buspirate pressed and (re)plug the USB-C cable.
  • A flash-drive appears on the computer, named RPI-RP2. Open it and copy the uf2 file into it.
  • Do not unplug, flashing will take place automatically directly after the file transfer was performed (takes about 5 seconds).
  • The display and LEDs turn off (don’t panic) Micropython has (yet) no idea of the peripherals .
  • You will notice the uf2 file on the flash drive is gone. Flashing is complete.
  • Repower the Buspirate (for good measure, not really needed).
  • The host computer will recognize a serial device. Connect to it in the same way, like you connect to the Buspirate.
  • Congrats, you just logged in the interactive Micropython shell.

Little Demo?
Micropython comes already with some modules and enough functions to get some stuff out-of-the-box working. E.g. the infamous version of “hello world” for microcontrollers aka led-blinking.

The following code will just do that (you can copy & paste it into the shell using CTRL-E to enter paste mode and CTRL-D to execute it):

from machine import Pin
from neopixel import NeoPixel
from random import randint

pin = Pin(17, Pin.OUT) #GPIO17  levelshifter for the LEDs (3.3V-5V)
shift_enabler = Pin(21, Pin.OUT) #GPIO21 shift enabler pin
np = NeoPixel(pin, 18) # amazing there are 18 little blinkelights
shift_enabler.off() #inverse logic

for x in range(100):
      np.fill((randint(0,255),randint(0,255),randint(0,255))) #just random colours
      np.write() #set them
      machine.lightsleep(250) #sleep for 250ms to avoid seizure
np.fill((0,0,0)) #set to 0 to avoid eye-bleach and burning 
np.write() 

If you want to see how insane fast the pico can be, set sleep to zero.
Current glitch: Sometimes the shell freezes after execution, just power cycle.

Going back to the Buspirate firmware:

  • Download the latest firmware version here:
    https://forum.buspirate.com/t/bus-pirate-5-auto-build-main-branch/20
  • Scroll all the way down to get the latest version.
  • Unzip it.
  • You will find two uf2 version for Buspirate revisions. Make sure you choose the right one.
  • Power-cycle the Buspirate keeping the rear side button pressed.
  • A flash-drive appears on the computer, named RPI-RP2. Open it and copy the uf2 file into it.
  • Do not unplug, flashing will take place automatically directly after the file transfer was performed (takes about 5 seconds).
  • LEDs and display should turn on (if not, now is time to panic).
  • Congrats you are back on the original Buspirate firmware.

Well, that’s it. As usual, I’m not responsible for bricked units or otherwise inflicted damage,

4 Likes

Not to criticize the Awesome Ian, but a MicroPython library that controls the BP hardware would be a cool option.

1 Like

What a great demo, thanks for sharing! When things settle down with the C firmware I plan to check out both micropython and rust.

2 Likes

4 Likes

:rofl: :rofl: :rofl: [Minimum of 20 characters]

Matt at Blinkinlabs nudged me on micropython. Now that there is a clean set of functions to control most hardware this should be doable. I’m reading over the docs.

I’m curious if it will be possible to run scripts directly from the NAND flash and our command line.

I also must apologize, until now I didn’t realize micropython actually ran completely inside the chip. I thought it was a wrapper for a C compiler.

3 Likes