Inaugural Hardware Hacking Meetup

5 minute read

Introduction:

I’ve been wanting to form a community group for hardware development for a while now. I finally bit the bullet and formed a couple of meetups - one for hardware hacking and one for React Native. We just had our inaugural meetup for the Hardware Hacking group, and it was a ton of fun. Turnout was fantastic and everyone was really interested in working with the project and sharing their ideas and questions.

Unfortunately, I was so overwhelmed with running the meetup that I really didn’t get the chance to take many pictures throughout the night. But after my brief introduction, we had two members demo projects that they’re working on. Sam is developing a Computer Vision controlled robotic arm that will incorporate Machine Learning. Eventually, he hopes to have a robot that can sense it’s environment and move around objects based on input from some cameras. Mason demo’d a really cool blockchain based connected lock proof of concept. Using a BeagleBone Black, a relay cape, and the blockchain, Mason demonstrated how we could assign physical ownership of an object by using cryptography. Both of these projects are awesome and I will be following their progress intently. As an aside, I’ll be more organized next month and actually get pictures of these awesome projects.

The Project

Since this was the first meetup, I thought it was appropriate that we should kick it off with the “Hello, World!” of hardware projects - blinking some LEDs. I had WS2812 LEDs kicking around that were left over from an old project, and I bought a handful of Arduino Nano clones off of Amazon. A little soldering later, and we’ve got the start of a bunch of projects! The sketch that we developed at the hacknight was pretty simple - it just allows you to set the individual RGB values over a serial port.

Driver Setup

The particular Arduino Nano clones I bought shipped with a CH340G USB-Serial chip. The “standard” Arduinos all ship with FTDI chips or repurpose and ATMEL 32u4 - both of which are recognized out of the box by OS X and Windows. So to get started, a driver for the CH340G has to be installed.

  • For Mac, this guide describes how to install a driver that’s compatible with OS 10.12.
  • For Windows, open Device Manager, and then select the “USB 2.0-Serial”. Right click and select “Update driver”. Windows should be able to find a CH340G driver in its database.
USB 2.0-Serial in Device Manager Driver Search Prompt
Windows Install Pictures

Library Setup

Our LEDs are WS2812 individually addressable RGB Light Emitting Diodes. They have three connections, power, ground, and signal. The signal to control the LEDs is very timing dependent - but no worries, a library has already been written so we can start blinking some lights right away. To install the library, first select the “Manage Libraries” option from the Sketch > Include Library dropdown.Then, search for the Adafruit NeoPixel library and install it!

Arduino Library Manager Menu Option Arduino Library Manager
Installing the Arduino Library

This library is really terrific for controlling the LEDs. The Fast LED library is another library that we could use to control our pixels and it’s installed in a similar fashion as the Adafruit NeoPixel library.

Hardware Setup

This is super simple. Make sure the Arduino clone is unplugged. First, plug the power and ground from the strip (red is power, black is ground) into the pins marked +5V and GND respectively.

Then, plug the signal wire (yellow) onto the pin labeled D2. You can use any of the output pins, but you’ll have to modify the code to match the pin number.

Connecting Power and Ground Connecting Data Line
Hooking up the hardware

That’s it! Once you plug in your USB cable, a pre-built demo showing off the pixels should start. Look at those blinky LEDs!

The Serial Control Sketch

Detailed below is a simple sketch that allows you to manually set the color of each pixel individually using the serial port. Using Serial.parseInt() is really slow and is not ideal for long term use. It’s simple enough, but we’ll do a basic walkthrough here…

#include <Adafruit_NeoPixel.h>
#define PIN 2 //LED PIN Location
#define NUM_LEDS 5 //number of leds
int inputCount = 0;
int serialArr[4];
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);

In this first bit, we include the NeoPixel library, and define the location and number of leds on our strip. Change the value for PIN if you’re not using D2 for the led signal. Next, we create an integer to keep track of the number of integers we receive over the serial port and an array to store these values. Finally, we create an instance of a NeoPixel strip, using the values we setup earlier.

void setup() {
  // setup pixel strip and show() nothing
  strip.begin();
  strip.show();
  //start serial port at 115200 bps
  Serial.begin(115200);
}

The setup() function is pretty simple, we setup the pixel strip and clear it out by calling strip.show() with no values being set. Then, we start the Serial port at 115,200 bps.

void loop() {
 //send (pixel, R, G, B) over serial
 //lights pixel with color
 if (inputCount == 4){
   inputCount = 0;
   strip.setPixelColor(serialArr[0], serialArr[1], serialArr[2], serialArr[3]);
   strip.show();
 } else {
 // read bytes from serial
   while(Serial.available()>0)
   {
     int input = Serial.parseInt();
     serialArr[inputCount] = input;
     inputCount++;
   }
 }
}

And our loop() function checks to see if we received the correct number of integers to set a pixel. If not, we wait for input from the serial port. Once we have the pixel number, and values for the R, G, and B leds, we use the strip.setPixelColor() function to set the individual pixels color. Then we use the strip.show() function to change the color of the pixel. Simple!

Wrapping Up the Night

It was great fun working with everyone and learning what they were interested in. Participants were able to get the projects running, and I’m really excited to see what they make over the next month. At the end of the night, I wanted to do some light painting, so I set up the camera in the courtyard and invited my new friends to try it out with me. Below are our results. Not bad for beginners!!!

Learning lightpainting

Going forward…

This was a really great learning experience for me. There were a few hiccups and I got quite a bit of insight into how I should structure the next meetup project. Next months’ theme will be sound, and I look forward to documenting the project build and the meetup here on the blog.