IR transmission with X series

Hi guys!
i want to make my picaxe send out an IR signal that can be received by another picaxe somewhere else. At first i was pretty convinced on using the M series to do this, as they have got "infraout" and that makes everything simpler. But my problem with those is that i'll then find it hard to connect them to these I2C EEPROMs (http://www.rev-ed.co.uk/images/full/8pin.jpg).

So i just thought to stick to an X series picaxe and to find a way of transmitting an IR signal. I've found out that i need a pwm pin to modulate the current and attach it, along with an output pin, to an AND gate, and then attach the IR led to its end.

What do you think about it? Would it really work? and... Could you give me some tips on how to code the IR led so that it sends specific bits? (example: i want to send "10001". How do i do that? do i just have to use high outputpin/low outputpin with pauses in between?)

:)
 

hippy

Ex-Staff (retired)
You might not even need the AND gate. Connect the cathode end of the IR LED + R to the PWM out, leave that running at 38kHz then connect the other end to a digital output, change the level of that to get the signal out you want.

A Forum Search should tun up more discussion on how to do this and transmit the required data. Yes, it's just highs and lows and pauses, although PULSOUT on a dummy pin is best used to provide finer control over timing than with PAUSE.
 

MFB

Senior Member
It is also possible to connect the IR emitter diode between a PWM output pin and a serial output pin, via a series resistor of a few hundred Ohms. This will effectively modulate the 38KHz carrier with the standard serial output. An IR receiver can then be used to directly drive the serial input of a second PICAXE.

The type of 38KHz receiver used will determin the maximum data rate, because their integral automatic gain control circuitry can make them pattern sensitive. However, it’s normally possible to achieve reliable operation at 1200 bps using standard PICAXE serial I/O commands.
 

hippy

Ex-Staff (retired)
The advantage of using a serial pin is that the PICAXE does all the timing for you and at the other end you probably just need an IR reciever chip and use SERIN.

It's not INFRAIN/INFRAOUT compatible but it's an easy option - I'd forgotten all about using serial :)

Besides, the same pin will be used whchever way you do it so you can easily experiment. This would be a quick way to get up and running.
 
alright i got it thanks. :) only one thing left for me to understand: how do i set a pwm pin at a certain frequency (the coding part i mean).

ps:today i'm getting my IR led so i can experiment a bit with it :)

edit: i forgot to mention the master-slave method: that is connecting a x-series picaxe to a m-series picaxe and to make the m-series one do the magic with "infraout" and "infrain". Maybe this would be more costly, but i'm not really sure (you know, maybe it's more precise or something like that). What do you think about this method?
 
Last edited:

BCJKiwi

Senior Member
PWM

Programming Editor / PICAXE / Wizards / Pwmout.

Make sure the right chip and clockspeed are selected. A #PICAXE 28X1 as first line of the code (should be mandatory IMHO) will take care of the chip type.

Tweak the default Hz to suit. Not sure what duty cycle the gurus would suggest - maybe it doesn't matter!

Read up Manual2 page 117. Also check out pwmduty. There is also hpwm... but not sure that would be any advantage in this instance.
 
thank you :) i too have no idea about the duty cycle.

one other thing; do you know what happens if the IR signal is only received partially? is there a way i can understand that?
(in other words, can i understand, by analyzing the data received, if the IR has missed not by much the receiver?)
 

Dippy

Moderator
On non X1/X2 parts the Serin will wait until it gets the data you have specified. By that I mean the number of bytes. Have a look at the Serin command in the Basic Manual. I'm sure someone can explain better than my attempts.
Bottom line: it sticks at the Serin command until it gets the number of bytes. Any extra bytes sent will be ignored.

X1/X2 parts have a 'timeout' so it can escape from getting stuck. However, this should be used with care as you don't necessarily want the receiver to pop out just before your transmitter transmits. Timing and getting things right can require a bit of planning.

I assume you are using the IR receiver module like the Rev-Ed one (which 'converts' the modulated 38kHz to digital?). I was wondering if you could connect the output of it to 2 PICAXE pins; one for an interrupt and another for the Serin? So that you could transmit a dummy byte to 'prepare' the receiving PICAXE to do a Serin. Just a thought, never tried it.

But getting corrupted/missing data can always be a problem. Sending your data bytes several times may help. The receiving end could compare consecutive bytes to check?

HSerin gives a whole lot more options but maybe you should start simple?

PS. I would hae thought 50% duty cycle would be a good starting point. This may depend a bit on how much oomph you wish to chuck out of the IR LED. Maybe the IR receiver Data Sheet shows some kind of info on Duty Cycle received vs sensitivity? Dunno, never looked.
 
Last edited:

eclectic

Moderator
CaptainT.
It should be possible to use 2 x 08M's as “Sender-slave” and “Receiver-slave”

Manual 2 page 81 onwards provides information.
Only 127 “send” codes are possible, but, there are ways around that.

I tried this using an 08M tx (IR LED and resistor, on pin 0)
and a 28X1/TSOP38 on pin 0 for rx.

The code is clumsy and incompletely commented, but, it works.

Code:
;Transmitter
#picaxe 08m

symbol high7    = b2
symbol lower6   = b1
symbol extrabit = b3
symbol counter  = b10
main:
counter = counter + 1
for b0 = 0 to 255

if b0 <= 127 then 
high7 = 0 :lower6 = b0 :extrabit = 0
endif

if b0 > 127 then 
high7 = 127 :lower6 = b0 - 127 :extrabit = 0
endif

if b0 = 255 then 
high7 = 127:lower6 =  127 : extrabit = 1
endif

infraout 1, high7
infraout 1, lower6
infraout 1, extrabit

pause 200
sertxd (#b0,"     ",#high7,"  ", " ",#lower6,"  ",#extrabit,"  ",#counter, cr,lf)
next

goto main
Code:
;Receiver

#picaxe 28x1
symbol high7    = b0
symbol lower6   = b1
symbol extrabit = b2
symbol total    = b10

main:
irin 0,high7
irin 0,lower6
irin 0,extrabit

total = high7 + lower6 + extrabit
sertxd(#high7," ",#lower6,"  ",#extrabit,cr,lf)
sertxd (#total,cr,lf)

goto main
It is possible to add many refinements, including:

timeout on IR input
Interrupt for reception of data

e (and oe)
 
hey thanks for the code that will come in handy.
actually i got another problem, i only thought of this now...

let's say im using the slave - master method with a 28x1 and a 08m.

alright. i'll tell you what i have to do that will make everything easier. i'm trying to make a set of laser tag "taggers". each one has to do the following: "shoot" IR signals and receive them.

but if the master microcontroller will be on "serin" then how can it follow its main loop too? i guess that will be another problem with the master-slave configuration (and maybe also with non master-slave, as i'll still be needing the infrain or the serin...)

:(

i could use a timeout on that...but what if the "bullet" or IR signal comes while i'm doing something else than serin/pulsin/infrain?
 

eclectic

Moderator
Captain.

First, get everything connected and working with a simple program.
Make an LED flash.

There are ways to use interrupt, but, simple things first.

e
 

Dippy

Moderator
Sounds painful!
But it saves getting a rear light for your bike I guess.

Yes, the circuit and also the project layout. I, for one, am getting muddled by what the Master and Slave are doing.
 
Last edited:

MFB

Senior Member
Regarding the good advice to start simple, link the output of the transmitter to the input of the receiver using wire at first, to check your PICAXE code, before replacing it with the IR link. You may have to change the direction of the transmitting diode to maintain the same signal polarity with the IR link as you had with the wire.
 

hippy

Ex-Staff (retired)
if the master microcontroller will be on "serin" then how can it follow its main loop too? i guess that will be another problem with the master-slave configuration (and maybe also with non master-slave, as i'll still be needing the infrain or the serin...)
If this is a master-slave where the slave is looking for IR the master should only enter its SERIN when it's checked and been told by the salve that it has something to send - Much like you would keep doing whatever you're doing, looking to see if anything is in your in-tray, if not carry on. Otherwise stop, read it, act, then carry on again.

If you have multiple things to do, none of which are allowed to stop the master loop, you'll need multiple slaves. Just like having a secretary who can stand next to a fax machine waiting for one to arrive, another sat at the front desk waiting for a visitor etc.
 

hippy

Ex-Staff (retired)
It does ... the trick is to not go into SERIN until there is something to receive. You poll the slave to see if it has anything to send, if not carry on. If it has get ready to do the SERIN, tell the slave to send it's data and enter the SERIN. The SERIN will complete with minimal delay and the master loop can continue.
 
ok guys. i played a bit with LEDs and with the serin and serout commands and everything works properly. Now i just need to buy some extra components to go on with my original project, like some IC slaves and infrared receivers/demodulators.

Before i buy them i wanted a little advice from you, since i don't want to waste my money :) (i haven't got too much :) )

(1)my project needs to have multiple IR receivers/demodulators. looks like (also stated previously) that i need an IC slave for each one of them, right?
(2)i mean, if i use one slave then i can only do an INFRAIN on one port, but still i could connect all 3 IR receivers to the same input port. But what if two signals are received at the same time?
(3)i could also use INFRAIN on my X1 with timeout options, so that it rapidly checks 3 different input ports ( one IR receiver connected to every port ). But here comes another problem. What if while i'm checking the INFRAIN on one port, another one receives the signal and i miss it?

so basically i stated three different ways to do what i'm trying to do, i'll summarise them:
(1) one IC slave for every IR receiver. No problems with that (i think).

(2) 3 IR receivers connected to the same input (only one slave). Problems: what if 2 receivers get a signal simultaneously?

(3) using INFRAIN on x1 with timeout. receivers connected to different input pins. check first input, timeout shortly after, check second input, timeout shortly after, check 3rd, loop. Problems: what if a receiver gets a signal while i'm INFRAINing another input pin?

what do you guys suggest? of course the first option looks nicer and all but it's also more expensive.
 

Dippy

Moderator
Why do you want to connect >1 IR demodulators onto a single pin? I've probably misunderstood. This is where a drawing of your complete proposed system would be VERY useful along with a brief explanation. Most of us have no Serin timeout on our Crystal Balls.

"3 IR receivers connected to the same input (only one slave). Problems: what if 2 receivers get a signal simultaneously?"
- who knows. They may 'work together' or slight tolerances in manufacture may upset things. Why would you want to do this?

"Problems: what if a receiver gets a signal while i'm INFRAINing another input pin?"
- the Serin/Infrain can only deal with one pin at a time and any other signal on another pin would be ignored. Not sure about hardware serial in on PICAXE I must admit.
HOWEVER, if 2 different infra-red signals impinge on the I/R demod then it will mess up your data. That sort of thing can be avoided with extra effort. It's like a data collision on a network.

But you STILL have to be careful with timeouts. You've got to ensure that transmissions are fairly regular OR that your Serin/timeout is the dominant part of your code. i.e. it's pointless have a 100mS timeout on a Serin call if your code is doing something else for 10 seconds as the chance of you transmitting at the 'right time' is small (an exaggerated example but hopefully you get my drift).

Coding and timing needs good planning and a large sheet of paper and a pencil.

I think you may have to set yourself a budget of £20 and buy a few things to experiment with.
 

Technical

Technical Support
Staff member
(2) 3 IR receivers connected to the same input (only one slave). Problems: what if 2 receivers get a signal simultaneously?
This has been discussed on the forum before and, although the theory says its not really a good idea, in practice it does actually work quite well e.g. We've used 3 sensors at 120 degrees to give '360 coverage' for a moving robot from fixed IR transmitter - no matter which way the robot points it still gets a good signal. The devices are open collector and so cannot be physically harmed by connecting in parallel, at worse you will get a corrupt signal.
 
i see... problem with same-input-receivers is, as you say, i might get corrupt data. Point is i'm not dealing with a remote controlled robot but with a (maybe already mentioned before, don't remember :) ) a laser tag system, so getting corrupt data from another "shooter" and having the "target" not receive anything would be really frustrating :D. So i think i might go for the "1 slave for each IR" option, i think that's the best thing to do. Then, when a receiver slave receives something via infrared, it tells the master he has something to communicate, and the master SERINs the data. This way i won't lose any data coming from other IR receivers as slaves will keep the data and transfer it only when the master is idle.

Guess this is the best option :) I might get 3 08Ms and an X1 and combine them together. or maybe even 4 08Ms, one for transmitting. (i could in fact use 3. it's kind of rare that a signal comes in exactly when i tell one of the 0Ms to transmit, but as you may already have understood, i want this system to be as precise as possible :) )
 
hi it's me again :D i've at last made a list of all the parts i am gonna use:

picaxe08M £1.76 x4
picaxe18X £4.35 x1
IR sensor £0.49 x3
IR led £0.47 x1

but before i make a schematic of it i would like to ask you two questions.
it was previously mentioned that the picaxe18X (which will be the master) has to go only on SERIN when there is data (from a slave) to transmit.

How to tell if there's data to transmit?
what i thought about is using the same interface as i would use if i wanted to connected a bumper(or any simple button) to my picaxe, and using a MOSFET instead of the bumper. The mosfet will be powered by the slave. So it would work this way: slave receives data, powers up the mosfet. the master check if there is some data to get by checking the digital output the mosfet is connected to.

Is this a good method to do that or would you suggest something else? i also thought about connecting an output pin from a slave directly to a digital input on the master, maybe with some resistor. Which is better?

Transmitting data:
say i somehow managed to understand there is data to transfer and so i make the master go on SERIN. Since i am using 3 slaves, is there a way to use only one input pin for all of them, considering that only one slave is gonna transmit at a time (=no simultaneous transmission of the 3 slaves)?
what i thought of, is connecting all three serout cables (coming from the slaves) to the same input pin on the master and then place some diodes so that current does not go from the SERIN of a slave to the SERIN of another slave. What do you think about this one?

thank you again :)
 

hippy

Ex-Staff (retired)
Your idea for signalling for slaves to master is okay but can be greatly simplified. Signals can be diode mixed ( Or'd for active high, And'd for active low ) and for 08M's signalling can use a pulled-up signal line and active-low multi-drop without any diodes, although they're a good precaution to add anyway.

A common line though may not be the best solution as you then have to interrogate each to find who caused the signal and you can have problems when some slaves are not expecting to be interrogated ( eg, executing INFRAIN ). It should be possible to have just three lines which can be used to signal and transfer data from and to the slaves.

Multi-node systems are quite complicated and will take a fair bit of effort to get right, both in hardware and software. I'd say avoid multi-node systems whenever possible. It would be well worth prototyping multiple IR sensors on a single input line to see how it does perform before discounting that option.

Others have used PICAXE in laser tag systems so a forum and Google search should give further details and experiences.
 
i've just finished my brain storming activity on transmission between slaves and master. As you said the 3 lines way may be the best one. So basically each slave will be connected with only one wire to the master.

What happens is this:
1- slave sends signal to master
2- slave goes SEROUT
3- master goes SERIN on that particular pin where he received the signal
4- everything back to normal

i hope this operation will be fast enough so that the slave can get back to the receiving task! (my main concern I'd say)
 
how cool! i finally managed to set up an ir connection between two microcontroller units by using SERIN and SEROUT. Now that I achieved this i wanted to move to the next step. I would like to transmit data without SERIN and SEROUT? Why? Because, as i am trying to make a laser tag system, i want to simulate a "near miss" situation. That means that when the player has been missed, but not by much, its system must tell him so.

I know this is possible since other laser tag systems already do this, but i don't think i can achieve this using SERIN and SEROUT. So i basically want to do something without them.

TRANSMISSION: as far as transmission is concerned, i think i will be just using high Xs, pauses and low Xs. I think this might work...am i right?

RECEPTION: ok here come the problems. I don't really know how to do this. I was thinking about using interrupts to detect signals, but i don't really know how to combine them to get the valu sent by receiver into, say, a variable.

Could you give me some help? Thank you!

EDIT: forgot to add something:
on the other systems i was talking about the "near miss" feature is achieved when the IR receiver only receives part of the signal from the transmitter. I also don't think this could be also possible with the M series.
 
Last edited:

Dippy

Moderator
The detection is the problem isn't it.
What's your definition of a 'near miss'.
Is your target 'hit' a 'bulleye' and 'near miss' 6 inches away the bullseye or something?
The IR sensors you use are quite on-offy and wide angle, so not much cop at showing incident levels.
I guess some kind of sensor array?

I hope someone with plenty of spare time (retired? similar initerests? done it before?) can walk you through this one. I don't imagine the theory is too difficult. Making it for a fiver may be more tricky.

I really think some nice generalised schematic overview would help. It's a lot easier than trying to read dozens of praragraphs. Spend some time on your plan, so that others can comprehend it quickly.
Remember, YOU know what you want, WE have to read minds :)

Are you using genuine laser btw?
 
no no not genuine laser, that would be really dangerouse, just IR leds...don't really know why they call it laser tag.

Anyways, on the other system it works like this: If i signal from the other's player gun is received properly (properly= every bit received) then that's a hit. If the receiver only receives part of it (say 6 bits only, where instead this system should only be using 8bits per signal) then that's a near miss.

I just asked the guy that made a laser tag system and this is what he told me that they have some kind of verification bit (transmitted by the gun of a player) with which you can understand if signal has been transmitted properly.

Point is Dippy, that i don't really know what i want myself. I mean... i know i want something like this to happen but have no ideas at all on how to do it, that's why i asked. And anyways, this "software" approach to detecting a near miss (6 inches away from bull's eye would do, or even more..actually anything would do) is the only one i've found so far by searching on the net.

GENERALISED SCHEMATIC: (summarizes what i want to achieve)

-microcontroller has to do something when only part of the signal has been received.
-receiving IR data from transmitter without SERIN. 1s and 0s come out of the demodulator, how to interpret them?
 
Last edited:

Dippy

Moderator
Oh I see, so you're not really detecting off-target in reality, you are detecting (in effect) how long the 'blast' was hitting the target. An intermittent hit. I realise that with a solid angle of IR light from an LED this would have a similar effect to off target slightly on many occasions.

Incidentally , how well focussed are your LEDs? Or are they just 'out of the bag' medium beam spread things? You realise that IR can bounce all over the place?

With a wide cone of light and a wide angle receiver with a wide gain range you're going to get some wide 'near misses'. And the angle of sensitivity will be affected by ambient light.

Well, PlanB is required here I think. PICAXE using serial commands will get bunged up if it doesn't receive a full byte.
Or send a stream of bytes and the receiver uses interrupt plus timeout to receive. As in "Oh, here come some bytes... oh it's stopped, I'll timeout now and analyse; how many did I receive and who were they from?" Theoretically dead easy to convert to Basic if your PICAXE (and hardware) permits.
If you can't do timeout on serial-in then all I can think of (quickly) is using an interrupt on the receiver plus a bit of bit banging if the ID of the 'assassin' is important.
If it's just any old beam hitting any old target you just fire a duty cycle (pulse stream) and the receiver counts the number of blips received, maybe using an interrupt+count method or a tight loop.

As I've never seen the system in action this probably requires a lot more thought, so if you'd just finish off my PIC spectrum analyser for me I'll devote the time to your project :) Fair trade? (I'm just kidding by the way).
 
Last edited:
well yeah the ID of the shooter is important..ok thanks for the informations mate, i'll try to put them into action and see what comes out of it!

the LEDs will be well focused in order to use the maximum range and precision available.

SUMMARIZED:

method 1 : interrupt and timeouts
method 2 : interrupt and bit banging

again, thank you!
 

Dippy

Moderator
Remember, for ease of focussing get the flat front 'wide angle' IR LEDs and a good quality lens. Dig out your camera, stick some IR filter over lens and have a play.
Good luck.
 

Mycroft2152

Senior Member
Run a google search on Lasertag DIY and you will find some very good construction projects. These will answer many of your questions. There is even one project that uses a 14 pin PIC.

Myc
 

moxhamj

New Member
Maybe have a look at the current threat on picaxe to picaxe comms.

Suffice to say, sending data between picaxes is really really complicated!

If you want near miss detection, try sending lots of bytes using pulsout. The bytes could be a character, eg "U" which is 01010101 in binary. You could send 2 or 3 Us, and see how many bits match up. That can be a measure of how long the target was in sight for.
 
nice idea dracula. Maybe i could even do this with a standard picaxe-M using the ultra-simple infraout and infrain. I just send the signal, say, 3 times. If every the receivers receives it 3 times then it's a hit, else it's a miss! This wouldn't be bad too!

EDIT:big typo : If the receiver receives every one fo the 3 signals then it's a hit. :)
 
Last edited:

Dippy

Moderator
How are you going to store these 'bits' to process Captain?

If you miss the start byte and simply have a stream of 1s and 0s how are you going to synch up to identify the sender?
If you're doing it on the fly then you're back to bit banging as mentioned before.

I will slightly disagree about sending (asynchronous?) data being really really complicated. I'd only use one 'really' once you've got your brain in gear:). It's the setup and contingencies of data-read-failure that can be tricky.
Without the timeout it can be trickier. Now that X1 etc parts have timeout this has made life easier. I think Stamp has always had a timeout(?) and on PICs you can set interrupts to give you a timeout.

I assume Captain that you are fairly new to all this sort of stuff?

How about forgetting serial transmission and using duty pulse streams and lengths.
Each transmitter would have different PWM transmit frequency and duty.
The receiver reads a few pulsins to get duration and then does a count to get the total number of pulses. From this you can calculate duty and frequency and hence ID the sender.

If each transmission was (e.g.) 50 pulses long at F and Duty% and only 10 were detected than that would be a near miss.
Pulsin would measure the 'On' duration and identifiy the sender. Being aware that the IR receivers will have a 'tolerance' of course.
Well, it was just a thought to avoid serial issues....
 
yeah i just started playing with microcontrollers, or well...with electronics, some 2 months ago, that's why i'm asking so many questions.

About storing the bits i was just thinking that the transmitter would send his own signal made of, say, 8 bits. This could be sent, as dracula suggested above, 3 times, or instead of that i could also use parity bits, as this guy does:

How the Parity Bit works (Even Parity): As the 16-bit data packet is transmitted, the "1"s in the data packet are counted. If the total number of "1"s is Even, then a "0" is transmitted as the 17th bit. If the total number of "1"s is Odd, then a "1" is transmitted as the 17th bit. So, for Even Parity, the transmitter ensures that the data packet always contains an even number of "1"s. The receiver can then simply count all the "1"s in the incoming data packet including the parity (17th) bit. If the total number of "1"s is Even, then the received data is assumed to be good.
(http://www.lasertagparts.com/mtformat.htm)

so to store them i could maybe use the IRIN command from picaxe? I could keep on executing that command (with timeouts) on the slave receivers.

about using different frequencies...well, i could do that but you know, players are gonna be many (even 20vs20) i could get really messy to work at so many different frequencies.
 
Top