Monday, 14 April 2014

Space Invaders alarm clock mod

I'm very conscious of the fact that the last two posts have been quite text-heavy, so here's a lighter weekend project.

I was once given a Space Invaders alarm clock. It's shaped like one of the aliens from the game, the 'pixels' of the LCD display are shaped the same, and when the alarm goes off it makes the aliens sound and moves from side to side as they did in the game.



Which is all well and good unless you have a small bedside table, and the clock just rolls off the edge every morning...

The lazy answer would be to just build a barricade, or some kind of stand that would stop the wheels turning.

Opening up the clock reveals a small PCB, with wires neatly labeled, and a small motor which operates a worm gear to move the wheels.

 

My plan is to replace the motor, and use it's wires to power some LEDs which I will place in the 'eyes' of the model.

Although labelled "M+" and "M-", the motor wires polarity changes - to allow the change of direction. This is great for motors, but reversing the polarity on an LED will likely result in the magic smoke escaping.

To get around this - and also provide a neat colour change effect - each eye will have 2 LEDs in parallel, and arranged in opposite directions. The LEDs of each colour for each eye will be in series (see below). Also don't forget a 100 Ohm resistor at one of the ends (doesn't match with one)

One green and one red LED per eye. As the current changes the LEDs will alternate


This means that when the current is flowing one way, it can't get through one LED, so moves through the other. When it changes direction, it can no longer get through that one, so it diverts to the other, effectively 'blinking' each LED in turn.

Then it's just a case of drilling eye holes, poking the LEDs through, and reassembling (I also used hot glue to act as a diffuser for the eyes)

Each stage of the end result. It doesn't roll off the table anymore, but I didn't count on it looking a lot more sinister.


Thursday, 3 April 2014

Creating a VirtualBox test system for Raspberry Pi development


Firstly, I'm going to walk through the process of setting up a Ubuntu Virtual Machine (VM) on VirtualBox, which I will use as a test environment for developing for the Pi.

Download the Ubuntu ISO from here if need be.
With VirtualBox installed on your PC. Go to New, and walk through the wizard, allocating memory, and creating a virtual hard disk.

Once that's done, boot the machine, and you'll get a "first-run" type prompt, asking you to select an installation source - direct it to the ISO you downloaded earlier.

Once the VM boots, select Install to hard disk, and walk through the graphical wizard for that. Once complete, reboot the virtual machine.

Once rebooted, login, and open a terminal.
Follow the same instructions to update the system and install the LAMP stack as we did in the post about setting up the Pi.

Once that's done, the next step is to install the VirtualBox 'Guest Additions'. These allow easier interaction between your host system and the VM.
Select this from Devices -> Install guest additions at the top of the VM window. After a few seconds you'll be prompted to run the software in the VM (you'll also be asked to authorise the installation)

Let that run through, and then reboot the VM. Now would be a good time to take a snapshot (Machine->Take snapshot). This effectively creates a backup of the system state at the time it was taken, so if you test something and screw it up, it's fairly trivial to get the system back to how it was.

Now, create a shared folder between the host and the VM - this'll make it easier to move files between them. Right-click on the folder icon at the bottom right of the VM window, and select shared folders. Click the 'Add' button at the right hand side of the dialog that appears - fill in the path, name, and options for the share (Uncheck read-only, check auto mount and make permenant)

You'll now find you have a folder on the virtual machine under /media/sf_FOLDERNAME, where FOLDERNAME is the name you gave your shared folder (eg, mine was named Temp, so on the VM it's /media/sf_Temp). You'll also find you can't access it.
To fix this, in the terminal enter

sudo gpasswd -a USERNAME vboxsf


replacing USERNAME with your own username. You will need to reboot for the changes to take effect.

The final step is to allow the host to access the VM's server.
Go to Machine->Settings->Network, and click Port Forwarding on the network adapter you're using (1 by default)
Click Add, then enter the name (HTTP), host port (I chose 8080), and guest port (80). Click OK.
Now when browsing to localhost:8080 on your host machine, you should see the "It works" page of the web server on the VM.

Take another snapshot here.

This was meant to be a short intro to the main development, but seeing as it's already a lengthy post, I'm going to leave it here, and pick up the rest of the development later.

Monday, 31 March 2014

Raspberry Pi LAMP Server

This is a simple guide to setting up a Raspberry Pi computer as a 'LAMP' (Linux, Apache MySQL, PHP) server.

I'll be using it at a later date to create a simple PHP-based To-Do list type system, which I'll cover in later posts.

Download and install the latest version of Raspbian from the Raspberry Pi website.
As I'm using linux, the command I needed was:

sudo dd bs=4M if=2014-01-07-wheezy-raspbian.img of=/dev/sdh

Boot up the Pi and go through initial setup:
  • Expand filesystem
  • Change user password
  • Boot to console
  • Enable SSH Server
  • Force audio through 3.5mm
  • Update tool to latest version
Finish the setup tool and from the command line run updates:

  • sudo apt-get update
  • sudo apt-get upgrade
Install the LAMP stack:

  • sudo apt-get install apache2 php5 mysql-client mysql-server
During this installation process you'll be asked to provide a root password for the MySQL server.
(Optional) Install PHPMyAdmin


  • sudo apt-get install phpmyadmin

This should boot the PHPMyAdmin installer tool:
  • In the first screen select the web server to configure (apache2).
  • Select yes to configure database for phpmyadmin with dbconfig-common.
  • Enter the root MySQL password. Create a phpmyadmin password for the sql server.
Now would be a good time to save the progress made. Shutdown the Pi with
  • sudo shutdown -h now
Once the systems shutdown, remove the memory card and make a backup of the cards data. I use the dd command again to create a gzipped image


  • dd if=/dev/sdh | gzip > /path/to/backups/backupname.img.gz

This allows backups to be restored just as easily, using the command

  • gunzip -c /path/to/backups/backupname.img.gz | dd of=/dev/sdh
If you want to run the Pi 'headless' - without screen or keyboard, now would be a good time to disconnect them.

Once the backup is done, put the SD card back in the Pi, and reboot.
Give it a little while to reboot, and then from your P, connect to it via SSH. On linux this is a command like

  • ssh HostnameOrIP -l pi
Once logged in, you can control the Pi from the command line as you were able to previously.


Monday, 24 March 2014

Motion activated Pac-Man lamp


Version 2

Migrated the control over to an ATtiny25, using the ATtiny cores for Arduino.
I found a ported version of the IRRemote library on Github. It looks as though this port was for a specific purpose, and lacked the IR codes I needed, however it was easy enough to port the necessary parts from the orignal IRRemote library.

This is the revised code:

#include "IRremoteTiny.h"

IRsend irsend;

#define PIR PB2 // pin 7 on ATtiny

void setup(void) 
{
  DDRB &= ~(_BV(PIR)); // Set as input
  DDRB |= _BV(PB3);

}

void loop(void) {
  
  if (digitalRead(PIR) == HIGH) {
    digitalWrite(PB3, HIGH);
    for (int i = 0; i < 3; i++) {
      irsend.sendNEC(0xF7C03F, 32);
      delay(40);
    }
    delay(10000);
    for (int i = 0; i < 3; i++) {
      irsend.sendNEC(0xF740BF, 32);
      delay(40);
    }
  } else {
    digitalWrite(PB3, LOW);
  }
}


Version 1
I was given a Pac-Man lamp for Christmas.
It's a simple RGB colour changing lamp that is remote controlled.


In my flat the hallway can be quite dark, and when leaving, there can be a few seconds between turning the flat's hall light off, and the external hall light being triggered.

I was considering getting a simple plug-in 'night light' type thing, but I didn't want something that stayed on all the time. And besides, I wanted to put Pac-Man to good use.

As it was a Christmas gift, it didn't seem right pulling it apart straight away, so the plan is to create a motion-triggered device that mimics the remote.

The first thing is to find the remote protocol being used.
To do this use a IR receiver module (I scavenged one from a VCR that was on the junk pile), and hook it up to an Arduino, using Ken Shirriff's arduino IR library. Using the 'IRrecvDump' sample sketch you can find the details of the protocol in the serial monitor - it'll look something like

F7C03F
Decoded NEC: F7C03F (32 bits) Raw (68): 15538 8950 -4200 700 -400 700 -400 650 -450 700 -400 700 -400 650 -450 650 -450 650 -450 650 -1500 700 -1500 700 -1500 650 -1550 650 -450 650 -1500 700 -1500 700 -1500 700 -1500 700 -1500 650 -450 650 -450 650 -400 700 -400 700 -400 700 -400 700 -400 700 -400 650 -1550 650 -1500 700 -1500 700 -1500 700 -1500 700 -1500 650 F740BF

Decoded NEC: F740BF (32 bits) Raw (68): 26860 8950 -4200 700 -400 700 -400 650 -400 700 -400 700 -400 700 -400 700 -400 650 -450 650 -1550 650 -1500 700 -1500 650 -1550 650 -450 650 -1500 650 -1550 700 -1500 650 -400 700 -1500 700 -400 700 -400 650 -450 650 -400 700 -400 700 -400 700 -1500 650 -450 650 -1550 650 -1500 700 -1500 650 -1550 650 -1500 700 -1500 650

My first thought that the pacman remote looks very similar to the remotes that tend to get bundled with rolls of RGB leds, and I had a couple of those going spare, so perhaps one of them could've been sacrificed, however performing the same test with those showed that they use a different protocol, and so wouldn't work.

The second thought was to make use of an old Sky TV remote - they have a feature that allows the protocol to be programmed to control several makes of TV, but after a while trying various codes, it appeared that the one I was after wasn't one of them.

So the final option was to use the arduino itself for sending the signal. It seemed a bit overkill, but I can always migrate it to a smaller microcontroller when I have one spare. The IR led was taken from the old Sky remote.

The next stage is to wire in the PIR sensor (motion detector)

I used one of these:


They're a simple 3 pin setup - Vcc, Ground, and Data. Data simply goes high for a few seconds when motion is detected.
It can be easily wired in, just effectively like a simple button.


Here's the code I used - when motion is detected, turn the lamp on for 10 seconds, then off again.

#include <IRremote.h>

IRsend irsend;

void setup()
{
  pinMode(4,INPUT);
  pinMode(13, OUTPUT);
}

void loop() {
  if (digitalRead(4) == HIGH) {
    digitalWrite(13, HIGH);
    for (int i = 0; i < 3; i++) {
      irsend.sendNEC(0xF7C03F, 32);
      delay(40);
    }
    delay(10000);
    for (int i = 0; i < 3; i++) {
      irsend.sendNEC(0xF740BF, 32);
      delay(40);
    }
  } else {
    digitalWrite(13, LOW);
  }
}

Wednesday, 19 March 2014

Telephone audio interface

I work from home, and my job requires I spend a lot of time on the phone, particularly in conference calls.


I could easily go and just buy a new headset or hands free desk phone, but I already have a general purpose headset that I enjoy using, and frankly, I have accumulated a lot of headsets over the years from various phones, consoles, computers etc.

One of the items I had in my junk bin was an old wall-mounted telephone - the kind where the keypad is on the handset.

Taking the phone apart revealed three PCBs - one in the base unit of the phone, and 2 in the phone itself. One is obviously the keypad, and the other appears to be an amplifier - it was on this board that the microphone and speaker was attached.

Making the connections - the main part of the interface, is really very simply. Just cut away the microphone and speaker, and replace them with connectors.

The next step is the hang up button. Hang up buttons are press-to-break - pressing the button breaks the circuit, so as it stands connecting this to the phone line will result in your line being open.

To add extra complexity on the phone I was using the hang up button was a Double Pole Single throw switch (DPST) - this means that the switch effectively controls two circuits.
When closed, the switch connects the 4 contacts (seen de-soldered above) as follows: 1 & 2, 3 & 4

Fortunately I managed to find a 'normal' DPST switch on an old amplifier PCB in my junk bin, so wired that in place.

Also, in order to make the end product neater, I removed the coiled cable between the base and handset, and cut away the keypad - I can always use my existing phone to dial. Besides, the keypad may prove useful in a future project.

All that remained was to create a new case for it. I was able to recycle an old business card box, and 3D printed a basic front panel for the connectors.

The finished box, just connect an audio source to input, and some headphones/speaker to output, and away you go.

Monday, 10 March 2014

3D printed cable tidy

Update 28/12/2017
I've revised the design of the cable tidy, and it's now up on Thingiverse.
The post covering the new design and why I created it can be found here.

For the purposes of testing the 3D printer, I'd just grabbed some files from Thingiverse.

This, however, is my first attempt at 3D printing something of my own design.

The next big choice is to select design software. As I come from more of a programmer background than design, I settled on OpenSCAD.This allows you to design objects with script, rather than manipulate the objects directly.

Once designed, the file is rendered, and can then be exported to STL format, which can in turn be used by Slic3r (can be done from within RepetierHost) to convert the STL to Gcode, which is then passed to the printer.

The inner piece - the cable will pass through the middle channel,
The outer piece - a bolt will run through the central hole to mount the inner piece.

The idea is the cable runs through the gap on the edge of the outer piece, through the middle channel of the inner piece, and out the other side of the out piece. So when the inner piece is rotated, the cable is wound around it.

Once printed, I attached a piece of clear plastic to the top to complete the enclosure (I could've 3D printed that, but as it's a flat plastic disc, it seemed wasteful to do so).

Mounting that was more of a pain that I'd thought. Hot glue alone had too much flexibility, so I added in a few miscellaneous screws to provide additional support (This was also worsened by trying to tidy a fairly thick USB charger cable - this tidy is best left to thin cables, such as headphones)

Some Sugru around the edges of the plastic finished the job:
The finished job - twist the blue edges to retract the cable


A few more lessons learned:
  • Remember RepetierHost has a pause button - handy if you need to switch rolls of filament mid-print.
  • Avoid needing to change rolls mid print in the first-place!
  • Make sure the bed is heated before starting to print, it's more important than you think.
  • Give thought to the integration of non 3D printed parts, make sure mounting holes are there if necessary.


Sunday, 9 March 2014

K8200 3D Printer review

Years ago, back when 3D printing was pretty much limited to the RepRap, I had this grand idea of building a 3D printer.

Problem was, I was fairly new to electronics, and DIY in general, so my skillset was, well, non existent.

Despite the failure of that project, I was still keen on the technology, and have been keeping a close eye on the commercial offerings. The downside to those options being both the price, and buying an 'off-the-shelf' printer seemed like the lazy way out to me.

Thankfully, Maplin has started selling the Velleman K8200 printer as a kit. This keeps the price to a more modest level, and being self-assembly, reduced my laziness guilt of not building one from scratch.


In the post-Christmas sales, I noticed the kits were on offer, so I finally caved and bought one.


I was planning to do a series of build posts about it here, but the truth is there's nothing much to report that isn't already covered in detail - the manual is a comprehensive 619 pages!

First attempted print - a Mobius Strip from Thingiverse


A couple of pointers I will offer though:

  • The leads on the thermistor for the hot end are very fragile. The guide does warn about it, but it's worth reiterating...
  • You'll have some bits left over. At least I did. Not sure if you're meant to, but mine works OK.
  • It won't work perfectly first time. Expect to have to tinker with it from time to time. Also, be prepared to lose a fair bit of filament in failed prints to start with. 
  • When putting the X carriage inside the frame (page 96 on my version of the manual), there's a picture that shows the carriage fully in the frame. The picture appears too early - the subsequent pages mention about sliding additional nuts into the frame, and actually means slide the first supporting rod of the x carriage into the frame, add the nuts, then the second supporting rod.