Microbit start

I have a microbit laying around since forever.

As my first program I wanted a dice rolling using not numbers but images from an array. To compile the program to a .hex file and upload to the microbit I used: makecode.

The program code:

input.onButtonPressed(Button.A, function () {
     dice_num = Math.randomRange(0, 5)
     dice[dice_num].showImage(0)
 })
 let dice_num = 0
 let dice = [images.createImage(`
     . . . . .
     . . . . .
     . . # . .
     . . . . .
     . . . . .
     `), images.createImage(`
     . . . . .
     . # . . .
     . . . . .
     . . . # .
     . . . . .
     `), images.createImage(`
     . . . . .
     . # . . .
     . . # . .
     . . . # .
     . . . . .
     `), images.createImage(`
     . . . . .
     . # . # .
     . . . . .
     . # . # .
     . . . . .
     `), images.createImage(`
     . . . . .
     . # . # .
     . . # . .
     . # . # .
     . . . . .
     `), images.createImage(`
     . . . . .
     . # . # .
     . # . # .
     . # . # .
     . . . . .
     `)]
 basic.showLeds(`
     . . # . .
     . # # . .
     # # # # #
     . # # . .
     . . # . .
     `)
On start the microbit shows an arrow that gives you the hint to press button A.
Pressing button A shows a random dice image from an array.
Not the most beautiful code. But it works and it was a good feeling to see it running and this small computer.

Format USB flash drive

I was in need of a really Windows compatible USB flash drive.
To be sure the drive is compatible I wanted to format it using Windows.
But the drive was used before, so Windows didn't want to format it.
The easiest way was to wipe the drive on linux using

sudo dd if=/dev/zero of=/dev/sdX bs=1k count=2048

After this procedure Windows asks to format the drive when plugged in.

Raspberry PI Shutdown on button press

After adding a button with resistors (there are lots of other resources about that). I wanted a version using systemd.

The gpio testing script is using wiringpi.

Add this as /root/pin-shutdown.sh:

#!/bin/bash

pin=29  # pin 40 (internal: 21) on raspi layout
gpio mode $pin in
gpio wfi $pin both
logger Shutdown button pressed
shutdown -h now

gpio wfi 21 both is blocking until the pin changes its state.

And the systemd service as: /etc/systemd/system/button-shutdown.service:

[Unit]
Description=button shutdown service

[Service]
ExecStart=/root/pin-shutdown.sh
Restart=on-failure

[Install]
WantedBy=multi-user.target

Enable the systemd service with: systemctl enable button-shutdown