Send and receive data through infrared (IR) between 2 mBots


#1

I would like to know how to comunicate two mBots with the infrared sensors of the Board. The maximum I have achieved is to detect in the mBot a button pulse off the remote control. What I would really like to do is to send ints from the first mBot to the second, but it looks like the mBot infrared code is only thinked for detecting the remote control buttons pulses. If I could just send from the first mBot the same pulse that sends the remote control when you press a button to the second mBot, then I could do a switch case and convert the received button pulse (button 0 for instance) to a number (int received = 0).

Instead of doing so, it would be better to directly send and receive ints or even strings. But at this point any way to comunicate the two mBots with the infrared would be fine to me.

This is the code i have for detecting the button pulse of the remote control in the mBot:

include Wire.h
include SoftwareSerial.h
include MeMCore.h

MeIR ir;
MeBuzzer buzzer;

void setup()
{

ir.begin();

}

void loop(){

if(ir.keyPressed(22)) // receive button 0 pulse
buzzer.tone(460,200); // make a beep
}

ÂżDoes someone know how it will be the code for sending and receiving data between the two mBots? (even if its only the pulses for the button numbers from 0 to 9)

Any help will be apreciated


#2

Solved!

How to comunicate two mBots via infrared:

1: Download the Arduino-IRremote library: https://github.com/z3t0/Arduino-IRremote

2: Go to C/programs/Arduino/libraries and erase the default IR library, since its not the same that this one and it causes incompatibilities. Then copy the Arduino-IRremote library folder to add it to the Arduino libraries.

3: Open the makeblock library and in the file MeMCore.h comment the line 68 (//#include “MeIR.h”). This is also to avoid incompatibilities.

Finally you are able to upload to your mBot the sketches to send and receive data via infrarred. This are the codes to send and receive data:

Send data via IR:

#include <IRremote.h>

IRsend irsend;

int robot_ori=91;
int n_coordenadas=4;
int x[10], y[10];

void setup()
{
x[1]=200; y[1]=217;
x[2]=199; y[2]=213;
x[3]=210; y[3]=179;
x[4]=212; y[4]=140;
}

void loop()
{

irsend.sendSony(robot_ori, 16); // data to send, nÂș of bits to send
delay(40); // for int type is 16 bits
irsend.sendSony(n_coordenadas, 16);
delay(40);

for (int i = 1; i <= n_coordenadas; i++)
{
irsend.sendSony(x[i], 16);
delay(40);
irsend.sendSony(y[i], 16);
delay(40);
}

delay(5000); //5 second delay between each signal burst

}
Receive data via IR:

#include <IRremote.h>

int RECV_PIN = 2;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}

void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, DEC); // DEC decimal, HEX hexadecimal, etc
irrecv.resume(); // Receive the next value
}
}


#3