Orthogonal Systems Ltd. Doing it right-angled.

Mabs - Input library for Arduino

Update: Mabs has now been merged Mutila.

* * *

Introducing Mabs - a library for buttons and other inputs for Arduino microcontrollers.

I think many coders have the experience of writing the same code over and over for different projects - basic infrastructural pieces which are easy enough to put together that we never bother putting them into a proper library - we just write them from scratch for every project. Code for reading button inputs is one of those things - I must have written code to implement a debounced button a dozens of times or more. 

Mabs is an Arduino library which wraps up button and other input handling code into nice easy-to-use, well tested classes which can be easily used in your projects. The most commonly used class is the DebouncedButton, which protects the user from fluctuations in the read value around the time a button is pressed or released.

Mabs classes use a "time-slice" approach. An update() function is called frequently (typically from a sketch's loop() function), which updates the object's state and quickly returns. Other member function can then be called to test the state of the object (i.e. has a  button press been registered?). For many applications this is preferred to the naive debounced button implementation which blocks while some timer expires and repeatedly tests the state of the button's input pin.

A minimal example:

#include <DebouncedButton.h>

// Button connected to pin 3 in pullup mode
// i.e. ground pin to register a press
DebouncedButton button(3);

void setup()
{
    button.begin();
    pinMode(13, OUTPUT); // the built-in LED on an Uno/Nano
    digitalWrite(13, LOW);
}

void loop()
{
    button.update();
    if (button.pushed()) {
        digitalWrite(13, HIGH);
        delay(500);
        digitalWrite(13, LOW);
    }
}

For more information, see the Mabs documentation, here.

Animatronic Monkey Head Prototype

On December the 3rd 2016, Nottingham Hackspace ran the second annual Nottinghack Crapthon. The Crapthon is a reaction against the fun of hackathons getting underminded by corporate sponsors who would like the events to be about promoting their products or recruiting, rather than making fun stuff. Also, we couldn't find a corporate sponsor.  The event is inspired by the Terrible Ideas HackathonHeboCon, and other fun events.

My contribution this year was to make this:

Components:

  • Arduino Pro Mini (5V version)
  • SG-90 servo
  • DFPlayer Mini audio module
  • 2W speaker
  • LM2596 DC-DC converter board

The DFPlayer Mini is very nice. I've used WTV020SD-16P modules the past, but have found them to be temperamental - having difficulty reading SD cards if not formatted in very specific ways, and requiring audio files in non-standard AD4 format. Not so with the DFPlayer Mini, which had no trouble with an SD card formatted with mkfs.vfat containing files in MP3 format which were encoded using Lame. The module is also capable of directly driving a 2W speaker, producing enough sound for my needs here. Docs and example code can be found in the link above.

I like the LM2596 DC-DC converter, although it's overkill for this project - I just happened to have one laying around so figured I might as well use it. These little boards take a DC input from 4.2-40V and output 1.25-37V, adjustable by the multi-turn pot, which gives quite good precision. If required they can provide a decent amount of current too. Worth getting a couple.

In keeping with the spirit of the Crapathon, the whole thing is just taped together, with no attempt made to make the mechanism robust or particularly useful. However, I'm somewhat interested in making a more robust and sophisticated version. I'd like to have the eye move in two axes rather than just left-right, and have some sort of sensing in the system.  To this end I started to make some models in Blender - a screenshot of which I shall leave here.

undefined

 

RGB LED effects

Recently I've been with working with Matt Little of Re-Innovation on firmware for some pedal powered educational game systems. Today I wrote some RGB LED effects, which add a nice dash of colour to the grey British winter.

These effects are triggered at the end of a pedal powered challenge - the player pedals a static bicycle which turns a generator which in turn powers the system and charges a large super-capacitor. When the capacitor voltage reaches some threshold, a random effect is triggered as a reward. The effect lasts until the suprt-capacitor voltage drops below a second, lower threshold, which takes about a minute.

The system is is controlled by an Arduino Nano, and has two different game modes.  Source code for the firmware is available on github.

Home ← Older posts