The page describes how to use IR Seekers with your i2c-compatible robot. For usage with LEGO Spike Prime, please refer back to this page.
QikEasy IR Seeker is natively an i2c device. With extra features over a general i2c device, we recommend using the QikEasy i2c Adapter for accessing QikEasy IR Seeker through i2c. The adapter provides these functionality:
The i2c Adapter board provides dupont 4-pin sockets on both ends of the board, the diagram below shows the pinout of these sockets.
Caution:
The IR Seeker hardware configuration is very much similar to how you would set it up with QikEasy Expander for Spike Prime, a QikEasy IR Seeker stack consists of a series of boards chained together.
The board connected to your i2c robot is the QikEasy i2c Adapter. After that, the first board (which should be an IR Seeker board) connected to the i2c Adapter board is called the First IR Seeker. If you have another IR Seeker on the stack, this last IR Seeker connected to your First IR Seeker is called the Second IR Seeker. The names are based on the order of the boards in the chain. The connections could be made either through stacking or through the 16-pin cable depending your hardware configuration.
It is important to get familiar with this naming convention as the i2c address of the First and Second IR Seekers will be different based on the positioning. See next section for more details.
i2c Address
FIRST QikEasy IR Seeker on the stack: 0x14
SECOND QikEasy IR Seeker on the stack: 0x15
Reading Register Values
0x00-0x07 (8 Characters)
Version String
0x08-0x0F (8 Characters)
Manufacture Name String
0x10-0x17 (8 Characters)
Device Model Name
0x20-0x50
Reserved
0x49 (1-byte unsigned)
IR Ball Direction : return direction value 0 to 9
0x4A (2-byte unsigned)
IR Strength detected by IR Receiver #1: range 0 to 1024
0x4C (2-byte unsigned)
IR Strength detected by IR Receiver #2: range 0 to 1024
0x4E (2-byte unsigned)
IR Strength detected by IR Receiver #3: range 0 to 1024
0x50 (2-byte unsigned)
IR Strength detected by IR Receiver #4: range 0 to 1024
0x52 (2-byte unsigned)
IR Strength detected by IR Receiver #5: range 0 to 1024
0x54 (2-byte unsigned)
Maximum IR Strength out of the 5 IR Receivers: range 0 to 1024
Below is an example code fragment from an Arduino program. (Note that this is NOT the full program. This only contains the parts necessary to demonstration how you may go about using i2c to read the measurements from the IR Seekers.)
#define IR_SEEKER_ADDRESS 0x14
#define REGISTER_DIRECTION 0x49
#define REGISTER_STRENGTH 0x54
void readI2cIrSeeker(int address, uint8_t &dir, uint16_t &strength) {
// Read 1-byte unsigned data from the "Direction" register
Wire.beginTransmission(address);
Wire.write(REGISTER_DIRECTION);
Wire.endTransmission();
Wire.requestFrom(address, 1);
if (Wire.available()) {
dir = Wire.read();
}
// Read 2-byte unsigned data from the "Strength" register
Wire.beginTransmission(address);
Wire.write(REGISTER_STRENGTH);
Wire.endTransmission();
Wire.requestFrom(address, 2);
if (Wire.available() >= 2) {
strength = Wire.read() << 8; // Read the first byte (MSB)
strength |= Wire.read(); // Read the second byte (LSB)
}
}
void loop() {
uint8_t direction1;
uint16_t strength1;
readI2cIrSeeker( IR_SEEKER_ADDRESS, direction1, strength1);
Serial.print("Direction = ");
Serial.println(direction1);
Serial.print("Strength = ");
Serial.println(strength1);
delay(10);
}