Sunday, January 29, 2012

Cycling turn signal gloves (or, ever so slightly less inconsequential blinking lights)

Building on the lessons learned in the making of the festivity gloves, I have completed my turn signal glove.  It's controlled manually by a single switch between the index and middle fingers (yes, I had to look up the names of the fingers on Wikipedia), and is really only convenient for turning left (unless you feel like contortion while riding).  The left-only limitation seemed reasonable to me, as I hug the curb out of terror while riding on the mean streets of Chicago, so I really only need to signal for lefts.

My professional ethics require me to state that this is not the first turning signal cycling glove; before getting started on this project, I did a quick Google search and found a guy who has built something slightly different.  His interface is an accelerometer, and is ostensibly compatible with the standard cycling hand signals. It looks cool, but he isn't selling them yet, and I already had an artistic vision in mind by the time I saw it, so mine is different enough to merit the necessary effort.  Also, I was interested in something that would be slightly water resistant (while the glove I made is not strictly water-resistant, everything other than the controller module is.  It would be relatively straightforward to water-resist that, too).

I wanted a glove-only turn signal approach (as opposed to something bike-mounted) because I ride a super-cheapo folding bike, and didn't want to deal with wires and whatnot having to cross the folding joints of the bike and getting repeatedly flexed and stretched.  Also, I wanted something that would easily transfer from bike to bike.  As an added bonus, always wearing a flashing glove gives you extra options for finding/guiding people in crowds.

In summary, here's an image of the completed gloves, followed by a video of them in action.




Oh, and if anybody knows somebody who knows somebody in the cycling accessory industry... let me know.

Hardware

All of the basic elements of the hardware are shown immediately below.  The black circle is one of the LED modules; below that is the switch module, next to the switch inside it.  Below that is the battery/controller module.  As before, for size and convenience reasons I am using the oh-so-beefy CR2450 watch cell for power.  The ATTINY85 is the controller; it's abilities are far more than what's necessary for this project, but it had just barely enough pins and I have some on hand.


In the interests of water-resistance, all of the exposed metal in the LED and switch modules are covered with two-part epoxy.  The switch was put inside a length of shrink wrap to allow it to be water-resisted without gumming up its delicate internal mechanisms.  Additionally, the controller module and connector are epoxy-coated.

For compactness, the ATTINY85, two dual FET switches for 'high-current' LED control and a switch and capacitor were superglued to the CR2450 watch cell snap and then epoxied for mechanical strength and a small amount of water-resistance.

The LEDs and switch are mounted on a rigid plastic to keep them oriented appropriately.  The plastic is from some binder dividers.  The wires are a very flexible stranded stainless steel insulated in white PTFE that I had laying around (I assume it was PTFE, judging by how impossible it was to strip, mechanically or with the iron tip.  I ended up burning the insulation off with a pentorch).

The wires were passed through the glove, along with a bunch of thread for mechanical stability.  I then gently pulled the glove inside-out, tied all of the sutures to keep the LEDs and switch on the glove, and then sutured the wires back to the wrist of the glove (the inside-out glove, assembled with extra slack in the leads to allow for testing, is shown directly below).


After turning the glove back out and testing the lights/switch, I shortened the leads and re-attached them to the module connector (shown below).  I then epoxied the connector and pentuple-sutured it three times to one of the heavy-stitched seams along the inside of the wrist.


The electronic design was similar to that used for by previous glove project, except that I needed to provide for more than two times as much current per channel.  I decided to go for the maximum current through each LED (30mA); for three in parallel, this far outstripped the 40mA limit on the ATTINY85 output pins.  To accomplish this, I picked some N-channel FETs (NTMD4840NR2G, the specs are way past what I needed here, but I picked these so I could buy a bunch and not have to worry about them being insufficient for future projects).  There is no resistor between the ATTINY pins and the gate of the FETs; the ATTINY outputs are going to be either all the way high or all the way low during normal operation, and the switch allows me to completely shut off power during 'abnormal' operation, so I saw no need for pull-down or gate-current-limiting resistors.

The switch pulls the relevant pin down to ground; an ATTINY internal pullup is enabled to keep the pin high otherwise.

To allow for easy programming and debugging, the connector has three extra pins (~Reset, MOSI and MISO).  SCK is the same pin as the switch.


Oh, and the parts for this project (excepting the glove, thread, needles, shrink wrap, two-part epoxy and plastic binder separators) are a subset of the Mouser order detailed in this document.

Software

The desired behavior for the lights was to go through wrist-to-fingertip flashing patterns (flashing the fingertip lights three times) so long as the switch was depressed.  This was to mimic the pattern you see on newer turn signals on emergency vehicles.  Additionally, the flash pattern should always be completely run before turning off (so no wiring the switch between the controller and the battery).

The software for this project was very simple (as you can imagine).  After power-on, the ports are set up and the outputs are set to low/off.  The device then sets up an interrupt on the switch and goes to sleep.

Upon switch-interrupt, the device wakes up and sets the lights to the first state in the hard-coded pattern (which so attractively flashes from wrist to fingertip, before flashing the fingertips three times before repeating).  It then resets a timer, un-sets the switch interrupt, and sets an interrupt on timer compare before going to sleep.

Upon waking up for the timer compare match, the pattern counter is incremented.  If the counter is less than the maximum, the new pattern is applied to the outputs and the device re-enters the sleep state.

If the counter is at the end of the pattern, it is reset to 0.  If the switch is still depressed, we continue on as we have (don't change any interrupts).  If, however, the switch is no longer depressed, we turn off the lights, un-set the timer interrupt, set the switch interrupt and go to sleep.

As I said, very simple.

Source and hex.

Lessons

I didn't learn too much on this project that was abstract-able past the limited scope of 'making gloves light up'.  The build went very well, and the device works nicely.  There are really only two things I would have changed (and likely will change on this glove):

1: If you have an interface whose ergonomics and function you aren't certain of, mock them up and test them out first.  The between-the-fingers switch has two marks against it; first, its base had to be narrow so as not to interfere with finger movement, and second, the heat-shrinking makes it more difficult to depress.  I've tried to add something to the switch to make it easier to depress, but it's still tough and often falls over.  Additionally, index-middle finger adduction is not a common task, and the muscles just don't have that much endurance.  I might end up making another switch and putting it between the thumb and the rest of the hand, or possibly replacing the switch with one that has a greater displacement distance or that is intrinsically water-resistant.

2: The controller module needs to be better attached inside the glove.  The controller connector is very well-connected, but I didn't want to directly suture in the controller module, to allow for ease of reprogramming.  However, this means that donning the glove is ever-so-slightly more involved that it aught to be (doffing is as easy as ever, though I have been babying the fingertips more than I used to).  Adding a felt panel might do the trick, allowing the hand to enter easily but still allowing the module to be removed easily.

Overall, I'm very happy with the way this turned out.  Hopefully it will make me slightly more visible on the street when crossing through traffic.  Additionally, it should really help when someone is trying to find me in a crowd.

Saturday, January 21, 2012

Yule-themed gloves (or, inconsequential blinking lights)

I recently had the idea to make a coin-cell-powered cycling signal glove for myself; to 'prototype' the idea, I decided to put together a set of holiday-themed blinky-light gloves as a christmas present.  The objective was to make the electronics as unobtrusive as possible; they ended up being barely bigger than a CR2450 coin cell battery.

Here are the gloves, in 2D and 3D:


Hardware
There are two halves to the 'hardware': the glove side (gloves, LEDs, wiring and connector) and the battery module side (battery, switch, controller and connector).

The overall electrical diagram for the project is below (sorry for the handwritten schematic; my philosophy is, if I'm not going to make a board or do any complicated simulation, the circuit doesn't get any further than dead trees)


As you can see, it is super simple.  The module is basically a battery, a capacitor, a switch and a breakout of the ATTINY85 to the connector.  The gloves are just LEDs and current limiting resistors (all of the resistors ended up being 30Ohm) wired common-cathode to the connector.

The battery modules were hand-made as small as possible; I roughed up the plastic of the CR2450 battery clip to allow the capacitor, ATTINY, switch and connector to be superglued directly to it.  I then made a bunch of tiny end-stripped lengths of wire-wrap (because it was on hand) and hand-soldered all the connections.  Since the connectors are 0.1" spacing and completely break out the pins of the ATTINY, this solution also had the benefit of making programming and debugging easy.


The gloves were just a bunch of fun arts+crafts work.  The green is felt, attached to some cheap CVS gloves with white string (surgeon's knots, in case anyone cares).  Each LED was soldered to two lengths of wire; the wires were then passed all the way through the gloves using large-gauge sewing needles.  The gloves were then turned inside-out, and the wires carefully routed to the wrist (with thread ties every so often; see immediately below).


The wires from the LEDs were then terminated through current-limiting resistors into the connector.  These connections, as well as those on the battery module, were mechanically stabilized with two-part epoxy.  The battery module is shown plugged into the glove with the wrist of the glove rolled up below.


Here is a document outlining the mouser order that contained all of the components used here, except the 10Ohm resistors, hookup wire, gloves and felt.

Software
As you can imagine, the software is exceptionally simple.  There are two firmwares, one for each glove.

Tree Glove
Here, I wanted the 'star' LED to flicker and the other LED pairs to randomly turn on and off at about 2Hz.  At any given time, no fewer than 1 and no more than 3 red LED pairs would be on at the same time.

The 'star' LED is driven by one of the PWM channels; 8 levels of amplitude seemed sufficient to me.  The evolution of the brightness levels was a random walk; it was equally likely to stay at the same level or rise or fall by 1, 2 or 3.  Any over/underflow beyond the [0 7] range is reflected back.

Instead of implementing a random number generator in software (Dec. 25 was fast approaching), I pre-generated a sequence of random bytes using MATLAB, and hard-coded them into the source.  The lower four bits specify which LED pairs are on, and the upper 3 bits specify the PWM duty cycle.

Source and hex.

Wreath Glove
For this one, I wanted all of the LED pairs to flicker independently.  Four amplitude levels for each LED pair seemed sufficient.  Additionally, this allows me to pre-generate and hardcode the necessary random bytes without reusing too many of the bits and thus doing unfortunate things to the independence between the channels). Bits 7:6 determine the level of pair 4, 5:4 -> pair 3, 3:2 -> pair 2, 1:0 -> pair 1, 4:3 -> pair 0.

Unfortunately, the ATTINY85 doesn't have five PWM output channels, so I had to improvise.  I could have simply implemented a five-channel PWM in software, driven by timer overflow interrupts.  However, since I only need four levels, including 'off'', I was able to use the timer overflow and two compare interrupts to set/clear the LED port according to the commanded level:

0-------->COMPa-------->COMPb-------->OVF

All levels (except 'off') result in a port being set at the OVF interrupt; only the 'high' and 'medium' levels are set at the COMPa interrupt; and only the 'high' level pairs are set at the COMPb interrupt.

Source and hex.

Lessons
Overall, this project turned out better than I would have expected.  I was especially pleased with the way the flickering star ended up; the walk frequency and pattern ended up looking exactly like I wanted.  Additionally, the battery modules ended up being nice and small, and with the epoxy ended up being reasonably comfortable.

The biggest thing that I would have changed is the choice of wire.  The wire I used was a stiff, insulated solid-core wire that I happened to have on hand.  This was fine for the holiday gloves, since they are not going to be used much and the wires are all on the back of the hand, thus safe from excessive flexing.  However, moving forward to the turn signal cycling gloves, I will have to find wire which can flex repeatedly without breaking.

Friday, January 20, 2012

Why would I do this?


I am currently trying to finish up a degree in neuroscience (officially biomedical engineering… doing basic motor control and behavioral research; mostly statistical analysis, experimentation and modeling).  Because of this, and a desire to get back into the electronical hobby I previously enjoyed, I have decided it would be in my best interests to document the little projects I design and fabricate.  It is my hope that the projects to come will indicate some useful talents to round out my professional representation, reflecting the training and talents which wouldn't be obvious from my CV.

Of course, it is considerably more likely that I will post inconsequential blinking-light projects (only slightly more likely than the possibility that this will be my last post).