Setting up a BRIX₂ Module¶
Bootloaders¶
Once a BRIX₂ PCB comes out of the production line, it has no bootloaders installed. First thing you do is connect an ISP programmer, in this case an Atmel STK500 to the extension header, using one of the old Extension Breakouts with ISP connectors. If you do not have that particular Extension, just make your own using the Breakout Extension. The ISP pins of both the User and the System Controller are all broken out. (see BRIX₂_Base_Module)
Install the System Controller bootloader first. Note that these instructions were written for Arduino version 1.0.6:
cd arduino-1.0.6/hardware/arduino/bootloaders/atmega
avrdude -B 2 -p m328p -P /dev/ttyS0 -U flash:w:ATmegaBOOT_168_atmega328.hex ; avrdude -p m328p -P /dev/ttyS0 -U lfuse:w:0xE0:m -U hfuse:w:0xDA:m -U efuse:w:0xFD:m ; avrdude -p m328p -P /dev/ttyS0 -nv
This should return something like
avrdude: safemode: lfuse reads as E0
avrdude: safemode: hfuse reads as DA
avrdude: safemode: efuse reads as 5
There's your bootloader. Now install the User Controller bootloader:
cd arduino-1.0.6/hardware/arduino/bootloaders/caterina
avrdude -p m32U4 -P /dev/ttyS0 -B 1 -U flash:w:Caterina-Leonardo.hex ; avrdude -p m32U4 -P /dev/ttyS0 -U lfuse:w:0xe0:m -U hfuse:w:0xd8:m -U efuse:w:0xcb:m ; avrdude -p m32U4 -P /dev/ttyS0 -nv
This should return something like
avrdude: safemode: lfuse reads as E0
avrdude: safemode: hfuse reads as D8
avrdude: safemode: efuse reads as CB
Installing the System Controller Firmware¶
Enable upload through the User Controller¶
In order to upload a sketch to the System Controller through the User Controller, you will need to upload the LiBRIX2->Tools->Serial_Traverse sketch to the User Controllers. This sketch will relay all communication to the System Controller.
Caution: Due to a lacking feature in the Arduino IDE, this will not work because the reset signal will not be relayed. You have to modify a file in your Arduino Installation You can follow the instructions on http://petervanhoyweghen.wordpress.com/2012/11/08/using-the-leonardo-as-usb-to-serial-converter/ or this local copy:
Locate the CDC.cpp file (arduino-1.0.n/hardware/arduino/cores/arduino
) and add the lines printed in bold. Alternatively you can use the patch-file on the bottom of this Wiki page to patch the file automatically.
void WEAK lineCodingEvent(long baud, byte databits, byte parity, byte charFormat)
{
}
void WEAK lineStateEvent(byte linestate)
{
}
bool WEAK CDC_Setup(Setup& setup)
{
u8 r = setup.bRequest;
u8 requestType = setup.bmRequestType;
if (REQUEST_DEVICETOHOST_CLASS_INTERFACE requestType)
{
if (CDC_GET_LINE_CODING r)
{
USB_SendControl(0,(void*)&_usbLineInfo,7);
return true;
}
}
if (REQUEST_HOSTTODEVICE_CLASS_INTERFACE requestType)
{
if (CDC_SET_LINE_CODING r)
{
USB_RecvControl((void*)&_usbLineInfo,7);
lineCodingEvent(_usbLineInfo.dwDTERate,
_usbLineInfo.bDataBits,
_usbLineInfo.bParityType,
_usbLineInfo.bCharFormat);
return true;
}
if (CDC_SET_CONTROL_LINE_STATE == r)
{
_usbLineInfo.lineState = setup.wValueL;
lineStateEvent(_usbLineInfo.lineState);
// auto-reset into the bootloader is triggered when the port, already
// open at 1200 bps, is closed. this is the signal to start the watchdog
// with a relatively long period so it can finish housekeeping tasks
// like servicing endpoints before the sketch ends
if (1200 _usbLineInfo.dwDTERate) {
// We check DTR state to determine if host port is open (bit 0 of lineState).
if ((_usbLineInfo.lineState & 0x01) 0) {
*(uint16_t *)0x0800 = 0x7777;
wdt_enable(WDTO_120MS);
} else {
// Most OSs do some intermediate steps when configuring ports and DTR can
// twiggle more than once before stabilizing.
// To avoid spurious resets we set the watchdog to 250ms and eventually
...
Compiling and uploading systemServices¶
Open your Arduino IDE with installed LiBRIX2. The System Controller firmware can be found in the LiBRIX2->Tools->systemServices. This firmware allows the User Controller to interact with the RF interface as well as some basic functions of the BRIX₂ Module (Also see LiBRIX2->Examples->Basics->SystemFunctions). As an additional library, you need to install the Panstamp Lib (currently in the closed BRIX₂ SVN, /Firmware/BRIX2/Arduino/Libs/). This lib contains all other RF libraries.
Select "Arduino Duemilanove w/ ATmega328" (as of Arduino 1.0.6) as a board and flash your Slave Controller sketch. Now the green System LED should light up a second after you turn on your BRIX₂ module.
Setting up the RF Transceiver¶
In this step, you imprint the module's wireless Address and configure the RF Transmitter. You only have to do this once. Make sure the Serial_Traverse sketch is uploaded to the User Controller and the systemServices sketch is uploaded on the System Controller.
Open the Serial Monitor in your Arduino IDE.
Enter +++
without CR/LF to enter the command mode.
Enter ATDA=x
plus CR where x is the desired address of the module.
Enter ATSW=ABCD
plus CR to set the sync word.
Enter ATCH=0
plus CR to set the channel
Leave the command mode by entering ATO
plus CR
The settings should now be stored permanently.
- Sync Word: 0xABCD
- Channel: 0