Skip to content

Latest commit

 

History

History

LND-L-PCA9685

LND-L-PCA9685 (and LND-L-TLC5947) - A 16(24) LED LocoNet decoder

Video demonstration:

mqdefault

LND-L-PCA9685

This is a firmware for LocoNet-only accessory decoder for LEDs.

PCA9685 module (or bare IC) is used to control LEDs. Theoretically, 62 PCA9685 boards can be connected to one I2C master, giving 992 possible LEDs. At the moment the firmware supports only 1 board and 16 LEDs.

LND-L-TLC5947

A firmware for the same PCB, but instead of PCA9685 it uses TLC5947 LED driver module.

It allows to control 24 LEDs (1 module).

The module uses shift-register-like interface, does not have separate LED power pin, so on the decoder itself there is no need for MOSFETs.

Thoretically, TLC5947 can be chained like shift registers, but the firmware does not yet support it.

Common features:

  • Smooth lightup/fade

  • Separate brightness for each LED output

  • OpSwitch-like configuration

  • Configuration via UART

Extra functionality:

  • 8 digital inputs value that are reported to LocoNet (Can be used as sensor board).

  • 2 analog inputs

The firmware is written using PlatformIO build system and Arduino framework. VS Code is recommended as an IDE. The code can also be built with Arduino IDE with minimal changes (some files need to be moved around and some libraries need to be installed).

The project requires the following libraries:

PlatformIO will install the required versions automatically.

Selection between PCA9685 and TLC5947 is done with respective defines (look into build_flags in platformio.ini). By default, PCA9685 is built.

Hardware

The firmware is designed to work with this decoder board:

The board features:

  • Arduino Pro Mini socket (5V variant required, the firmware fits into both 32 and 16 Kb)

  • Socket for PCA9685 board (TLC5947 can be used instead)

  • 2 LocoNet jacks

  • Can be powered through LocoNet bus or from external power connector

  • Button to enter configuration mode

  • Indicator LED

The code is compatible with PCBs v1 and v2 (pins are different), the board in use can be selected by uncommenting corresponding ifdefs in .ino file.

User manual

Addressing

Each mast has its own 11-bit address. The preferred way to control the masts is to issue a LocoNet OPC_IMM_PACKET packet with raw DCC data that contains an extended accessory DCC packet. Such packets contain an address of the mast and an aspect to be set, so this maps naturally to the mast+aspect architecture of the decoder. However, I don’t know how well it is supported by different throttles. JMRI supports these packets for sure.

For compatibility, ordinary turnout commands (OPC_SW_REQ) are also supported. Presumably, any throttle can send these packets. Sending a turnout ON command (both Thrown or Closed) at address M+A will set aspect A at mast with address M. Therefore, in this mode, each mast has a range of addresses associated with it (2 to 8, depending on the number of heads in the mast), and it is required that ranges for different masts do not overlap. The firmware, however, makes no checks for this and will operate several masts if the turnout address falls into ranges of several masts.

All inputs have a continous range of addresses. Only the first address I is stored in the firmware, i.e. address for the first input channel. 2nd channel gets address I+1, 3rd gets address I+2, etc. When the inputs change state, the firmware sends a OPC_INPUT_REP LocoNet packet with input address and new input state. As far as I know, these addresses may overlap with mast adresses without problems.

Aspect values

Aspects are modeled after ModellDepo TrafficLight decoder (RU), which supports USSR and Russian signaling system.

Current version supports 1-, 2- and 3-lamp signals.

Table 1. 1-lamp signal
Id Description 1 r R 1 g G 1 y Y 1r w W

0

off

1 gr

1 gr

1 gr

1r gr

1

on

1 r

1 g

1 y

2

blink

1r w(bl)

Table 2. 2-lamp signal
Id Description 2 g r GR 2 w b WB 2 g y GY 2h r r RR

0

all off

2 gr gr

2 gr gr

2 gr gr

2h gr gr

1

1st lamp on

2 g gr

2 w gr

2 g gr

2

2nd lamp on

2 gr r

2 gr b

2 gr y

3

1st lamp blink

2 g(bl) gr

2 w(bl) gr

2 g(bl) gr

4

alternating blink

2h r(bl) r(bl)

Table 3. 3-lamp signal
Id Description 3 y g r YGR 3 y r g YRG 3h r w r RYR

0

all off

3 gr gr gr

3 gr gr gr

3h gr gr gr

1

1st lamp on

3 y gr gr

3 y gr gr

2

2nd lamp on

3 gr g gr

3 gr r gr

3h gr w gr

3

3rd lamp on

3 gr gr r

3 gr gr g

4

1st lamp blink

3 y(bl) gr gr

3 y(bl) gr gr

5

2nd lamp blink

3 gr g(bl) gr

3h gr w(bl) gr

6

3rd lamp blink

3 gr gr g(bl)

7

1st and 3rd alternating blink

3h r(bl) gr r(bl)

8

1st and 3rd lamps on

3 y gr g

Configuration

The firmware supports configuration via Arduino’s UART (at 115200 baud, 8N1). This way of configuration is always availalble, there is no need to switch to configuration mode. An UART converter (USB-UART) needs to be attached to the Arduino, so physical access to the decoder is required. The commands are separated by "\n" or "\r". The following commands are implemented:

  • listmasts - print list of all defined masts

  • addmast <nh> <addr> - add mast with address <addr> and <nh>(1..3) heads

  • delmast - delete last mast

  • clearmasts - remove all masts

  • br <ch> <max> - set maximum brightness of output channel <ch>(0-based) to <max>(1..255)

  • inaddr <addr> - set address of first input channel to <addr>

  • reset - load default configuration

  • save - save current config to EEPROM Don’t forget to issue this command after changing configuration!

  • off - Set aspect 0 to all masts (turn them off)

  • ch <ch> <val> - set output channel <ch>(0-based) value to <val>(0/1)

  • mast <N> - select mast <N>(0-based index) for the following command

  • 0..9,A..F - set aspect of selected mast to this hex value

The firmware had a way to configure some parameters via throttle commands without the need for a PC and UART. This functionality is removed now, but may be implemented again in future.

LocoNet commands (SV or CV) may be implemented in future.