Go Down

Topic: Controlling Lego Powerfunctions IR with Arduino sketch (Read 7045 times) previous topic - next topic

Martend

Hello tinkering people,

I'm trying to create a robotics 4WD platform with my Arduino Uno & Lego Power Functions.
To help me understand what I'm doing, I did some basic projects about sending and receiving data with IR.
In my research about this, I did stumble on a Lego Power Functions Library to use with the Arduino.
Since the library is not updated for some time, it was not working with the new 1.0 interface.
With some help of this forum I managed to get it working. (rename a file to Arduino.h was the solution.)

So after that fix, I setup my Arduino with a IR-LED and made a sketch. After some trial and error I produced
this code:

Code: [Select]

//include the library files we need
#include <legopowerfunctions.h>

//set up the IR Port for the Arduino
LEGOPowerFunctions lego(5);

//set up the program
void setup()
{
  //nothing to do here yet
}

void loop()
{

  lego.ComboMode(PWM_FWD2, PWM_FWD4, CH4); //Forward 4WD
  delay(5000);
 
  lego.ComboMode(PWM_FWD1, PWM_FWD1, CH4); //Left Backward
  delay(5000);
 
  lego.ComboMode(PWM_FWD2, PWM_FWD2, CH4); //Left Forward
  delay(5000);
 
  lego.ComboMode(PWM_FWD4, PWM_FWD4, CH4); //Right Forward
  delay(5000);
 
  lego.ComboMode(PWM_FWD3, PWM_FWD3, CH4); // Right Backward Not Working
  delay(5000);
}



I managed to get everything working, except the Right Wheels Backward part.
For a reason unknow to me, that line of code does nothing. I tried different channels,
different sequence in forward and backward. When I grab the original remote controller,
everything works like it should.

Since I could find nothing in the sketch or wiring, I did take a look at the library again.
I asume the problem lies somewhere in that area, but my knowledge to debug the library are to limited.
Maybe someone here can take a look at it and point me in the right direction. I also attached the used library.
Thanks in advance!

M



LEGOPowerFunctions.tar.gz

Go Up