Brainlink Hardware Description

Introduction

Brainlink is a tool that links devices controlled via infrared (IR) remote control with computers and Android-powered smartphones. Brainlink allows you to:
  • Write programs that control toy robots, TVs, VCRs, and just about anything else with an IR remote
  • Expand the capabilities of these devices with additional sensors or outputs
  • Decode, visualize, and replicate the signals of most infrared remotes

Table of Contents

  1. Features Overview
  2. Battery Characteristics
  3. Charging
  4. Built-in Sensors
  5. Built-in Outputs
  6. Infrared Receiver and Emitter
  7. External I/O Connectors
    1. External I/O Signal Characteristics
  8. Bootloading Custom Firmware
  9. Bluetooth Hardware
  10. Bluetooth Communications Protocol
    1. General Information
    2. Individual Commands
  11. Electrical Schematic
  12. Mechanical Drawings

1. Features Overview

  • Infrared LED capable of replicating signal from any IR remote
  • Infrared Receiver tuned to 38KHz carrier
  • Bluetooth connection to computer or smartphone
  • Pre-built software support for PC, Mac, Linux, Android
  • Built-in Sensors:
    • 3-axis accelerometer
    • Light sensor
    • Battery voltage
  • Built-in Outputs:
    • Full-color LED
    • Multi-tone beeper
  • External I/O:
    • 10 Digital I/O
    • 6 analog inputs
    • 2 PWM outputs
    • 2 DAC outputs
    • 1 auxiliary serial port
    • Unregulated battery voltage and regulated 5V and 3.3V available to power external circuits
  • Based on the highly flexible ATxmega16A4 microcontroller
  • Customizable firmware
  • Rechargeable 450 mAh battery
  • Mechanical shell

2. Battery Characteristics

Brainlink includes a built-in lithium-polymer rechargeable battery with over- and under-voltage protection. 

Characteristic Value Units
Battery Life 7 Hours
Nominal Voltage 3.7 V
Capacity 450 mAh
Charging Current 100 mA
Time to full charge 5 Hours

3. Charging

To charge Brainlink, turn off Brainlink and connect to computer or USB charger(not included) via the included USB cable. An orange charging light located next to the power switch will turn on until charging is complete.

Plugging Brainlink into a charger while it is on will charge the battery very slowly or not at all, but may be useful if you wish to maintain battery charge or operate Brainlink in a constantly-on mode.

4. Built-in Sensors

Brainlink features three built-in sensors:

3-Axis Accelerometer. Brainlink contains a 6-bit, 3-axis MMA7660 accelerometer. The sensor has a range of +/-1.5g along each axis, and can be used to detect orientation, shaking, and tapping. 

Photodiode. The Brainlink's photodiode provides a reading of the amount of light reaching the sensor. The sensor is located in the left vertex (with the power switch oriented down). 

Battery Voltage. Brainlink's battery voltage is available to allow host programs to detect low battery states (defined as less than 3.5V). 

5. Built-in Outputs

Brainlink has two built-in outputs:

Full-color LED. The full-color LED is located under the Brainlink's shell in the top vertex (with power switch oriented down). It can be programmed to turn that vertex of the shell any RGB color.

Buzzer. The Brainlink's buzzer can produce tones of frequencies from 20 Hz to 30 KHz.  

6. Infrared Receiver and Emitter

Infrared Receiver. Brainlink's infrared receiver is used to capture signals from IR remote controls. The receiver is a Sharp GP1U module sensitive to a 38 KHz carrier, making it compatible with the vast majority of IR remote controls. The receiver is located in the right vertex  (with power switch oriented down) of the Brainlink. 

Infrared Emitter. The infrared emitter is used to mimic IR remote control signals from other devices. It is on a long, flexible cable extending out of the top vertex of the Brainlink. The emitter's dome must be pointed towards the IR receiver of the device you wish to control. The range of the emitter depends in part on the device being controlled, but is generally between 2 and 10 meters. 

See the tutorials section to read more about IR signals, and to read how to hack the IR emitter to increase range.

7. External I/O Connectors

Brainlink has two connectors that allow you to add numerous sensing and output devices. The following tables provide an overview of the signals on each connector, followed by descriptions of each type of signal.

10-pin Connector

Wire Color Signal 1 Signal 2
1 Red Regulated 3.3V none
2 Yellow Battery voltage (~3.7V) none
3 Blue Regulated 5V none
4 Green Digital I/O pin 0 Analog Input 0
5 Green Digital I/O pin 1 Analog Input 1
6 Green Digital I/O pin 2 Analog Input 2
7 Green Digital I/O pin 3 Analog Input 3
8 Green Digital I/O pin 4 Analog Input 4
9 Green Digital I/O pin 5 Analog Input 5
10 Black Ground none

8-pin Connector

Wire Color Signal 1 Signal 2
1 Red Regulated 3.3V none
2 Green Digital I/O pin 8 PWM Output 0
3 Green Digital I/O pin 9 PWM Output 1
4 Blue Digital I/O pin 6 DAC Output 0
5 Blue Digital I/O pin 7 DAC Output 1
6 Green Serial Receive (Rx) none
7 Yellow Serial Transmit (Tx) none
8 Black Ground none

7a. External Signal Characteristics

Absolute Maximum Ratings

Characteristic Value Unit
Regulated 3.3V max current output 100 mA
Regulated 5V max current output 200 mA
Battery voltage max current output 500 mA
I/O Pin sink/source current 20 mA
Maximum applied voltage (I/O pins 0-5, Rx) 20 V
Maximum applied voltage (I/O pins 6-9) 3.3 V

Digital I/O

Ten pins on Brainlink can read digital inputs or output digital values. All digital I/O are shared with alternate functions.

Characteristic Value Unit
Output high voltage 3.3 V
Output low voltage 0 V
Maximum input voltage for logical 0 1.0 V
Minimum input voltage for logical 1 2.3 V

Analog Inputs

Six pins on Brainlink can read analog voltages, frequently used to convey information from sensors.

Characteristic Value Unit
Resolution* 8 bits
Input Voltage Range 0 to 3.3 V

* - Resolution can be increased with custom firmware

All analog inputs have protection circuitry that prevents voltages greater than 3.3V from causing damage. A voltage greater than 3.3V will simply read as the maximum analog value.

PWM Output

Two pins on the Brainlink can output pulse width modulated signals, frequently used for motor control.

Characteristic Value Unit
Resolution* 2 to 16 bits
Frequency Range 0.5 to 8000 KHz

*- Resolution is inversely related to frequency. The equation that describes resolution is: Resolution = log2(32000000/(Frequency in Hertz))

DAC Output

Two pins on the Brainlink can output programmable voltages.

Characteristic Value Unit
Resolution* 8 bits
Output Voltage Range 0 to 3.3 V

* Resolution can be increased with custom firmware

Serial Port

Brainlink contains an auxiliary serial port which can be used to communicate with additional modules, or which can turn the Brainlink into a bluetooth->serial bridge to communicate with robots (such as Roomba) that have a built-in serial port.

Characteristic Value Unit
Baud Rate Range 1200-115200 baud
Default Baud Rate  115200 baud
Number of data bits 8 bits
Parity bit none  
Stop bits 1 bit
Transmit high voltage 3.3 V
Transmit low voltage 0 V
Receive Maximum Applied Voltage* 20 V
Receive Buffer Size 31 Bytes

The Receive pin is protected from over-voltage to allow for compatability with 5V devices.

8. Bootloading Custom Firmware

The Brainlink has a built-in bootloader that allows the user to modify the firmware or introduce firmware updates. Brainlink uses the powerful ATxmega16A4 as its core microcontroller. The Xmega series from Atmel is very well-supported by an open-source toolchain, making it possible to re-write the Brainlink firmware with tools that are free to you. 

To place the Brainlink in bootloader mode, turn off the Brainlink. Ground wire 2 of the 8 pin connector by connecting it to wire 8 of the connector, and turn on Brainlink. Brainlink's LED should be blue, indicating it is in bootloader mode. Once the Brainlink is in bootloader mode, follow the tutorial instructions for reprogramming the firmware.

9. Bluetooth Hardware

Brainlink uses a Bluetooth module, the RN-42, to communicate between its microcontroller and a computer or smartphone. Each module has a unique Mac address which can be used to idenfity it - this address is printed on the back of the Brainlink. Once paired with a host computer, the RN-42 will connect as a bluetooth serial port, and the computer or phone will assign it a port number.

Characteristic Value Unit
Baud rate 115200 baud
Number of data bits 8 bits
Parity bit none  
Stop bits 1 bit
Range* 10 meters
Pairing Pin # 1234  
Receive buffer size 256 bytes

* - Range listed is line-of-sight. Walls, weak host transmittors, and other factors may reduce range.

10. Communications Protocol

Brainlink's default firmware communicates with a computer or smartphone using the following protocol. The protocol can be used to communicate with Brainlink using a simple serial terminal program, and may be of interest to developers creating support for Brainlink in software languages and environments that are not currently supported.

10a. General Information 

Discovery Mode

Before connecting to a host, the Brainlink will transmit two characters, ASCI B and L, every 500 ms.  To connect to a Brainlink, the host device should send an ascii * character.

Time-out

The Brainlink will time out and return to this mode if no commands are sent for a period of 1 minute.

Error Checking

  1. Brainlink will echo all submitted characters back to the computer.  

  2. In order to prevent incorrect setting of outputs due to lost bytes, additional parameters must be received within roughly 350 ms (per character) or the command will not be executed.

  3. If any command is sent incorrectly, Brainlink will respond with three ascii characters: ERR

10b. Individual Commands

Each command is an ASCII character. Commands may require additional bytes to be sent, and may cause bytes to be received by the host computer/smartphone.

Q: Send the Brainlink into discovery mode

L: Return the light sensor value (one byte, more light = higher value)

B: Make the buzzer beep. Send the frequency of the tone as two bytes, high byte first.  For example, 440 Hz would be sent as 0x01 0xB8.  Buzzer will continue playing until the turn off command is sent.

b: Turn off buzzer.

A: Returns the X, Y, and Z acceleration values, one byte each, followed by a byte encoding if the Brainlink was tapped or shaken. The accelerometer  has a range from 0x00 to 0x3F (6 bit).  0x00 to 0x1F map to +0g to +1.453g.  0x3F to 0x20 map from -0.047g to -1.5g.  To convert to g-force, take the two's complement if the value is greater than 0x1F.  Then apply the following equation:  g-force = value * 1.5/32. Finally, the tap/shake byte encodes whether the Brainlink has been tapped or shaken since last read.  Encoding is as follows:

  • If bit 7 (highest order bit) of the byte is a 1, then the Brainlink has been shaken since the last read.

  • If bit 5 is a 0, then the Brainlink has been tapped since the last read

X: Returns 6 bytes corresponding to the 6 analog input values on the auxiliary port. The value of analog input 0 is sent first, following by 1, 2, 3, 4, and 5.

V:  Sends back the value of the tether’s battery voltage.

O:  Sets the full-color LED.  Send one byte for the intensity of the red LED, one for green, and then one for blue.

I:  Initializes the IR emitter and sets the following:
IR Carrier Frequency:  Two bytes (should be an unsigned int, follow the formula to determine what to send:

int to send = 32000000/(desired frequency in Hz)
Send Most significant byte first.

Start pulse sequence: First byte is length of sequence in pulses (one pulse = two bytes)
This can be up to 32 bytes (16 pulses), sent as:
two bytes for pulse on length, two bytes for pulse off length, etc..  (Length is encoded in 2 microsecond increments, with two bytes giving values between 0 and (2*65,535) us).  Send MSB first.  Returns ‘R’ if the number of pulses is too long (>16).

Bit encoding: Alternating (0x00), up-time (0x01), down-time (0x02) (most common), and iRobot (0x03).

Length of bit sequence: One byte to describe number of bits in a typical sequence (8 for robosapien, 12 for prime-8, etc).  This number will be divided by firmware to determine the number of bytes that are expected with an 'i' command. Due to an error in firmware, this value is echoed twice.

Length of time for a logical 1:  Two bytes

Length of time for a logical 0:  Two bytes

Length of up-time/down-time if applicable:  Two bytes, send 0x00/0x00 if not applicable (not applicable in modes 0x00 and 0x03)

i:  Send bytes to the robot corresponding to remote control signals.

This is a packet that combines the byte codes for a remote control signal (which can be 1 to N bytes long) with a command to regularly repeat the command (two bytes, making up the N+1 and N+2 bytes of the packet).  If the command does not need to be repeated, set these two bytes to 0x00,0x00.  

If the robot has a number of bits not divisible by eight, pad the least significant bits with 0s.  For example, the Prime-8 has 12 bits, which fit into two bytes.  The second byte’s least significant four bits should be all 0s.

!:  Turn off IR. A simple way to turn the IR signal off (useful in case you need to shut down a repeating signal to mimic a stop command).

R: Captures an IR signal. If capturing is successful, the brainlink will return a stream of bytes. The first byte is the length of the byte-stream, including itself. Subsequent bytes represent the space between rising or falling edges in the IR signal. These spaces are measured using 16-bit unsigned integers, therefore, each pair of bytes represents one number. When converted into 16-bit numbers, they can be further converted to microseconds by multiplying by 2. For example, a pair of bytes like 0x04 0x025 would convert to the decimal number of 1061, which would indicate a time 2122 microseconds between edges.

The first number of the stream indicates the space between a rising and a falling edge, the second between a falling and a rising edge, and so on. The last number will always indicate the space between a rising and falling edge. For this reason, the number of spaces is always odd.

This stream represents the Raw data format Brainlink can use to send infrared signals.

If capturing the stream is unsuccessful, Brainlink will respond with three bytes: ‘E’, ‘R’, ‘R’. Reasons for failure include:
1. No IR signal detected within a 5 second time-out period.
2. There was noise in the IR signal that invalidated the signal. Noise can be caused by sunlight or fluorescent lights.

S: Stores the most recently captured IR signal.

Stores the most recently captured IR signal in EEPROM. There are five locations that can store IR signals in EEPROM. You specify which by sending ascii numbers ‘0’, ‘1’, ‘2’, ‘3’, or ‘4’ after sending S. The stored format is the Raw data format specified in the ‘R’ command description.

s: Outputs an IR signal based on raw IR data from serial.

If you wish to send a command followed by a Raw data bytestream, use this command instead of ‘i’. The format of the message is:

Raw IR data as specified in ‘R’ followed by two bytes. These two bytes specify if the IR signal should be repeated.  If the command does not need to be repeated, set these two bytes to 0x00,0x00. Repeat time is specified in units of 2 microseconds. Send the high byte first.

Example: Roomba’s repeat should be on 20ms - which means the two bytes are 0x27 0x10

G: Plays a stored IR signal.

This command will output one of the five IR signals stored in EEPROM using ‘S’ over the IR LED. The command is followed by the location of the stored signal(an ascii number, ‘0’ through ‘4’), followed by two bytes. These two bytes specify if the IR signal should be repeated.  If the command does not need to be repeated, set these two bytes to 0x00,0x00. Repeat time is specified in units of 2 microseconds. Send the high  byte first.

Example: Roomba’s repeat should be on 20ms - which means the two bytes are 0x27 0x10

g: Prints a stored IR signal.

This command will print a stored IR signal over serial. The printed data will be in the Raw data format specified in the description of the ‘R’ command. The command is followed by the location of the stored signal (an ascii number, ‘0’ through ‘4’).

P: Set the frequency of the external PWM.   Two bytes (should be an unsigned int, follow the formula to determine what to send:
int to send = 32000000/(desired frequency in Hz)
Send Most significant byte first.
Note that the host computer should record the value of int to send because it needs to be used to calculate the duty cycle for small p commands.

p: Set the duty cycle of one of the two PWM ports. Followed by an ASCII 0 or 1 (to determine port) followed by two bytes (an unsigned int corresponding to duty cycle).  The formula for determining the int to send for duty cycle is as follows:
int to send = (int to send from big P command) * desired duty cycle as a percentage
For example, if you set the PWM to 20 KHz, you would first use P to set the frequency, using a value of 32000000/20000 = 1600
If you wanted to then set pin 1 to a 10% duty cycle, you’d next send p 1 160.

Setting the PWM will disable the digital output on this pin.

>:  Sets one of the ten output pins on the Brainlink.  Followed by two bytes - the first is the pin to set (in ascii, 0-9), the second is the value to set the pin to (in ascii, 1 for on, 0 for off). If the pin shares a function with the PWM or DAC, setting the output will disable these.

<:  Reads one of the ten input ports on the tether.  Followed by a byte specifying the port to read (in ascii, 0-9).  Returns an ascii 1 if the port reads high, and ascii 0 if it reads low.

If the pin being read is used for PWM or DAC, reading the input will disable these.

d: Sets one of the two DACs on the auxiliary port. Followed by a byte specifying which port (ascii ‘0’ for DAC 0, ‘1’ for DAC 1). This byte is followed by the value to set the specified DAC to (one byte). To calculate the value of this byte, use the following equation:

Value of byte = desired voltage/3.3*255;

C:  Set up the auxiliary serial port.  Followed by three bytes composed of an unsigned int (BSEL) and a signed byte (BSCALE).  These are raw values that get used to set the baud rate (the port is always configured as 8n1).  Here are some BSEL and BSCALE values for common baud rates:

Baudrate BSEL BSCALE
115200 131 -3
57600 135 -2
38400 204 -2
19200 825 -3
9600 829 -2
230000 983 -1

A bug in the release firmware (version 1.0) causes BSCALE to be echoed twice.

t:Transmits a string of bytes through the auxiliary serial port. The first byte should indicate the length of the byte stream (not including the length byte). The maximum number of bytes to send atonce is 255.

r: Returns the receive buffer from the auxiliary serial port.  The buffer can store up to 256 bytes, and so calling r will transmit to the host somewhere between 0 and 256 bytes. Calling r repeatedly will ensure that no data is being lost from a device hooked up to the auxiliary sensor port.

11. Electrical Schematic

We provide the electrical schematic for use in debugging and hacking the Brainlink. The following is provided under the terms of the Non-commercial share-alike creative commons license

Click image to download a larger version:

12. Mechanical Drawings

 Click the drawing to download a larger version.