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 matter 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.


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.


Tuesday, 18 February 2014

Phone-based document scanner


Recently  I moved home, and in the process of packing up my belongings, I realised how much of my stuff is just paper - Old notebooks, documents, paperwork, etc.

I didn't particularly want to take it all with me and I had neither the time or the inclination to sort through it all by hand, so I started looking at ways to digitise it.

A flatbed scanner would've taken far too long, and I didn't want to go buying new hardware.

My phone (Samsung Galaxy S3) has a pretty good camera. The resolution is high enough to be able to read text from a page, and it's ability to take multiple pictures in succession meant speed wasn't an issue.

Using it by hand however can be a problem. Results were too inconsistent - shakiness caused blurring, inconsistent distance meant time was lost waiting to refocus.

So I built this simple jig from some wood scraps to hold the phone at the optimal distance.



It's an improvement, but the vibration from tapping the screen to take the picture was still causing some distortion.

After some messing around with various options - IOIO board, custom camera apps, etc. I realised that when I was using a USB-OTG adapter with an external keyboard, the stock camera app would treat the enter key as a shutter button.


Rather than waste a whole keyboard on this, I remembered I had a PCB from one in my junk box that was destined for a project that never materialised.




It already had the key matrix wired to a connector from an old IDE cable, so all it took was some probing with a breadboard jumper wire to find the connections for the Enter key, and wiring in a button.

A bit of Sugru later to make the button more comfortable, and I had a quick way of digitising my old documents.

Next Steps
  • An update to the stock camera app stopped it recognising the keyboard as the shutter button. I've been using the new voice commands instead, but it's a lot slower. Maybe switch camera apps / make a new one.
  • Software to analyse all the scans I've taken to help organise. 

Wednesday, 12 February 2014

DIY Phone-Controlled Mains Sockets


Next Steps
  • Get it working with Wiring-Pi so that RC Switch can operate from the Raspberry Pi directly and free up the Arduino.
  • Adapt the android code to work with SSH/Pi/etc (Currently using command line via ConnectBot)

Version 2
After the original was broken (physical damage from a fall), I re-implemented with the RC-Switch Arduino library. (http://code.google.com/p/rc-switch/).

Version 1
The RF plugs I used were the Maplin Gadget range. The controller is powered by a 12V battery and allows 4 sockets to be controlled across 4 channels (so theoretically up to 16 different sockets could be used)

Each button on the controller has 3 connection points - let's call them left, top and right. all three need to be connected in order for the button press to register.

In the "On" column, the left connections on all the buttons are connected to the same line.

In the "Off" column, the left connections are connected up in the same way.

The top point on all 8 buttons is connected to the same point - this is the one that controls the little LED at the top.

The right hand side for each row is connected - ie, the right point of 1-On is the same as the right point of 1-Off.

So, the transistors need to go as follows:

1: Between the left point of one of the on buttons, to the top point of the same button.

2: Between the left point of one of the off buttons, to the top point of the same button.

3: Between the top point of one of the buttons, to the right side of either button 1 (on or off)

4: Between the top point of one of the buttons, to the right side of either button 2 (on or off)

5: Between the top point of one of the buttons, to the right side of either button 3 (on or off)

6: Between the top point of one of the buttons, to the right side of either button 4 (on or off)












The channel selection switch has 6 points. The two middle ones are grounds, and the 4 others represent each channel. Use a transistor to connect each channel to ground

Now you have 10 transisitors: 1 & 2 are On and Off, 3-6 are the switch selection, and 7-10 are the channel selection.

Connect these transistors to the microcontroller & write your software.

To operate the remote, 3 transistors need to be active.

I found the easiest way to do this was to firstly choose the channel and make that transistor active. Then choose either on or off and make the appropriate transistor active. Then finally, pick the switch to activate. I found that it's best to make the switch active for a second and then turn it off. Having the transistor remain active and "hold down the button" didn't work. If necessary, have the switch transistor pulsed a couple of times.

Remember to make sure that the transistors are deactivated after you've sent your signal.

Originally the code was written for Arduino, but has now been moved to an ATTiny2313.

Due to the number of microcontroller outputs required, a 74HC595 shift register was used. To enable serial communication, the ATTiny was connected to a Wiznet ethernet to serial module, via a MAX232 level converter.

The android software uses a simple ListActivity as the display, and reads the list items from a text file on the SD card in the below format.

// This is a comment line
11. Item Name

The numbers indicate which channel and button the device is on, the rest of the line is a plain-english description of the device. Upon selecting an item, it displays a simple dialog box asking the user to confirm their choice, before sending the command to the Wiznet device via Wifi.