PDA

View Full Version : Receivng IR signals



leshea2
04-26-2006, 04:19 AM
If Pulsout is the best command reference to use to have an IR led emit a signal, is Pulsin the best reference to use to have the IR detector receive·the signal and send it to the stamp, so the stamp can then send the data·to my desktop computer ?


Thanks !

allanlane5
04-26-2006, 04:36 AM
Well, "FREQOUT IR_LED, PulseTime, 38500" is usually the signal used to drive an IR_LED, and "PULSIN IR_Dec, PulseVal" the signal used to read (and measure) the response.

leshea2
04-26-2006, 06:00 AM
I've tried this code but it doesn't seem to work. Is this the way the code should·be ?

' {$STAMP BS2sx}
' {$PBASIC 2.5}


GJH VAR Byte


Main:
SERIN 16, 16624, [WAIT("Ready")]
PAUSE 20
FREQOUT 3, 2000, 2500
PAUSE 200
PULSIN 6, 1, GJH
PAUSE 200
SEROUT 16, 16624, [GJH]
END

(The serin and serout command are for interacting with my desktop computer.)

Thanks !

allanlane5
04-26-2006, 06:21 AM
Yeah, the IR_Decoder won't respond to a 2000 HZ signal -- it wants a 38500 signal, or it will ignore the light completely.

Now, if you want the BS2 to send to itself, you shouldn't have that "PAUSE 200" in there.

And it's not clear what the "PULSIN 6, 1, GJH" is supposed to do...

leshea2
04-26-2006, 06:31 AM
I'm trying to send to myself as a test, and you said PULSIN is used to read and measure the response from the IR led, so when I use "PULSIN 6, 1, GJH" in the code, I’m trying to receive what I just sent.

Thanks !

allanlane5
04-26-2006, 08:17 AM
Yes, but the BS2 is a "single-tasking" processor. Now, if you're using an IR_Decoder, it will ONLY respond to a "FREQOUT MyPin, MyDuration, 38500". It wants that 38500, and NOTHING else.

The PULSIN is very forgiving. But if you don't output 38500, the IR_Decoder will never pull the signal low.

leshea2
04-27-2006, 12:26 AM
So you mean if I use this code,

' {$STAMP BS2sx}
' {$PBASIC 2.5}

GJH VAR Byte

Main:
SERIN 16, 16624, [WAIT("Ready")]
PAUSE 20
FREQOUT 3, 2000, 38500
PULSIN 6, 1, GJH
PAUSE 200
SEROUT 16, 16624, [GJH]
GOTO Main
END

instead of the previous code, it should work ?

Thanks !

SSteve
04-27-2006, 01:43 AM
FREQOUT 3, 2000, 38500
You don't need to generate the 38500 Hz frequency for that long. On the BS2, I use FREQOUT IRPin, 1, 38500 to modulate for 1ms.

Is your PC looking for a binary byte or a string representation? If the latter, you'll want to use SEROUT 16, 16624, [dec GJH].

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows

Tom Walker
04-27-2006, 03:56 AM
Perhaps I am just not reading this right, but I don't understand what you think this code will do. As it currently stands, your stamp will send out a pulse of light modulated to 38.5 kHz for 2 seconds. After sending it out, the Stamp will wait for a short period of time to see if a detector connected to pin 6 senses any 38.5 kHz light (assuming that your detector is connected to pin 6 and it is a detector that triggers on light at that frequency). If the detector actually saw the light (pun intended) and it is designed to indicate that by transitioning the "correct" way (based on your PULSIN), then your PULSIN will load GJH with the amount of time, expressed in 2 us units, that pin 6 stayed in the "correct" state.

I am not sure that this is what you intend for the result to be. Better help with better info.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Truly Understand the Fundamentals and the Path will be so much easier...

leshea2
04-27-2006, 07:45 AM
Ok, I revised my code,

' {$STAMP BS2sx}
' {$PBASIC 2.5}

GJH VAR Byte

Main2:
PAUSE 500
FREQOUT 3, 100, 38500
PULSIN 6, 0, GJH
DEBUG DEC GJH
GOTO Main2:
END

and now a whole·bunch of numbers show up. My question is, does anyone know what is suppose to be on the debug screen? Is there a specific patten of numbers that have to be printed on the debug screen, that tells you that both the IR LED and the IR detector are working properly ?

Thanks for all of your help !

Nate
04-27-2006, 05:22 PM
I may be missing the point entirely, but seems that what you are tying to do:

"I'm trying to send to myself as a test, and you said PULSIN is used to read and measure the response from the IR led, so when I use "PULSIN 6, 1, GJH" in the code, I’m trying to receive what I just sent"

is analogous to standing in a dark room with your eyes closed, flicking the light switch on and then off, then opening your eyes to see the 'leftover' light.·

Unless there is a large latency in the IR detector (ie reports is seeing modulated IR long after the IR has stopped being received) this will never work.

The speed of light·is ~3x10^8m/s.· If the op instruction execution speed of a stamp is ~250us and there is no latency in the IR detector, your IR emitter and detector will need to be at least 75,000m apart for this to even have a chance of working.· Hope you're using a superbright IR emitter!

Nate

PS:·For IR emitter/detector test, use two Stamps, or a TV remote & a Stamp.

Post Edited (Nate) : 4/27/2006 10:26:33 AM GMT

Bruce Bates
04-27-2006, 05:45 PM
Nate -

My sentiments exactly when I first read of someone doing this, some time back. However, I've been around here for a while, and suspected that Parallax might have a tricky circuit floating around which might permit such a seemingly impossible methodology. Indeed they did!

What happens if you add a decent sized capacitor to the I/R emitter·control lead? Oops http://forums.parallax.com/images/smilies/smile.gif

By using just such a "charge source" for the I/R emitter, the latency which you correctly mention, is created, and it's just long enough to get to an immediately succeeding Pulsin command and have it execute properly. Indeed the power was off, and the lights stayed on!

My apologies if I described it slightly incorrectly, as I'm a programmer type, and not a circuitry type, but I'm sure you get the idea. Sustained power is the key to it.

Simple but powerful circuit, and entirely appropriate for the type and caliber of robots usually seen around these forums. Now you can utter the same chuckle that I did, when I realized what was afoot!

Regards,

Bruce Bates

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->

Post Edited (Bruce Bates) : 4/27/2006 10:54:44 AM GMT

Tom Walker
04-27-2006, 10:04 PM
Bruce,
If I am reading you correctly, then wouldn't the cap on the IR emitter just provide "DC-like" (or at best, pulses with a DC bias) power to the emitter for a short while after the FREQOUT completes? If the detector is indeed looking for ONLY 38.5 kHz modulated light, then it probably would not ever see what it is looking for, because the capacitor would "mush" (integrate) the signal going to the emitter. If the detector is just a generic IR detector, then ANY IR (sun, remote control, etc...) would trigger it and the FREQOUT becomes irrelevant.

I recall, however, that the "tuned" can-type detectors DO hold their output in the "detected state" for a slightly longer time than the appropriately modulated IR is detected, which would allow this type of code to DEBUG one of two outputs...detected or not.

...or I could be on the wrong track....

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Truly Understand the Fundamentals and the Path will be so much easier...

Bruce Bates
04-27-2006, 11:26 PM
Tom -

Perhaps this (attached) sensor can't be used in this application, but this documentation is where I learned about the basic technique, for better or worse. BTW - You take your LIFE in your hands when you ask a software guy like me ANYTHING significant about circuitry or HARDWARE! :-)

Regards,

Bruce Bates



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->

Nate
04-27-2006, 11:31 PM
All points above valid.·· But.....

My understanding was that the poster wanted to send and recieve a multi-bit signal with one BS.· I do not·believe this could be done without additional memory devices or a long distance between the sender and receiver (or a multi-dimensional phase converter).


Nate

Tom Walker
04-28-2006, 12:33 AM
leshea2,
How about it? What is it you really want to do? Maybe more info on the desired result will help us to help you...

and Beau,

· I am also a "programmer with a screwdriver" (the most dangerous thing you may ever run into<g>).· So back at ya'





▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Truly Understand the Fundamentals and the Path will be so much easier...

leshea2
04-28-2006, 02:19 AM
Right now I'm just trying to make sure my IR LED is emitting a 38.5 signal and my IR detector is receiving the emitted signal. So I've connected the IR led to pin three and connected the IR detector to pin six. I'm using freqout to send the 38.5 signal to the led for emission and pulsin to receive the 38.5 signal.

' {$STAMP BS2sx}
' {$PBASIC 2.5}

GJH VAR Byte

Main2:
PAUSE 500
FREQOUT 3, 100, 38500
PULSIN 6, 0, GJH
DEBUG DEC GJH
GOTO Main2:
END

The debug screen shows a lot of numbers, (1000, 00001, 30087, and so on), even if the emitter is not connected. So is there a way to make sure that the detector is actually receiving the emitted signal, like a specific repeating pattern of numbers ?

Thanks !

allanlane5
04-28-2006, 02:34 AM
Hmm. I suspect you need to tie the detector's signal pin high, through a 10 Kohm resistor. As I recall, it 'drives' low when it sees a signal, and 'floats' high when it doesn't see a signal.

If it was really seeing the signal, then the pulse-width would only vary by a few counts.

SSteve
04-28-2006, 02:47 AM
leshea:

Download the StampWorks manual and check out experiment #20. If you're using the same type of IR Detector that comes with the StampWorks kit, I don't think you really want to use PULSIN to read the status. You simply want to check the status of the pin the detector is connected to. If it's low, IR was detected. If it's high, IR wasn't detected. So your code would be more like this:

detected VAR BIT

Main2:
PAUSE 500
FREQOUT 3, 100, 38500
detected = ~IN3 ' Detector is active-low. (Change IN3 to your IR Detector's pin.)
IF detected then
DEBUG "IR Detected", CR
ELSE
DEBUG "No IR detected", CR
ENDIF
GOTO Main2:

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows

leshea2
04-28-2006, 02:59 AM
When you say (I need to tie the detector's signal pin high, through a 10 Kohm resistor), do you mean change PULSIN 6, 0, GJH to PULSIN 6, 1, GJH, because I already use a resistor (220 is what my IR detector requires). Also, (it 'drives' low when it sees a signal, and 'floats' high when it doesn't see a signal), does that mean that the pulse-width, or numbers on the debug screen should be something like 010101, or 001000100001, or what ?

allanlane5
04-28-2006, 03:09 AM
"tie the detector's signal pin high, through a 10 Kohm resistor", means to install a 10 Kohm resistor between the signal pin and +5 volts (aka Vdd). That means it's a "hardware Modification", not a "software modification" like a code change. I assume the 220 ohm resistor you have is tied between the signal pin and the BS2 pin.

Now, I don't know what the numbers you're seeing SHOULD be. That depends on the placement of the IR_LED and the IR_Decoder. However, they shouldn't vary that much. Meaning, IF you got 600 one time, the next time shouldn't be more than 610, or less than 580. If it was all working properly, that is.

leshea2
04-28-2006, 03:33 AM
SSteve:

The code works, but why does the debug screen say IR Detected, even when I disconnect the IR Emitting LED ? If there is no 38.5 signal being emitted, what is the IR Detector, detecting ?

SSteve
04-28-2006, 04:28 AM
You changed "detected = ~IN3" to "detected = ~IN6", right? When I wrote the example code I didn't remember that you had the detector connected to pin 6.

Which IR detector are you using? The one I've used (the one that comes with various Parallax kits) doesn't require any resistors when connecting it to a Stamp. You said that your detector drives low when it detects and floats otherwise. Do you have it wired the way Allan suggested? If so, then a 0 on pin 6 means that it is driving the pin low which is supposed to mean that it has detected IR.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows

leshea2
04-28-2006, 06:46 AM
Ok, now I'm only using your code and no resistor, and the debug screen still says IR Detected when the emitter isn't connected, but only every so often. Is that normal ?

Thanks !

SSteve
04-28-2006, 06:55 AM
I think we need more info about which IR detector you're using.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows

leshea2
04-28-2006, 10:42 AM
What I'm using is a Panasonic 38kHz IR detectors, as used in our Sumovore kits.
It says it's also a bipolar integrated circuit with a photo detection function.

SSteve
04-28-2006, 11:09 AM
Without a manufacturer/model number I can't be sure, but I'm guessing it's about the same as the one in the StampWorks kit. If so, you don't need a resistor. The three leads connect to Vdd, Vss, and an I/O pin (pin 6 in your case). Do you have it wired up like in experiment #20 in the StampWorks manual?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows

leshea2
04-29-2006, 12:33 AM
Yes, I do have it wired up like in experiment #20 in the StampWorks manual, and the manufacturer info is right here, http://downloads.solarbotics.com/PDF/PNA4602_datasheet.pdf.

Thanks !

SSteve
04-29-2006, 12:37 AM
That URL doesn't seem to be working. I just get a timeout when I try.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows

leshea2
04-29-2006, 12:51 AM
Try this.
http://lib.store.yahoo.net/lib/e-clec-tech/38khz.pdf

SSteve
04-29-2006, 01:09 AM
Ok, so it's the same as the Parallax detector. Looking at the pin numbers on the datasheet you should have the detector's pin 1 connected to your stamp's pin 6, the connector's pin 2 connected to ground and the detector's pin 3 connected to +5V. If you are reading a 0 at pin 6 at that point it means the detector is seeing IR. If you aren't transmitting IR and you're reading a 0 at pin 6 it means something is broken or not wired correctly.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows

SSteve
05-15-2006, 08:52 AM
Hey, leshea. I just noticed something. You are using the BS2SX. You should be using 15400 for the frequency. (On the BS2SX, the frequency units are 2.5Hz. 15400 * 2.5 = 38500.)

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows