Showing posts with label Arduino. Show all posts
Showing posts with label Arduino. Show all posts

Sunday, September 1, 2019

SVLocoIO firmware for Arduino updated

A new functionality has been released for SVLocoIO firmware. This is the Arduino program we use for all I/O Loconet modules. This means, it is the main Arduino software to manage sensors and outputs (street lights, layout illumination, ...).

It was missing a functionality that other boards do, which is to inform about the state of the inputs (sensors) at power on. When the command station is turned on, or the power on button of your software like Rocrail or iTrain is pressed, the module will send the current state of those ports configured as input.

With a bit more of technical detail, when a OPC_GPON command is sent throuth Loconet, the board responds a OPC_INPUT_REP message for each configured input.

If you want to deactivate this functionality, delete or comment the line in the top of the code:

#define INFORMATPOWERON

I also corrected some errors when calculating the input number of a pin. It was affecting to the debug mode making the input numbers to be printed wrong. With this correction the maximum input number has been increased to 2048.

You can download it from: https://github.com/ClubNCaldes/SVLocoIO

NOTE:
If you use this firmware with GCA185 Loconet shield board, remember you don't need the pulldown resistors of the board as the program uses the Arduino internal pullup resistors.


Thursday, August 29, 2019

DIY Simple DCC Command Station for less than 20€

In our last exhibition we missed to have an independent command station to read and write CV. Normally we are managing trains in automatic mode, so command station and Rocrail are busy managing trains and we cannot stop if we need to program a new locomotive or read its data if we don't know the locomotive number it has.

So we decided to make a new module with two independent tracks and an independent command station so we can read, program and test locomotives. This module will be in the operator's side, connected to the "T" module that we use to enter or extract compositions to the main tracks.

We took profit of the fantastic DCC++ project, and just changed it to add a display, keypad and slider so we don't need the PC to perform any of the above operations before running a train in the main layout.


Disclaimer


Before continue reading, please consider the following typical disclaimer for DIY projects that applies to all this blog:

DIY projects are purely “at your own risk”. As with any DIY project, unfamiliarity with the tools and process can be dangerous. Posts should be construed as theoretical advice only. I’m not a professional, but only a hobbiest passing on ideas and tips to other hobbiests. Information and techniques I show here can change, and there can be mistakes in the information I publish, so I’m not responsible if that happens. Please consider my instructions as a guide only.


Shopping List


Arduino MEGA 2560 R3, 5€

L298 Motor Shield, 5€


4x5 matrix Keypad, 1€


Slide Pot, or linear potentiometer, 1€
We chose a linear potentiometer, but it can be a regular button potentiometer or any other kind.


20x4 LCD display with I2C controller, 6€


A bunch of DUPONT cables for the connections, 1€


Two power sources, one for Arduiono and an independent one for the motor shield. We recomend a 16Vdc 3Amp power source for the motor shild, as we found with less voltage some decoders do not respond to CV commands, or sound decoders do not work properly.

Connection


Please check first my previous post about how to mount the original DCC++ command station here (http://www.clubncaldes.com/2016/02/build-your-own-dcc-command-station-for-8.html). Motor shield needs some preparation (cutting a pad and making a bridge between pins 2 and 13).

After that you can connect the new elements (keypad, display and slider pot) as shown in the following scheme. Take into account that the keypad of the scheme is not the correct one (we are using the 4x5 keypad, see photo above these lines), but I couldn't find the Fritzing object for the right keypad:




  • Display needs 5V, GND and two wires to SDA and SCL pins of Arduino (pins 20 and 21)
  • Potentiometer needs 5V and GND in the same way, and the signal is connected to A8
  • Keypad is connected using 9 pins (from 22 to 30)
  • You will need one power source for Arduino, and an independent 16Vdc power source for the motor shield

Program


You will find always the latest version of the program to upload to the Arduino in the following link, were you can freely download from ClubNCaldes github repository and upload it to the Arduino Mega board:




How it works


I tried to make it as much intuitive as possible, but this are the main keys:

"*" ON, tracks are feeded with current
"#" OFF, no current to tracks
"F1" RUN MODE, this is the mode to run and test trains
"F2" PROG MODE, this is the mode to read and write CV in the programming track

In RUN MODE the left and right arrow are used to set the direction of travel, while the numbers activate or deactivate the functions. Speed is controlled with the slide pot.

In PROG MODE you can see a little help in the last line of the display which tells you the meaning of each CV entered (just for the standard ones like address number, acceleration, break, config...)


I hope you enjoy this simple but useful DCC command station for you own projects.


Sunday, November 18, 2018

Testing Peter Giling GCA50_AN for Arduino NANO

GCA50_AN BOARD FEATURES


Hi All! In this post I'm not showing more digitalizations, basically because I run out of decoders.... but I have a more interesting issue: the new board from Peter Giling GCA50_AN



And what is this board used for? Basically it is a Loconet interface for Arduino NANO. Probably you saw in older posts the board GCA185. You can check as an example how to build a 8 servo module with frog polarization and turnout feedback using that Loconet interface and Arduino UNO:

It's basically the same board but instead of being an standard Arduino UNO shield shaped board, it is a base board for Arduino NANO giving you the same functionalities:

- Power source to arduino via Loconet
- Sub DB9 and RJ12 connections to Loconet
- J5 and J6 connectors for standard Giling driver boards connection

It can be used as substitution of the old GCA50 board, but having Arduino connected to your Loconet bus and being able to receive and send any Loconet command, you can build any type of device: throttles, sound modules, illumination, turnout control, automation, signaling...

Club N Caldes has all the system based in two of the most famous standards (DCC and Loconet), but everything implemented in Open Source and Open Hardware platforms like Arduino.



This board has also an extra feature: it fits in a Littfinsky LDT-1 box like GCA51:



Here you can see how I tested the board connected to two of the most used boards form Peter Giling: GCA93 ( 8 port current detector) and GCA77 (Interface for turnout coils and illumination):




Make sure the jumper is properly set, depending on how you connect the board to loconet (using the DB9 connectors or RJ12):



HOW TO PROGRAM AND SET UP THE ARDUINO


First of all you will need to upload the desired firmware to the Arduino NANO board. In this case, the example is with the SVLocoIO firmware which is the firmware we created in Club N Caldes as the standard module for illumination control and sensor feedback. You can download it freely from the public GitHub of Club N Caldes:


After you downloaded it, open the sketch (sketch is the name used in "Arduino" terminology for the programs or firmwares) from the Arduino environment:


Make sure the line of code below is commented or directly deleted to use the software with GCA50_AN or GCA185 boards:



If your module was not connected yet to the computer, it's time to do it now using the USB cable. It doesn't matter if your module is also connected to the Loconet network or not, and you don't need to unplug the Arduino from the base board or disconnect anything, everything is safe.

Check in your Arduino environment that Arduino NANO board is selected and the right USB Serial port appears and it is checked:




Now you can select the Upload function from the Sketch menu or click the second button with the right arrow symbol from the tool strip menu. If everything goes ok, it will show the message "Done uploading" in the bottom strip, ignore the rest of messages:



I assume now that your GCA50_AN board is properly connected to your Loconet network and Rocrail is also running and connected to your layout. To set up the module functions, select the GCA50 configuration option from the "Programming" menu:




Clicking the Query button from the Addresses tab it should appear the module 081/001, this is the standard address for any new module (that you should change immediately to avoid conflicts with a new connected board):




In the Easy Setup tab you can read the current configuration clicking the button Get All, and change any configuration and save it again to the board with the Set All button. The configuration you see in the following screen is the right one needed for the GCA77 and GCA93 driver boards as connected in the previous photos: 



Using the test button of the last port, you can see the board responds illuminating the test led I connected:



Thank Peter Giling for your work, and congratulations for another excellent board which allows all railroad modellers who believe in Open Source Communities and like DIY to implement standard and professional digital buses in their layouts. Same greetings for Rocrail people and MRRwA for the Loconet libraries for Arduino and everybody supporting these groups.

Like always, you can order this and any other board directly to Peter Giling sending and email. All information and prices are in the following link:






Wednesday, August 16, 2017

Arduino based 8 servo modules with frog polarization Loconet

ClubNCaldes has developed a new Loconet module to manage switches, based of course in Arduino. Our previous version (see this old post) was using a simple sensor shield that manages servo motors connected directly to Arduino PWM pins. It's been working with no problems, but we noticed some servos glitched a little bit from time to time. Probably it was because no external power source was used to feed the servo motors, and it was taking the 5v power directly from the Arduino.

Then new module and firmware uses an specific servo shield with its own PWM generator, and communicates through I2C bus, so the rest of the pins are free to use. It has an external 5Vcc connector to use a separate power source for servos. The result is a smother servo movement with no glitches or interference.

Here you have the instructions to build your own module:

MATERIAL LIST


PCA9685 I2C 16-Channel 12-bit PWM/Servo Drive shield For Arduino
You can find it in ebay for less than 5€.

1 x Relay board
There are 1, 2, 4, 6 or 8 channel optoisolated relay boards for arduino. Take the one you need according to the number of servos and switches you want to manage.


Dupont cable female - female
This is used to connect the relay board to the servo board.

Servo motors
In ebay you can also find cheap TowerPro 9G servos, enough to manage a N or H0 scale switch.
Servo mounting bracket
My favorite way to fix servos under the table is with aluminium servo brackets from Hobby King.


Arduino UNO
Standard Arduino, you can also use NANO or MEGA version, but the provided firmware has been only tested with UNO VERSION.
Loconet Shield (GCA185)
This is always needed in any Loconet module implemented in Arduino, you can make your own or buy a GCA185 board to Peter Giling (see Rocrail page).


MOUNTING


Just put Servo shield on top of Loconet shield, and that last one on top of Arduino UNO.
Upload the SVLoco8ServoRelay sketch to Arduno UNO board. You can download it from:

https://github.com/ClubNCaldes/SVLoco8ServoRelay


CONNECTIONS


You have to feed the servo shield with a 5Vcc power source, be careful to respect the polarity shown in the board when connecting. Servos and relays are connected to the servo shield pins as indicated in the following photo. The servo connected to pin 0 uses the relay connected to pin 8, and so on:



Keep in mind these pins on the servo shield are independent of the pins on the Arduino board. Only Arduino pins 0 and 1 are used for debugging purposes, and Arduino pins 7 and 8 communicate with the Loconet shield. The rest of Arduino pins are free to use, so you can change the firmware if you like.




PROGRAMMING


Programming and adjusting is done from Rocrail as in the previous version. (NOTE: a new version using standard CV programming is planned to be released soon). Access to GCA50 configuration in Rocrail menu:


Pressing the query button it should appear the connected servo module. By default, it will have the address 81/1:


Selecting your module, you can change its Low and Sub addresses from the General tab (two modules cannot have the same Low and Sub addresses). Be careful, the RESET button of this screen will reset ALL modules connected to you Loconet network, not only the selected one:


Then you can access the Easy Setup tab, here you assign an output number to each of the 8 servos (left part of the screen marked in red), and a number to the input that tells to the sofware when a servo motor has finished its movement (servo feedback signal). Normally, the same number is assigned as in Loconet inputs and outputs do not share the same range of numbers. Set up the screen as in the following image:



To adjust the servos go to the last tab named "Servo":


Each of the ports (1 to 8) select one of the 8 servos that can be connected. When pressing the Get button it will read the configuration:

Pos1: one of the positions of the servo, with a value from 1 to 127 (1=0º, 127=180º)
Pos2: second position of the servo, with a value from 1 to 127 (1=0º, 127=180º)
V: Speed of movement from 0 (slow) to 5 (fast)

The SET button will overwrite the values and servo will move to POS1, wait one second, and will move back to POS2 so you can visually check the adjustment.

I recommend you to first set Pos1 and Pos2 values to 63. This will center the servo. Then mount the servo in place, and bit by bit reduce the value of Pos1 and increment the value of Pos2 until archive the desired servo movement.

Thursday, April 13, 2017

Cheapest DCC Command Station with Loconet interface

In a previos post I talked about the DCC++ Command Station. This is an open project to build you own DCC command station using the Arduino platform. It's quite simple and easy to mount, and features a full DCC command station with PC interface and compatible with Rocrail and JMRI. This time I want to go a little bit further and be able to build a more standard command station with Loconet interface. There are very cheap and professional command stations like DR5000, for sure much better than this, but building things by your own provides satisfaction, right?

Clicking Here you can read the complete information in my previous post.

Both the protocol and interface of the basic command station project shown in my previous post aren't standard, and despite you can connect to the available Arduino I/O's some sensors, lights or switches, it's not enough for a medium sized layout. Anyway is a good command station to have apart from your layout to program and test locos. It's worth the 12€, for sure.

I took the source code of the DCC++ project (it's open an published in github) and tried (successfully) to add Loconet support, with some goodies like:

  • 3 Led to know the state of the command station (ON, OFF, SHORT CIRCUIT)
  • 2 Buttons to turn on and off the track current
  • 2 relays to switch to the programming track current automatically when a programming command is received
  • Display support, showing CV values when reading or writing and current consumption
  • External emergency button
My new sketch can only work on Arduino Mega. I had to discard Arduino UNO and Arduino NANO support as the program was too big for them, and I wanted to have a better performance with a lower cicle time.

The source code and the sketch to upload to Arduino MEGA can be downloaded from my public GitHub repository:


The PC interface support does not longer exist in this version of the command station, as my intention is to have a pure Loconet command station, exclusively dedicated to manage the trains. I prefer to have individual devices for each function, so for PC interface I use a dedicated Arduino UNO with an Ethernet shield. I'll post the information about how to mount the PC interface for a Loconet network in the next post. All this has the advantage that I can change any device without affecting the other Loconet devices or having to change any setup.

Having an independent PC Interface allows me, for example, to change my Intellibox Basic command station and use my new Arduino Based DCC++, or a DR5000. It's just disconnect one, and connect another. No changes in PC, software, or any other device.

So let's go with the connection diagram:


 You see the base is an Arduino MEGA with the Motor Shield on top and the bridge between pins 2 and 13, exactly as the original DCC++ project.

Then you have the 3 led to indicate "track power connected", "track power disconnected" or "error/fault/shortcircuit".

Two external buttons to turn on or off the track power, plus an extra external emergency button. Pressing this emergency button will provoque sending an emergency stop message through the loconet network, and not a normal power off message like with the normal buttons.

Relays are also optional, but if you use them the isolated track section will have normal current and will switch to programming current just when needed (read or write command received from Rocrail or the program you use). So you don't need to use manual switches or to have a separated track for it.

The display is not exactly the one from the photo, sorry but I couldn't find the right one in Fritzing software, but the connection schema is correct. I'm using an standard Keypad LCD shield from DFRobot (check it here). Two of the keys of the Keypad LCD shield can be used to turn on and off the command station, so the external buttons are not necessary.

Finally, a loconet shield board (like GCA185 from Giling Computer Applications) has to be used, connected to pins 47 and 48 instead of the usual 7 and 8 when you are using an Arduino UNO.

But there is an important issue with Loconet!
Any Loconet network needs a "Loconet Terminator" and a 12V power source to work. This is always provided by the command station, but in this case we need to add this. In this page from RR-Cirkits you can find information about it. 

You can use an old ATX PC power source to supply the 12V to Loconet and build your own "Loconet Terminator".  A "Loconet Terminator" is just a 15 mA pull up constant current source to 12V.:





If you have a LocoBuffer conected to the LocoNet it has also the option to provide this pull up termination by selecting 'Term" option.

Finally there is another solution to the previous issues, this is using a GCA101 from Peter Giling. This a board that provides you 3Amp power to Loconet, so you will never run out of power to connect more and more modules, and the board has also a jumper to activate the "Loconet Terminator" already included in the board. This board also provides you the PC Loconet interface to connect you layout to Rocrail.

This is the command station mounted in a simple electricity box, but we use it in the club and has been proved reliable enough to drive trains during all week end in exhibitions with no errors:



I hope to have more free time to post other Arduino based modules I have developed. Thanks for reading!!!





Sunday, December 4, 2016

PSX DenshaDeGo Loconet controller

In my last trip to Japan I found an old PSX "Densha De Go" Japanese controller. This is a controller simulating a train cab and used with that train simulator game, very popular in Japan.


I don't remember if I found it in a BookOff second hand store or in Mr Potato, Last one is a very famous retro gaming shop in the heart of Akihabara district in Tokyo.

My idea was to use the controller to move trains in my layout, and to accomplish that I would use an Arduino acting as interface between the PSX controller and my Loconet network.

Let's check the hardware needed:

1 x Arduino UNO. (Another Arduino version is also possible)
1 x Loconet shield. As always that you want to interface Arduino and Loconet, you need a Loconet shield. You can build it your own, or buy it directly to the Rocrail guys. The item code is GCA185 and here you have all the information about it and the electrical schemes if you want to build it by your own: http://wiki.rocrail.net/doku.php?id=gca185-en
1 x Sensor Shield v5. This is not strictly needed, but makes it easier to connect wires and build the prototype before soldering everything in place. You can have it from ebay for 2$
You will need also some Dupont female to female jumper wires for easy connecting and testing of the prototype.

Connections:

Plug the Loconet shield GCA185 on top of Arduino UNO, and Sensor shield on top of GCA185. Then you have to connect the pins of the PSX joystic to the following Arduino pins if you want to use directly the Arduino sketch I'm providing later on in this post:

PSX pin 1 (DATA) to Arduino PIN 12
PSX pin 2 (COMMAND) to Arduino PIN 11
PSX pin 4 (GND) to Arduino GND pin
PSX pin 5 (VCC) to Arduino +5V pin
PSX pin 6 (ATT) to Arduino PIN 10
PSX pin 7 (CLOCK) to Arduino PIN 13

You can check in this page all information about PSX controller, also how to identify which is the pin number 1 of the connector: http://www.gamesx.com/controldata/psxcont/psxcont.htm


Here you have an image of my temporary connections of the PSX connector and the Arduino Sensor shield for further clarification:



Software:

Finally, you need to compile and upload the following sketch into the Arduino board:

https://github.com/ClubNCaldes/ArduinoDeGo

To be able to compile the sketch you need to add two libraries to the Arduino environment:

MRRWA Loconet library: http://mrrwa.org/download/
PSX library: http://playground.arduino.cc/Main/PSXLibrary

The first one is the library in charge of Loconet communications. You have many examples included in the library. I used of them, Loconet Throttle, as basis for making the current sketch. The example turns the Arduino in a Loconet Throttle receiving the commands through the serial monitor. You only need to change it a little bit to use any device connected to Arduino. In my case I changed it to use a PSX controller, but you can connect a potentiometer, a LCD display and a keypad or anything you imagine to build your personalized throttle.

The second one is a library written by Kevin Ahrendt and based on the PSX communication protocol analysis from Andrew J McCubbin. I also had to do some reverse engineering as this controller is not like the normal ones. And I found the brake throttle is not working properly, some times it is sending strange values. That's why you will find in the sketch some weird code to skip strange values that my controller sends some times. But if it works with my broken controller, I guess it will also work properly with a good one.



If you have any question just comment under the post or open an issue in the GitHub repository. If it works well and you try it, you can also comment.  :P




Sunday, May 29, 2016

New projects and organization of the blog

I'm sorry to have my blog a little bit unattended, but I'm involved in some interesting projects that are taking all my free time.

Complete digital system (Loconet and DCC) based on Arduino


In the Arduino side, my purpose is to build a complete digital system based on this fantastic open source platform. Until now I was using Arduino just to implement some Loconet modules with special functionalities that I was not able to find in the market. Those developments where always thanks to Alex Shepherd and his Loconet libraries for Arduino (www.mrrwa.org). Peter Giling, from Rocrail team, created an interface board usable with MRRWA libraries that enabled those project from the hardware side.

Two months ago I found another interesting development to turn Arduino into a complete DCC command station. It has no possibilities to be connected to an standard bus like Loconet, but it can be connected to JMRI and Rocrail via the USB serial port of Arduino or an Ethernet shield.

Having all the mentioned code, I plan to merge it and have a complete DCC command station with Loconet connection. For that I need some changes to the Loconet Shield (GCA185) from Peter Giling as it should have the Loconet terminator for all system to work properly. It would be also very useful to have a power source of 12Vcc feede from this command station board to the DB9 connectors.

Unexpectedly, a friend from India wrote me and offered his help to develop not only this shield, but a lot more of useful boards to develop this complete digital system (Loconet + DCC) for Arduino. I'll be posting all information here as I get some free time. As always, all my code will be Open Source and public, so everybody can contribute and expand it.


Source code and blog reorganization


I'm also working in a reorganization of the sections of the blog and a common repository for all source code. I'm moving all .ino files to github. I think it's the best option, or at least better than shared spaces with no specific source code support like I'm doing with Google Drive.

New standard for N-scale digital modules


Members of Club N Caldes are quite excited to build our digital system ourselves, and we want to apply it to modules. At least in Spain, is very difficult to see digital modules in train fairs. Until now each member had his own layout, and we were sharing our knowledge and helping ones to the others. As soon as we have all software and hardware ready we want to define a norm to construct our modules and be able to assist to some of the big module fairs.

We plan to use EuroN norm as it is the most extended here, and redefine or add an extension to the norm for digital use. Some requisites are the possibility to change rail current to analogue if desired, keeping the management of switches, lights or any other automatism through Loconet.

New train fair in Logroño (La Rioja - Spain)


Also came to me the opportunity to collaborate in the organization of a train fair in Logroño. I think it will be a very special one, as it will be held in a magnificent place, not the common pavilions. Also this Spanish region is very well known by its wines, and in Autumn the landscape and red colours of the vineyards are superb. We also plan to add an extra value making some workshops and talks for both beginners and seniors in the hobby. But I still have to wait a little bit to post more information. I'll do it soon.

So, the plan is to develop our digital - open source system, make some modules, and assist to the train fair in Logroño in October to present it. We will be quite busy for the next three or four months....


I'll keep you informed!





Sunday, March 6, 2016

Arduino 8 servos module with feedback

I've been always using servos to move my switches. I use GCA136 boards, from Peter Giling, plus GCA137 boards mounted on top to feed the switch frog. A friend asked me if it would be possible to drive servos with Arduino and make a cheap module, and that's what I want to share with you.

This module cannot manage frog polarization, if you need that use Peter Giling boards. But just to move servos, is a great and cheap solution. It's possible to adjust the movement and speed of each of the 8 servos. And the module sends back 8 feedback signals for the software to know when the servo movement has finished and can allow move a train on it. Many servo modules that you can find in the market cannot be used with slow movement because trains are released before reaching the end position and provoques short circuits or derailments.

Configuration is very easy, using the GCA50 configuration screen of Rocrail. It has an special tab for servo adjustment.

So, let's go for the shopping list:

An Arduino UNO:


A Loconet shield GCA185:



And finally a Sensor Shield V5. This is just to make the connection of servos easy:

Sketch is using pins 2,3,4,5,6,9,10 and 11 to connect servos. Pin 13, connected to the on board led,  is also reserved and will be activated during a servo movement.

You can download the last version of the sketch (software) for Arduino from the ClubNCaldes github repository:


This sketch is using the ServoTimer2 library. This is a special library developed by Michael Margolis not using the internal Timer1 of Arduino as this timer is already in use by the Loconet libraries and wouldn't work. I had to fix the code to make it work with the last version of the Arduino environment and you can find also this fixed library in the code repository with the sketch. 

Once uploaded, you can configure it going to GCA50 configuration screen in Rocrail, under "Programming" menu. In this screen go to Addresses tab and click the Query button. By default sketch is configured with the 81/1 identification, and it should be shown in the screen. It's recommended to change first of all this address to any other number. You can change it in the general tab.

Going to the Easy Setup tab you can read the board configuration clicking the button Get All. The first 8 ports must be configured as output and assign an output number for each of the 8 servos. The last 8 ports, from 9 to 16, are the input numbers assigned to the feedback signal of each servo. You can use the same number for the input as assigned to the output. In Loconet input numbering is independent from the outputs:



Click the Set All button to write configuration into the board. The last tab labelled Servo is used to adjust the movement and speed of each servo:


Select which of the 8 ports (=servos) are you configuring. Each of the two positions have a range from 1 (equivalent to 0 degrees) to 127 (equivalent to 180 degrees). "V" is the speed of movement, being 0 the slowest and 5 the fastest. Each time you press the Set button configuration will be stored and servo will move one side and the other at the selected speed.

Current to feed arduino and servos is taken directly from Loconet, but you can feed also the sensor shield with an external 5V power supply removing the jumper in the sensor shield board.

Here you can see it in action. I hope you like it: