Freerails Home 
Home Search search Menu menu Not logged in - Login | Register
Freerails > Model Railroad Forums > R.C. The Future Now If You Desire > 'Arduino' Based R.C. For Locos & Layouts

Freerails IS ACCEPTING new Members ... To join Freerails ... See how to Register as a Member in the 'Joining Freerails' Forum

'Arduino' Based R.C. For Locos & Layouts
 Moderated by: . Page:    1  2  Next Page Last Page  
New Topic Reply Printer Friendly
 Rating:  Rating
AuthorPost
 Posted: Tue Dec 10th, 2019 02:18 pm
  PMQuoteReply
1st Post
John Boshier
Registered


Joined: Tue Nov 26th, 2019
Location: United Kingdom
Posts: 23
Status: 
Offline
I've mentioned the Arduino based RC system I'm working on a few times, so thought I would start a topic on it. Progress is very slow, and I haven't got it installed on a layout yet, but it's looking promising. One of my main reasons for doing this is cost, and this system is very cheap compared to the commercial alternatives. Another is that I wanted a proper handheld control panel, with knobs, switches and stuff, and no phones, touch screens, or complicated mixes of Wi-Fi, Bluetooth and other annoyances. Basically this system is very simple. I also want to be able to operate everything from it, DC, DCC and BPRC locos, and all servos, LEDs, stepper motors etc. on the layout.

The complication is that I have more than one layout under construction. Rather than having to make 8 control panels, I've got one universal controller that will operate all of them, and any more I start in the future! The complexity is more related to this than to the radio technology itself. I've had to compromise a bit on my desire for a good old fashioned control panel, but there are no phones or touch screens involved so I'm happy with it!

This is the current state of the Tx. Visible is a 16 key keypad, 2 inch 320x240px TFT display, and two slide potentiometers. In the top right corner is a rotary encoder, but I'm not sure if it will be used, or if I'll remove it. Underneath is an Arduino Mega 2560, and an nRF24L01 2.4GHz transceiver. As you can see, it's grown a bit, as it originally only had one pot. It also started off with an Arduino Uno, but due to the size of the software, or my sloppy programming, I ran out of memory. The Mega is bigger, so I thought I would add the extra pot at the same time, hence the messy add-on to the circuit board. When I get my filament 3D printer working again, I'll design and print a case for it.





Also in the photo is my first attempt at a BPRC loco. It's a Lima British GWR Diesel Railcar that I converted to EM gauge many years ago. The Lima motor is infamous for being inefficient, and apparently needs about 7 volts to start moving. So I've replaced it with a Susumotor, which is a CD drawer motor supplied with the correct gear fitted, and fitting instructions. I ignored the instructions to glue the motor in place, and 3D printed a proper mounting for it on my resin printer (that is working, but too small to print the Tx case!).

On the breadboard is an Arduino Nano and an L298 motor driver. The nRF24L01 transceiver is at the end of a cable, and not visible in the photo. I can't tell how well it works yet, but at least it's alive, and does work! The next step is to assembly it in the railcar so I can test it on the track. Since taking the photo, I've replaced the L298 motor driver with a smaller DRV8833 board.

The Nano is too big for any other loco I have, but it will fit in this one, and is an easy way to start. My plan was to use the smaller Pro Mini, that's conveniently available in both 3.3v and 5v versions, but this is proving a bit too big as well. I've just bought a couple of ATtiny 48 microcontroller chips, that are in the same series as the chips used in Arduinos, and if I can get my head round programming them will save a lot of space. So there's still some way to go before I can start playing trains!




____________________
John
Back To Top

 Posted: Tue Dec 10th, 2019 02:36 pm
  PMQuoteReply
2nd Post
John Boshier
Registered


Joined: Tue Nov 26th, 2019
Location: United Kingdom
Posts: 23
Status: 
Offline
For controlling features on the layout (sort of equivalent to a DCC accessory decoder), I've come up with this. It's just three components that plug together. Turnout servos simply plug into the rows of pins on the edge of the board, and stepper motors, LEDs etc. are just as simple. They're cheap, so I can use as many as I want on a layout, and position one wherever as many servo cables as possible will reach it. It then just needs a power supply, that could be a battery, or a simple cable from a wall wart power supply. So basically, no layout wiring at all in many situations!

The possible catch is that these expansion boards for the Nano aren't very common. Similar boards are readily available, but this one has a socket for the nRF24L01 transceiver. On the other boards I need to make up a cable connection for it, or an add-on plug-in circuit board. Not a big job, but this is simple.







____________________
John
Back To Top

 Posted: Tue Dec 10th, 2019 03:21 pm
  PMQuoteReply
3rd Post
John Boshier
Registered


Joined: Tue Nov 26th, 2019
Location: United Kingdom
Posts: 23
Status: 
Offline
Some not very good screenshots,
of where most of the programming work went on the Tx.

On power up, the display goes into the layout menu,
where the option is selected on the keypad:





The display then shows the selected layout name, and a track diagram,
which is a simple line drawing written into the software:





To select a loco, or access the menu for another reason,
*# is pressed on the keypad:





The Loco menu displays a list of locos, and fixed controllers,
available to the current layout:





After selecting the required loco,
it's assigned to either the left or right potentiometer:





Returning to the main screen shows the selected locos for each pot:





Sliding the pot displays speed and direction.
Speed is currently what is sent to the Rx, in the format used by servos and RC ESCs,
which is a number between 1000 and 2000, with 1500 as stop:





When a button on the keypad is pressed,
if it's a valid key for that layout the key is displayed on the screen,
but if it's invalid an error message is displayed.

Each key can have three functions, the key pressed on it's own, *key and #key.

The Tx is pretty dumb, and just broadcasts the keypress,
which every active Rx checks against its list of instructions to see if it needs to do anything.

Loco control is also picked up by every Rx,
which then decides if its supposed to act on it.




____________________
John
Back To Top

 Posted: Tue Dec 10th, 2019 05:21 pm
  PMQuoteReply
4th Post
John Boshier
Registered


Joined: Tue Nov 26th, 2019
Location: United Kingdom
Posts: 23
Status: 
Offline
Although the nRF24L01 2.4GHz transceivers allow full two-way communication, to start with I'm just using them for broadcasting instructions from the Tx, with no acknowledgment from the Rx. If this isn't reliable I'll have to make it more sophisticated. I'd also like to add communication from the Rx for error messages and telemetry one day, but not yet.

Very little data is actually broadcast. For those nerdy enough to understand such things, the data is stored in a C structure that the RF24 can send with a simple instruction.


struct radioData {
  byte rxID; //ID of Rx this message is for. For future use with remote programming
  byte layoutID; //ID of layout this message is for
  short controlID; //Key Press/locoID
  short controlValue; //Value of control, if any
};


In something passing for English, this is:
  1. (rxID) A number between 0 and 255 to identify the specific Rx to contact. This won't be used for layout control, but will be needed when I get as far as being able to program Rx settings from the Tx. So far I can use it to move a servo remotely, but can't yet store settings in the Rx.
  2. (layoutID) A number between 0 and 255 to identify the currently selected layout. I don't think I'll ever manage to have that many layouts, finished or unfinished!
  3. (controlID) A four digit number identifying the button pressed on the keypad, or the loco ID allocated to one of the potentiometers.
  4. (controlValue) An optional four digit number to send the required value related to 3). This can be:
  • No value sent. This would normally be where a button toggles a servo or relay, between two positions that are stored in the Rx
  • A value between 1000 and 2000 sent to a servo to set a position between 0 and 180 degrees
  • A value between 1000 and 2000 sent to a loco motor, where 1500 is stop, 1499 to 1000 is reverse speed, and 1501 to 2000 is forward speed. This is what is sent to an RC ESC, as used mostly in planes, boats and cars. For an H-bridge motor driver, the Rx converts this to a PWM value between 0 and 255 and the required direction.
  • Some value to control the position of stepper motors, and the brightness of LEDs, but I haven't done that bit yet.
Every active Rx receives the signal, and checks to see if its relevant to it. This could be the rxID if it's a setup instruction, the layoutID if a button has been pressed, or the controlID if it's for loco speed/direction control. It then either acts on it, or ignores it.

There is a list (AKA an array in the program, although I hope to store this in EEPROM later) of all the controlIDs handled by the Rx, which Arduino pin the relevant device is attached to, and any stored settings for it. The program loops through the list, checking if each entry matches the controlID, and if it does takes the necessary action, then carries on. This means a single button on the Tx can control:
  • A single turnout, and the Rx will toggle it between two positions
  • Multiple turnouts, logically with a specified position, so it can set a route with several turnouts on each of multiple receivers
  • Any combination of servos, stepper motors, relays, LEDs etc.
Most of this is already working, but not on a layout yet.

Most of the code is pretty standard stuff to control devices commonly used with Arduinos, from numerous examples on the internet, and tweaked a bit. So the system is actually quite straightforward for anyone with a reasonable knowledge of Arduinos. you don't need to be any sort of expert to do it, or I wouldn't have got this far! As I mentioned earlier, any complexity is added by making it able to control multiple layouts. You wouldn't even need to send four pieces of data for a single layout!

I'm keeping my fingers crossed that it will work satisfactorily on my layouts. It could still be a total failure, or just not very good and beyond my ability to make usable!



____________________
John
Back To Top

 Posted: Tue Dec 10th, 2019 08:34 pm
  PMQuoteReply
5th Post
fallen
Registered
 

Joined: Wed Apr 3rd, 2013
Location: United Kingdom
Posts: 197
Status: 
Offline
Hi John,
This is fascinating stuff. I am just getting to grips with the Arduino system, the add-ons that are available, and what they can do. I had started out with the idea of connecting an Arduino to a Deltang transmitter, as all the control inputs are simple DC voltages that the Arduino could probably generate fairly easily, directly or with an add-on board of some kind. However I have now discovered the available radio link systems and am thinking about using these instead.
Frank

Back To Top

 Posted: Tue Dec 10th, 2019 08:50 pm
  PMQuoteReply
6th Post
John Boshier
Registered


Joined: Tue Nov 26th, 2019
Location: United Kingdom
Posts: 23
Status: 
Offline
fallen wrote:
Hi John,
This is fascinating stuff. I am just getting to grips with the Arduino system, the add-ons that are available, and what they can do. I had started out with the idea of connecting an Arduino to a Deltang transmitter, as all the control inputs are simple DC voltages that the Arduino could probably generate fairly easily, directly or with an add-on board of some kind. However I have now discovered the available radio link systems and am thinking about using these instead.
Frank


Apart from the time involved, much of which is learning, I like this because I'm in control. Not because I'm a control freak, but because, within my abilities, I can make it do what I want, and not have to live with what the manufacturer wants to sell me. An Rx that costs a few pounds, rather than tens of pounds, is very appealing too!

If you can find a way into the system, I think Arduinos have great potential for enhancing commercial systems too though.




____________________
John
Back To Top

 Posted: Fri Dec 27th, 2019 04:15 pm
  PMQuoteReply
7th Post
John Boshier
Registered


Joined: Tue Nov 26th, 2019
Location: United Kingdom
Posts: 23
Status: 
Offline
It's alive! I got my first loco running last night :2t:.
This is the Rx temporarily dumped roughly where it will be going. The plan is to stick the floor/seating in permanently, cut the bottom out of the chassis, and fix this in place upside down. That will give access to the batteries and electronics from underneath. I've put an on/off switch in the feed to the Rx, and two diodes to reduce the voltage a bit, and it will protect it from anyone clever enough to put the batteries in the wrong way round!





The Rx has lots of changes from what I had planned above! I've gone back to my original plan of using an Arduino Pro Mini, rather than a Nano. The Nano has a built-in USB connection for updating the software, but as it's on the end of the board I would need to lift it part way out to update. The Pro Mini needs an external USB link, through the 5 header pins at the far end, but they're vertical, so I can fix this unit in place. The Pro Mini is also available in a 3.3v version, and as the transceiver is 3.3v, it means that all the electronics are powered from 3.3v, rather than a mix of 3.3v and 5v. Another major change is to use a TB6612FNG H-bridge motor driver. I discovered the L298 and DRV8823 I tried first require a higher voltage that the minimum output of the batteries, so are probably unsuitable. This will drive the motor from as little as 2.5v, so is much better. I've also changed the batteries, from a 9v Li-po  to two 10440 Li-ion. These are the same profile as normal AAA batteries, but 3.6v, giving a lower output which is what I wanted, and they will fit under the floor, which the 9v one wouldn't.

The Pro Mini is the blue board at the bottom. The red board is the TB6612FNG motor driver, and next to it is a 3.3v regulator for the electronics. The black board is the nRF24L01 transceiver. It took a while to wire it up, but it worked first time! The two thinner wires on the motor driver go to the motor, and will be redone neatly later!





The most fiddly bit was the 7 wires going to the transceiver. The most time consuming part of the job was working out how to assemble it!





Very standard looking AAA battery holder and batteries, except these are 3.6v Li-ion. I'm hoping I can use a single one of these batteries in my Kato powered O9 locos.

 


This is a Lima GWR diesel railcar, that I converted to EM gauge several decades ago. The original motor apparently needs around 7v to start, and would probably eat batteries, so I've replaced it with a Susumotor, AKA a CD drawer motor, which is a nominal 5.9v. It comes with the right gear already fitted, and fitting instruction, that I mostly ignored as they tell you to stick the motor in, and I 3D printed a mounting. Running isn't great at the moment, but OK. The gear train isn't brilliant, and converting to EM didn't improve it. I'll give it a good run on the rolling road to see if that helps, and to see how long the batteries last. But it works, and should be usable, which is all I really care about with this one. Perfect running can come in future locos!







____________________
John
Back To Top

 Posted: Fri Dec 27th, 2019 04:22 pm
  PMQuoteReply
8th Post
John Boshier
Registered


Joined: Tue Nov 26th, 2019
Location: United Kingdom
Posts: 23
Status: 
Offline
While I was at it, I took some photos of the Tx, to show how it's assembled.
Some of the wiring is a bit messy, as it originally had an Arduino Uno, and only one slide potentiometer.
This is obviously the front:





Here it is naked! The two slide pots are fixed in place. In the top right corner is a rotary encoder that I may, or may not, remove. The 16 key keypad and 320x240 colour TFT display just plug in. Those with sharp eyes may spot a superfluous 4 pin header socket, where I original had an OLED display before changing to the TFT. Note the very effective support for the top of the keypad! One day something more sophisticated may replace it!





This is the back view. While testing I put it down across a piece of track, which must have shorted out something on the nRF24L01 transceiver at the top. At least it just plugs in, and they're cheap! The Arduino Mega 2560 is the big blue board at the bottom. I need a battery mounting of some sort in the space at the top:





Here it is naked:





When I eventually get round to getting my filament 3D printer working again,
I need to design and print a case for it, to avoid future accidents!




____________________
John
Back To Top

 Posted: Fri Dec 27th, 2019 04:26 pm
  PMQuoteReply
9th Post
John Boshier
Registered


Joined: Tue Nov 26th, 2019
Location: United Kingdom
Posts: 23
Status: 
Offline
I'm wondering where to go next. The railcar needs plenty of testing, but the next phase is the modelling bit where I fit the electronics neatly inside and put it all back together. The Rx does work, and seems to prove my efforts so far have been heading in the right direction, but it's big. It's fine for 4mm scale heretical diseasals, but I've only got one of those, and I want to use it with my 7mm NG locos. That Rx and battery won't fit inside the O9 Ruston Proctor (a free download from Shapeways designed by Tebee), which is currently next on the list, despite it being over scale. So I need a much smaller version, which has always been my plan. The person I originally got the idea from was using a microcontoller chip from the same range as the ones used in Arduinos, which was beyond me when I started on this, but hopefully it's not now. So I think it's time to start on the next stage, rather than trying to squeeze more Arduino Pro Minis into small spaces.

I haven't tested any of this yet, so it may not work, or may just defeat me, but this is the current idea. The black board at the bottom is the nRF24L01 transceiver, with it's pins sticking up on the left. On it's back with it's legs in the air is an ATtiny84 microcontroller. The green board is the controller out of an SG90 servo, which can be adapted into what's known in the non railway modelling RC world as an ESC (electronic speed controller). I've read and watched videos on how to do it. This should all work on 3.3v, and the idea is to use a single 10440 (AAA size) 3.6v Li-ion battery. These have a maximum output of 4.2v, which is too much for the nRF24L01, but hopefully a diode in the battery feed should solve that, and it's smaller than a voltage regulator. The ESC needs a couple of resistors added, and the nRF24L01 may need a capacitor, although I may get away without it as it's not working as a Tx. The loco will have a Kato chassis. If anyone has any suggestions I'd like to know them.





This is a size comparison with the railcar Rx:





I've just ordered a 14-pin ZIF socket to make a programmer for the ATtiny84, so have a few days to think about it before I start.




____________________
John
Back To Top

 Posted: Fri Dec 27th, 2019 10:01 pm
  PMQuoteReply
10th Post
bobquincy
Registered


Joined: Sun Jan 27th, 2013
Location: Florida USA
Posts: 303
Status: 
Offline
I am following this with great interest!

DRV8835 and 8838 will work down to 0 V (motor supply),
although they need 1.8 V logic supply.

I have used analog servo boards as ESCs,
they work ok although the deadband is sometimes too narrow to get the motor to stop.

A dedicated microcontroller may be the way to go for low cost and small size.
Maybe you can even get by with an 8 pin chip.

Keep up the good work (and sharing)!

boB




____________________
Monorail modelers have a one track mind.
Back To Top


 Current time is 12:22 pm
Page:    1  2  Next Page Last Page  

Freerails > Model Railroad Forums > R.C. The Future Now If You Desire > 'Arduino' Based R.C. For Locos & Layouts
Top



UltraBB 1.172 Copyright © 2007-2016 Data 1 Systems