Wednesday, 30 July 2014

App Update: Bluetooth Macro Input

The Bluetooth Macro Input app has been updated and is now available on Google Play.

New Features

As well as it's existing ability to send text files stored on phone, it is now possible to use voice recognition to transcribe voice to text and send that text via bluetooth in the same way, effectively allowing your phone to act as a dictation machine for your computer, without needing to install additional software on your computer.

Please note the voice recognition uses Google's voice recognition API. As a result, I do not have any control of the quality or accuracy of the voice recognition. It does also mean that Internet access is required to use the voice recognition feature.

Usage guide for the original file-based macro system can be found here.

Requirements Changes

Companion hardware is still required, see the original post for details.

The minimum required version of android is now Honeycomb (Android 3.0)



Sunday, 13 July 2014

Dog-controlled treat dispenser part 2


This is the second part of my project to create a dog treat dispenser that my dog, Jack, can operate on his own. For the first part, click here.

Building an enclosure
I thought about 3d-printing an enclosure for the control box, but before I commit the time and effort to designing and printing one, I want to make sure that the project works - and that Jack actually uses it.
So for now, I've managed to fit the electronics into an old business card box, with basic cut outs for the buttons and wiring. It's not pretty, but it works.

The enclosure (the croc clips are for power - final version recycled a charger from a Playstation portable)

The floor switch is connected to the control box by a length of old VGA cable - it's nice and sturdy, and has more than enough wires for this project.

The components for the floor switch


In use
I finally managed to get a short video clip of Jack using it


Future improvements 

The floor switch is too light, as you can see in the video, when Jack uses it, he knocks it across the floor, so I've since mounted it to a bit of wood which helps hold it in place.

The small metal tin that I used to make the contact area larger & easier for Jack to use, ended up making the capacitive switch too sensitive - it basically became like a motion sensor - so I removed that, and used the original metal disc (about 15mm diameter) instead. Although the disc itself is smaller, it still manages to detect capacitance from contact anywhere on the switch, so it works just fine.
The floor switch - unfortunately the hot glue made a bit of a mess, but it's all contained on the underside of the switch, and actually helps diffuse the light a bit.


Source Code (Arduino cores for ATTiny2313
int latchPin = 8;
int clockPin = 12;
int dataPin = 11;
int capBtn = 7;

int plusBtn = 3;
int minBtn = 4;

int enabledLight = 5;

int motorPin = 6;

int treatCount = 0;
int valToDisplay = 0;
int timerBypassPin = 9;
long myTime;
boolean treatEnabled = false;

void setup() {
  //set pins to output so you can control the shift register
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(capBtn, INPUT);
  pinMode(enabledLight, OUTPUT);
  pinMode(motorPin, OUTPUT);
  pinMode(plusBtn, INPUT);
  pinMode(minBtn, INPUT);
  pinMode(timerBypassPin, INPUT);
  digitalWrite(motorPin, LOW);
  digitalWrite(enabledLight, LOW);
  treatCount = 3;
}

void loop() {
  if (digitalRead(plusBtn) == HIGH) {
    treatCount++;
    if (treatCount > 8) { treatCount = 8; }
    delay(500);
  }
  
  if (digitalRead(minBtn) == HIGH) {
    treatCount--;
    if (treatCount < 0) { treatCount = 0; }
      delay(500);
  }
  
  if (digitalRead(timerBypassPin) == HIGH) {
    treatEnabled = true;
  }
  
  if (
      ((millis() - myTime) < 0) ||
      ((millis()-myTime) >= 3600000)
     ) {
    myTime = millis();
    treatEnabled = true;
  }
  digitalWrite(enabledLight, treatEnabled);

  if (digitalRead(capBtn) == HIGH) {
    if (treatEnabled) {
        digitalWrite(enabledLight, LOW);
        treatEnabled = false;
        treatCount--;
        digitalWrite(motorPin, HIGH);
        delay(3000);
        digitalWrite(motorPin, LOW);
    }
  }
  

  switch (treatCount) {
    case 0: valToDisplay = 0; break;
    case 1: valToDisplay = 1; break;
    case 2: valToDisplay = 3; break;
    case 3: valToDisplay = 7; break;
    case 4: valToDisplay = 15; break;
    case 5: valToDisplay = 31; break;
    case 6: valToDisplay = 63; break;
    case 7: valToDisplay = 127; break;
    case 8: valToDisplay = 255; break;
  }


  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, valToDisplay);
  digitalWrite(latchPin, HIGH);
  
}

Tuesday, 24 June 2014

Dog-controlled treat dispenser

I picked up one of these treat dispensers from Maplins on a whim - one of those "I'm-sure-I'll-find-a-use-for-this-someday" things. Subsequently I started wondering if I could train my dog, Jack, to use it (with some modifications, obviously)

An initial attempt involved simply wiring a switch to a footpedal for Jack to step on. That lasted all of 10 seconds as the plastic lid I'd repurposed as a pedal cracked under his weight.

One of the things that attracted me to the gadget in the first place was the capacitive button that it used. A quick test with my phone screen showed that dog's paws can operate capacitive switches.

Simply extending the leads alone wouldn't be enough. Although I want to give Jack the freedom to get his own treats, I still want to keep control over how many!

The touch sensors board has simple connections - just power, and leads out to the motor. I didn't really want to waste time modifying the board, as it's all small surface-mount components. Since I know the motor was only driven one direction by the board, I simply connected an optocoupler to the motor outputs. A couple of pull-up resistors later and the switch was done.

The finished capacitive button PCB with optocoupler


I connected a metal lid in place of the small capacitive disc to make it more dog-friendly.

Now onto the human's control system..

My original plan was to use something web connected such as an old android device, so that I could give Jack treats whilst out at work, but in practice, it was totally overkill, so I opted for a microcontroller based system instead.

The only controls I really need are to limit the number of available treats, set a time limit so he doesn't eat them all at once, and a way to see how many were available.

I found an old PCB with two buttons on it in my junk box. One button to add a treat, one to remove.
 
The salvaged button PCB (I believe it once belonged to a toaster...)


For a display I went with a 10-segment LED, controlled by a shift register. Due to the limitations of the shift register, the maximum treats available at any one time is 8 - which is more than enough anyway. The remaining 2 LEDs are left unused.
The 10 segment display (3 treats available) - the bottom 2 LEDs are not used.



The time limit I chose to fix at 1 hour in the microcontroller. As it's impossible to precisely measure the amount of treats that will be dispensed, the motor was set to a 3 second interval.

Finally I added a small LED module to the pedal, that lights when the timer ticks down and a treat is available, so that Jack could see when he can get a treat. According to the Pavlovian theory, he should soon learn that light=treat.

The LED module (it's just from one of those battery operated 'cupboard lights' you see in nearly every pound shop) - for this project I just connected a jumper over the button.


As with other projects I opted for using an Attiny (in this case the 2313) with the Attiny arduino cores, as they make it nice and easy to prototype with Arduino and switch to a regular AVR for the end product.

Stay tuned for part 2 - building an enclosure for it, some pictures of the completed project, source code, and hopefully some pictures/video of Jack using it.

UPDATE - Part 2 is now available here.

Tuesday, 10 June 2014

Android App: RSS Media Grabber

My second android app is now available on the Google Play store. It's a port of a desktop Java application I wrote a while back, which will retrieve image media from RSS feeds - useful for web comics/cartoons, pic-of-the-day sites etc.







Usage
When using the app for the first time, use the menu button and select "Add New Source".
On the next screen, enter the URL for the feed, and give a folder name (this will be where the app stores the files it downloads - eg, if you enter "MyFolder", the directory will be sdcard/RSSMediaGrabber/MyFolder/)
Select OK to return to the main screen, and select menu->Load sources. This will list all the RSS feeds you've added.
Select one of the feeds to be prompted to retrieve the feed. Select OK and it will load the feed, grabbing any image media, and saving them to the folder.

You'll then be able to view the downloaded media through your photo app of choice.


Future development plans
  • Wider media selection (MP3 for podcasts etc).
  • Integrated media viewer/player
  • Scheduling to check feeds at set intervals.

Support/Feedback
As with my other apps, it's free (ad-supported), and I welcome feedback. Unfortunately I'm not in a position to offer any kind of official support for this, so use entirely at your own risk. If you have any trouble with it, then feel free to contact me on twitter/G+/leave a comment, and I'll try to help as and when I can, but I make no guarantees!

Any feedback, particularly with regard to different phone/tablet hardware and android versions is appreciated.

Thursday, 22 May 2014

Android App: Bluetooth Macro Input

UPDATE - Please note this version of the Bluetooth Macro Input app is no longer supported. Although it's still on the Play store, it will not be updated in future. Please consider migrating to the new Bluetooth Macro and Voice Input app instead.
 
A while ago I posted this snippet of Arduino code for an upcoming project. Unfortunately with a looming redundancy and several courses on the go at the moment I've not had the free time to follow up until now.

All the code does is read a character from the serial pins of the arduino, then outputs that character as a keyboard keystroke using the keyboard emulation functionality of the Arduino Leonardo variants.

The rest of the hardware is very simple - just a bluetooth serial module, such as one of these - connected to those pins. There's just 4 pins - power, ground, TX and RX.

With that done, and the arduino sketch uploaded, the rest of the work is in the android application, which is now available for download by clicking the button below.







What it does
You can provide a library of snippets of text on your devices external storage (any ASCII filetype is fine), and then this app can access them, and send them via bluetooth to the arduino hardware, which emulates a USB keyboard and types the contents out.
This is handy for maintaining a library of code/command snippets that you might want to use across different computers or devices. (Or if, say, your day job requires you to often type the same thing on a computer that you have little control over software/config wise...)

Requirements
  • The hardware described above.. Without it, the app is kinda pointless.
  • Supports versions of android from 2.2 (Froyo) upward, though only tested on a Samsung Galaxy S3.
  • Bluetooth serial device (115200 bps)
  • Permissions
    • Requires bluetooth and external storage access.

Usage

To run the app, first turn on bluetooth.
When you first run the app, you'll need to enter the MAC address of your bluetooth device - you should be able to find this in the docs of your serial device (or printed on it). Once done it should automatically connect.
Create or move your text snippet files to the a folder on the SD card under BluetoothMacroInput directory.
Use the Menu key in the app to bring up the menu, which is basically just the folder structure of the directory - click on your chosen file and it'll load it into the text view. Click 'Type' to have the device start typing your text.
Depending on your external hardware, you might need to adjust the delay value (if the typed text is garbled, then you need to increase the number)


Future Development plans
  • One-button input for frequently used commands.
  • Mouse emulation using phone touchscreen/sensors
  • Dynamic macro recording (using USB host passthrough for a keyboard)
  • General UI improvements..

Support/Feedback
Unfortunately I'm not in a position to offer any kind of official support for this, so use entirely at your own risk. If you have any trouble with it, then feel free to contact me on twitter/G+/leave a comment, and I'll try to help as and when I can, but I make no guarantees!

Any feedback, particularly with compatibility on different hardware (both android devices and Bluetooth/keyboard hardware) will be much appreciated.

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.