Bike Persistent of Vision Wheel
Raspberry Pint, 1st April 2020
Ben Clifford
benc@hawaga.org.uk
Decathlon B'TWIN TILT 120

Goal... (adafruit)

Hardware: Controller

Raspberry Pi Zero W

Hardware: LEDs

  • Adafruit DotStar strip
  • 1 metre x 144 LEDs/m
  • 24 LEDs fit on wheel radius => 1 strip = 2 sides x 2 wheels
  • SPI bus - 2x output pins from Pi Zero => LED strip
  • Each LED: independent 24-bit colour

Hardware: Rotation detection

1. Magnet sensor: hall effect switch

Hardware: Rotation detection

2. Neodymium magnets from Amazon x 40 (39 excess)

"These magnets are perfect for sticking receipts, tasks, papers or instructions on a magnetic board or hanging kids art work or family photos on the fridge."

Hardware: Rotation detection

Hardware: Power supply

Poundland £1 USB battery

Probably can do better

Lasts about an hour

Hardware: Board

Adafruit Pi Zero W Permaproto

+ level convertor + buttons + screw terminals

Hardware: Assembly

Hardware: Damage

Software

  • Python
  • adafruit_dotstar - set LEDs
  • gpiozero - read magnet sensor

Software: setting LEDs

import board
import adafruit_dotstar as dotstar
dots = dotstar.DotStar(board.SCK, board.MOSI, 24, 
                brightness=0.5, auto_write=False,
                baudrate=1000000)
                # theoretically up to 8000000 haha

dots[3] = (255,0,0)  # red 
dots[4] = (0,255,0)  # green
dots[5] = (0,0,255)  # blue

dots.show()  # slow

Software: reading magnet sensor

import gpiozero
magnet = gpiozero.Button(27)  # pin 27

magnet_start = time.time()
last_magnet_start = magnet_start - 1

def set_magnet_edge():
    global magnet_start
    global last_magnet_start
    last_magnet_start = magnet_start
    magnet_start = time.time()

magnet.when_pressed = set_magnet_edge

Software: How far round the wheel?

last_duration = last_magnet_start - magnet_start

now = time.time()
time_since_magnet = now - magnet_start

pos = time_since_magnet / last_duration  # approx 0 .. 1

Software: Main loop

loop as fast as possible:
    update LEDs with latest pattern

4 different pattern/sections:

  • Flash each loop iteration
  • Logo by rotation
  • Red/blue by time
  • Green stripe by magnet

Wheel Maths

Radius: 0.5m / 20", Circumference: 1.6m

LED update: 120Hz

Speed Rot/sec angular pixels note
5km/h 0.9 137 walking pace
17km/h 3 40 fast ride in London

LED maths

In practice, 120 updates/sec. But...

  • LED data rate: 1Mbit/sec
  • Bits/LED: 24
  • LEDs: 24
  • 1M / 24 /24 = 1700 updates/sec

... => 10x angular pixels (vs 120 updates/sec)

Displaying Text (WIP)

Get a 5x7 font.

render letters

Attempt at NHS logo

To slow to render. Hard to photo.

Future

  • Ride this thing around (Friday)
  • Mounting/casing
  • Speed up frame rate: no python?
  • Remote control using bluetooth/wifi
  • Mode buttons
  • Other side of wheel

Alternatives

  • Faster language/library
  • Arduino/ATtiny85 probably enough for basic patterns