Thursday, January 28, 2016

New version 7 of the sound module based in Arduino for Loconet

I made some improvements to the existing version 6 of the sound and outputs module for Arduino, releasing last version 7. For those who didn't read old posts, this is a Loconet module (like any other from Digitrax, Uhlenbrock or any other brand) where you can upload sounds and assign an output number to each one. It has also 16 output pins that you can set up individually as puse output, continuous or with fading. Use of this pins is intended for illumination, putting Mosfets in between if you plan to connect more than 1 or 2 led in each output.

Configuration is done via LNCV programming. It's the same idea like CV in mobile decoders, but this is an invention from Uhlenbrock. In future versions I plan to change all the configuration system to SV variables, a mechanism more standard of Loconet and supported not only by one builder.

Arduino sketch of the Sound and Outputs Module can be downloaded here.
You can also download an Excel file with the definition of all LNCV variables to setup properly the module from here.

If you want to read a more extensive review of the old version 6, click here to read the old post.

New functionality in v.7

There is a restriction added, is that in this version you can only manage 30 sounds máximum and not as many as you want like in the previous version. The explanation to this is that now you can configure the volume of each of the individual sounds so I needed to put a limitation in the number of files to manage. You can also specify for each of the sounds the preference or type (normal or ambient sound), and if it has to be reproduced in loop until a new sound is played or stop output activated.

The sound type (normal or ambient sound) is used in the following way: if a sound is being played in the exact moment a new sound request arrives, and the requested new sound is ambient, petition is ignored. If the new sound is normal, the file being played is interrupted to start the new one. Let's imagine we have a train announcement (configured as normal) and a birds background sound (configured as ambient). If the birds sound is playing, the train announcement will interrupt the birds sound to be played. But it will not happen the same in the other way. No announcement will be interrupted to play a background sound.

There is also the possibility to set up an output number to play all music uploaded in random and loop mode, non stop.

I hope you like it and use it, and if you need any assistance do not hesitate to get in touch with me making a comment to this post or sending me an email.

Thursday, January 14, 2016

Layout illumination and weather simulation system

From time ago I've been thinking about how to make a good illumination system for the layout. The current illumination system is good for a garage, just fluorescent tubes, but very bad for the layout. Even for some kind of works I need to use a portable light. But I don't want just a good illumination to work on the layout and make beautiful photos, I also want to create weather effects, like sunrises, sunsets and storms.

Last year, updating my Rocrail installation, I realized there was a new option in the Tables menu called "Weather" and seemed to be exactly the functionality I was looking for. So, I took a look to the documentation in the Rocrail wiki:

As you can read this functionality to manage ambient lights is compatible with some special systems like RocNet or OpenDCC Bidib, but also with some commercial system, what I liked the most. First of all I took a look to the Philips HUE system:

Philips HUE

Philips HUE consist in a a group of lights connected by wi-fi to some kind of router or concentrator that you can manage to set the intensity and color of each light individually. It's a very good solution because if you are not using Rocrail you can still manage the lighting system with the Philips application. But the bad news are the price of the lamps, too expensive in my opinion and restricted to Philips lamp models.

DMX lights

Next compatible system is called DMX. I made further investigations and learned it is the most standard protocol for managing lighting systems like those used in theaters, concerts and discos. According wikipedia: "DMX512 (Digital Multiplex) is a standard for digital communication networks that are commonly used to control stage lighting and effects."

There is a huge range of spot lights, flood lamps, lasers, stroboscopic lamps, motorized led beamers, ..... but of course we are talking about professional systems, what means each light is expensive because it implements an special DMX connector and protocol to receive the orders.

Lamps can be found in ebay at a moderate price, but you also need a PC interface to convert the orders sent by the software normally through the serial port USB to the DMX format.

Rocrail is compatible with EuroLite USB-DMX512 Pro converter or DMX4ALL, but you have to order them to Germany and cost 80$ or more. Looks like those interfaces are not sold internationally.

At this point, being the DMX-USB interface the difficult issue, I thought about implementing it myself using an Arduino. And I found DMX shields and libraries, but most of them discontinued or even more expensive than a commercial and complete interface. So my hope went out in smoke again.

Art-Net receiver

Last chance, Rocrail is also compatible with an Art-Net node receiver. This is a lighting control protocol which appeared after DMX512 to allow connections through LAN or wi-fi networks to DMX systems. Basically it is an encapsulation or transport protocol for DMX based on UDP though a normal computer network. You can read more about it in wikipedia.

This system has more or less the same problems than the previous one. You need an Art-Net receiver, receiving UDP commands (that's the easy part), but again you have to transform this commands to DMX format. If you want to do it yourself with an Arduino, you need a DMX shield and use DMX lights.

Final solution

Art-Net looks like a good protocol. You can access the lights from the wired lan or via wi-fi, and you don't need a special interface connected to PC. There are also free applications for PC, tablet or smartphone to manage Art-Net lighting systems. And I found these libraries from Christoph Guillermet (karistouf) for Arduino implementing an Art-Net receiver using a cheap 5$ Ethernet shield:

Inside the libraries it gives the idea of using the PWM outputs to manage RGB lights or leds according to the Art-Net commands received, so you can skip all the DMX stuff, and I found this idea perfect and started to assemble my lighting kit:

Arduino UNO
Ethernet Shield
Sensor Shield V5
4 MOSFET breakout board
12V Pure white led strip
12V RGB led strip (not addressable)
First of all plug the ethernet shield on top of Arduino UNO, and Sensor shield V.5 on top of the Ethernet. Sensor shield provides and easy way of connecting sensors and breakout boards (like the mosfets boards) to Arduino using cheap Dupont cables that you can also buy in ebay.

Using Dupont wires (female in both ends) connect outputs 3,5,6 and 9 to the Mosfet board. These Arduino outputs are PWM (you can adjust the intensity), and will correspond to channels 1,2,3 and 4 of the ArtNet receiver.

Connect the pure white led strip to one of the mosfets, and red, green and blue channels of the RGB led strip to the other three mosfets through the screw headers. Feed the power of the mosfets board with 12Vcc power source. I use a normal power source from an old computer.

You can download directly my program for the Arduino HERE. It is based on  Christoph Guillermet example. By default uses the IP, you can change it in the header of the sketch.

Software configuration

If you are not using Rocrail, I suggest you to change and start using it. :P
Well, if you still want to use your system, for sure it will not have a weather functionality and an Art-Net implementation. So you can use any freeware Art-Net console in your PC or tablet to adjust your new illumination system.

If using Rocrail, the best way is to download the weather example plan because the documentation is not completely clear and easy to understand. These are the basic steps to make it work:

First, define a new command station of type "dmxartnet" in Rocrail Server configuration and setup the IP assigned to your Arduino in the sketch:

Then you need to create an output object of type "light". In the "Interface ID" select this new command station dedicated to lighting. Is important to fill the field Value with 255 and the type of output "Lights":

In the color tab specify the channel of each of the colors and white and the desired color you want when activating the output:

There is an aid to select the color, it's not needed to work just with RGB values:

At this point, pressing the output symbol your led strips should glow in the predefined color. You can create many of them for different ambient lights or an output with strong white to have a good illumination to work on the layout.

But the best thing of all this is to be able to define all the color and intensity sequence depending on the time of your layout clock. This is defined in the Weather section inside the Tables menus:

The basic thing you need here is to define the output (or outputs separated by comma) of your output-light objects to use. In my case I have only one light composed of 4 channels (red,green,blue and white). But you can put some of them ordered from east to west and the software will make light transitions simulating the sun movement. It's possible also to specify different lights for night simulation.

You have different options to make it work. The basic one is to define the time and color for the sunrise, noon and sunset and Rocrail will be calculating the transition according to the time and adjusting your led strip lights. But I prefer to use the color table where you can adjust the exact light during a whole day at 30 minutes steps.

Your lights will be adjusted according to the Rocrail clock. If you set up the clock to run faster, lights will also be adjusted at its rhythm. Finally, you can create several Weathers (one for each season, as an example) and an Action to activate or deactivate each of the defined Weathers. Putting outputs linked to this actions, your lighting system will simulate it.

Last but not least, you can create Themes. I use them to define storms, and can be linked to actions and outputs or any layout event to activate them.

My storm Theme uses another light-output object, but linked to the same white channel of my Arduino Art-net receiver. For the thunder sound, I activate the output linked to a storm sound stored in my "Arduino sound and outputs module" that you can also mount following the instructions of this post.

Here you can see a video example of a sunrise and a storm. Mobile phones do not get properly the real light and color, it's much better that what you can see in the videos, sorry for the poor quality:

In following post I will try to install RGB Led Flood lamps instead of RGB led strips and several of them to test the sun movement simulation. I will keep you informed!