Infrared communication

adub

New Member
I'd like to send and receive using 08M's with an ir module.

Unfortunately Infrain2 ties up the whole chip so nothing else gets done.

What I'd like to do is send an ir pulse out from one 08M and have the other one pick it up on an interrupt and then use infrain2 to recieve data.

The problem is how do I use one ir module to two pins. One for the setint and another one for the infrain2?

Been done?

Arvin
 

hippy

Technical Support
Staff member
The signal from the TSOP IR Receiver goes low when IR is present, so you could simply set the PICAXE up to interrupt when the pin used for INFRAIN2 goes low, enter the interrupt, then execute an INFRAIN2. Only the one pin needed.

The problem is that if an IR pulse is seen which isn't a Sony IR Code, the program will still hang in the interrupt. That can be overcome by bit-banging the IR code in rather than using IFRAIN/2, because that won't hang if no code appears.

One way to get round the waiting problem is to use an 08M dedicated to reading IR which then signals your main PICAXE that a code has appeared and passes the information over, using Serial or some other mechanism.

Have a look at http://www.hippy.freeserve.co.uk/picaxeir.htm
 

adub

New Member
Thanks hippy.

I tried sending a pulsout to infraout to use with the senint on the receiver but it didn't work.

It does seem to hang on the infrain2 when I try to use infrain2 after I jump to the reading code.

I've included the code. See if you can tell me why.
<code><pre><font size=2>
' lights leds on pins 1,2,&amp;4 giving
' digital outputs of 0,1,2,3,4,5,6,7
Main:
' Low pin3
SetInt %00000000, %00001000

LOOP:
for b0 = 1 to 100
b3 = pin3
b3 = b3 * 16 ' just something to do
' wait for a signal on interrupt pin3 while still doing something
next b0
goto loop

Interrupt:
infrain2 ' waits for signal
if infra = 0 then zero
if infra = 1 then one
if infra = 2 then two
if infra = 3 then three
if infra = 4 then four
if infra = 5 then five
if infra = 6 then six
if infra = 7 then seven
myBACK:
goto Main

zero:
low 1 : low 2 : low 4
goto myBACK

one:
high 1 : low 2 : low 4
goto myBACK

two:
low 1 : high 2 : low 4
goto myBACK

three:
high 1 : high 2 : low 4
goto myBACK

four:
low 1 : low 2 : high 4
goto myBACK

five:
high 1 : low 2 : high 4
goto myBACK

six:
low 1 : high 2 : high 4
goto myBACK

seven:
high 1 : high 2 : high 4
goto myBACK
</font></pre></code>
 

adub

New Member
I probably should add that we will be using about a dozen individual tiny robots that will be doing their on little waltz waiting for an event to occur to signal them to change their behavior for a set time then back to their norman little waltz again.

Two 08M's per little bit of robot makes for a lot of 08M's. We're talking tiny. About the size of a matchbook.

Honest. Not my idea, I'm just the implimentor.

Arvin
 

adub

New Member
The ir module I'm using is one from Radio Shack here in the USA not the one from rev-ed.

Arvin
 

adub

New Member
The rx code I posted does work with a sony remote control. Just off by one. Pressing 1 gives zero while pressing 8 gives 7.

That agrees with the infrain docs, so I must have something wrong with the tx code.

I'll let you know how that works out.

Arvin
 
G

Guest

Guest
Success.

I had some old code in the tx chip and I replace it with what I thought was there and now it transmits 0 through 7 and receives the same!

I have 3 leds on the tx and 3 on the rx.

They agree on what's being sent and received so I guess all is good.

Here's the tx code. should anyone besides me want to give this a try.

Arvin

ps. hippy, I had already visited your site many times and am using your circuit as you can see below. Thanks.
<code><pre><font size=2>
' Use pins to get pin0 through pin4
' _______
' | o |
' +5V =|1 8|= 0V
' Serial in =|2 7|= out0/Ser out/Infraout - pin0
' pin4 - in4/out4/ADC4 =|3 08M 6|= in1/out1/ADC1 - pin1
' pin3 - in3/Infrain =|4 5|= in2/out2/ADC2/pwm - pin2
' |_______|

'This is the basic IR Transmitter circuit which
'is the easiest to construct although it does
'have limited transmission range ... ~10 ft.
'
'
'+V --------.
' |
' .-------^-------.
' | PICAXE-08M | IR LED
' | | ____
' | 0 &gt;----|____|-----.
' | | 220R _|_ --&gt;
' | | _\./_ --&gt;
' `-------.-------' | --&gt;
' | |
'0V --------^-----------------------'

b0 = 0

Main:
low 0
pause 1000

b0 = b0 + 1
if b0 &lt; 8 then skip ' send #'s 0 through 7
b0 = 0
SKIP:
' Set appropriate Led's on
if b0 = 0 then zero
if b0 = 1 then one
if b0 = 2 then two
if b0 = 3 then three
if b0 = 4 then four
if b0 = 5 then five
if b0 = 6 then six
if b0 = 7 then seven

SEND: ' send it out pin0
pulsout 0, 150 : pause 250
for b1 = 1 to 10
infraout 1, b0
pause 45
next b1
goto Main

zero:
low 1 : low 2 : low 4
goto send

one:
high 1 : low 2 : low 4
goto send

two:
low 1: high 2 : low 4
goto send

three:
high 1 : high 2 : low 4
goto send

four:
low 1 : low 2 : high 4
goto send

five:
high 1 : low 2 : high 4
goto send

six:
low 1 : high 2 : high 4
goto send

seven:
high 1 : high 2 : high 4
goto send
</font></pre></code>
 

hippy

Technical Support
Staff member
Using PULSOUT to kick an IR pulse won't work; the IR needs to be modulated for the receiver to see it. You could try sending two consecutive INFRAOUT's; the first to trigger the interrupt, the second to feed the INFRAIN2.

I'd suggest going back to building the program up iteratively; check you can send from one PICAXE to another, then check you can trigger an interrupt, then trigger an interrupt and a read an IR command, then add the code to handle the command.

If using INFRAIN/2 there is always a chance that the program will hang up as there's no guarantee that the complete IR sequence will be seen; a flash of sunlight or IR from another source could corrupt the data stream and a turning robot may lose the signal. To avoid that, there's no choice but to use another PICAXE ( or other hardware ) or use bit-banging.
 

BeanieBots

Moderator
If you have a spare input, you could connect the Rx signal to both inputs but have one of the inputs see the signal delayed. This can be done using a couple of buffered RCs. The &quot;real time&quot; signal is then used to trigger the interrupt. The interrupt routine then looks at the delayed signal. This method gives the interrupt time to respond and be ready with the command waiting when the delayed signal arrives. I've never actually tried it with IR signal but it works for serin.
 

adub

New Member
Thanks for the RC thought. I however am a little squimish about making my own since I'm learning electronics using the meltdown method.

I program adequately and can usually impliment a schematic but making my own is still too much for me..

I think I will try doing some bitbanging.

The funny part is that the code I posted was working until I took out the pulsout statement and now nothing works.

I'm currently charging the batteries. Read ok but only marginally.

Thanks for the input
Arvin
 

adub

New Member
And why didn't any one tell me about branch?

branch b13,zero,one,two,three,four,five,six,seven)

Would have been much better than all those if-then statements!

The bit-banged code does work. Except zero is considered to be an invalid input so the leds never get all turned off.

Not a problem since this it just test code for a larger problem that hasn't even been properly defined as yet.

Thanks all for the help.
Arvin
 
Top