OpenLCB for Hobbyists

If you want to build your own OpenLCB nodes and play with them, there are several ways to proceed.

Generally, the Arduino platform is the easiest way to proceed. “Arduino” refers to a family of open-source hardware based on the AVR processor. There's a basic software development tool kit (IDE) that lets you easily and quickly download your code into an Arduino board, and then debug it there. (For other hardware, generally requiring more advanced work, please see the hardware prototypes page.)

After you download the IDE, start it and open 'Arduino-->Preferences'. Change the sketch directory to be 'OpenLCB/trunk/prototypes/C' or wherever you have placed it. Close the IDE and reopen it. You should now be able to see the libraries in 'Files-->Sketchbook' and the examples in 'Files-->Examples'.

You can download software for a basic OpenLCB node from our code repository and build it within the Arduino IDE. You can basically run it on any Arduino-compatible board, but to communicate with others you need to have Controller Area Network (“CAN bus”) hardware attached. The usual chipset is an MCP2551 and MCP2515 from MicroChip.com. LEDuino boards have this already present, or you can put together a CAN controller on a prototype board from the schematic.

Once you've got the basic communications working, you can connect your OpenLCB board via digital and analog input and output leads, servo or motor drivers, XBee radio links, LCD display drivers, or lots of other methods. There's a large community of Arduino hobbyists who are connecting all sorts of devices.

The easiest way to connect OpenLCB to hardware is through consuming and producing events. For example, here's the code that takes events detected by the basic software and uses them to drive a servo output to one of three positions:

  // Invoked when an event is consumed.
  // "index" is the index of the consumed event, 0 to 2
  if (index == 0) {
    servo9.write(0);
  } else if (index == 1) {
    servo9.write(90);
  } else if (index == 2) {
    servo9.write(180);
  }


This, along with some glue code, is compiled with the basic OpenLCB libraries in the Arduino IDE, and then downloaded into your board. See the OlcbServoNode sketch for the complete example.

This video describes two very simple Sketches, OlcbBasic4C and OlcbBasic4P, and the two nodes they implement. 4C and 4P Sketch Video


Site hosted by

This is SVN $Revision: 3111 $