Here's an idea we had quite some time ago, while proposing ideas for the HackLlan show-and-tell session in November last year. It was for a poker table which could read cards without using expensive RFID hardware.
Well, at BuildBrighton we're talking about holding our first poker night - so it'd be really cool if we could broadcast it live - complete with overlay graphics, just like they use on the telly!
The original idea for identifying cards was to use "intensities of light" and non-primary colours to determine which grid pattern was showing over a single exposure. After a bit of trial and error, we found it difficult to tell when one, two or three squares of the same colour were showing in a pattern and the card detection device failed.
That's not to say we're giving up!
Nick at Custom Stuff has arranged to create some decks of customised playing cards, entirely to our own design rather than through their online editor, so we're now thinking about a different layout. The latest idea is this:
Each card will have "index" numbers in all four corners (this is an option you can set in the custom stuff online editor) BUT we're going to put each index into a different coloured square.
We'll have an LDR under each corner of the playing card (which sits on a black plate with holes cut in the corners, so only the colour in each corner is displayed from underneath) and then flash an RGB LED through red, green and blue.
By measuring the reflected light from each corner, we should be able to work out which colour is at which corner (and thus, which card is face down on the detector)
We've come up with this pattern sequence for our playing cards. The idea is to find which corner contains the black or white square (if black, the LDR under this corner will always return zero, if white, it should always return full brightness) and then read the colour pattern off the card.
If every card has only one black or white square, then we can convert a sequence of colours into a card value and it won't matter which way around the card is placed on the detecting plate.
The beauty of this design is that we don't have to work out intensities of colour - simply set a threshold value and if that value is met, we can detect the presence of a particular colour; it turns the result into a binary operation once more.
For example, let's say we've put the six of diamonds onto our detector (for the sake of example, let's assume it's the same way around as the blocks in the diagram above).
We flash the RGB red and read the values, clockwise, from each LDR at each corner of the card (the LDRs are inside black tubes, so are only reading reflected light, not direct or ambient light from the LDR).
The first LDR (top left) reads 190 which is above our threshold value of 100.
The second LDR (top right) reads 180 which is above our threshold value.
The third LDR (bottom right) reads 30 which is below our threshold value.
The fourth LDR (bottom left) reads 54 which is below our threshold value.
We need to allow for a little bit of leeway in our threshold, in case any ambient light creeps in, or if the blue, for example, is not an exact blue with absolutely no red pigment in the ink. This is where our "intensity" approach failed last time - the inks were not perfectly exact colours and the range for error was greater than our range for detecting colour. This time, we're simply saying "is this corner red, green or blue?"
Now let's flash the RGB blue and read the values again.
The first LDR (top left) reads 43 which is below our threshold value of 100.
The second LDR (top right) reads 176 which is above our threshold value.
The third LDR (bottom right) reads 156 which is above our threshold value.
The fourth LDR (bottom left) reads 78 which is below our threshold value.
Lastly, flash the RGB green and read the values once more:
The first LDR (top left) reads 57 which is below our threshold value of 100.
The second LDR (top right) reads 185 which is above our threshold value.
The third LDR (bottom right) reads 41 which is below our threshold value.
The fourth LDR (bottom left) reads 158 which is above our threshold value.
Now collating these results, we can see that the first LDR (top left) responded only to the red light. So let's say that is red. The second LDR (top right) responded to all colours, so that must be our white square (if it was black, it would be the only one to respond to none of the RGB flashes). The third LDR (bottom right) only responded when the RGB was flashed blue and the fourth (bottom left) only responded to green light.
So we have red, white, blue, green. In our look up table, this corresponds to only one card in the deck - the six of diamonds. To look up the card in our microcontroller, we'll probably cycle the colours until we either start with black or white - so our sequence would be white, blue, green, red. This means we don't have to store all possible permutations of each colour sequence to be able to perform an accurate look-up
(we don't want to try to look up red, white, blue, green and have no matches because the microcontroller is comparing against white, blue, green red!)
Showing posts with label ldr. Show all posts
Showing posts with label ldr. Show all posts
Monday, April 23, 2012
Tuesday, April 26, 2011
It's stopped working!
Last night we celebrated (albeit in true nerd style, with a cup of tea and a Bourbon biscuit) after getting our "shadow harp" working properly.
It was possible to trigger 1,2,3 and even 4 different samples in sequence (one after the other) or together (by spreading my hands sideways and covering all four inputs at once). It seemed to be working exactly as designed.
This morning, keen to repeat the successes of last night, I plugged the new instrument into my PC and tried to play a simple tune. Nothing!
The LDR values didn't seem to change. I altered the sensitivity threshold but only saw activity when it was reduced down to 2 instead of 10 as it was last night. This was so sensitive that other inputs were triggering sounds even at the slightest movement near them.
I noticed that the raw input values had increased from around 220 to 252 and reduced very slightly when the end of each tube was covered.
Thinking about how the LDR works (with a variable resistance from 5Mohm down to a few hundred Kohm) it sort of made sense. During the day, natural daylight floods the room, so the "top" resistance is lower, compared to the fixed 1Mohm resistor to ground. At night, when playing the instrument under artifical light, the somewhat dimmer conditions mean the "top" resistor has a higher value - so the ratio between the top and bottom resistors is lower on each input pin. This theory is in line with the input values seen: at night, the input values are noticeably lower than during the day.
The solution? Not sure - my gut reaction is to replace the bottom resistors with linear pots, so that the instrument can be "tuned" to the ambient light conditions.
A simple set-up screen when the instrument is first switched on will allow the user to find the optimum values for the "bottom" resistor before play commences.
Perhaps something like take a reading from each pin in turn, compare to the mid-point (128) value and display it as a bar on the screen. The user then twiddles each pot in turn, until all inputs are set to about half-way. They can then press a button to start playing the instrument, knowing that hand gestures will be correctly sensed and processed as inputs for the device.
[update: I just tried replacing the 1Mohm bottom resistors with lower valued ones (about 330Kohm) and the instrument once again became sensitive enough to play. It seems that allowing the user to change the initial resistance of the bottom resistors (i.e. replace with potentiometers) could be the way to go!]
It was possible to trigger 1,2,3 and even 4 different samples in sequence (one after the other) or together (by spreading my hands sideways and covering all four inputs at once). It seemed to be working exactly as designed.
This morning, keen to repeat the successes of last night, I plugged the new instrument into my PC and tried to play a simple tune. Nothing!
The LDR values didn't seem to change. I altered the sensitivity threshold but only saw activity when it was reduced down to 2 instead of 10 as it was last night. This was so sensitive that other inputs were triggering sounds even at the slightest movement near them.
I noticed that the raw input values had increased from around 220 to 252 and reduced very slightly when the end of each tube was covered.
Thinking about how the LDR works (with a variable resistance from 5Mohm down to a few hundred Kohm) it sort of made sense. During the day, natural daylight floods the room, so the "top" resistance is lower, compared to the fixed 1Mohm resistor to ground. At night, when playing the instrument under artifical light, the somewhat dimmer conditions mean the "top" resistor has a higher value - so the ratio between the top and bottom resistors is lower on each input pin. This theory is in line with the input values seen: at night, the input values are noticeably lower than during the day.
The solution? Not sure - my gut reaction is to replace the bottom resistors with linear pots, so that the instrument can be "tuned" to the ambient light conditions.
A simple set-up screen when the instrument is first switched on will allow the user to find the optimum values for the "bottom" resistor before play commences.
Perhaps something like take a reading from each pin in turn, compare to the mid-point (128) value and display it as a bar on the screen. The user then twiddles each pot in turn, until all inputs are set to about half-way. They can then press a button to start playing the instrument, knowing that hand gestures will be correctly sensed and processed as inputs for the device.
[update: I just tried replacing the 1Mohm bottom resistors with lower valued ones (about 330Kohm) and the instrument once again became sensitive enough to play. It seems that allowing the user to change the initial resistance of the bottom resistors (i.e. replace with potentiometers) could be the way to go!]
How the new shadow harp works

Each of the four analogue inputs as a simple voltage divider.
5V is connected to one side of a light-dependent resistor (LDR), which is wired in series with a resistor to ground. The input signal is taken from between the two resistors.
As the user places their hand over the LDR, the resistance falls, causing the ratio between the two resistors to drop. This variable voltage is fed into an analogue pin, converted to a digital value (0-255) by the microcontroller's ADC hardware and compared to the last value read in.
Even when static, analogue input values tend to "drift" - i.e. float around, +/-1 or +/-2 (so a "constant" value of 128 may actually vary between 126 and 130 over time!)
To overcome this, we take a reading from the analogue pin, compare it to the previous value and if the difference is greater than 2, this represents a genuine change in resistance, which we then process.
In fact, depending on light levels, sometimes it is necessary to adjust this value to 4 or 5, to avoid cross-talk as the user places their hand in a position that influences to LDRs, next to each other. By making this threshold value a variable, we can allow the user to set their own "sensitivity" level for playing the instrument.
In indoor lighting, the LDR inputs typically read around 220.
When you place your hand over an input tube, this value drops to around 205.
Sometimes neighbouring LDR values drop when you place your hand over an input - by setting the sensitivity to 8, in this case, only the sensor with a hand above it actually triggers an input signal.
Triggering inputs is quite simple - if an input value is falling compared to its previous value, this represents the presence of a hand above the input.
When the input value is constant, the hand is still present. When the value is rising, this is the user removing their hand away from the input.
Using Oshonsoft's hidterm DLL and an 8-byte USB buffer, we can send the raw input values AND the trigger values (0 or 1) for four inputs at a time:
Monday, April 25, 2011
Simplified shadow harp
After nearly a week of getting nowhere, we're thrilled to announce that we've (finally) got a working, consistently accurate shadow-type harp! It's much simpler than original designs, using only four LDRs (light dependent resistors) and a modified enclosure.
The original pocket- or shadow- harp designs used a pinhole "lens" to detect the position of the player's hand above the instrument. Even the original instrument's designer, Peter DeSimone, said that his original design was plagued with problems and false-triggers. To solve his false-triggering problems, Peter introduced capacitors and used the LDRs to create an oscillating input (counting the time between pulses to detect the presence - or otherwise - of a shadow).
This seemed like a lot of work for us - the problem is the LDR changes resistance continually, even by small amounts. In theory, a simple voltage divider approach should still work, we just need to eliminate the "false reads" caused by fluctuating analogue inputs.
Using a combination of hardware and software limits and sensitivity settings, we've managed to solve the problems associated with the voltage divider approach and by encasing each LDR inside a black tube, we've also managed to get rid of the cross-talk the plagued other designs.

Our LDR tube sleeves were just drinking straws covered in black crepe paper. There were no black straws in our local Morrisons, so we got these 80s style neon ones and covered them!
We're using just four LDRs and we're treating each as an individual input.
This means that we can trigger four different samples - in software we can decide whether a single sample plays or multiple (polyphonic) sounds can be produced.

Obviously four different notes/chords/samples is a bit limiting, so we're working on a dial that lets the player select a "sample set" during playing - in the same way they can change the key or chord/scale type (e.g. set to C major and the notes could be C, E, G, C, twiddle the dial and the notes could become E,G,A,B from the Em pentatonic scale).
The first thing we need to do is check we've enough spare pins for an LCD display, 4 analogue inputs, 4 LED outputs (an addition that might be useful: an indicator to show that an input has been detected) plus a few extra analogue inputs for the pots/dials. On a beefy 18F4550 that would be a doddle - we've a load of 18F2455 chips lying around from previous projects and it'd be nice to squeeze a bit more use out of those!
Check back for schematics and more videos shortly.......
The original pocket- or shadow- harp designs used a pinhole "lens" to detect the position of the player's hand above the instrument. Even the original instrument's designer, Peter DeSimone, said that his original design was plagued with problems and false-triggers. To solve his false-triggering problems, Peter introduced capacitors and used the LDRs to create an oscillating input (counting the time between pulses to detect the presence - or otherwise - of a shadow).
This seemed like a lot of work for us - the problem is the LDR changes resistance continually, even by small amounts. In theory, a simple voltage divider approach should still work, we just need to eliminate the "false reads" caused by fluctuating analogue inputs.
Using a combination of hardware and software limits and sensitivity settings, we've managed to solve the problems associated with the voltage divider approach and by encasing each LDR inside a black tube, we've also managed to get rid of the cross-talk the plagued other designs.

Our LDR tube sleeves were just drinking straws covered in black crepe paper. There were no black straws in our local Morrisons, so we got these 80s style neon ones and covered them!
We're using just four LDRs and we're treating each as an individual input.
This means that we can trigger four different samples - in software we can decide whether a single sample plays or multiple (polyphonic) sounds can be produced.

Obviously four different notes/chords/samples is a bit limiting, so we're working on a dial that lets the player select a "sample set" during playing - in the same way they can change the key or chord/scale type (e.g. set to C major and the notes could be C, E, G, C, twiddle the dial and the notes could become E,G,A,B from the Em pentatonic scale).
The first thing we need to do is check we've enough spare pins for an LCD display, 4 analogue inputs, 4 LED outputs (an addition that might be useful: an indicator to show that an input has been detected) plus a few extra analogue inputs for the pots/dials. On a beefy 18F4550 that would be a doddle - we've a load of 18F2455 chips lying around from previous projects and it'd be nice to squeeze a bit more use out of those!
Check back for schematics and more videos shortly.......
Sunday, April 17, 2011
Pinhole box to focus light beams
Here's the basic idea - to place a row of LDRs (light dependent resistors) in a row, then place the whole lot inside a box. The inside of the box stays darks, and a small pin-hole is placed in the lid. Each LDR can now receive just a little bit of ambient light, but only from a specific direction. By moving your hand around above the hole, each LDR should be affected but only when your hand covers a narrow region above the box.

By doing this, we should be able to map when the user has placed their hand to a specific sound-trigger. I think this is how the pinhole light harp works. We're working on creating a digital trigger device to begin with, then we'll add an ultrasonic range-finder to calculate how high the player's hand is above the instrument (perhaps to increase volume or play different notes).

By doing this, we should be able to map when the user has placed their hand to a specific sound-trigger. I think this is how the pinhole light harp works. We're working on creating a digital trigger device to begin with, then we'll add an ultrasonic range-finder to calculate how high the player's hand is above the instrument (perhaps to increase volume or play different notes).
Subscribe to:
Posts (Atom)
