Introduction: Controlling a SaikoLED Myki (or Arduino Leonardo) With a Simple Button Box -- Using the ICSP Header

Picture of Controlling a SaikoLED Myki (or Arduino Leonardo) With a Simple Button Box -- Using the ICSP Header

Welcome! Today we're going to explain how to build a controller with 3 buttons that connects directly to an Arduino Leonardo-compatible board--in this case, the myki light from SaikoLED. More information on the Leonardo is available here and in this Instructable.

You will need the following tools:

- Smallish/Needlenose Pliers (Leatherman worked great!)
- Exacto knife or razor blade or small scissors
- (optional) soldering iron and hair dryer/rework blower

materials:

- A cleaned and dried cylindrical takeout container with lid (or any other container of appropriate size)
- 3 arcade pushbuttons e.g. thesefromsparkfun
- 4 of 12 in / 30cm lengths of ~22 gauge wire
- 1x6-pin ICSP ribbon cable, or 4x female-female .1" pitch jumper cables 
- (optional) solder and/or heatshrink tubing

and

- A SaikoLED myki light (available via crowdsupply)
OR
- An Arduino Leonardo setup with red, green, and blue LEDs connected to PWM ports

Step 1: Gather and Select Your Buttons

Picture of Gather and Select Your Buttons

"Pick a button, any button, don't tell me what it is..."

If you're going to use the ICSP header like we will be, there are only 3 GPIOs to work with, so short of using a
"Parallel-input, serial output shift register" to multiplex the inputs, we're limited to 3 buttons.

Step 2: Cut Holes in Box/container

Picture of Cut Holes in Box/container

Take your buttons one at a time, and figure out where to place them. It might be helpful to remove the ring (if you button has one) or cut a piece of paper to size so that you can trace the path to cut with your knife. 

Remember with a blade to cut on a surface with scrap underneath. If you must cut in the air, make sure the blade is always facing and moving away from you.

Step 3: Place the Buttons Into Their New Positions

Picture of Place the Buttons Into Their New Positions

Put your buttons in their new homes. Make sure you leave space for the wires and for the top to close.

Step 4: Connect Ground Wire

Picture of Connect Ground Wire

We're going to use the pull-up resistors that are internal to the Atmega32u4 (a myki or Arduino's "brain"). That means we'll have the 32u4 connect those inputs through some resistance to 5volts--also known as a digital 1 or HIGH logic level. To create a change, the buttons, when depressed, will connect and input directly to ground--switching that input to a digital 0, or LOW logic level. 

The easiest way to do this is to use one wire that connects to one pin from each of our buttons, and hook that up to the ground plane.

To do this, strip the ends of the cable, one short and one long. The long end can be threaded through one pin from each button. I looped it around and crimped it pliers-tight.

If you would like to solder it, or better yet use the appropriate connectors--please, by all means, go right ahead!

Step 5: Prepare Insulating Heat Shrink Tubing (optional)

Picture of Prepare Insulating Heat Shrink Tubing (optional)

I like to cover my connection joints with heat shrink tubing to prevent them from shorting and to make the connection cleaner. In this case, as I am not soldering and depend on friction for the electrical connection, it also helps to keep the connection strong, and it is easy to remove later if I want to repurpose the buttons or redesign the case.

Testing the 1/16 inch diameter tubing I picked up from eBay, it fit fine over the wire and over the button contact individually, but it seemed like it might not fit over both together. So, I decided to cut a small slit in the tubing to make it easier to slide on. 

If this trick doesn't work, you'll have to get larger tubing or simply use electrical tape/glue/etc.

Step 6: Connect Button-Switched Ground to Input Lines

Picture of Connect Button-Switched Ground to Input Lines

Cut and strip 3 lengths of wire that will be the connection between your button and the digital input pin on the myki / Arduino.

Bend the end of the wire with pliers and loop it into the hole on your button. If you button leads lack a hole or it's too small, you'll have to wrap it around and solder it, especially if there's not a good frictional hold. 

Since we haven't connected the other end of the wire, now's a good time to slide on the heat shrink tubing.

Do this for each button.

Step 7: Finish the Button Box

Picture of Finish the Button Box

Now that all your internal cables are connected, make sure they are all solid and there are no shorts.
You can do this by using a multimeter's continuity tester or resistance reading. Connect one lead to ground and one to the input line coming off the button, and see the difference pressing the button makes!

Cut a small hole in the lid and slide the wires through it. Close the lid, and there's your button box, ready to be plugged in!

Step 8: Prepare the Myki/Arduino and ICSP Line

Picture of Prepare the Myki/Arduino and ICSP Line

Make sure your Leonardo-compatible board has an ICSP header available, plug your cable into it and make sure you know where ground, power, and reset are.

myki's pins (x's) are labeled as follows:

GND   x x   RST
MOSI  x x   SCK
VCC   x x   MISO

We want to plug the common ground into GND, and the three button input lines to MOSI, SCK, and MISO.

Depending on your ribbon cable, the pin locations might be mirrored. If you don't have a ribbon, and only have .1" jacks connected to wires, you might actually be better off. If you only connect GND, MOSI, MISO, and SCK, you are more likely to avoid shorting power and ground. READ: DO NOT CONNECT VCC to GND!  

If you connect GND to RST, it should reset your board when you unplug it. Handy!

You can also try connecting GND to MOSI, MISO, and SCK using a jumper wire without hooking up the button box to test the sketch we will be programming in the next section.

Step 9: Program the Microcontroller!

Picture of Program the Microcontroller!

First of all, great thanks to this ible  which provided me with the correct pin mappings for MISO MOSI and SCK.

What follows is a sketch for your Leonardo or myki, programmable via the Arduino IDE.
Refer to the inline comments (lines beginning with "//") for more detail.

Feel free to post a comment to this Instructable with questions, and I'll try to get back to you in a timely fashion.

/*
* This sketch shows a simple button-controlled color routine
*
* Copyright 2013,  Daniel Taub                   
* http://saikoled.com                            
*/
 
#define RED_IN 14    // MISO - Button to trigger Red LED
#define GREEN_IN 15  // SCK - Button to trigger Green LED
#define BLUE_IN 16   // MOSI - Button to trigger Blue LED

#define RED_OUT 9    // Red LED connected to digital pin 9
#define GREEN_OUT 10 // Green LED connected to digital pin 10
#define BLUE_OUT 11 // Blue LED connected to digital pin 11
#define WHITE_OUT 13 // White LED connected to digital pin 13 -- unused here

#define BRIGHTNESS 255  // ranges from 0 to 255 for 8-bit color

int b1,b2,b3;

void setup() {
  // Set MISO, MOSI and SCK as Digital Inputs
  pinMode(RED_IN,INPUT);
  pinMode(GREEN_IN,INPUT);
  pinMode(BLUE_IN,INPUT);
 
  // Set LED PWM pins as Outputs
  pinMode(RED_OUT,OUTPUT);
  pinMode(GREEN_OUT,OUTPUT);
  pinMode(BLUE_OUT,OUTPUT);
  pinMode(WHITE_OUT,LOW);
 
  // Set Pullups to VCC for inputs
  digitalWrite(RED_IN,HIGH);
  digitalWrite(GREEN_IN,HIGH);
  digitalWrite(BLUE_IN,HIGH);

  // Set LEDs OFF
  digitalWrite(RED_OUT,LOW);
  digitalWrite(GREEN_OUT,LOW);
  digitalWrite(BLUE_OUT,LOW);
  digitalWrite(WHITE_OUT,LOW);

}

void loop() {
  b1 = digitalRead(RED_IN);
  b2 = digitalRead(GREEN_IN);
  b3 = digitalRead(BLUE_IN);

  int r,g,b;
  if (!b1) r = BRIGHTNESS; else r=0;
  if (!b2) g = BRIGHTNESS; else g=0;
  if (!b3) b = BRIGHTNESS; else b=0;

  digitalWrite(RED_OUT,r); 
  digitalWrite(GREEN_OUT,g); 
  digitalWrite(BLUE_OUT,b);
 
  delay(100);
}

Step 10: Test Your Button Box-Controlled Light!

Picture of Test Your Button Box-Controlled Light!


You'll see that the light is clearly visible through the transparent plastic, which is one of my favorite things about this as a controller. Consider markering, painting, or taping up the box to decorate it.

Thanks for reading along!

As a reminder, we're trying to crowd fund the myki right now! If you think it's cool please share the link or back the project.
 
Thanks again! 

Comments

dmt (author)2013-03-21

More fun with the ICSP header on the SaikoLED blog.

Hoping to make a regular thing of it, so let me know if you have ideas or want to help!

About This Instructable

5,812views

13favorites

License:

More by dmt:Controlling a SaikoLED myki (or Arduino Leonardo) with a Simple Button Box -- using the ICSP headerUpgrade a Battery-Powered Closet Light (Solderless!)Upgrading a Smart Pals Learning Bear
Add instructable to: