Friday 4 August 2017

DIY Spectrometer

Have you ever wanted to see what the stars are made of, what is in a light source or even what is inside of your drinking water? Well, there is a tool for that in Star Trek it is called a tricorder but in the real world, we use a tool called a spectrometer. A spectrometer is a device that can analyse what is inside of an object based on the light that passes through that object.

How a Spectrometer Works

There are many different components that make up a spectrometer:
The sample/light source: This is what you are analysing

The slit: This allows only a sliver of light to pass through to be analysed.

The grating: It is similar to a prism where it splits the light into the different colours that make up that light.

The recorder: All this does is collect and capture the data provided from when the light is split by the grating.

When you put it all together it should work like this.


The setup:

Shine the light towards the spectrometer.
Place sample in between light and spectrometer (Optional)

What happens:

The light will pass through the slit allowing a narrow beam of light to pass through.
It will hit the grating at a 45-degree angle and be split into a spectrum.
The webcam will record that data and send it to the computer.


How to build a spectrometer:

The first step is to get an enclosure that is not too big but has the length width and height to fit your web camera.Next, you are going to need to completely fill it with black paper or cover every surface with black ink.

Then you will cut out a square where you can place the slit. To make the slit what you need to do is put two razor blades together then split them using a piece of paper. tape them down to a piece of black cardboard then once you've made the slit cut the piece of paper where the separation is to allow light to pass through. Go to 1:22 in the video to see how.
https://www.youtube.com/watch?v=fl42pnUbCCA

After that get a piece of grating. To make grating what you need to do is take an old CD and cut around the outer and inner edges of the CD. Then place tape all over the CD then peel it off. With the purple coloured disk cut that into a tiny rectangle that will fit on your webcam. Go to 3:03 in the video to see how.
https://www.youtube.com/watch?v=fl42pnUbCCA

Next, tape the grating to the webcam. Then place the webcam at a 45-degree angle to the slit and make sure the lens is perfectly lined up and that is a working spectrometer.

The Software

I have written two codes that work together to capture and analyze the data collected by the spectrometer.

What this code does is it captures the image. The image will pop up on the screen. In that image, we will take the Y value and input that into our next code

import numpy as np
import matplotlib.pyplot as plt
import cv2

cap = cv2.VideoCapture(1)
ret, frame = cap.read()

fig = plt.figure()
myax = plt.imshow(frame)
plt.show()

What this code will do is using the Y value from the image it will plot that row. It will plot it so that it is the intensity compared to the pixel position of that row.

import numpy as np
import matplotlib.pyplot as plt
import cv2

cap = cv2.VideoCapture(1)
ret, frame = cap.read()

spec = np.empty((0))
for x in range(1280):
    [r,g,b]=frame[305,x]
    #print x
    intensity = (int(r)+int(g)+int(b))/3.0
    spec = np.append(spec, intensity)

# Subtract minimum of spectrum
spec = spec - min(spec)

plt.plot(spec)
plt.show()








Wednesday 12 July 2017

Updated version of the drum machine: Drum machine 3.0 (Even more noise, even more portable.)

If you have read my blog before you will know about the wearable drum machine that I made previously. This year I decided to make the project true to its name. I created a drum machine that was literally on the T-shirt itself. (Picture below.) As you can see it uses four sensors. Of course, there are still limitations because currently, you require the internet connection to run the drum synthesizer.

Major new features compared to gen. 2 project:

PHONE

This year I decided that since it had to be attached to a laptop it would not be deemed wearable. So this year I decided I had to make it fully portable so it now uses an adapter to connect the Arduino to a synthesizer on my phone.


How it works.

The hardware 

The FSR when tapped allows the current to pass through.
The current passes through the copper tape to the crocodile clips.
The crocodile clips connect to the wires which are attached to the Arduino. (To learn how to wire look at the link below.)
The Arduino through an adapter connects to a phone which has a drum synthesizer which activates based on keyboard commands.

The software

The Arduino is acting as a keyboard. Each time the Arduino receives a signal from one of the FSR it produces a keyboard command.
The Synthesizer relies on keyboard commands. For example, if I were to press the button on the keyboard 'F' it would make the sound of cymbals now when you press the FSR on the shirt it would do the exact same thing.


The brains of the project (Arduino)

Connect the FSR to the Arduino


To help you with connecting the FSR to the Arduino I have provided a link. In this link it shows a diagram showing the where to connect the FSR and what type of resistor you require to do so. To understand how FSR work you can do a quick and easy test by also adding an Led into the circuit and seeing how based on how hard you press the led for instance you can make the LED brighter and brighter. If you scroll further down it shows you multiple example codes.

Make it print out keyboard commands when pressed
An important part of the project is the synthesizer. This part of the project remains the same. It uses an online drum machine synthesizer that requires keyboard commands. This way whenever you touch an FSR it produces a keyboard command which gets sent to the synthesizer and produces the sound. The key component of making keyboard commands comes from the Arduino Leonardo which is the only Arduino with the capability of emulating a keyboard or a mouse. To look at how to make keyboard commands using the Arduino Leonardo you can look at the code below or take a look at my older version of the blog. In that, it shows the code for using readings to print keyboard commands.

/* Modified FSR code and USB keyboard code */

#include "Keyboard.h"

int fsrAnalogPin0 = 0; // FSR is connected to analog 0
int fsrAnalogPin1 = 1;
int fsrAnalogPin2 = 2;
//int LEDpin = 11;      // connect Red LED to pin 11 (PWM pin)
int fsrReading0;      // the analog reading from the FSR resistor divider
int fsrReading1;
int fsrReading2;
int pressForce = 20;
int LEDbrightness;

void setup(void) {
  Serial.begin(9600);   // We'll send debugging information via the Serial monitor
//  pinMode(LEDpin, OUTPUT);
  Keyboard.begin(); // initialize control over keyboard
}

void loop(void) {
  fsrReading0 = analogRead(fsrAnalogPin0);
  delay(50);
  fsrReading1 = analogRead(fsrAnalogPin1);
  delay(50);
  fsrReading2 = analogRead(fsrAnalogPin2);
  delay(50);
  //Serial.print("Analog reading = ");
  //Serial.println(fsrReading);

  if (fsrReading0 > pressForce) {
    Keyboard.print("e");
  }
  if (fsrReading1 > pressForce) {
    Keyboard.print("f");
  }
  if (fsrReading2 > pressForce) {
    Keyboard.print("v");
  }

  // we'll need to change the range from the analog reading (0-1023) down to the range
  // used by analogWrite (0-255) with map!
  // LEDbrightness = map(fsrReading, 0, 1023, 0, 255);
  // LED gets brighter the harder you press
  // analogWrite(LEDpin, LEDbrightness);

  delay(50);
}



Saturday 26 December 2015

Halloween

Every body loves halloween. Whether it's snowing or raining or sunny outside you meet up with friends, go around the neighbour hood and collect as much candy. There is so much to enjoy about it... candy, friends, candy, games, candy, scaring people and candy. Did I mention that you get candy? But there is one thing that can make halloween really special... it's DIY costumes. If the people like your costume you get extra candy, take selfies with random people and gather attention without even trying. So earlier this year I made my own custom R2D2 costume from trash cans and candy bowls. Now I am going to show you how too can make it.

Materials you will be needing:

  • One garbage bin size a bit bigger than your body.
  • One candy bowl
  • Blue spray paint
  • Silver spray paint
  • White spray paint
  • An Arduino
  • A few cables
  • A Adafruit neopixel LED. All droids have lights.
  • Tape
  • Bicycle helmet. Yes safety first. Just kidding.
  • Styrofoam sheets
  • An iPod or a phone along with a portable speaker


Step 1: Cut the bottom of the garbage bin. Then spray paint the garbage bin all blue and then place tape to mark out the patterns. Finally spray paint it all white. Be sure to do this where there is plenty of fresh air. Your neighbours might still hate you!
The reason that we spray paint the body all blue at first is because the designs on R2D2 are all blue then you place tape in whatever pattern you want on your droid. Then you spray paint it all white. When you remove the tape only those designs would be blue.


Spray paint the cut bin
Step 2: Tape helmet to the candy bowl with double sided tape or velcro. Then spray pant candy bowl all blue, place tape to make patterns like circles and squares and finally spray paint it all silver.
This is very similar to the earlier step only this time it is a candy bowl you are spray painting and instead of white you're using silver. You will see the results in pics below.

Cut bin with stencils spray painted

Step 3: Make arms out of styrofoam and silver tape. Then connect it to garbage bin using tape. You cut the styrofoam at around the size of you garbage bin but when you mount it make sure to place it slightly lower than than the top of the garbage bin. You can use silver tape to create more patterns on the droid body. I used images from the web to guide me.

Candy bowl painted as R2D2s head
Step 4: Don't forget that you have to carry this around on your shoulders for the whole day. So make shoulder straps. I used duct tape to make these. This way the garbage bin can rest on your shoulders. By cutting the bin open you're allowing your head to go through the bottom and with the shoulder straps it makes it easier to have the costume with you because you don't have to hold it up. Remember the bin is upside down.

R2D2 carried on my shoulder with straps

Step 5: (optional) Add adafruit neopixel inside the helmet. Very basic coding involved connect it to Arduino. So basically what you are doing right now is adding a eye to your R2D2 costume. First you will be working with the circuits. Connect the arduino to the neopixel as shown here. Then use the code shown in the same page to create different colours that go around in circles. I powered the whole thing using my brother phone charger pack. Shout out to my brother, Maaran!

Step 6: (optional but super cool) Download the sound of R2D2 from the web and play it in a loop using an iPod or a phone. Connect the phone to a small portable speaker and carry the iPod and speaker in your pocket. This way the sound really comes from inside the robot.


Conclusion:
Apart from being the ultimate candy attracting device, this is a fun and basic experience to introduce yourself to arduino and basic wearables. Also you get more candy. Did I mention I love candy! Mmmm!
Here is a video of the finished creation. ENJOY!
https://youtu.be/zn4ycgPEccc




Sunday 20 September 2015

Get Your Bot On

Hello there my fellow makers. Lately my latest work has been on prepping for get your bot on. At GYBO I built a interactive skipping rope.

It will become an art instalment at parks. It is controlled by gesture. You can control direction and will be able to control speed as well.
The link to our devpost is: http://devpost.com/software/gest-jump
Please Like!

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.