A Xpressnet protocol implementation for Arduino Mega 2560
Switch branches/tags
Nothing to show
Clone or download
nzin update with some improvments:
- check to not fill up the commands stack (and the memory): I can pile up max 100 commands
- try to resync when I get a XOR error message (mostly when the arduino lost its way)
- bugfix my TCO table array
- update schema: my command GPIO is 7, not 38 now
Latest commit 1eb512c Oct 7, 2013


This is a basic xpressnet arduino implementation.
My goal was to create my own switch remote controller, so it implements only what I was looking for, but it is very easy to add features.
There is video (in french) of what I'm trying to do at http://youtu.be/JcD7iC3VbOw

Arduino Mega
You need an Arduino Mega 2560. Why? because xpressnet is a 9bit serial protocol. Standard Arduino SDK don't provide 9bits. But someone reimplement a 9bit Serial library (I put it into the arduinoSdk directory).
So you need to take HardwareSerial.h and HardwareSerial.cpp and replace these in the Arduino SDK (in /hardware/arduino/avr/cores/arduino/), and of course select Arduino 2560 in the Arduino IDE (in Tools/Board)

You will need a Max485cpa chip, and pay attention to the wiring image provided. I'm a bit confused on the RJ12 where is the GND and where is the VCC. Also, there is a sense between A and B. If not in the correct position, my program don't decode it properly (I guess bits arrived in the reverse state, i.e. 1 is seen as 0 and 0 is seen as 1). In brief: I don't have code a "auto-reverse".

When everything is in place, you can use the code. Mine currently is used to switch every 2 seconds a turnout (its id on my lockmauss is 38, and in the code, it is 37, because human counts from 1.. and computer begins to count from 0)
The "architecture" is the following:
- decodeXpressnet will read on a serial device data coming from xpressnet (via rs485), and will use decodeStage2 to decode data payload.
- if it is a "normal inquiry" message, poolEvent() will be called.
- poolEvent will check the XpressCommand stack state. If there is something, it will pop up one XpressCommand from the stack and send it.
- in your other part of the code, when you want to emit a command, you need to
 * create it: XpressCommand c = new XpressCommand()
 * populate it : c->pushData(0x21); c->pushData(0x81);
 * put it on the queue: XpressCommand::pushStackCommand(stack,c);

Hope it can help!

Nicolas Zin (nicolas.zin@gmail.com)