Sunday, August 30, 2015

New Loconet Sound and Outputs Module with Arduino

I want to share with you the last version (v. 6.2) of the Sound and Outputs module fully compatible with Loconet. You can upload to this module as many MP3 files as you wish, and assign an output number to each one, so you can play them from your central station, throttle or software. From the software, you can set conditions to play sounds depending on locomotives, sensors, time or whatever. It has also 16 outputs that you can use for lighting, motors or any other device.

I use it to provide sound to the stations, with announces and ambient sounds. And I also control the lights of the station buildings and platforms with it. The total cost is arround 40€, much less that a Sound Director from Uhlenbrock (more than 100€) and with extra connections and extra functionality. I've used it also to automate the Faller Mine and any other place in your layout where you want to have individual sounds.

It can be used also as a Loconet Monitor to listen and view all messages travelling in your communication bus.

This is a sample of the module running:




HARDWARE


Let's begin with the needed hardware to build it:

Arduino UNO R3 compatible board

Now you can find them in ebay for less that 4 €. For more information about Arduino and how to use it, refer to the official page: www.arduino.cc

GCA185 Loconet shield for Arduino

You can purchase it from Peter Giling, myself in Spain, or isolate you own boards. See this post about the shield. The board with components can be around 13€ depending on the chosen components.



MP3 shield from elechouse

Arround 20€ and can be purchased here or ebay. Note that the shield comes prepared to communicate via software serial, but hardware serial (pins 0 and 1) is needed, so you will have to solder two pads in the bottom (everything is explained in detail in the shield manual). This shield has a jack connector for headsets, but you can better solder 4 pins to connect 3W/4Ohm speakers. You can reuse the speakers from an old computer.


There is an optional hardware that I recommend:

Sensor Shield v5

Led lights can be connected directly to the Arduino, but it's very useful to use this Sensor Shield v5 in order to have 5V and GND pins next to each signal pin (2€ in ebay):

Mosfet boards

You have to be aware also of the current limitations of arduino, which are 40mA maximum on a single output, and 200mA in total. So for bigger charges better to use MOSFET drivers. You can find them in single boards or 4 channel boards:



SOFTWARE


You will have to upload the software to Arduino. To do it, download the development software of Arduino from the offical page and install it. Then you will have to add the following library to the environment. Download the MRRWA Loconet libraries from the offical page: http://mrrwa.org/download/ clicking on "Download LocoNet library ZIP Archive".

Then, from the Arduino environment, select Sketch -> Include library -> Add ZIP library

Now get my Arduino program directly from here, and upload it to the Arduino board. If the MP3 shield is plugged, you will have to press the "SLEEP" button first in order to deactivate it, or you will not be able to communicate with the Arduino board to upload the program.


CONNECTION


Boards are plugged one on the top of order, in this order: Arduino UNO in the bottop, and on top GCA185 shield, MP3 Shield, and finally Sensor Shield v5 if you are using this one.

If you want to drive lights and use mosfets, they are connected to the sensor shield with female to female Dupont wire:


Now to feed the module, you have several option:

Feeding from Loconet DB9

My favourite is to feed it directly from the DB9 Loconet connector. I use a GCA101 Loconet booster, and using this connector it delivers an extra power line of 12V and 3Amp. 
In this case you have also two options: you can skip mounting the voltage regulator of the GCA185 board, and install both JP1 and JP2 jumper. In this way the shield will feed Arduino with 12V through the Vin pin, and will get 5V to operate from the Arduino 5V pin. In this way the internal voltage regulator of Arduino will provide power to all the shields. I normally do it in this way when only Arduino and GCA185 shield are used. But having an Mp3 on top, the consumption at maximum volume can overpass the capacity of the Arduino voltage regulator. You will notice it if playing a sound the module resets itself. So, next option is recommended.

A best option is to mount the voltage regulator components of the shield, but cutting the pin of the GCA185 board corresponding to the 5V supply. Make sure you do this, if both Arduino and GCA185 are providing 5V to the same pin, it will be a short circuit and one of them will blow up. Doing it like that, GCA185 will be feeding the MP3 shield and all boards above it, so you will have plenty of power for them.

Feeding from Loconet RJ12

Exactly as the previous option, but make sure you connect it to the Loconet T of the Intellibox command station. That's the only one connector providing 12V. The Loconet B has Railsync signal instead. Also, take care on how many modules you connect to the Loconet T. It has only 500mA (that's the reason to implement a power source in the Loconet shield), and one sound module can consume more than 250mA when playing at maximum volume.

Feeding directly Arduino UNO through the Power Jack

In this case, you don't need the voltage regulator components of the GCA185 shield. And make sure you don't put the JP1 jumper. Arduino will be feeding 12V in the Vin pin and it could cause a short circuit. Install the JP2 to feed GCA185 shield from the 5V pin of Arduino.


CONFIGURATION


The program uses LNCV to set up the module. LNCV is an invention from Uhlenbrock that emulates the CV configuration variables in decoders, but for loconet modules. The basis are the same, in each LNCV (LocoNet CV) variable, you can set a number to configure a function. Those LNCV can be set from the central station (if it is a Uhlenbrock one), or via Rocrail. There is a special configuration screen to read and write LNCV variables from modules.

The different variables and its meaning as follows:

LNCV NAME DEFAULT MEANING
0 Module Address 1 Module Address
1 Address pin 2 (J5 1) 1 Address number, setting this one the following are correlatively numbered
2 Address pin 3  (J5 2) 2 Address number
3 Address pin 4  (J5 3) 3 Address number
4 Address pin 5  (J5 4) 4 Address number
5 Address pin 6  (J5 5) 5 Address number
6 Address pin 9  (J5 6) 6 Address number
7 Address pin 10  (J5 7) 7 Address number
8 Address pin 11  (J5 8) 8 Address number
9 Address pin 12 (J6 1) 9 Address number
10 Address pin 13 (J6 2) 10 Address number
11 Address pin 14 A0 (J6 3) 11 Address number
12 Address pin 15 A1 (J6 4) 12 Address number
13 Address pin 16 A2 (J6 5) 13 Address number
14 Address pin 17 A3 (J6 6) 14 Address number
15 Address pin 18 A4 (J6 7) 15 Address number
16 Address pin 19 A5 (J6 8) 16 Address number
17 Config pin 2 (J5 1) 1 0 Output inverse, 1 Output normal, 2 Output pulse thrown, 3 Output pulse straight
18 Config pin 3  (J5 2) 4 0 Output inverse, 1 Output normal, 2 Output pulse thrown, 3 Output pulse straight,  4 Output fade, 5 Output fade inverse
19 Config pin 4  (J5 3) 1 0 Output inverse, 1 Output normal, 2 Output pulse thrown, 3 Output pulse straight
20 Config pin 5  (J5 4) 4 0 Output inverse, 1 Output normal, 2 Output pulse thrown, 3 Output pulse straight,  4 Output fade, 5 Output fade inverse
21 Config pin 6  (J5 5) 4 0 Output inverse, 1 Output normal, 2 Output pulse thrown, 3 Output pulse straight,  4 Output fade, 5 Output fade inverse
22 Config pin 9  (J5 6) 4 0 Output inverse, 1 Output normal, 2 Output pulse thrown, 3 Output pulse straight,  4 Output fade, 5 Output fade inverse
23 Config pin 10  (J5 7) 4 0 Output inverse, 1 Output normal, 2 Output pulse thrown, 3 Output pulse straight,  4 Output fade, 5 Output fade inverse
24 Config pin 11  (J5 8) 4 0 Output inverse, 1 Output normal, 2 Output pulse thrown, 3 Output pulse straight,  4 Output fade, 5 Output fade inverse
25 Config pin 12 (J6 1) 1 0 Output inverse, 1 Output normal, 2 Output pulse thrown, 3 Output pulse straight
26 Config pin 13 (J6 2) 1 0 Output inverse, 1 Output normal, 2 Output pulse thrown, 3 Output pulse straight
27 Config pin 14 A0 (J6 3) 1 0 Output inverse, 1 Output normal, 2 Output pulse thrown, 3 Output pulse straight
28 Config pin 15 A1 (J6 4) 1 0 Output inverse, 1 Output normal, 2 Output pulse thrown, 3 Output pulse straight
29 Config pin 16 A2 (J6 5) 1 0 Output inverse, 1 Output normal, 2 Output pulse thrown, 3 Output pulse straight
30 Config pin 17 A3 (J6 6) 1 0 Output inverse, 1 Output normal, 2 Output pulse thrown, 3 Output pulse straight
31 Config pin 18 A4 (J6 7) 1 0 Output inverse, 1 Output normal, 2 Output pulse thrown, 3 Output pulse straight
32 Config pin 19 A5 (J6 8) 1 0 Output inverse, 1 Output normal, 2 Output pulse thrown, 3 Output pulse straight
33 Maximum intensity 255 Maximum intensity for Outputs of type Fade (1 - 255)
34 Fade speed 10 Milliseconds to wait between each intensity step change. If we set 10 milliseconds and we have the maximum intensity (255), it will take 2550 milliseconds to turn on or off.
49 Mode Sound or Monitor 0 0 Sound (Elechouse MP3 shield), 1 Loconet serial monitor
50 Address first sound 0 Address to assign to the first sound (0 = no sound)
51 Number of sounds 0 Number of sounds (0 = no sound)
52 MP3 Volume (0 to 30) 15 Volume MP3 (0 - 30)
53 Sound Source 1 Sound Source (0=SD card, 1=SPI, 2=Udisk)
54 Output number to stop  50 Output number to stop sounds
100 Config command: 1 - Stores config, 10-Copy USB->SPI, 99 - Reset

The module number to acces to the config is 90010, and by default it has address 1 (you can change it in LNCV 0).

Note the LNCV 100 is not an address to read. It is used to send configuration commands to the module. Writing 1 in this address all configuration is stored in the internal EPROM memory, so remember to save your changes or they will be lost when you power off the Arduino.

Value 10 writen in this command LNCV 100 is used to copy all the contents from a memory stick into the internal memory of the MP3 shield. It has 8Mb of internal memory to store MP3. Seems not very much, but you can upl oad a lot of files, enough for all the announcements of a big station.

If you need any type of clarification or more detailed explanation, please feel free to comment.

I hope you use it and found it interesting enough for your layout!!

Thanks to:

MRRWA people, without they work on the loconet libraries it would have been impossible
Southern Lines Pacific and their Loconet prototype board
Peter Giling and his endless enthusiasm and his awesome electronic designs
The infinite number of pages I browsed with tutorials and instructions about arduino, mosfets, programming, electronics...

Disclaimer:

You must accept that You and You Alone are Responsible for your safety and safety of others in any project in which you engage. With this instructions I hope to enable some Arduino enthusiasts and inventors to keep experimenting and inventing, You are Responsible. You are Responsible for knowing your limitations of knowledge and experience. I test all prototypes and programs I explain, but there can be errors or mistakes, so you are Responsible for verifying its accuracy and applicability to your project. It is your responsibility to make sure that your activities comply with applicable laws and to take all safety measures applicable despite they are not here explained. I disclaim all responsibility for any resulting damage, injury, or expense. 

8 comments:

  1. IS the GCA-185 available? I see references to it being available but no place to order one for testing. this could be very exciting to work with.

    Thanks,
    Richard

    ReplyDelete
    Replies
    1. I had to do many of them for the minimum quantity of the supplier, so I have some to sell. Also is possible to acquire them from Peter Giling like any other GCA boards. Check www.phgiling.net and send an email to Peter.
      Cheers,
      Dani

      Delete
  2. This comment has been removed by the author.

    ReplyDelete
  3. hello dani

    I want to change the address in the sketch. LNCV program is not working. problems to connect with mt ecos.
    Where do i have to change the address in the sketch ?

    regards ronald

    ReplyDelete
  4. hello dani

    For me is it handier to program directly the address in the sketch.
    Where can i change the address in the sketch. its no problem that the address have for example from 17 to 32.

    regards ronald

    ReplyDelete
    Replies
    1. Hello Ronald! If you want to overwrite the settings manually inside the sketch, just set the desired values in the "lncv[]" array, following the description of each of the LNCVs. As an example, if you want to set the address 70 for pin 2, after the loadSettings() function call inside the setup block, just set:
      lncv[1]=70;
      If you want to set the first address for sounds to address 150:
      lncv[50]=150;

      That LNCV configuration mechanism is something from Uhlenbrock, and just works if you have an Intellibox command station or from Rocrail software.

      If you need more help, just send me an email to dguisado[at]gmail.com

      Regards,
      Dani

      Delete
  5. Hello,

    Will this loconet sheild work with my digitrax version of loconet ? I am looking to use LED strips to use as layout lighting.

    If so, could you please contact me about pricing and shipping to the US ?

    Thank you, Tim

    ReplyDelete
    Replies
    1. Hi Tim, yes, it's fully compatible with the Loconet standard defined by Digitrax. I manage led strips also adding a mosfet board between the output pin and the led strip.

      Price of the board only is €6,75, and complete kit including D-connectors and RJ12 cable 0.5 m €17,00

      You can send an email to Peter Giling (peter.giling@rocrail.net) and he will make an estimation of shipping costs for you.

      Here you can see all the available board and kit types:
      http://wiki.rocrail.net/doku.php?id=gca:gca-index-en/

      Cheers,
      Dani

      Delete