3D printed mold for silicone parts with embedded LED’s

Categories Design, Technology
silicone-molding-3d-print
Getting ready to make some multi-coloured LED buttons using a 3D printed mold.

As part of the design of a digital instrument I was working on, I wanted to have a grid of square soft-touch silicone buttons that could light up in any colour using RGB LED’s. Unfortunately, I couldn’t find existing buttons that fit the size specifications that I needed in the design. The solution: cast my own silicone buttons using a 3D printed mold.

silicone-rgb-led
Testing light diffusion against various thicknesses and densities of silicone to inform the mold depth. Most good suppliers should have samples like this, the battery powered light I simply ripped out of a cheap RGB LED toy.

The 3D printed mold

Since this was a prototype, I was able to be creative with how I fabricated the components. The idea I landed on was to cast the buttons with the LED’s already inside them. There were a few benefits to this:

  1. The was mold significantly less complicated, because it could be achieved with a single piece of material
  2. The LED provided good leverage for easy mold release
  3. Air bubbles had plenty of surface area to escape from and barely anything to get stuck underneath*

*I mixed a few batches of silicone, varying the amount of catalyst slightly: in some of the ‘harder’ mixes the bubbles were caught underneath the LED pins.

led-embedded-silicone-button
RGB LED suspended in 3D printed mold, waiting to be filled with silicone

I got the set of molds 3D printed in Melbourne through my good friends at 3DPE – who not only turned around the parts quickly (I was in a rush), but offered invaluable advice on things like layer height, layer orientation and surface finish, all things which would transfer to the silicone surface. Experimentation was half the fun.

I made the files for the mold by simply taking the CAD drawings I had of my variously sized buttons and subtracting them from prisms.

Once I had the molds, it was just a matter of suspending the RGB LED’s in place (by bending their legs and using some tape) and slowly pouring in the silicone mix.

3d-printed-molds-silicone
3D printed mold with the silicone poured in. Most of the air bubbles slowly work their way out, however a vibrating table would have helped.

Testing out the lights

Once I had my first test button (which came out a little deformed as I removed it from the mold too early) I grabbed a breadboard and quickly hooked up the light to an arduino, and got it cycling through the rainbow.

button-rgb-led
Testing the embedded RGB LED diffused through the custom made silicone button.
Testing the button tolerance against the lasercut steel face plate

The final result

Happy with the experiments above and confident that I’d be able to cast better quality buttons as I got the hang of the process, I had additional molds 3D printed. This sped up the cycle times between pour and cure by increasing the batch sizes I was producing (I needed to get a total of 3 sets of 25 buttons, one for each prototype).

I ended up casting far more silicone buttons than actually made the cut, this was because a) I still had some things to figure out about how to mix and cast effectively b) Some of the silicone didn’t cure properly, leading to deformation c) I didn’t have an effective way to release all of the trapped air from inside the silicone mixture.

Through what seemed like shear brute force, I managed to cast a full 3 sets of buttons to a quality that I was happy with. Each button had it’s own individually controllable RGB LED fully embedded within it.

The finished prototype, with 25 custom made silicone buttons using 3D printed molds

What I’d do differently

Although the grippy texture worked well for the prototype, it wasn’t the finish that I would ultimately want, this was simply due to the surface finish “grain” of the prints and silicone’s ability to produce mirrors of even the most intricately detailed surfaces.

After talking further with 3DPE, I learnt that it is possible to use a post-process to smooth the surface of the 3D printed mold – which would then give me the smooth surface I want. If anyone is looking to do something similar, I’d also recommend trying to find a vibrating table that you could use (or even better, hack together your own) for peace of mind.

Oh, and try to find a better working space than a share house bedroom to avoid the serial-killer level of plastic that needs to be laid over everything when casting silicone.

plastic-sheets-silicone-casting

Using Xbee with Arduino Yún

Categories Interaction, Open-source, Programming, Technology

Came across an issue today when upgrading a project I’m currently working on to make use of an Xbee + Arduino Yún stack instead of an Xbee + Arduino Uno stack and found that the solution wasn’t very apparent online. I thought I’d post a short writeup here. Special thanks to Bo for solving this issue.

Firstly, the Yún is amazing in that is has built-in WiFi capabilities, but this also means a few peculiarities with the serial due to the split architecture. If you are trying to use an Xbee with a shield, you will need to make a few modifications to both hardware and code in order to get it working.

Firstly, we cannot use the normal serial communication pins (0,1) and instead need to use alternative pins. I assumed I could use the SoftwareSerial library to allocate another set of pins (for example 10, 11) however for reasons I still don’t fully understand this doesn’t work either.

The solution was suggested by cmaglie in this thread to use AltSoftwareSerial (download the library here). I had not heard of AltSoftwareSerial before, it is an emulated serial comm.

What you need to do is install the above library (read here if you have never done that before) and change your code to include the new serial method. The example code below will recieve packets from another device and print them to serial:

#include <XBee.h>
#include <AltSoftSerial.h>

XBee _xbee = XBee();
AltSoftSerial altSerial;

void setup()
{
  Serial.begin(9600);
  altSerial.begin(9600);
  _xbee.begin(altSerial);
}

void loop()
{
  value="";
  processXBeePackets();  
}

void processXBeePackets()
{
   _xbee.readPacket();
   if (_xbee.getResponse().isAvailable())
   {
      _xbee.getResponse().getZBRxResponse(rx);
      //Serial.println(rx.getDataLength());
      for(int i=0;i<rx.getDataLength();i++){
         value.concat(char(rx.getData(i)));
   }

   Serial.println(value);
   }
}

Then on the hardware side, you need to modify your Xbee shield (or if not using a shield, simply reroute your pin-out). This is as simple as bending out two header pins (we’ve used spacers) so that they don’t actually come into contact with their Arduino counterparts. So, pins 2 and 3 don’t connect to Arduino and we instead use some jumpers to reroute them to 5 and 13 respectively. See the images for reference:

Xbee shield working on Arduino Yun
Rerouting pin 3 > 5 and pin 2 > 13

 

sparkfun xbee shield header pins modified for serial with Yun
The header pins for 2 and 3 need to be bent so that they don’t interface with the arduino.

You should now be able to pass your Xbee communication data on to your Arduino Yún and then pass it on to a server or computer via WiFi.

How to send multiple variables from Processing to Arduino

Categories Interaction, Programming

I wanted to be able to send a set of 4 integers to an Arduino from a Processing application that I am working on, I also wanted to be able to prefix the set with a tag, so that I could deal with different sets of integers in specific ways, for specific purposes.

For instance, I have an LCD screen and some LED’s connected to my Arduino, or maybe I have a servo motor and a speaker that I want to control based on events happening in software running via Processing.

I modified* the code below from the code shown here (Arduino Cookbook @ inkling.com)

*I simply expanded the amount of variables being sent per packet.

Processing Code:

// Processing Sketch

/* SendingBinaryToArduino
 * Language: Processing
 */
import processing.serial.*;

Serial myPort;  // Create object from Serial class
public static final char HEADER    = 'H';
public static final char A_TAG = 'M';
public static final char B_TAG = 'X';

void setup()
{
  size(512, 512);
  String portName = Serial.list()[1];
  myPort = new Serial(this, portName, 9600);
}

void draw(){
}

void serialEvent(Serial p) {
  // handle incoming serial data
  String inString = myPort.readStringUntil('\n');
  if(inString != null) {     
    print( inString );   // echo text string from Arduino
  }
}

void mousePressed() {
  sendMessage(A_TAG, 8,5,20,33);
}

void sendMessage(char tag, int a, int b, int c, int d){
  // send the given index and value to the serial port
  myPort.write(HEADER);
  myPort.write(tag);
  myPort.write((char)(a / 256)); // msb
  myPort.write(a & 0xff);  //lsb
  myPort.write((char)(b / 256)); // msb
  myPort.write(b & 0xff);  //lsb
  myPort.write((char)(c / 256)); // msb
  myPort.write(c & 0xff);  //lsb
  myPort.write((char)(d / 256)); // msb
  myPort.write(d & 0xff);  //lsb
}

You can see in the void sendMessage function that each integer is being split into two bytes, but both the header and tag are sent as a single byte – this means we are sending 10 bytes all up (we will need to reference this in the Arduino code in TOTAL_BYTES).

Arduino Code:

// BinaryDataFromProcessing
// These defines must mirror the sending program:
const char HEADER       = 'H';
const char A_TAG    = 'M';
const char B_TAG    = 'X';
const int  TOTAL_BYTES  = 10  ; // the total bytes in a message

void setup()
{
  Serial.begin(9600);
}

void loop(){
  if ( Serial.available() >= TOTAL_BYTES)
  {
     if( Serial.read() == HEADER)
    {
      char tag = Serial.read();
      if(tag == A_TAG)
      {
        //Collect integers
        int a = Serial.read() * 256; 
        a = a + Serial.read();
        int b = Serial.read() * 256;
        b = b + Serial.read();
        int c = Serial.read() * 256;
        c = c + Serial.read();
        int d = Serial.read() * 256;
        d = d + Serial.read();
        Serial.print("Received integers | a:");
        Serial.print(a);
        Serial.print(", b:");
        Serial.println(b);
        Serial.print(", c:");
        Serial.println(c);
        Serial.print(", d:");
        Serial.println(d);
      }
      else {
        Serial.print("got message with unknown tag ");
        Serial.write(tag);
      }
    }
  }
}

You can see under Serial.available() after the comment “//Collect integers” that each byte is being stored in a variable (multiplied by 256 to reverse the division on the Processing side) and then the second byte is added to that (thus reversing the rejoining the split that took place on the Processing side) – in this way we are reassembling the data that we sent into a useable format to be used.

From here you can do whatever you like with the data, use it for conditionals or set it to analog outputs. The applications are nearly endless.

Make a custom button pad for Raspberry Pi [Pt I]

Categories Interaction, RMIT

I needed a button matrix to use as an interface for a new digital instrument that I’m making as part of my undergraduate major project. Something like the monome would probably work quite well, but I cannot justify being lazy and paying for one when I feel like I could probably hack some existing things together and end up with a custom result.

In earlier posts I talked about establishing serial connection between raspberry pi and arduino, because initially I intended to read a button array with the arduino and then send little data packets via usb that told the raspberry pi which buttons were pressed.

Previous design exploration: 16-Digit Keypad connected to Arduino, connected via USB serial to Raspberry Pi using a 3.5″ TFT LCD Screen as display.

For a few reasons, particularly the latency issues, this wasn’t a viable solution. I am vaguely aware that the arduino could be cut out of the process, and the button array read by the raspberry pi directly, but I’m also vaguely aware that to try and figure out how to do that may set me back a month.

The solution was to buy a cheap USB Keyboard, gut it, rip the chip out and hook it up to a custom button array made up of a 5 x 5 grid of N/O buttons.

I like this solution in that it doesn’t really matter which contacts I solder the buttons to, so long as each button triggered a different keystroke. I can then assign each button to it’s specific keystroke and then map each keystroke to it’s corresponding position in my Processing/Python sketch.

Ultimately, the keyboard is controlled by a small chip that communicates via USB. The chip has two banks of 13 contact points. To get any of the ~101 keystrokes available you have to close the circuit between two specific contact points.

So I started blindly shorting the board with alligator clips and a probe with notepad open on my laptop to capture the keystrokes.

Ended up with some glitch poetry

Now I just need to perform the time-consuming task of soldering up an array of N/O buttons to the keyboard chip, based on the combinations that results in 25 useful keystrokes (letters, numbers, punctuation – no function or naviagation keys). Then I need to house it all in a 3D printed case.

continue to Part II

Drawing in Python using Arduino data via serial

Categories Open-source, Programming, Visuals

Following on from my previous post where I established serial communication between an Arduino and a Raspberry Pi, I needed to find out if I could store the data being sent from the Arduino in a variable on the Raspberry Pi and use it to alter some functions in a Python script.

I wrote up a piece of code that tries to read the data from the serial and use it to change the colour of a circle drawn in the center of a 640 x 480 pixel screen:

# Title: Arduino2RPiSerial
 #
 # Goal: to draw a circle based on colour values sent from the arduino
 #

import pygame
 import sys
 import serial

pygame.init()

#create a screen
 screen = pygame.display.set_mode((640,480))

#create colour
 redValue = 255
 fgColour = (redValue,0,0)
 bgColour = (0,0,255)

screen.fill(bgColour)

#serial(device,baud)
 ser = serial.Serial('/dev/ttyACM0',9600)

# LOOP
 while 1 :

#Update from serial
 redValue = ser.readline()
 #update colour value
 fgColour = (redValue,0,0)
 pygame.draw.circle(screen, fgColour, (320,240), 200, 0)
 pygame.display.update()
 pygame.time.delay(5)

# check for quit events
 for event in pygame.event.get():
 if event.type == pygame.QUIT:
 pygame.quit(); sys.exit();

Getting the Raspberry Pi to talk to Arduino

Categories Open-source, Programming

As part of an exploratory design project I am undertaking within my undergraduate Major Project, I needed to establish serial communication between a Raspberry Pi (a miniature, credit-card sized computer) and an Arduino Uno (an electronic prototyping board). I found that Raspberry Pi could both supply power and talk to the Arduino Uno via USB cable.

I also found that as a beginner in many aspects of Python programming, Linux commands and serial communication that much of the documentation on the internet seemed daunting, so I’ve made a very thorough documentation here to help anyone out who has the same amount or less of the starting knowledge that I had. Hopefully it can aid in the creation of more open-source Raspberry Pi / Arduino projects.

I based my efforts on the steps outlined here.

 

 

 

Arduino Uno, Raspberry Pi and Laptop.
Arduino Uno connected to the laptop, with  a Raspberry Pi bundled with it’s own 3.5″ LCD Screen running below.

 

Firstly, I needed to install pyserial onto my Raspberry Pi. I have no ethernet cable or Wi-Fi dongle connected to my Raspberry Pi and so I had to transfer the pyserial-2.6.tar file via a USB Flash drive. The file can be downloaded here.

After transferring the file to desktop (home/pi/desktop) and unzipping it’s contents to it’s own folder on the desktop (home/pi/desktop/pyserial-2.6) I opened up the LXterminal to execute the following commands:

cd /home/pi/desktop/pyserial-2.6

The cd command directs the terminal to a folder on the Raspberry Pi (in this case, the desktop), to give future commands a context of operation. Basically, the command tells the terminal where we are working from and where to look for any files called upon.

Next:

sudo python setup.py install

This command tells python to install pyserial. I hit enter and the terminal spat out line after line of output, completing the install process shortfly after.

From this point, the Raspberry Pi was ready for serial communication via the pyserial module.

I needed to find out what the device name for the Arduino Uno was on the Raspberry Pi so that I could reference it in the python shell when opening up serial communications. For this I used a command that lists the devices:

ls /dev/tty*

The ls command lists files within a directory, the second part ‘/dev/tty*’ is a filter. The use of the wildcard character ‘*’ means that we are looking for any files that begin with ‘/dev/tty’ and that end with any other combination of characters. I ran the command without the Arduino Uno connected and then again with the Arduino Uno connected so that I could see the difference between the two lists, and find out what it’s device name was.

 

 

 

Using ls /dev/tty* to display a list of devices
Using ls /dev/tty* to display a list of devices

 

It’s hard to see in the picture above because the 3.5″ TFT LCD screen has such a horrible resolution (and has a strange flickering colour issue) but in the second list positioned at 3 items from the bottom of the rightmost column, a file appeared that wasn’t present in the first list (/dev/ttyACM0). I made note of that file because I would need to reference it later.

Then, the code below needed to be uploaded to the Arduino Uno to generate a test signal:

//Code originally by simon monk (http://www.doctormonk.com/2012/04/raspberry-pi-and-arduino.html)
//Commented by Daniel Kerris

//This code makes use of the Arduino's built-in LED which is located on Pin 13
const int ledPin = 13;

 //This sets up the code and defines the baud rate as 9600 - it's important to use the same baud rate on the Raspberry Pi
 void setup()
 {
   pinMode(ledPin, OUTPUT);
   Serial.begin(9600);
 }

 //This part of the code loops continuously with a delay of 1000 milliseconds between each loop
 //It sends the message "Hello Pi" over and over again via USB
 void loop()
 {
   Serial.println("Hello Pi");

   //This section checks to see if the Raspberry Pi is talking back
   //and then makes a call to the flash() script which is define below
   if (Serial.available())
   {
      flash(Serial.read() - '0');
   }
   delay(1000);
 }

 //This flash() script takes the number that the Raspberry Pi has sent over via USB (stored in the variable n)
 //and uses it to determing how many times the LED should flash
 void flash(int n)
 {
   for (int i = 0; i < n; i++)
   {
     digitalWrite(ledPin, HIGH);
     delay(100);
     digitalWrite(ledPin, LOW);
     delay(100);
   }
 }

After the code was uploaded to the Arduino Uno, I connected it via USB to the Raspberry Pi. I could see that it was powered and that the code was working because the LED for Tx (serial communication) was flashing, showing that it was being used. The Raspberry Pi still needed some code to tell it to listen to the messages coming through the USB port.

I booted up the Raspberry Pi and opened up the application called IDLE, highlighted the Python Shell Window and entered the following commands, hitting enter after each line:

import serial
ser = serial.Serial('/dev/ttyACM0', 9600)

You’ll remember that ‘/dev/ttyACM0’ was the name of the Arduino that I had found out earlier. 9600 is the baud rate, which is set the same is in the Arduino code above.

Then:

while 1 :
     ser.readline()

The while statment is used to do a set of actions while a statement is true. In computer languages 1 and 0 are stand-ins for true and false or on and off. Basically, this line of code is saying that whilst 1 is equal to true (which is constantly) then do something. This creates a loop that executes itself until the program quits, just like the void loop() in the above Arduino code. The ser.readline() is telling our serial object ser that we want to execute the function readline() which reads from the serial device (‘/dev/ttyACM0′) that we established earlier.

I had to hit enter twice after the ser.readline() command to let Python know that I am finished writing commands within the while statement’s block (you can read more about code blocks here if you don’t understand).

 

 

Success!
Success!

 

Finally, the Raspberry Pi successfully read from the Arduino.

I couldn’t get return communication happening successfully, though luckily for me the project I am working on only requires one-way communication from Arduino Uno to Raspberry Pi and not the other way round. I’m going to be using the Arduino Uno to handle sensors and tangible controls as I am much more comfortable coding and prototyping in that environment. I will write code that analyses and packages the information from sensors and tangible controls and sends it via USB to the Raspberry Pi, which will handle all of the GUI and Sound output (which the Arduino would otherwise struggle to handle).