IRCM to Brainstem Example
Last Modified: 2006-10-25
find:

basket

Acroname Robotics PDF webpage version IRCM to Brainstem Example PDF

Related
Products

Product image for BrainStem Moto 1.0 Module
BrainStem Moto 1.0 Module
Product image for 4X AA Battery Pack w/Connector
4X AA Battery Pack w/Connector
Product image for BrainStem to InfraRed Cable
BrainStem to InfraRed Cable

Contents

Physical setup of BrainStem and IRCM example.

Introduction

In this example, a BrainStem Moto 1.0 module uses a Total Robots Infrared Communications Module (IRCM) to receive commands from an IR remote control.  A second example program shows how two Stems, each with an IRCM, can communicate with each other.  The BrainStem module uses its built in IIC bus to communicate with the IRCM.  For this example, any BrainStem module could be used as they all share IIC commands and all have the same IIC connector. 

Circuit Schematic

Wiring diagram of IRCM to BrainStem.

In the above schematic, one of the 2 IIC headers on the BrainStem is used to interface to the IIC port on the IRCM.  The IIC headers provide power and ground connections for the device.  The photo shows how to connect the color-coded adapter cable (sold separately) between the Stem and IRCM. 

Source Code - IR Commands to a Single Brainstem

With one IRCM module, a user can receive commands via an infrared remote control.  The module will automatically detect transmissions from a remote using NEC, RC5, Sony, or SKY Digibox protocols.  The example program polls the IRCM to see if it has received any new data.  If the device has new data, the program prints the bytes in hex. 

The program uses the TEA language which is a subset of ANSI C.  It is compiled using the BrainStem Console by entering the steep command.  It may be downloaded to the BrainStem and executed using load and launch commands.  This program uses standard TEA libraries as well as an IRCM library. 

These examples use Build 19 or later of the BrainStem Console. 

/* IRCM Remote Control Example 1 */ /* ircm-1a.tea */ #include <aCore.tea> #include <aPrint.tea> #include <aIRCM.tea> #define ADDR_IRCM (unsigned char)0xC0 void main() { char c; int i,j; /* set I2C baud rate to 100KHz */ aCore_Outportc(aPortIICBaud, 0); while (1) { /* see if data is available (-1 = 0xFF) */ if (aIRCM_GetRCStatus(ADDR_IRCM) == -1) { /* view contents of the remote control registers */ i = aIRCM_GetRCWord1(ADDR_IRCM); j = aIRCM_GetRCWord2(ADDR_IRCM); aPrint_IntHex(i); aPrint_IntHex(j); aPrint_Char('\n'); } /* repeat check every 10ms */ aCore_Sleep(100); } }

Source Code - IR Commands between Networked BrainStems

Multiple controllers each equipped with an IRCM can exchange data via an infrared link.  IRCMs perform their own error correction and collision detection.  It is possible to create a network of up to 255 IRCMs.  These built-in networking features make the IRCM a useful tool for developing distributed or collaborative robotic systems. 

The following test program will demonstrate some of the networking features.  It requires two Stems and two IRCMs.  One of the Stems must be configured with an I2C address of 4, the other with an I2C address of 2.  The program will automatically make Stem 2 transmit test data and Stem 4 receive test data.  Configure Stem 2 to run the test program at power-up.  Attach an IRCM to Stem 4.  Apply power and run the program from the Console.  Then attach an IRCM to Stem 2.  Set them several feet away from Stem 4 and apply power.  Stem 2 will begin transmitting data and you should see the values appear in the Console window as Stem 4 receives them.`

/* IRCM Network Example */ /* ircm-1b.tea */ #include <aCore.tea> #include <aPrint.tea> #include <aIRCM.tea> #define ADDR_IRCM (unsigned char)0xC0 void init(char addr) { /* set I2C baud rate to 100KHz */ aCore_Outportc(aPortIICBaud, 0); /* give IRCM the Stem's address */ aIRCM_SetLocalAddr(ADDR_IRCM, addr); } void test_node_rx() { char c; char cdata; char i; while (1) { /* check read status register */ c = aIRCM_GetRRStatus(ADDR_IRCM); /* see if data is available (-1 = 0xFF) */ if (c == -1) { /* retrieve first byte of data */ cdata = aIRCM_GetRRData(ADDR_IRCM); aPrint_CharHex(cdata); /* retrieve extended data */ for (i = 1; i <= 4; i++) { cdata = aIRCM_GetExtData(ADDR_IRCM, i); aPrint_Char(','); aPrint_CharHex(cdata); } aPrint_Char('\\n'); } /* repeat every 10ms */ aCore_Sleep(100); } } void main() { char i; char c; char myAddr; myAddr = aCore_Inportc(aPortAddress); init(myAddr); /* switch functionality based on Stem address */ /* Stem 2 will transmit, Stem 4 will receive */ if (myAddr == 2) { while (1) { /* send 10 packets of dummy data */ for (i = 0; i < 10; i++) { /* fill up first 4 extended data registers */ aIRCM_SetExtData(ADDR_IRCM, 1, i+1); aIRCM_SetExtData(ADDR_IRCM, 2, i+2); aIRCM_SetExtData(ADDR_IRCM, 3, i+3); aIRCM_SetExtData(ADDR_IRCM, 4, i+4); /* send value i to node 4 with 3 second timeout */ /* (also starts transmission of extended data) */ aIRCM_Transmit(ADDR_IRCM, 4, 3, i); /* wait 1 second */ aCore_Sleep(10000); } } } else { aPrint_String("receive\\n"); test_node_rx(); } }

Revision History:

  • 2003-10-13: Example Created
 

Related Links:

Brainstem Software: Console Overview

voice: 720-564-0373, email: sales@acroname.com, address: 4822 Sterling Dr., Boulder CO, 80301-2350, privacy
© Copyright 1994-2008 Acroname, Inc., Boulder, Colorado. All rights reserved.