Bojan Pavsic

Train automation - upgrading PF

Recommended Posts

Since i'm very much involved in our LUGs displays, i have some experience in different Lego train technologies. There is 12V which is perfect for displays, but costs a little fortune and has some weaknesses with track contacts and pickups. Then there's 9V which is still used a lot in displays. There's quite some interesting options (ME rails, 9V motor repairs) but lacks the "control" of the 12V. And ofc, it's obsolete from TLGs point of view. Basicly if we wanted to go with the flow of time, we had to switch to PF. But a new problem came into view because we don't only display city/train dioramas. There's Technic too which messes up with the PF channels.

After some thinking, tinkering and designing, we finally have a promising alternative for PF trains.

I tried to keep everything very affordable and as small as possible and the result are a couple of modules that make our dioramas more interesting to the public (especially the kids) and have a lot more control.

Let's cut to the chase...

Some highlights:

- The whole system works with RF (radio frequency) at 2.4 GHz. The frequency can be set from 2400 MHz to 2483 MHz in steps of 1 MHz (but can even go up into the 2500 area, so it doesn't interfere with WiFi & Bluetooth). They can be "hidden" inside creations, since they don't need the IR sensor to be in visible range.

- RF transceivers (transmitter + receiver) are used, so 2-way communication is possible (thou not yet used, but there are some ideas).

- Custom LiPo batteries that are smaller, can be recharged faster and have higher capacity then TLGs.

- Multiple control options (tablet, phone, pc, ...)

- Modular.

First there is the IR receiver replacement (the little connector on the right side is for debugging & programming... isn't there in the final cards). It's a PCB with dimensions of 21 x 29mm (3 x 4 studs minus 1.5 mm on each side, if maybe there will be a 3x4 case made). It has a 3.3V voltage regulator, a 32 MHz micro controller (Atmel Xmega16D4), 3 status LEDs (1 is power, other 2 are for info / status / lightshow :grin:). There's a connector for wire communication (I2C) and power supply. Another connector is for the communication card (currently it's a RFM73, but there will be an IR card too - for PF compatibility). It also features 3 headers for a "daughterboard". Let's call this module the "receiver".

The second module is the driver card (it's an old picture, that doesn't have both driver chips and output connectors soldered yet). It is the "daughterboard" for the before mentioned receiver. It features two driver chips DRV8833 (same chip that's built in PF IR receiver V2), which makes it possible to control 4 motors (twice as much as the original PF receiver). It also has a power connector with separate

pins for each driver chip (2x up to 3A power supply). A picture of both cards next to eachother.

There will be different modules in the future: 10 LED channels for lighting or semaphores, 2 motors + 4 LEDs or servo + LEDs for track crossing or track switches.

The third module is the "control" card which has 4 RJ45 connectors (network) with 6 input lines + power supply in each of them so 24 inputs all together. 4 boxes with buttons can be connected to it. They're ment to be put on the "keep away" fences in front of the displays. When a button is pressed, the microcontroller send the command to one of the receivers over the cable (for non-moveable motors like a windmill or anything that's not like a train) or over RF to a receiver inside a train. The command can be preprogrammed with a timer so it switches the motor off after let's say 30 seconds (That's a win-win because kids LOVE to press the buttons and check what they do, on the other hand the motors are not running the whole time of the show which lowers the battery usage & spares the motors). The "static" motor receivers use the PC ATX power supply (with DC-DC converters to lower the 12V down to 9V).

The power supply part includes some LiPo cells (1200 mAh) with a 2S LiPo protection circuit. Dimensionwise it fits into an AAA battery box with half height (basicly it's a 4 x 8 x 2 block). Cells can be charged with 5C, discharged with 15C, so plently of power :) I'll switch the 2S PCM with some BMS (BatteryManagement) that will make it a "smart battery" with all the info that a phone or notebook battery has (cycles, temp, max. current etc..). It will be possible to notify the user when some battery will run out in a train etc...

I made a usb stick with the RF transceiver too, so everything can be controlled and setup from a pc.

WIP is a WiFi module with a web server that will be enable connections from any mobile device (notebook, tablet, phone) and control & setup everything.

Another WIP that i'm currently working on is fitting the train engine receivers with a MPU9150 module (3-axis accel, 3-axis gyro, 3-axis compass) from which i'll try to get some usefull data about the x-y location (i hope i can get good enough data by using kalman filtering on the sensor data and correct the errors that will skyrocket after 2 integrations: accel -> velocity -> position). Here's where the 2-way link will come in handy because if the positioning will work as i hope, then there's a posibility of "auto-pilots" for trains, that will watch over the train compositions so they don't colide.

Anyways... it's a WIP, just wanted to see if anyone has some additional ideas what could be useful to have in this system.

p.s.: We have a display this weekend, i'll make some additional pictures from there (the system in action).

Edited by Bojan Pavsic

Share this post


Link to post
Share on other sites

Amazing ! Basically a wholesale replacement for IR. What interests me the most is the battery system. I have toyed with lipos before, but have failed to find a protection system for them...

Share this post


Link to post
Share on other sites

Not sure if i can post an ebay link here, but it's the SM157 LiPo PCM. China made :) But i already got sample ICs from TI and i'm planning on building a full blown BMS with primary & secondary cell protection, gas gauge, sm-bus (which is basicly i2c that already exists on the receivers so it can gather battery data and send it back...).

The cells are Turnigy nano-tech 1200 mAh which are used for hobby/model RC planes, cars etc...

Well, yes, it's a replacement for IR (the RF cards support up to 5 byte addresses, so basicly unlimited, compared to 4 channels with PF). But i will probably make an RF transceiver pin-compatible IR sensor that can be used to use the receivers with the original PF controllers.

Another thing is to replace the PCBs in the original controllers to add support the RF cards, but currently i only have tin plated PCBs and for the controllers should be gold plated (since it has button contacts...)

Share this post


Link to post
Share on other sites

This is really great to see that somebody else is workin on this! I am also looking into an RF option for PF. My favorite is somehow the 868MHz spectrum. Did you look into PIC powered stuff, there are PIC processors that have the wireless stuff included.

My intention was to have a 1:1 retrofit for the IR Receiver, same formfactor but with RF.

Same reason as you said, IR is not very useful for exhibitions and with bright sunlight it is not reliable!

Share this post


Link to post
Share on other sites

Very nice project! I prefer Arduino / Teensy and try to keep some PF compatibility (because it is also doable for non-engineers and because I teach Arduino in high school and college ;)). You did a great job however! How are the concurrency capabilities?! We have almost finished an educational project that controls trains using XBee, our own China-made Arduino (uh, the print that is, soldering is our own work) to make a train that works with color sensors etc.

Share this post


Link to post
Share on other sites

@freakwave

No, i didn't. Tbh, i switched from PIC to Atmel some time ago. Atmel also has some RF series, but tbh, these uC are hard to get and cost more. About the spectrum. I was checking out 433, 868 and then switched to 2.4gHz... Reason: cost of the RF modules. I bought 100 pcs of RFM73D for about 120$. There's an alternative too... NRF24L01+ which has a different connector (2x4 @ 2.54 pitch while the RFM has 1x8 @ 1.27) but is pin to pin compatible. Even registers and everything is like 99% identical and these can actually be bought for less then 1€ a piece (thou it's slightly bigger overall).

At first i wanted the same (retrofit - exchange the PCB in the IR receiver), but then i actually wanted it smaller then the original so it could be fitted in a 4 stud wide model (by using panels on both sides). That's why i settled for 3x4 dimension.

@JopieK

Yea, those aren't bad, but i wanted a custom board. It'll have full PF compatibility if the IR communication card will be used.

At some point over the year, i made a PCB with an ARM processor (LPC 1114) which is an Cortex M0 microcontroller. I took the small one in QFN package (5x5 mm) and i also had the drivers on the same board with additional 4 mosfet outputs (so 4 pwm motor + 4 pwm mosfet for leds & stuff). I scrapped that because it was hard to solder (thou i have hot air station). The biggest problem on a board this small are actually connectors. The power supply has to support 6 amps (each driver has two 1.5A outputs and there's 2 of them). The motor outputs have to support 1.5A each. Even AWG 22 or lower flat cables are soooo hard to find (practicly there's none, at least not any that i found). I'd like cables that TLG uses, but can't find any that would support 1.5 amps.

XBee is nice. But costs a lot.

What do you mean by concurrency capabilities? How many can be controlled at once? Didn't try more then 2-3 for now, but since the RF comunication goes up to 2 mbps and i'm sending like 6 bytes, the transmit time is very short. And the RF modules have built it retransmision and acknowledge, so no worries whatsoever.

@dr_spock

Well, depends how your switches are motorized :) If it's PF/9V motors, then yes, ofc it can. But i'll add another part that will support RC model servos which can be very small (i have some in dimensions of a 1x2 brick - will try to control switches with them).

I'm getting a 3D printer in a couple of weeks and i'll try to print some housings for the receivers and some lego compatible RC servo holders etc...

Share this post


Link to post
Share on other sites

Hello:

I have been interested in trying to implement additional and better functions into Lego trains. I am not an electronics engineers but here are features that I would love to see:

1. Sound, sound, sound. A couple basic diesel prime movers and a steamer would be amazing.

2. additional speed control, especially slow speed control.

3. More channels.

Let me know when we can buy one! :)

Cheers ,Steve.

Share this post


Link to post
Share on other sites

Excellent project, very interesting! I question why you would look at using WiFi vs. Bluetooth LE. WiFi cards are like 4-6x the cost of BT cards, they require an access point or complicated Infrastructure Mode configuration (like on the AR.Drones), and consume vastly more power (I know that you have LiPos but why not save that energy for the motors?). I'd recommend taking another look at BT LE-- most of the modern phones now support LE, so you could still have your control.

Also, if you need flat ribbon cable 22AWG or finer that will support >5A, check out McMaster-Carr. Their product numbers 9634T201, 9634T203, or others in this same series should work for you (depending on how many conductors you need).

Share this post


Link to post
Share on other sites

@SpokaneSteve

Yea, sound module was one of the future options too. PF has 7 speed stages, my receivers have 100 (in %), but you need to keep in mind that at low duty cycles motors don't have as much power so many of that 100 stages aren't useful at all. And finally, i'm not into making this a commercial product. I will publish the PCB files, firmware source and everything so everyone can make them (the problem is only that they have to have some knowledge about it).

@Rob Klingberg

I wasn't talking about WiFi modules connected directly to the receivers. I will keep using the 2.4GHz cards, but i intend to make a WiFi gateway that will just "forward" the commands from the WiFi network to the RF one. Thanks for the info about the cables. I was actually looking at http://www.moddiy.com/products/Corsair-Style-5%252dConductor-Flat-Ribbon-Cable-Wire-%2822AWG-Black%29.html]Corsair Style cables[/url]. They have them in 18 and 22 AWG with 3, 4 or 5 conductors. The thing is that i'll need to buy a "sample" quantity first to see if they're what i expect from them. Then i need to check if they're compatible with the connectors that i'm currently using.

Share this post


Link to post
Share on other sites

After the whole weekend "testing" at our local LUGs Lego event, some minor glitches came to the surface. The motor driver chip has a Chip Enable line, that has to be pulled up to enable the chip (it's a power saving feature, so u can disable the whole driver if not needed). The thing is that the driver works at 9V and the micro-controller works at 3.3V. A "1" from the uC can cause problems in case of little voltage drops (especially when multiple motors are driven). We had 12V LED strips powered at 9V too and the these voltage drops caused the driver to disable which again caused flickering of the LED strips. At site, i had to cut the CE lines from uC to the drivers and pull them up to drivers power supply (with a resistor ofc) so they were always on (They used up a little bit of power even when all outputs were off, because of the internal chip logic, but that's so low that it isn't really an issue).

All in all visitors (especially the kids) were very happy pressing the buttons and watching what they start. I implemented some additional options like a command that starts a motor in one direction for some time, then switches the direction for some time (a motor was moving a boat out of a cave, then brought it back inside). Another "special" command was random flicker of LED lights in some skull head eyes (like lightning).

Back to the drawing board now... implement a couple little PCB changes, have them made and finish a "final" version :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.