(No one should follow anything in this thread at all, ever.)
I am in the process of building a Model Railroad Engine Controller.
This first post will have all the updated schematic, code, and images.
It will be edited to include the latest code and design as I develop them.
The latest code with html control is attached to this first post.
(I have removed the ground side diode, fuses, to prevent ground floating)
Click link to get image bigger (3meg image)
I purchased a North Woods Logger G-scale train set by Bachmann.
Everything about this train set sucks(mostly).
The track is cheap hollow steel, the engine smoke device leaks and is entirely too large, and barely puts out any smoke.
The leds are dim and a dull orangish color, the engine and tender circuitry is completely analog and useless.
The tender came with sound that literally sounds like someone banging a trashcan with a baseball bat,
(they used a hand full of discrete parts to make it), I'll give them an A+ for making a chuff sound with as little parts as possible.
The motor circuitry was almost nothing, it was powered by DC on the tracks.
I purchased a LGB 5v smoker, brass LGB track, bachmann is all about profit, made in china, and reduced costs as much as possible.
However their couplers are decent and look good, and cars look good, and engine frame/tender are ok, and all their wheels are metal, (surprisingly)
The tender has a large 1/2 watt 8ohm speaker which sounds ok with the proper amp and signal.
Currently the engine is only going to be controlled by a WIFI webpage that resides on a CODE customized Parallax WX Esp8266 WIFI device, connected to a ActivityBoardWX (rev1)
The track voltage is 14v and can be DCC because I am using a GBU4G full wave 4amp rectifier. (I need to include a larger capacitor than I currently use, so I just use 14vDC for now)
The motor drive is a Parallax Dual MC33926 board, which is fully wired for PWM control, status flag, and the current feedback is connected to the A2D chip on the ActivityBoardWX.
I currently only use 1 channel of the dual board, I will eventually use the other channel to power a cooling fan in the tender. (g-scale engines get hot in the outdoor sun)
The sound is also driven by the ActivityBoardWX, however I will need to find an amplifier, because it doesn't have enough power to push a 1/2 watt 8ohm speaker.
I pulled out the speakers from an old music cell phone, but they won't work due to a severe lack of power, with an amp of some kind, I can use the tender housing as a effective baffle.
Eventually I will drill small holes in the sides of the tender to use the cell phone speakers with, that is not my priority as I don't have an amp/circuit resolved yet.
The smoker was replaced with a LGB 5v smoker, which looks good quality, and doesn't look like it will leak, I will need to modify my setup to fit it in the smokestack, right now I just put it inside the smokestack sticking out.
The ActivityBoardWX is powered by 14v rectified track power (with the regular voltage drop from the rectifier).
I am currently using 1amp fuses during testing, but as I turn the motor, I will pop these, so I will need to use different fuses to power the motor board.
One of the axles inside the engine has a crude switch to sense the axle rotation for chuff sound, its just a copper metal flap pushing against the axle. The axle has 2 positions with conductive metal, so 1 full rotation of the axle will close the switch twice.
I wired the axle switch so that one side goes to ground, and the other goes to a H11AA1 optoisolators led, with a 1k resistor to 3.3v.
I will wire the optoisolator led to track voltage, because attaching it to 3.3v makes optoisolation pointless.
I just did this for testing, and the axle sensor SHOULDN'T ever touch track voltage, but bachmann made in china.. dont trust it.
I optoisolated the axle sensor for any possible shorts with track voltage of 14v, I don't want that going to my propeller pin.
The output of the H11AA1 goes to a prop pin with proper pull up resistor and a protection resistor going to the prop.
The headlight in the engine and the rear light in the tender will both be replaced with a Luxon Rebel LED with proper resistors to limit current, these are very bright at very low current, exactly what I want.
The rear light will be blue, and the headlight will be a white-orangeish color.
I would put a deep red rebel led into the firebox, and a white one in the cab, but I have run out of wires from the tender to the engine, I may just run another since its pretty easy, the wire bundle is already there.
I may one day use "EL wire" to make the engine look like the back to the future one, lol, but elwire uses seriously high voltage, so if I do that, it will be battery powered.
I would also only do that if I had other, better engines, like the big boy, and some diesel engines. (If wishes were fishes, we'd all live in the sea?)
The tender is the only electrical pickups for it all, which are copper metal pressed up against the metal on the axles, because I don't have enough wires to run electrical pickups from the loco also, but if it gets bad, i will wire those up also.
I am hoping a very large capacitor in the tender will solve that. I could replace the tender wheels with higher quality LGB ball bearing wheels that have nice electrical pickups with good connection points, but only if I need that.
The control of the engine is currently done using the Parallax WX esp8266 wifi device, and their open source code for it, I have modified it a bit so it looks more custom to the engine.
I don't have the code working at all for it yet, I am still learning how that happens, but the SPIN examples have left me in the dust, they are basically non-existant. The C code examples are excellent, and very thorough.
I am slowly learning how the C-code works and perhaps I can recreate it in spin, I am not sure how extensive it will be to make a spin file for the INCLUDE files they show in the c code to talk to the propeller.
The motor control in software is also something I will need to learn how to do, but that seems much easier than getting the WX to talk to spin code on the propeller.
I will also need to learn how to read the signal from the current feedback into the ActivityBoardWX A2D chip, I do not know if any examples exist in spin yet, I need to look into that.
I did some sound tests to play wave files from the microsd card plugged into the ActivityBoardWX. My tests went ok, but I quickly learned I will need to learn more to do multiple wave file output, if I want any kind of decent sound.
The idle, chuff, whistle, steam effects, brake squeel, coal shovel sound, wheel slip, and STACK TALK (very important), will all need to be able to be played simultaneously, so that means over 8+ wave files need to be accessed on the sd card and played independently, at any given time, potentially all of them at the same time. I don't know if the propeller is up to that task, I may need to limit that.
I plan to include more fuses and TVS diodes for an enhanced circuit protection, I am tired of my model railroad electronics frying.
This whole project was inspired by my problems with a brand name DCC command station going nuclear, up in smoke in less than 2 seconds simply because the manufacturer failed to include some of the most basic protection circuitry available.
for 10cents they could have saved a 250$ command station, a 60$ decoder/motor drive, and a 40$ sound unit. Seriously?
I gave up on the repair because after repairing 6 npn, and pnp transistors, the programming voltage still was not rising to the proper level, showing other damage that wasn't obvious.
You can read all about it here: https://forums.parallax.com/discussion/172039/can-ya-help-me-not-throw-250-into-the-trash-circuit-repair-help-request/
As far as DCC track control, I have not worked on this part, I may someday, but that would require more circuitry and extensive work in the SPIN program once I have all the above working I may start at.
But that would require me to create a Custom Command station of my own, this involves precise current sensors, powerful h-bridge, 10amp 14v power supply for it, and all the code involved, plus making a throttle device etc.
One problem with using wifi is I don't have a way to detect which block the train is in, for automation of train using JMRI control software.
However I have looked into multiple potential solutions to this and RFID might work, if I can get a RFID detector close enough to the tags that would be under the track.
I do not know if the track brass that has 14v dc would affect the RFID signal, I will need to do more testing to find out, and I have read some attempts by others to boost the range of RFID...
Using opto sensors for track block detection might work if the (IR) sensor is on the tender looking down at a reflective material of some sort, and even possibly using neodymium magnets under the track with reed switches on the tender trucks.
I would need to make each signal be unique so I can tell what part of the track I am on, that makes using IR and magnets abit more difficult, multiple (8 of them) sensors under the tender, on the trucks in strategic locations might work.
Then each sensor can be used in combination with others to make a unique "signal".
I just realized after reading this thread over, using a BARCODE laser scanner to read track zone barcodes in between the sleepers, might be a very realistic solution to this!!!!
Here are some images of my current progress, I will be posting a schematic very soon, (working on it now) because its very hard to code by just staring at the wires to remember what goes where to what pin.
My web page control is not working due to a lack of SPIN examples with the Parallax WX wifi device, they have C examples which have helped me start the html code for the webpage control.
This will be slow going because I will need to learn how the C works and make an attempt to replicate it in spin. (feel free to get them examples made guys!)
That is all for now, wish me luck.
When I first started to install the ActivityBoardWX into the tender, I quickly realized I had to remove the speaker.
https://forums.parallax.com/discussion/download/131231/Activity Board Tender.jpg
I got a bit farther in tender wiring here, this is when I did some WAVE sound tests, you can see my test spin CODE here (most of the code is from the obex, THANKS GUYS!!!!):
I currently use FlexGUI and SimpleIDE for coding and uploading the propeller programs via WIFI.
I have now wired EVERYTHING up, (except the 5v smoker, because I forgot to order the relay in the parallax store, darn shipping costs are more than the relay)
Heres an image of everything wired in the tender.
And here is an image with the tender and engine, up on test roller bearing's (bachmann g-scale brand)
I power the track with 14v DC from a PS2012 digitrax power supply set to N-scale voltage. (13.8v)
Here is the webpage control that I custom changed and compiled using my ESP compile instruction thread.
Link to esp compile thread: https://forums.parallax.com/discussion/169250/parallaxwx-esp8266-raspberrypi-debian-esp-open-sdk-simpleide-openspin-proploader-devel/
My future plans are to wire up this engineering car with the track signals going to a LIPO battery powered Parallax Propscope connected via WIFI.
(esp8266 to esp8266 to prop plug to pc with propscope software, lol, no idea if that will work) to do TRACK diagnostics.
My bachmann caboose has a LGB rail cleaner kit (spring loaded) installed on the underside of the caboose.
I will NOT be manually cleaning the tracks. NO SIR!
I will be installing the bachmann smoker inside the caboose, once I fix the leaking issues, it will be powered by track power directly.(rectified and fused)
I put rubber on the wheels for more traction, (you need to use epoxy that can bond to rubber)
I installed a AMBER luxeon REBEL led in the front light.
And a Luxeon Z Royal Blue led in the tender rear light.