linear1 forums
[part of the linear1 network]
+ [linear1 case mods]
+ [LED Center]
+ [privacy policy]
Welcome, Guest. Please login or register.
March 21, 2010, 02:32:59 AM

Login with username, password and session length
Search:     Advanced search
* Home Help Search Login Register

linear1 forums  |  LED discussion  |  LED questions and discussion  |  Topic: LED Sensor Array « previous next »
Pages: [1] 2 3 Print
Author Topic: LED Sensor Array  (Read 38111 times)
justDIY
Microcontroller Madman
Administrator
Smart like tractor
*****
Offline Offline

Posts: 1652


UFOric


WWW
« on: October 24, 2005, 12:52:31 AM »

man am I stoked!!

My objective this weekend was to become a slave driver, or at least, learn how to make slaves.

Mission Accomplished!

I now own a slave army of picmicros!

What is a slave you ask?  Well, in the digital electronics world, a slave is something subjegated to a master controller.

I am using the Phillips I2C bus as my protocol of choice - it offers great speed (400 kbps) and reliability, and only uses two wires

I've moved my LED sensor array project onto its own large breadboard, which houses three picmicros (one master, two slaves)

If How is it done? was my Iliad... this topic will be my Odyssey.

The pics I'm using only have five ADC ports each (*pout*), but that's OK, as it turns out, I only had eight red leds of the exact same type ... but when the pics I'm waiting for Microchip to release finally arrive, I'll have 12ADC ports on each slave (*woot*) ... and the addressing scheme I've chosen for my slaves will allow me up to 16 of them, so I conceivably could build a 12x16 array (*damn*)!  T 1 3/4 leds are a bit large to make an array from anyway, so I've ordered 200+ T1 (3mm) sized ultra-bright red leds from a popular online auction site (for cheap too!).  I need to get some more 150 ohm resistors, no way I'm buying any more from a not-so-popular electronics retailer

Right now, all I have is the simplest of routines loaded on my slave ... they power up, turn on their "i'm alive" LEDs and then do an array test.

the only commands they support is turning their status LED on and off ... but the fact its working means a great deal, as I can easily add more commands, as well as the ADC routines - I have all the LEGO pieces, now it's time to build!
Logged

Want to contact me directly? gmail gordonthree
My Project Blog - http://projects.dimension-x.net

Favorite numbers:
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
Rob
LED guy
Administrator
Smart like tractor
*****
Offline Offline

Posts: 1970


The constant-current gardener


WWW
« Reply #1 on: October 24, 2005, 12:05:17 PM »

* Rob pulls up a lawn chair, sits back, and cracks open a cold naturally-carbonated cereal malt beverage
  chug-a-lug
Logged

justDIY
Microcontroller Madman
Administrator
Smart like tractor
*****
Offline Offline

Posts: 1652


UFOric


WWW
« Reply #2 on: October 24, 2005, 12:08:17 PM »

My odyssey begins:


Here is my breadboard ... the array is only 8 leds right now, and already a ton of wires!



This is the readout from my visual basic app, as I slide my finger around on my led array
Logged

Want to contact me directly? gmail gordonthree
My Project Blog - http://projects.dimension-x.net

Favorite numbers:
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
justDIY
Microcontroller Madman
Administrator
Smart like tractor
*****
Offline Offline

Posts: 1652


UFOric


WWW
« Reply #3 on: October 24, 2005, 02:29:19 PM »

I made my last post in a rush to get out the door ... I could sit at home and play with microelectronics all day, but I wouldn't make any money from working, so that wouldn't last too long.

anyway, the breadboard:

along the top row you see six ICs, from left to right they are:

hehe, I bet you're thinking, I only see four ICs ... well, there are six, trust me Smiley

#1
Power Supply - 7805 - This is a regulated 5 volt power supply, with some filter caps, buffering caps and a power-on led.  The 7805 is infact an integerated circuit, just disguised as a transistor.

#2
"SlaveA" - PIC16F876A - This is one of my slave microcontrollers ... it autonomously scans its row (the bottom row) in the array with blistering speed, approx 600 uSec per pixel in the array, so 2.4 mSec total - which is kind of slow actually, as I add more lights to the array, the responsiveness of the array grows ... I can probably shorten my sample time now.  The blue LED indicates the slave is operational and the program is running.

#3
"SlaveB" - PIC16F876A - This is the second slave microcontroller, which scans the top row of leds.  It is running the same program as SlaveA, but with a different slave address.

#4
"Master" - PIC18F252 - This is the third microcontroller, playing the master roll.  It polls the slaves every 100msec for an update, and feeds that data to the host PC.   This microcontroller is severe overkill for the job its doing, but these are the PICs i had on hand, so thats how the chips fell (har har har).  The blue led indicates the master is polling a slave (in real-time, the led blinks very fast)

#5
"Clock" - DS1065T-060 - This is a digital clock generator from Dallas.  It is programmed to generate any clock frequency I want, currently provideing a 20mHz clock that is used by all three pics.  Although not as accurate as a crystal, it does provide better temperature stability ... the only reason I am using it is to save board space (and the fact I obtained a sample of one from Maxim a long time ago but never used it) ... three separate crystals and their associated load capacitors would have taken up way too much board space.  The DS1065 is the first TO-92 package (on the left).  Next to it is a regular 2n2222 transistor which controls the MCLR (reset) line on the slaves)

#6
"Interface" - MAX233 - This is a Maxim RS232 line driver IC ... The MAX233 is very similar to the popular MAX232 except it requires no external capacitors for its voltage doubler circuit, again to save board space.  This chip boosts the cmos level serial data from the "master" pic to TTL level for transmission to the host pc.

Operation of the slaves:

Each slave normally runs in a infinite loop, sampling the LED sensors as fast as it can and storing their values in a memory buffer.  When a polling request is received from the master, an interrupt is generated which branches out of the sampling loop.  I2C commands are pretty complex on paper, but merely a matter of setting and clearing bits in the digital world, so at 20mHz the pic handles them with lightning speed.  Here is the blow by blow of the most complex series of commands, a multi-byte read

1) Master sets a "start condition" which basicly places a certain state on the bus

2) Master sends the slave address onto the bus with the read flag cleared... a slave address is the seven most significant bits of a byte (7:1), with the least signifcant bit (0) reserved for a read flag.

3) The I2C hardware in the slaves simultaniously receive this address, and compare it to their internally programmed addresses.  The slave matching the address then sends an acknowledge bit on the bus.

4) Master receives the acknowledge bit and sends a command byte.  Since the start condition is still present, the last slave addressed  acknowledges receipt of the byte by sending an ack bit.  This command byte is $04 in my application.

5) Slave receives the command, executes it and sends an acknowledge.  The command $04 tells the slave to copy the ADC buffer to the transmit buffer.

5) Master receives the ack and sets a "restart condition", which causes all the slaves to actively watch the bus for a slave address.

6) Master sends the slave address this time with the read flag set.

7) Slave matching the address sends an acknowledge.  It then sends the first byte of the transmit buffer, without further prompting from the master.

Cool Master receives the first data byte, and stores it in the receive buffer.  The master sends an acknowledge.

9) The slave last addressed (since bus state is still START) sends the second byte in its transmit buffer.

10) Master receives the byte, stores it in its buffer, and sends an ack.

11) steps 9 and 10 repeat until the master sends an NACK and sets the bus state to STOP.  This tells the slave to stop sending bytes.

each of these steps takes a tiny fraction of a second ... the entire transaction is comprised of a multitude of commands and data going both ways and is finished in the blink of an eye, indicated by a fast flashing of the masters' status led, which blinks twice (once for each slave), but so fast it looks like a single blink.  The only reason the master status led isn't solid on is there is a 100mSec delay allowing for the host PC to process the data.  If I send data out as fast as possible, the serial port on my PC can't keep up... even a simple terminal program just locks up trying to deal with a constant stream of data at 115 kbps... I do have a very simple serial program that is must be written in C or C++, it directly accesses the serial port via the windows HAL, it is the only program that can keep up with a full speed datastream.  It really burns my biscuits that a 20mHz $10 microcontroller (the 18f252) can send data faster than a 1600 mHz $400 (back when I bought it) CPU can process it.  Visual basic must be the slowest language on Earth.

If you've made it this far, congrats!

It's interesting to point out (not that I've seen any evidence of it on the host pc), that there is some lag introduced by the i2c routines in the ADC sampling process.  Since i2c transactions are not just simple "one shot" commands, the slave is continuing to do ADC sampling while waiting for the next event from the master.  This is acheived through the use of interrupts.   whenever the slave is in the ADC loop, it gets pulled out to talk to the master, but since each time it talks to the master is only a very brief instant, its spending 99% of its time in the ADC loop.  however, by me copying the ADC buffers to a transmit buffer only once during a transaction, the data in the buffer is 'stale' by the time it gets requested by the master.  I'm going to look into ways of directly interfacing the i2c routines with the ADC buffers, which should let the master receive the freshest data possible.  The problem here is, the ADC buffer is eight double-byte (word) values (only which four are actually used) but the transmit buffer is sixteen single-byte values, since the i2c protocol deals strictly with bytes.  so the command to copy the adc buffer actually breaks the words into bytes to store in the  transmit buffer.

but like I said, maybe if I wanted to use the array to detect fast moving objects this would be important, but it responds to human interaction quite nicely now, even with the 100msec sampling delay imposed by visual basic.  I think is due to the fact that the 'missed' samples are discarded instead of buffered, so the PC is still receiving real-time data from the array, just not very fast.

Logged

Want to contact me directly? gmail gordonthree
My Project Blog - http://projects.dimension-x.net

Favorite numbers:
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
Rob
LED guy
Administrator
Smart like tractor
*****
Offline Offline

Posts: 1970


The constant-current gardener


WWW
« Reply #4 on: October 24, 2005, 04:55:26 PM »

Just to tie in with a comment from an earlier thread, could you make the uCs issue MIDI events?
Logged

justDIY
Microcontroller Madman
Administrator
Smart like tractor
*****
Offline Offline

Posts: 1652


UFOric


WWW
« Reply #5 on: October 24, 2005, 05:33:30 PM »

Yes you can; I've seen several projects regarding interfacing microcontrollers with MIDI

I know next to nothing about MIDI other than it is used to interface musical instruments to each other and to computers
Logged

Want to contact me directly? gmail gordonthree
My Project Blog - http://projects.dimension-x.net

Favorite numbers:
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
justDIY
Microcontroller Madman
Administrator
Smart like tractor
*****
Offline Offline

Posts: 1652


UFOric


WWW
« Reply #6 on: October 24, 2005, 11:53:08 PM »

OK ... Rob has raised a good issue, that has been in the back of my mind for a while.

I have established a well working "Three Dimensional*" human interface here ... but what are good applications for it?

Rob's idea of using the interface as a MIDI controller is excellent, and something I should be able to implement easily.

* although the array can sense a full three dimensions, its resolution on the z-axis is rather limited ... it can only "see" an object a few inches away, and bright ambient lighting also causes problems with this.

so ideally the application would need one or two input axis.

I'm thinking a one dimensional application would be anything that currently uses a "slide potentiometer" ... the led array can detect your fingers presence on the array and the direction it is moving, so you could couple it to a digital potentiometer and use a bunch of arrays as gain sliders in a dj mixer.

micro arrays of two or or four leds could be used as "keys" on a "no moving parts" keypad ... pressing your finger firmly to a surface covering the leds should cause sufficient reflection to register as a "keypress", the array would also serve purpose of backlighting the keys for that extra coolness factor.  different color leds could be used for control keys, function keys, etc.

my work so far has involved red leds, but my research shows that any LED works... from infrared to blue.   

what say you all?
Logged

Want to contact me directly? gmail gordonthree
My Project Blog - http://projects.dimension-x.net

Favorite numbers:
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
sanjed
Imaginator
Smart like tractor
*****
Offline Offline

Posts: 105



WWW
« Reply #7 on: October 25, 2005, 01:10:01 PM »

Used as an on off power switch for tv, monitor etc, no moving parts, just tap the on/off area. this would be cool if an infra red was doing the sensing, as it would not emit any visible light when in standby.

Fully waterproofing something, the switches are on the inside, the outer shell is transparent where the switches need to be seen.

Star Trek style "sliding controls". very good application for the dj mixer mentioned, when you "slide" the leds up they follow the slide, eg... slide it right up, they're all lit, slide it right down, they all go out, and somewhere in the middle, the bottom half are lit.

Mouse buttons.. that clicking noise ticks me off.  go the whole hog on the mouse and make a slide panel for wheeling.

If you made a large enough array, you could make a big drawing surface, if my previous suggestion about lowering the intensity is feasable.

Logged
justDIY
Microcontroller Madman
Administrator
Smart like tractor
*****
Offline Offline

Posts: 1652


UFOric


WWW
« Reply #8 on: October 25, 2005, 07:46:20 PM »

I've managed to squeeze some more performance out of my visual basic

I guess spending more than 10 min to code something in vb is probably a good idea

here is a short video of my finger passing back and forth across the array

[img width=480 ]http://projects.dimension-x.net/pictures/sensor_array/bargraph1.gif[/img]
right click, save-as...
video will not stream off server

*edit: in order to be dial-up friendly, I've compressed the heck out of the video, I used XVid - you'll need a suitable divx/xvid player and codec to view it;  ffdshow, div-x.com, etc

the graphic on the screen represents the actual sensors in the array now ... so you can see the full 3D effect your interaction has on the array... the reponse for the edges of the array is rather poor ... as soon as more leds arrive I will surround the array with a solid-on border of leds to provide more light for the edges
« Last Edit: October 26, 2005, 12:32:30 PM by justDIY » Logged

Want to contact me directly? gmail gordonthree
My Project Blog - http://projects.dimension-x.net

Favorite numbers:
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
Rob
LED guy
Administrator
Smart like tractor
*****
Offline Offline

Posts: 1970


The constant-current gardener


WWW
« Reply #9 on: October 25, 2005, 09:14:12 PM »

I'll happily host videos as needed.
Logged

justDIY
Microcontroller Madman
Administrator
Smart like tractor
*****
Offline Offline

Posts: 1652


UFOric


WWW
« Reply #10 on: October 25, 2005, 10:05:39 PM »

were you able to view that video?

any suggestions on a better free codec to encode with?

hehe, the raw screen capture was 700 meg, xvid squished it down to ~300k
Logged

Want to contact me directly? gmail gordonthree
My Project Blog - http://projects.dimension-x.net

Favorite numbers:
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
Rob
LED guy
Administrator
Smart like tractor
*****
Offline Offline

Posts: 1970


The constant-current gardener


WWW
« Reply #11 on: October 26, 2005, 10:51:06 AM »

It seemd to be truncated--the download went quickly to maybe 7% and then terminated. I only got a couple seconds of wiggling colored bars. What should the file size be?

FWIW I viewed it in the DivX player.
Logged

justDIY
Microcontroller Madman
Administrator
Smart like tractor
*****
Offline Offline

Posts: 1652


UFOric


WWW
« Reply #12 on: October 26, 2005, 12:17:42 PM »

file should be 292KB

it is about 26 seconds of play-time

Logged

Want to contact me directly? gmail gordonthree
My Project Blog - http://projects.dimension-x.net

Favorite numbers:
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
justDIY
Microcontroller Madman
Administrator
Smart like tractor
*****
Offline Offline

Posts: 1652


UFOric


WWW
« Reply #13 on: October 26, 2005, 12:28:27 PM »

I'm making good progress on things here - nothing has really changed array wise, but a lot of fine tuning of the firmware handling the array and the visual basic program interpreting the data.

I've managed to get the polling time down into the double digits, I'm not sure the exact number, but the led that blinks during master polling is now blinking so fast it appears solid on, not even the slightest flicker... so I'd estimate well over 60hz ... which is ~17msec ... or in terms of visual sensitivity - 60 'frames' per second.  I'll have to figure out how to time the actual process now that it's too fast to see visually.

video screen captures of the interface program really don't mean much unless you can also see me interacting with the array ... unfortunately I'm no whiz with digital video ... any one have ideas how I can do a "picture in picture", overlay a video feed from a live camera focused on the array on top of my screen capture of the interface program?

Logged

Want to contact me directly? gmail gordonthree
My Project Blog - http://projects.dimension-x.net

Favorite numbers:
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
Rob
LED guy
Administrator
Smart like tractor
*****
Offline Offline

Posts: 1970


The constant-current gardener


WWW
« Reply #14 on: October 26, 2005, 12:53:49 PM »

If you post the individual vids, I'll see if I can combine them. I have some tools for that stuff, but I'm not very expert in the use of them (so no promises).
Logged

Pages: [1] 2 3 Print 
linear1 forums  |  LED discussion  |  LED questions and discussion  |  Topic: LED Sensor Array « previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.7 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.413 seconds with 20 queries.