Controlling LEGO power functions with IR-commands, can it be done ?

bonaur

New Member
LEGOs power functions has an IR transmitter and reciever.
By using the standard transmitter you can start/stop and reverse 2 motors per. channel on 4 channel in total 8 motors.
But only 2 moters at one time (or you will need 4 remotes)

But by looking in the 'LEGO power function RC' document. You will notice a lot of cool stuff that is normally not available like:
-PWM control in 7 steps forward/reverse
-Stop-brake
-Stop-float
- Controlling all motors 'at once'

To what I can read the protocol uses a 38 kHz modulated signal.
http://www.philohome.com/pf/LEGO_Power_Functions_RC_v110.pdf

-Has anyone tried this before ?
-Can it even be done with the current BASIC commands ?
- If so I would REALLY like to see some code snippes for doing it.

It could be AWSOME to have an PIXACE unit wireless controlling your LEGO:
Excavator, Bulldozer, crane, train, traffic light
Make your own controller, push-butten = Parkingbrake, running batch commands....just let your imagination take off.....

Of course you will not be able to do it with accurate precision like the NXT (Mindstorms)
And there is no feed back from sensors (unless you mount your PICAXE on top of your LEGO-creation). But there are kazillions of other fun projects waiting.

If it's an software issue in 'PICAXE programming editor' i would like to request that the LEGO RC protocol will be supported somehow.
My argument is that LEGO is much like PICAXE, originally made for younger people (I think) but a lot of us 'older' people takes great pleasure in building stuff because it's fun and easy.
And by doing this, it will open up to a whole now world of 'programmable LEGO'
Fast prototyping as you most likely will have, motors, shafts, gears, cams, wheels, etc. at hand.
Robots, cars, trucks, sorting devices.........

The PICAXE-LEGO control will also plunge right in the middle of the big hole between the standard basic ON/OFF control with the LEGO remote. And the very expensive LEGO Mindstorms NXT.
By using PIXAXE you can 'program' your LEGO Power functions.
AWSOME !!!!

pls. comment.

Best regards, Bo Andersen.
 

hippy

Ex-Staff (retired)
It might be possible but would most likely require an X2 operating at 64MHz.

The IR pulse is rather short at around 155us ( six 38 kHz cycles ) and the minimum interval between pulses is about 260us. Trying to programmatically generate a pulse train with that timing would be a challenge using bit-banged Basic commands. I don't think the question can be answered definitively without someone trying to do it. As it's a 16-bit data packet plus start and header I suspect it can but cannot promise that.

One alternative is to build a hardware shift register or some memory buffer, fill that at leisure and then churn the bit stream out at an appropriate rate.

An easier alternative may be for a PICAXE to interface to a Power Functions IR Remote Control to stimulate button pushes and so on.
 

hippy

Ex-Staff (retired)
I don't think the question can be answered definitively without someone trying to do it. As it's a 16-bit data packet plus start and header I suspect it can but cannot promise that.
Now I think I can. Using a 20X2 at 64MHz, HSEROUT to generate the IR pulses on Output Pin C.0, using PAUSEUS to set the inter-burst gap for 0/1 it seems to come in faster than the Lego protocol requires.

Code:
#Picaxe 20x2
SetFreq M64
HserSetup B31250_64, %010
Do
  w0 = %0011001100111100

  HSerOut 0,(%01010101)
  If bit15 = 1 Then
    PauseUs 1
  Else
    PauseUs 1
  End If

  [i]repeat for bit14 to bit0[/i]

  Pause 1000
Loop
The baud rate and PAUSEUS values need tweaking plus start and stop bits adding but that's the principle, and it seems it would also work on an M2 at 32MHz.

Oops - Just noticed that only generates 5 IR pulses not 6. Would need to change that to be a modulator of required length and then mix with 38kHz PWM in the usual manner. Might be able to use PULSOUT rather than HSEROUT.
 
Last edited:
Top