the files for my spaceteam console. this repo is a platformio project and also a python project meant to run on a raspberry pi.
the platformio files are in src/
and lib
, and control the on-board microcontroller.
i am using this maple-mini clone which is 5x more expensive than a bluepill, but is available next-day on amazon and has nice buttons instead of jumpers and correct pull-up resistors/bootloader for usb programming.
the maple-mini can be programmed by running platformio run --target upload
.
in some cases, the ACM device is not enabled or is stuck (like, if you accidentally wrote a busy-loop that spews to Serial
).
you can get around this by booting the microcontroller into perpetual bootloader mode.
in that mode, the device will boot straight into DFU mode.
you'll need to add the DFU port to program it.
on the raspberry pi, it'll be something like platformio run --target upload --upload-port <path-in-dev>
.
you can figure out what the path is by running sudo strace -e open dfu-util -l
i used this pi that comes with a case and heatsinks and this breakout board/cable. i had problems powering the pi with a random 5V power supply -- undervoltages would cause reboots. using an official power supply made life easier.
to run the python controller, invoke spaceteam.py
.
it doesn't need root
atm.
the file install.sh
will correctly configure the pi so that the python project works.
there are quite a few settings, especially those controlling the i2c device, disable bluetooth so that hardware serial is available, disable serial consoles, etc...
the script will also install various dependencies, including platformio
and various python modules.
run it as root on your raspberry pi:
$ sudo ./install.sh
the spaceteam
directory contains the python project files.
there are device drivers for several peripherals attached to the pi:
- microcontroller - controls comms with the microcontroller (maple mini)
- mcp23017 - this is digital IO multiplexer, we talk to it over i2c. i used this one and have a few spares
- ads1115 - an ADC, also on the i2c bus. i used this one off amazon (yay next-day delivery)
for any on-board lights, i used a single WS2812 run. ws2812 leds are often known as neopixels in the hobbyist community. i used this generic one off amazon.
in hindsight, ws2812 is not a good choice for this project. it's very difficult to drive off the raspberry pi. i tried this library but the DMA was causing segfaults (with SPI) or DMA errors which put the filesystem into RO (with PCM). in the end, it was easier to run the lights off a microcontroller where precise timing is easier. even there people often use DMA, but i found a bit-banged library that seems to work pretty well without consuming an entire IO port.
don't forget about level-shifting the lights!!! thankfully, there's an easy, elegant hack that just involves one diode.
to talk between the pi and the microcontroller, i used a binary protocol over serial.
this is fast and efficient, i highly recommend using it.
the microcontroller library is in lib/PacketSerial
and on the python side the code in spaceteam/microcontroller.py
uses a built-in library.
TODO: i haven't figured out how to read the data off the microcontroller from python yet, since python 2.7 removes the ability to set a custom eol
character for serial.readline()
; i'll probably have to read one char at a time, but still a binary protocol is way faster and more reliable.
no diagram right now. the basic idea is:
- raspberry pi is connected to an ethernet hub and to power supply via microusb port
- pi I2C bus is connected to an ads1115 and an mcp23017
- pi
/dev/serial0
tty is connected toSerial3
on the maple mini - pi USB connected to maple mini USB for programming (via
platformio
) and debugging (viaSerial
on maple andminiterm.py
on Pi) - maple mini is connected to led strip
- potentiometers on the ads1115, switches on the mcp23017
- 3.3V bus powers all the peripherals
- LED strip powered by separate 5V power brick
i used a bunch of buttons and switches off amazon: