All prices in Canadian dollars. Free shipping on orders over $150!

News

June 12, 2017

Posted in neopixel, projects, store news


Clap on 👏👏, Clap off 👏👏

The offices next to Elmwood's must be wondering what we've been up to over the last couple of days. They would have heard sudden bursts of applause, then giggling, then more applause, and so on. There is, I can now reveal, a very good reason for this odd behaviour.

We've been testing Verbal Machines' Hand Clap Sensor VM-CLAP1. While it might look a bit like a cheap “noise detector” board, VM-CLAP1 has a bunch of clever signal processing built in so that almost all background noise is filtered out. Only handclaps or finger snaps will make the sensor trigger, and will do so over a range of a few metres.

We tried it with a speaker blaring right next to the microphone, and it could still pick out our handclaps over the noise. Really short percussive sounds like sharp snare hits might confuse the VM-CLAP1, but the board makes audio control of your electronic projects much simpler.

VM-Clap1 is really easy to set up, with only three connections:

  1. GND – to your system's ground
  2. PWR – anything from 2.5 – 5.5 V, so it will work with all common micro-controller project boards, including the Raspberry Pi. It draws only 1.7 mA at 3 V, too.
  3. OUT – this is an open collector output, which means the sensor sinks current when it is triggered. To use it with an Arduino, be sure to set INPUT_PULLUP for the VM-CLAP1 pin, or use an external pull-up resistor. Output is normally HIGH but is held LOW for 40 m/s when triggered.

I've written a couple of Arduino demos to show off what the VM-CLAP1 can do. The first is a very simple “clap twice for on, clap twice for off” script that switches the built-in LED on and off. Flashing LED_BUILTIN is no big deal, but choose a different pin, add a coffee maker and a Power Switch Tail II, and you've got a clappuccino machine!

Wiring is as follows:

  • OUT → Pin 2
  • PWR → 5 V or 3.3 V
  • GND → GND

And here's the code for Arduino:

/*
    Verbal Machines VM-CLAP1 sensor test
    clap twice within ¼ second to turn Arduino LED on or off

    by  scruss - 2017-06
    for Elmwood Electronics - https://elmwood.to/

    Sensor wiring:

      OUT   → Arduino Pin 2 (use INPUT_PULLUP)
      PWR   → 5V or 3.3V
      GND   → GND
*/

#define CLAPIN  2             // pin must be interrupt-capable
#define CLAP_DELAY   250      // max gap between claps to trigger

volatile boolean clap = false;                // clap detected state
boolean led_state = false;                    // LED on/off state
unsigned long clap_time, last_clap_time = 0;  // clap time records

void setup() {
  pinMode(CLAPIN, INPUT_PULLUP);
  pinMode(LED_BUILTIN, OUTPUT);     // control built-in LED by clapping
  Serial.begin(57600);
  Serial.println("# Clap sensor test ...");
  attachInterrupt(                  // register Interrupt Service Routine (ISR):
    digitalPinToInterrupt(CLAPIN),  //   pin to watch for interrupt
    heard_clap,                     //   void function to call on interrupt
    FALLING                         //   trigger interrupt on HIGH → LOW change
  );
}

void loop() {
  digitalWrite(LED_BUILTIN, led_state);  // set LED based on clap status
  if (clap) {                       // we heard a clap from ISR
    clap = false;                   // make sure we don't trigger again too soon
    last_clap_time = clap_time;     // store old clap time
    clap_time = millis();           // note current clap time
    if (clap_time - last_clap_time < CLAP_DELAY) {  // if two claps heard in ¼ s:
      Serial.println("clap clap!");                 //   notify
      led_state = !led_state;                       //   and switch LED state
    }
    else {
      Serial.println("clap!");                      // notify of only one clap
    }
  }
}

void heard_clap() {
  clap = true;      // just set clap state in ISR
}

 The next demo is a "clapometer", where we use an Adafruit NeoPixel Stick - 8 x WS2812 5050 RGB LED as the indicator. The faster you clap, the more LEDs light up - and in different colours, too!

Wiring is as follows:

  • VM-CLAP1 Sensor OUT → Pin 2
  • VM-CLAP1 PWR → 5 V or 3.3 V
  • VM-CLAP1 GND → GND
  • NeoPixel stick DATA IN → Pin 6
  • NeoPixel stick PWR → 5 V
  • NeoPixel stick GND → GND

You'll need to install the Adafruit NeoPixel Arduino Library to use the code:

/*
    Verbal Machines VM-CLAP1 sensor test
    clapometer with neopixel output

    by  scruss - 2017-06
    for Elmwood Electronics - https://elmwood.to/

    Sensor wiring ("open collector"):

      OUT   → Arduino Pin 2 
      PWR   → 5V
      GND   → GND

    8 Neoxpixel strip on Arduino pin 6
*/

#define CLAPIN          2     // pin must be interrupt-capable
#define CLAP_INTERVAL   600  // time over which claps are counted
#define MAX_COUNT       7    // max claps to count
#define NEOPIN          6     // 8 px strip on pin 6
#define NUMPIXELS       8     // 0 ..7

// this is a colour table of pleasing(ish) HSV hues:
unsigned long hues[] = {0x7F0000, // 0 degree hue
                        0x7F5F00, // 45 deg
                        0x407F00, // 90 ...
                        0x007F40, // 135
                        0x007F7F, // 180
                        0x00407F, // 225
                        0x40007F, // 270
                        0x7F005F  // 315
                       };
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif

volatile boolean clap = false;          // clap detected state
unsigned long clap_times[MAX_COUNT];   // clap time records
int array_pos = 0;                      // index of current time record
int clap_count = 0;                     // count of claps within CLAP_INTERVAL
unsigned long current_time = 0;
int i, j = 0;
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, NEOPIN,
                           NEO_GRB + NEO_KHZ800);

void setup() {
  pinMode(CLAPIN, INPUT_PULLUP);
  Serial.begin(57600);
  Serial.println("# Clapometer ...");
  pixels.begin();
  for (i = 0; i < NUMPIXELS; i++) {
    // turn all pixels off
    pixels.setPixelColor(i, 0);
  }
  pixels.show();
  attachInterrupt(                  // register Interrupt Service Routine (ISR):
    digitalPinToInterrupt(CLAPIN),  //   pin to watch for interrupt
    heard_clap,                     //   void function to call on interrupt
    FALLING                         //   trigger interrupt on HIGH → LOW change
  );
}

void loop() {
  if (clap) {                       // we heard a clap from ISR
    clap = false;                   // make sure we don't trigger again too soon
    clap_times[array_pos] = millis();
    array_pos++;
    if (array_pos == MAX_COUNT) {
      array_pos = 0;
    }
  }
  current_time = millis();
  clap_count = 0;
  for (i = 0; i < MAX_COUNT ; i++) {
    if (current_time - clap_times[i] <= CLAP_INTERVAL) {
      clap_count++;
    }
  }
  // set neopixels to clap count in right hue

  for (i = 0; i <= clap_count ; i++) {
    pixels.setPixelColor(i, hues[i]);
  }
  if (clap_count < NUMPIXELS) {
    // blank any unused pixels
    for (i = clap_count + 1; i < NUMPIXELS ; i++) {
      pixels.setPixelColor(i, 0);
    }
  }
  pixels.show();
  Serial.print("clap count: ");
  Serial.println(clap_count);
  delay(10);
}

void heard_clap() {
  clap = true;      // just set clap state in ISR
}

Have fun with your new 👏-enhanced projects!

 

Stewart  would like to thank/blame Brent Marshall and Anna Humphrey for the idea of the "clappuccino" machine.

June 05, 2017

Posted in projects


Build your own retrogaming joystick

Retrogaming joystick

Tracking down old Atari-style joysticks for retrogaming can expensive, and it’s hard to tell if you’ll get something reliable. So I made one for less than the cost of a used stick on eBay.

To build this, you will need:

  • 8-way joystick , or any stick compatible with the industry standard Sanwa JLF-P1 mounting plate. This has M4 holes at 84 × 40 mm.
  • Two concave momentary arcade push buttons.
  • DE-9 (DB-9) Female Socket Connector
  • Terminal block, with at least seven connectors. You’ll likely want more, so this 12 position screw terminal block should work.
  • 4× M4 countersunk (oval head) machine screws with nuts and lots of washers. You’ll need washers to act as spacers between the box and the joystick mounting plate. This allows the joystick’s dust washer to move freely.
  • a couple of metres of 8-core stranded signal cable
  • hookup wire and spade connectors for building the button harness.

The case is made from 6.4 mm high quality plywood, using a template generated by BoxMaker.  The external dimensions of the box are 163 mm x 143 mm x 83 mm. I haven’t included any kerf width in the design, so the edges should fit together easily for gluing.

Joystick box plan

Joystick box plan for download: joystick-box-201706.svg (SVG: best in Inkscape); joystick-box-201706.pdf (PDF).

If you want to make your own design, here’s the top plate plan: joystick-box-top-201706.svg (SVG); joystick-box-top-201706.pdf (PDF).

The basic DE-9 pin wiring for Atari-style joysticks goes like this:

1 — Up
2 — Down
3 — Left
4 — Right
6 — Button
8 — Ground

There are many variants that add features to this scheme, however. If you’re building for a specific computer, Tomi Engdahl’s Joystick information page has the details.

Many thanks to Andrew Horsburgh for the use of Protolab‘s laser cutter.

May 23, 2017

Posted in projects


Raspberry Pi Powered Temperature Logger

We just moved to a new office, which has been great, but as the outside temperature reached 30°C the other day, we realized that our air conditioning was not working!

Our landlord is great and we suspect he will fix the AC quickly, but we figured it would be a good idea to track the temperature.  There are many ways to do this, but we thought it would be most fun to use Python on a Raspberry Pi.  

We really like the DS18B20 temperature sensor, as you can communicate with them via I2C.  We have several flavours of these sensors, they all work the same:  bare sensor, waterproof, and high temp waterproof.

We started with Adafruit's excellent tutorial on the DS18B20 for the Raspberry Pi.  There you can learn the basic wiring and how to hook it up to the Pi.  We will also use their example code in our program below.  This example will work on Raspbian and other similar distributions.  

Next, we created a database to log the temperature. There is a great Python library called sqlite3 that allows you to make simple or powerful databases.   SQlite is not installed by default on Raspbian, so we need to install it:

sudo apt-get install sqlite3

We also need a few Python libraries for managing time, so install these as well:

sudo pip install python-dateutil

Now that we have all the dependencies installed, we can get to coding.  The below code is available for download here.

First we get the required libraries:

import sqlite3
import os
import glob
import time
import dateutil.parser
from datetime import datetime

Now we connect to the database:

conn = sqlite3.connect('temp.sqlite3')
cur = conn.cursor()
And we create the table if it does not yet exist:
CREATE TABLE IF NOT EXISTS templog
(date TEXT, hour TEXT, temp_f FLOAT, temp_c FLOAT)''')
Here we connect to the temperature sensor and tell the program how to read it:
os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')
base_dir = '/sys/bus/w1/devices/'
device_folder = glob.glob(base_dir + '28*')[0]
device_file = device_folder + '/w1_slave'
And now we read the temperature
def read_temp_raw():
    f = open(device_file, 'r')
    lines = f.readlines()
    f.close()
    return lines
def read_temp():   
lines = read_temp_raw()   
while lines[0].strip()[-3:] != 'YES':       
time.sleep(0.2)       
lines = read_temp_raw()   
equals_pos = lines[1].find('t=')   
if equals_pos != -1: 
temp_string = lines[1][equals_pos+2:]       
temp_c = float(temp_string) / 1000.0       
temp_f = temp_c * 9.0 / 5.0 + 32.0       
return temp_c, temp_f
Here we grab the time and temperature and print it to the screen:
while True:       
timenow = datetime.today()        
timedate =  timenow.strftime("%Y-%m-%d")      
timehours = timenow.strftime("%H:%M")       
print timedate, timehours, read_temp()       
temp = read_temp()       
temp_f = temp[1]       
temp_c = temp[0]
And now we write the temperature and time to the database
cur.execute('''INSERT INTO templog (date, hour, temp_f, temp_c) VALUES (?, ?, ?, ?)''',(timedate, timehours, temp_f, temp_c))
conn.commit()
Lastly we sleep for 60 seconds before we start all over again:

        time.sleep(60)

 

With that done, our next step is to run the code and log the temperature!  Just type the following:

python readtemp.py

You should see the temperature and time output to the screen, and a new file will appear called temp.sqlite.  

Now you can simply connect to your Pi, get the temp.sqlite file, and open it up in a database browser!  We prefer to use DB Browser for SQLite, which is a simple and high quality open source tool for viewing and editing databases.  Here is a screenshot:

Within DB Browser you can do many things, but if you are comfortable in Excel or similar spreadsheet programs, many find it easiest to just export the data to CSV.

Once you have the CSV, you can plot or do anything you like.  Here is a plot of 3 days worth of temperature collection. 

You can see that the temperature does not vary much.  The X-axis shows time, we did not clean this up but you get the idea!

We hope you enjoyed this post, thank you for visiting our site! 

 

 

April 10, 2017

Posted in projects


Solar Powered Beckoning Cat

I picked up a battery powered "beckoning cat" on a to Shanghai, and it has consumed 3 "AA" batteries over a period of 36 months.  Seems like a silly waste of batteries, right?

With spring upon us and some sunny days in Toronto, I decided it was time to put one of our Adafruit Solar Badges to work.  These little badges output 40 milliamps @ 5 volts in direct sunlight, which seemed like enough for our cat.

 

The cat was originally powered by a single AA battery, which provides 1.5 volts.  Being a good engineer, I thought it would be best to give it around the same voltage.  One way accomplish this is with voltage dividing resistors.  

 I won't get into the theory here, but I knew that using lower resistance would consume less power, so I went with 10 ohm and 18 ohm resistors.  This would provide 1.79 volts.

You can learn more about this calculation at LearningAboutElectronics.com

 

It turned out that my efforts to match the voltage were in vain, as with the resistors the cat's arm barely moved in direct sunlight!

Resistors dissipate energy, and it turns out that even these low impedance resistors were sapping too much energy. 

I thought about it, and realized that the reason the cat had an AA battery probably wasn't due to delicate electronics that could only tolerate 1.5 volts...rather, it was for cost savings and packaging.  So I thought, why not just hook the solar cell directly to the cat.

It turns out that this is all the cat needed!  

 The cat even works in lower levels of sunlight:

 

Here's a picture showing how I soldered the wires to the AA battery terminals:

February 25, 2017

Posted in projects


Hungry Hippos

This project is a digital remake classic board game Hungry Hungry Hippos. I decided to try and recreate the motion of the hippos from the game at the push of a button. I knew going into this that the hippos had two main motions: the forward and backward motion of their body and the up and down motion of their head. I figured that I could use a servo to control the body motion and a solenoid to control the head motion. I decided that would program my hippo using an Arduino Mega 2560 R3. I started by 3D printing a head for the hippo and a rack and pinion that would represent the hippo's body. This was an iterative process (it took a few tries to get the pinion to fit on the servo), but I finally ended up with a set of parts that I was happy with.

The next thing I had to do was connect the head to the rack. I knew that the head had to pivot up and down in order to "eat" the marbles, so I attached it to the rack using a hinge and some superglue.

I then started working on attaching the solenoid to the rack and head. I was going to glue it to the rack and use a piece of copper pipe to attach it to the head. However, I quickly realized that the solenoid drew too much power to be powered by the Arduino alone. I was able to resolve this problem using a 9V battery adapter and a TIP120 transistor. (Side note: when working with transistors, make sure you use the right one for your project. I thought I could get away with using a transistor that I had laying around in an electronics kit, and when I went to touch it after hooking it up I almost burnt my fingers.) I then encountered another setback: the solenoid did not have enough pullback force to lift the head. I realized that I either had to get a larger solenoid (which may or may not have solved the problem) or come up with another way to move the head. Since I was short on time, I ultimately ended up putting the solenoid aside for another project.

In the mean time, I got to work on setting up the pinion attached to the servo since I was confident that my rack and pinion system would work. I pressure fit the pinion on the servo and taped the servo on the underside of the box lid I was using as the base for the project. I cut a hole in the box lid so that the pinion would be able to connect with the rack.

At this point it was time to wire everything. I decided to make two hippos so I got everything setup and taped all the wiring and components in place on the bottom of the box lid. I used standard push buttons as the controls and a 9V wall adapter to power the Arduino. The wiring was a little bit messy but it was functional nonetheless.

I then put the finishing touches on the hippos. I realized that I needed more weight on the body in order for the rack and pinion to work so I glued an eraser on top of the rack. As for the new head movement, I found out that if I glued a string to the top of the head and tied it back, the tension would cause the head to move.

In the end, everything came together and I was very pleased with the result. The hippos functioned as expected although they were not great at picking up marbles. Still, they properly recreated the motions of the hippos from the actual games. Check out the video below!

Overall, this was a pretty simple project. I would definitely recommend experimenting with servos. In addition to the 180° servos I used for this project, there are also continuous rotation servos that rotate a full 360°. Servos come in a variety of sizes and can be fitted with a variety of attachments. You can basically handle any type of rotational motion you need using a servo. They are very easy to program as well. For more information on this project, please check out the documentation about it that I wrote for my class on my website. You can also see the code I used to program the hippos on GitHub.

September 16, 2016

Posted in neopixel, projects


NeoPixel Colour Picker

The lighting in my garage was pretty poor, and since we sell lots of NeoPixels, naturally I had a strip lying around!  So I figured NeoPixel LED's would be an efficient and bright way to light the garage!

The lighting in my garage was pretty poor, and since we sell lots of NeoPixels, naturally I had a strip lying around!  So I figured NeoPixel LED's would be an efficient and bright way to light the garage!

Of course I didn't want just an on / off switch, it would be way more fun to be able to pick colours.  So, I grabbed a set of round tactile buttons, and luckily there were red, green, blue, yellow, and gray.  I decided red, green and blue would control the colour, yellow would be "white", and gray would be off.

To control everything I used a Pro Trinket 5V, which is like an Arduino Mini with more pins and USB.  I  used 5 input pins for the switches and one output pin for the NeoPixel Strip.

The buttons are wired to ground, meaning, when you press the button the switch closes and sends a ground (LOW) signal to the Trinket.  I wrote the code so it constantly loops to see what buttons are pressed.  What's nice about this is that I was able to have it see if more than one button is pressed, so you can make more than just Red, Green and Blue!

Programming the Pro Trinket is easy via a microUSB cable.  More details on programming the Pro Trinket can be found in the Adafruit Learning System.

On my first prototype I used a basic solderless breadboard with some hookup wires, but to really finish it off i used an Adafruit Perma-Proto board.  This was a good choice because i could easily mount it to the wall and wire up all the connections.  

Adafruit has a great tutorial on how to use NeoPixels, so I will not get into much detail on how they work.  The important thing to know is that they need a good amount of power if you are using a bunch of them, so I used a hefty 10 amp 5V power supply to run 150 NeoPixels.  Also pay attention to the guide's suggestions regarding capacitors and resistors to avoid damaging your NeoPixels.

You'll want to make sure you install Adafruit's NeoPixel Library and also set your Arduino IDE up for the Pro Trinket.

See below for my Arduino code.  Basically I just took the Adafruit NeoPixel strandtest code and added some logic for the buttons.  Super simple!  

 

 

#include <Adafruit_NeoPixel.h>

#define PIN 4
#define HIGH 1
#define LOW 0

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(150, PIN, NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.

// constants won't change. They're used here to
// set pin numbers:
const int offPin = 10; // the number of the pushbutton pin
const int whitePin = 13;
const int greenPin = 6;
const int redPin = 8;
const int bluePin = 5;

// variables will change:
int offState = 0; // variable for reading the pushbutton status
int whiteState = 0;
int greenState = 0;
int redState = 0;
int blueState = 0;
int pixelSpeed = 10;

void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
pinMode(offPin, INPUT_PULLUP);
pinMode(whitePin, INPUT_PULLUP);
pinMode(greenPin, INPUT_PULLUP);
pinMode(bluePin, INPUT_PULLUP);
pinMode(redPin, INPUT_PULLUP);
pinMode(13, OUTPUT);
}

void loop() {
// Some example procedures showing how to display to the pixels:
whiteState = digitalRead(whitePin);
offState = digitalRead(offPin);
greenState = digitalRead (greenPin);
blueState = digitalRead (bluePin);
redState = digitalRead (redPin);
if (greenState == LOW | redState == LOW | blueState == LOW) {
colorWipe(strip.Color(255 * (1-redState), 255 * (1-greenState), 255 * (1-blueState)), pixelSpeed); // RGB
}
else if (whiteState == LOW) {
colorWipe(strip.Color(255, 255, 255), pixelSpeed); // WHITE
}
else if (offState == LOW) {
colorWipe(strip.Color(0, 0, 0), pixelSpeed); // WHITE
}
}

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}