Vagrearg Logo  
 
Bang Head Here
Pain is no substitute for satisfaction
Gamification is a modern way of saying to take a piss with reality and do what is, apparently, fun while creating something. An MBA would see gamification as another way to get what (s)he wants while the other side is just as bad off, but hopefully feels better about his/her situation. Whether or not a gamified system is useful remains to be seen and may be determined by your peers.

At least, that is the cynical view on gamification.

To counter the cynicism, we can simply gamify a bad situation and have a good laugh at the same time. It is even more satisfying when the pun is lost on those who are the target, while bystanders see a funny device to be used for their own satisfaction.

The funny thing is; creativity is often fueled by seeing a negative and converting it into a positive.

So, we take a coping system, mangle it in the gamification engine, add some electronics sauce, apply engineering and look at the result. Now we can bang our head with just the right amount of force and get feedback about our state of mind while we are applying gamified self-punishment. Say hello to Bang Head Here.


bhh-operational
Figure 1, Bang Head Here - On the wall, ready for use (click to enlarge)

Design concept

Question:What is the right amount of self-punishment?
Answer:Right in between too much and too little.

With that in mind, it can be concluded that the right amount of self-punishment is a game of applying the right amount. That means a device can be built and measure "the right amount" for an arbitrary value of right. A second approach could entail the counting of how much self-punishment is left, but it is assumed that the person undergoing this self-treatment will be confused which direction to take anyway(*).

bhh-design
Figure 2, Device design concept (measures in [mm])
As a starting point, a central acrylic disc, with "BANG HEAD HERE" engraved on the back, serves as a replacement for the familiar poster version that shines your wall (with various blood-stains). A visual indication for hand-support is usually present because banging your head may have influence on your balance. Incidently, we can detect the presence of a person, willing to undergo self-punishment treatment, when the hands touch some electrically conductive stainless steel plates.

A strip of indicator LEDs with a central bar is used to show the magnitude of self-punishment. The game's target is to apply enough power with your forehead to get to the middle of the vertical bar of LEDs. A piezo-buzzer is mounted under the acrylic disc as sensor to measure the magnitude of the bang and auditive feedback. The acrylic disc is furthermore side-lit for visual indication purpose.

The game's operation is as follows(**):
  • place hands on plates, the disc will light up to indicate ready
  • apply the right amount of self-punishment by hitting the acrylic disc with forehead
  • see the LED bar whether the right amount of self-punishment has been achieved
  • release hands from plates
  • repeat from step 1 if not satisfied with the result
It should be noted that the right amount of force is a subjective quantity. Luckily, the piezo-buzzer is a very bad measuring device, especially when you consider that it is mounted in a lose fixture. A bit of variability can be expected as to what result is achieved at constant force. This is not a bug. It can even be suggested that the user's state of mind has influence on the measurement. However, it is unclear which state of mind causes measurement errors in any particular direction.

(*) Pun intended. When hitting your forehead repeatedly, you probably cannot distinguish left/right, top/bottom or front/back anymore anyway.
(**) The creator of the device is not responsible for any injuries. Please seek professional help if a) the device's use takes up too much of your precious time, b) physical discomfort is the result of use, or c) blood is left on the acrylic disc after use.

Electronics

bhh-schematics
Figure 3, Bang Head Here schematic diagram (click to enlarge)
Schematics as PDF: headbang-sch.pdf

A voltage is generated in the piezo-buzzer when you bang your head on the disc. The voltage is detected in a high- and low-level peak detector to record the magnitude of the bang. The microcontroller records the peak levels by reading the PEAKL and PEAKH signals continuously and records the highest/lowest levels seen.

The peak detectors can be reset with the clear signals CLRL and CLRH. A high level and low level on CLRL and CLRH respectively will take the peak detectors to the opposite end of the detection range. The CLRL and CLRH signals are set to high impedance inputs on the microcontroller while detecting the actual peaks. The microcontroller must disable the digital input buffers for the CLRL, CLRH, PEAKL and PEAKH signals to prevent analog voltages from causing excessive transitional currents in the microcontroller.

The piezo-buzzer can operate in two modes:
1 - Speaker The buzzer is driven from the low-side NPN transistor, while the high-side PNP transistor of switched on (low on PULL). The low-side transistor is switched on/off using the timer output of the ATmega chip on Arduino pin 10 (OC1B), thereby generating a tone.
2 - Microphone The high-side PNP driver is switched off (high on PULL) and the low-side NPN transistor is switched on (high on TONE). The buzzer will settle at 1/2 Vcc (with R2 and R3) and any disturbance on the piezo-element is translated into a modulation around 1/2 Vcc. A "bang" on the buzzer will result in a self-resonant mechanical response, and can be measured as an electrical AC signal of approximately 4kHz. The peak level approximates the force of the bang.

The peak detectors use low leakage diodes and the opamps have an ultra low input current. The residual leakage current (<1nA) still results in a down-slope for the peak of about 10..20 seconds, but this is slow enough for the microcontroller to detect the highest/lowest peak level within a few percent. The series resistors (R11 and R12) are to stabilize the opamp (as per datasheet). The introduced RC-time is low enough not to impede the measurement of the 4kHz resonant frequency too much.

Hands are detected by a simple high-impedance input with a pull-up resistor (R6). A low level digital signal is seen on the input when both hands are touching the plates, using the body as a conductor. The plates pick up a considerable amount of EMI from the surroundings, which can be seen as an induced 50Hz line-voltage (a ferrite bead on the wiring close to the PCB may be used to reduce the impact and dampen common-mode induction). Increasing the input impedance is not recommended as it will increase EMI sensitivity. The input impedance may be lowered by lowering the pull-up resistor (≥470kΩ). Too low values for the pull-up will no longer ensure that the body-resistance can overcome the voltage divider between R6 and body to result in a low enough voltage and consequently the input may no longer be detected as a digital low-level.

Note: The hand-plate input uses Arduino pin 13, which is shared with an on-board LED on the Arduino board. The LED interferes with the input impedance, by lowering it significantly, and thereby preventing detection of the hands touching the plates. The LED must be removed for the input to work properly. In hindsight, a different input should have been used, but the designed PCB was already produced at that point. A simple removal of the on-board LED fixed the problem.

There are two LED-based indicators. The first uses a strip of 23 WS2812B pixels, indicating the strength of the bang. The WS2812B pixels are controlled by a one-wire interface. The second indicator are four RGB LEDs placed on the edge of the disc, which light up the engraved text on the disc. These RGB LEDs are controlled by the Arduino PWM infrastructure and buffered using three transistors.
bhh-pcb-assembled-mounted
Figure 4, PCB assembled and mounted
The whole hardware was produced and assembled by a group of pupils as a small project. This was their first practical project. Everything worked after sorting out a few soldering joints, short circuits and help on how to handle the machinery and other practical stuff for mechanical work (all beginning is hard). Magnus, Michael and Patrick did a great job; thanks guys!

Mechanical construction

Overview of the work in progress versus the final result.
in_progress_front in_progress_back
finished_back finished_front
Figure 5, Progress and finished (click to enlarge)

bhh-buzzer-holder
Figure 6, 3D printed holder and spring-loaded buzzer
The buzzer is mounted in a 3D printed holder and a spring presses the buzzer against the back of the acrylic disc. The advantage is that all parts can be separated again (in contrast to hot-glueing the buzzer to the back of the acrylic plate). However, the mechanical vibration transfer is not consistent. This is, as noted in the concept design, not as problematic as it may seem for this application. There is a some luck involved to bang with the right amount of power.
bhh-stencil
Figure 7, Hand-plate stencil (click to enlarge)
The hand-plates are 1mm stainless steel plates. A hand indication is spray-painted on the plates using a laser-cut stencil. A transparent printer sheet is used as the base of the stencil. A few more holes were cut into the plastic sheet (using a knife) through which it was adhered to the plate by means of sticky tape.

bhh-painted
Figure 8, Hand-plate painted (click to enlarge)
Stencils and paint do not always mix very nicely. Capillary forces take over once the paint touches the interface between stencil and plate. This is especially true for spray-paint with a large amount of thinner. The paint was half-dried in an oven at 60°C for about 3 minutes after spray-painting. Then, a small cotton-swab was used to scrape off the smeared paint. Finally, the plate was put back into the oven for 30 minutes at 60°C to cure the paint.

bhh-milled
Figure 9, Milled wiring groove (click to enlarge)
The wiring of the device has been hidden in a reverse-V milled groove using a hand-held mill. The groove allows for all wiring to be fixed and hidden while keeping the backside of the device free of protruding wiring.

bhh-wirefixture
Figure 10, Wire fixture in milled wiring groove (click to enlarge)
The wiring is fixed into the groove using small plastic clippings from a tiewrap.

Software

The software is built around a state-machine as shown below in simplified form. The major movement in the state-machine is the measurement sequencer. The peak detectors must be enabled and the analog hardware must settle before a measurement can be taken. This is especially important because the piezo-buzzer is used both as detector and speaker. Almost any state will go to idle directly if the hands leave the plates. The game only operates when you keep your hands on.

bhh-statediagram
Figure 11, Simplified state-machine diagram
The sequence of a normal gameplay is as follows:
  • hands are placed on plates
  • a single tone is played
  • peak detectors are primed and waiting for a detection
  • if peak detected and recorded
    • animate level of the peak
    • if peak is at right level
      • animate winning situation
      • play winning tune
  • if no peak is detected
    • show failure after timeout
  • hands are released from plates
The animations on the LEDs are coded in their respective state-machines. The main idea in the code is to use event-based programming, where timer events and input events are the driving forces.

The code uses the Arduino framework, but many features program the ATmega328P chip directly. For example, tones are generated using hardware timer 1 and outputs on OC1B. This prevents software timing from interfering with the tone consistency. The analog to digital conversion is coded directly to the hardware ADC. The timing requirements and sequencing make it more appropriate to bypass the Arduino libraries. Care has been taken to reduce input leakage currents on the analog pins by disabling the digital input buffers on these pins explicitly.

The WS2812B strip is controlled by Adafruit's NeopPixel library, with an addition to control the pixels in the HSV color space. The acrylic disc LEDs do use the Arduino infrastructure for PWM (analogWrite).

Design documents and code

bangheadhere.svg Original design document
headbang-arduino-code.tar.gz Source code of the project
headbang-buzzerholder.tar.gz 3D printed spring-loaded buzzer holder
headbang-kicad-pcb.tar.gz Schematic and PCB (KiCad project)
headbang-lasercut.tar.gz Lasercut documents, acrylic disc and stencils

Posted: 2016-11-28
Updated: 2016-11-28

 
 
Overengineering @ request