Friday 31 July 2015

Making your own wearable drum kit and other noisy devices

How to build your own wearable drumkit

Note: this is a project that I presented at the 2015 Toronto MakerFest event.

So everybody loves wearables and people are making their own. Big companies like Apple are making their own wearable technology and there are companies only for wearables. So I thought would it not be cool if I were to build my own. But I had to mix my wearable with something I like such as music. Therefore I fused the two and out came up with "the wearable drum kit." Another reason I had to make it a wearable is because everybody else has a wearable... even puppies do!





My design is composed of an Arduino hooked up to a capacitive touch sensor and also connected to a PC. You hook it up to anything that is conductive and it will start playing music through the PC. How this works is when you move your hand close to an electrically conductive material, its capacitance changes. The capacitive touch sensor is able to detect this tiny change in capacitance of the object and it will automatically send a signal to the Arduino through the I2C communication. The arduino emulates a keyboard and sends a key press command to the PC when this event is detected. If the PC has a music program setup to play notes when a key press occurs, you can get the PC to play music every time your hand gets close to the touch sensor. Simple!
Here is me proudly wearing my final design as a necklace. The touch pads are the tiny aluminum squares you see at the end of each long LEGO piece. 




Another close up showing the Arduino Leonardo, CAP1188 breakout board and contacts all attached to one LEGO frame. The only outside connection is a USB cable to the PC.

The Materials required are:

1. Arduino Models: Leonardo (see below for why you need Leonardo)
2. CAP1188 (capacitive touch sensor) found here.
3. a few connection wires
4. aluminum tape or foil
5. scotch tape
6. A few lego pieces as a base or a 3d printed non conductive enclosure

The maker process

As most makers do I had to look for inspirations for this project. So I browsed the web patiently. What you don't expect me to invent everything do you. I actually came across something called the beet-box get it. Beet box. You will see why it's a word play. Well that gave me the idea of touch capacitive sensor. So at that time all I wanted to build was a interactive drum kit but then I saw Drumpants I knew at that moment I had to make a wearable drum kit.
I have the link below for 
Drumpants: https://www.youtube.com/watch?v=6VS2jWqFKM0
Beet-Box: https://vimeo.com/55658574

The steps:

STEP 1: Prototype
IN this step you shall be trying to make only one sensor work just to make sure that everything is working. So my goal is to build a quick and dirty test. I hooked up one wire on the breadboard to pin C1 of CAP1188. Then I connected CAP1188 to a Arduino Leonardo using I2C. For detailed instructions on wiring click here. In the wiring instructions just follow the first segment using I2C. Some problems you may encounter are a double tap but you just have to add a simple debounce to the code or just make the wait a bit longer. See below for sample code on how to deal with issues. Hopefully the comments will help. 
One precaution you have to take is making sure the wire to the capacitive inputs should not be too long because the sensor will sense your hand from a long distance.

STEP 2 : Layout of the shirt
This might be one of the hardest parts of this entire process. You have to decide  how to place your touch capacitive sensors. Lucky for you, I went through almost every mistake so it might be easier for you.  Before we move on I'd like to show you the failures I've been through. 
First, I built my dream wearable. The touch pads were conveniently located on a shirt. Copper tape was used to connect it to the side of the shirt where it would be connected to the Arduino through the CAP1188. But There were two problems. The first being that it would false trigger with the slightest body movement because the sensor would rub against my body. Then because the copper strips were too long, they started to act as if they were sensors and whenever my hand was above these copper strips it would trigger randomly. Here is an illustration of my dream design.

Then I tried to insulate the shirt. I put a copious amount of electrical tape around the shirt. But it still did not work because I did not change anything about the copper tape. So it continued to trigger randomly.
My next attempt involved putting the whole design on a card board piece. I encountered a new problem. In this scenario the paper was still changing the capacitance of each touch pad. So it continue to trigger randomly :-(
This motivated me to come up with a design that was totally non conductive. LEGO to the rescue! This worked because Lego pieces are plastic and thick. So they are not conductive. Also, the design made everything compact. So all the wires were as short as possible. The wires also did not move as much because of the design was rigid. You can see this design at the top of this post.


STEP 3: Hook it up to a music synthesizer after programming
I started with the sample code that came with Adafruit's CAP1188 board. You have to use a Leonardo here because it readily emulates keyboards. The UNO does not support this cool feature. The setup of Arduino Leonardo programming to use the CAP1188 is given here. You will notice that you have to download a special library and add it to the programming environment. Then you will have access to the sample code. I was being creatively lazy and definitely made use of this sample code.
Now I had to code the Arduino to emulate keyboard commands every time a touch pad was touched. I used the Keyboard function that comes with Leonardo to send keyboard commands when a capacitive touch event occurred. 
In the example code below you will see that I sent key presses '2', 'k', 's' and '6' when one of the four touch pads are contacted.

/***************************************************
  This is a library for the CAP1188 I2C/SPI 8-chan Capacitive Sensor
  Designed specifically to work with the CAP1188 sensor from Adafruit
  ----> https://www.adafruit.com/products/1602
  These sensors use I2C/SPI to communicate, 2+ pins are required to
  interface
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!
  Written by Limor Fried/Ladyada for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
 ****************************************************/

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_CAP1188.h>
// Reset Pin is used for I2C or SPI
#define CAP1188_RESET  9
// CS pin is used for software or hardware SPI
#define CAP1188_CS  10
// These are defined for software SPI, for hardware SPI, check your
// board's SPI pins in the Arduino documentation
#define CAP1188_MOSI  11
#define CAP1188_MISO  12
#define CAP1188_CLK  13
// For I2C, connect SDA to your Arduino's SDA pin, SCL to SCL pin
// On UNO/Duemilanove/etc, SDA == Analog 4, SCL == Analog 5
// On Leonardo/Micro, SDA == Digital 2, SCL == Digital 3
// On Mega/ADK/Due, SDA == Digital 20, SCL == Digital 21
// Use I2C, no reset pin!
Adafruit_CAP1188 cap = Adafruit_CAP1188();
void setup() {
  Serial.begin(9600);
  // keyboard initiationlization
  Keyboard.begin();

  Serial.println("CAP1188 test!");
  // Initialize the sensor, if using i2c you can pass in the i2c address
  // if (!cap.begin(0x28)) {
  if (!cap.begin()) {
    Serial.println("CAP1188 not found");
    while (1);
  }
  Serial.println("CAP1188 found!");
////from post https://forums.adafruit.com/viewtopic.php?f=8&t=49138&p=247522&hilit=1188#p247522
//
//uint8_t reg = cap.readRegister( 0x1f ) & 0x0f;
//cap.writeRegister( 0x1f, reg | 0xF0 );   //0xF0 is slowest and 0x04 is default
////NOTE: Above code is for sensitivity. Key bounce delay is set at 0x22 register (pg. 49/50 of CAP1188 manual)
//
  uint8_t reg = cap.readRegister( 0x22 ) & 0x0f;
  cap.writeRegister( 0x22, reg | 0x04 ); // or whatever value you want
}
void loop() {
  uint8_t touched = cap.touched();
  int touchedPin;
  // I put two lines here to fix double press problem
  delay (50);
  touched = cap.touched();
  if (touched == 0) {
    // No touch detected
    return;
  }

  // complicated code to figure out which pin was touched
  for (uint8_t i=0; i<8; i++) {
    if (touched & (1 << i)) {
      touchedPin = i+1;
      //Serial.println(touchedPin);
    }
  }
  // if touchedPin is 1 then send keyboard command 'a'
  // if touchedPin is 2 then send keyboard command 's' etc. etc.
  if (touchedPin == 1) {
    Keyboard.write('2');
    delay(150);
  }
  else if (touchedPin == 3) {
    Keyboard.write('k');
    delay(200);
  }
  else if (touchedPin == 5) {
    Keyboard.write('s');
    delay(200);
  }
  else if (touchedPin == 7) {
    Keyboard.write('6');
    delay(150);
  }
  else
  {
    touchedPin = 10;
  }
}


STEP 4: Find ways to advance your own wearable drum kit
I have shown how to emulate keyboard commands in my project. It will be amazing if the device can send MIDI commands. This way, you can hook up the device to any MIDI device such as iPad, iPod touch or a smart phone. This will make the whole design whole lot more portable. Let me know if you manage to get MIDI working with Leonardo by commenting below.

STEP 5: Have fun and post back your successes (and failures). I will try to help where I can.



Wednesday 15 July 2015

My own arcade in a (shoe) box

Hi there! We live in a gaming world full of tablets, computers and video games but do we know where these came from? So I decided I would do my own type of history lesson. I went back to the retro days and found where this all started. So I wanted to build my own but on a  low (shoestring) budget. Find out how to build an arcade in a shoebox by continuing to read this post...



Materials required:


  1. A shoe box (I'm sure you'll be able to find one in your house)
  2. A Raspberry pi (around 40 dollars at a place like sayal)
  3. Some connection wires
  4. An interface board that can emulate a keyboard. I used an Ultimarc iPac board rather than all the I/O pins on the RaspberryPi because I wanted to build it easily with no additional programming. You could call it being creatively lazy!
  5. A joystick and buttons
  6. A wire stripper
  7. A exacto knife
  8. Finally a whole load of perseverance!!

As you can see from the materials I made the design easy with a interface board instead of wiring up the buttons to the I/O pins on the RaspberryPi. This way, any game that can be controlled with a keyboard can be controlled with retro looking buttons. No programming required!

The steps to success


  • Browse the web with patience but I'm assuming you already did because you're here.
  • Then test repeat Prototype then test repeat prototype then test.
  • Did I mention you have to Prototype then test.
  • Finally, build on the success of others. There is no need to reinvent yet another wheel. Good folks at Retro Pi have made things easy for you folks. They've done all the software and a lot of emulators are already installed.

Steps:

1. Quickly prototype the basic system... The first and probably one of the most important things to do in a successful project is to test to make sure that it works as a prototype. So I made sure that my buttons, my micro-switches, my interface board and my RaspberryPi worked. In this process you may expect to find a few glitches with your switches. But an easy way to check if your switches and buttons are good is with a continuity checker. Another bug you may expect is if your interface board is not working. A common problem is wiring of the test button to a wrong key in the interface board. There are many different options and it is very confusing so keep trying till it works.







2. Now set up your joysticks and your buttons with the micro-switches. There should be four switches in total that are mounted in the corners of the joystick. There should be no problems in that area but if there are please do report them in the comments section and I can try to help.




















3. Cut your shoe box open and measure to the size of your buttons and your joystick. In this section if you are under twelve of age I recommend the help of an adult due to use of extremely sharp knives. You will be using an Exacto knife to cut open the holes. The better way to be cutting open holes in this is by using a paper and then copying it down onto the shoebox.




















4. Now place your buttons and joysticks carefully into the shoebox. In this section you have to be extremely careful because if the microswitches are damaged  then you have to get another set of switches. Another thing is that the joystick will need to be screwed in to the shoebox so that it doesn't fall down or rattle too much -- like when you are in the middle of some major gaming session.























In the following step you may may want to use a wire stripper -- Man's second best friend...

5. Now attach the wires to the sensors and  hook them up to the interface board. When connecting to the switches make sure that you are connecting to those pins that close the circuit only when the switch is pressed. Use a continuity checker to figure out the right pins if the switch has more than two pins. Another thing that I suggest is that you make it so that all your wires are different colours (colour coded). This way it's easier to wire it all together and trace the wires in case you want to confirm the wiring of the correct buttons to the correct input pins on the interface board.
Connecting from the buttons to the interface board is quite simple. Connect one wire from each button to one screw post in the interface board. Each screw post is marked with a keyboard button name like up, down, return etc. I used the standard MAME key assignments.
Finally, hook up all the ground connections (one each on each button) and then connect them to the ground screw post on the interface board. Done!























6. Attach the raspberry pi to the interface board through a USB cable.

7. You are almost ready to have a lot of fun. Now you have to install and setup the RetroPi software with ROMs in the RaspberryPi. I followed the steps in LifeHacker blog to complete this.

Don't forget to enjoy and post back your experiences.