# Arduino multi-supply



## Shdwdrgn

A little something to wet your whistle until I have more time to update... I've been waiting on parts from China to build the smallest multi-output power supply that I could, and here are the results:










On the left, the black rectangle is the diode bridge. Track voltage goes to the top two pins (polarity doesn't matter). You can take track voltage at a known polarity (maximum 1.0A) from across the capacitor to feed the loco motor. On the right, the bottom pin is the common ground. Behind that is a 5v regulated output, again up to 1.0A output. And on top the solder pad marked "OUT" is a regulated 3.3V (800mA).

In total I have three available outputs to feed the motor, plus 5v and 3.3v to power various components of the circuit. Full size is approximately 20x12x10mm.


----------



## wvgca

Looks interesting ...
I do some process control stuff, but nowheres near that small
might have to get one of those critters and play a bit.. seems that they are pretty cheap?


----------



## Shdwdrgn

So here's a shot of the individual modules I used to put this together. I'm still waiting on a tiny 100uF capacitor, all I had in my box was 10uF -- not quite as good at filtering, but it was enough to provide a smooth output to my meter.


$0.99 - Adjustable DC-DC Step Down Converter Module
$0.20 - SMD 1A 1000V DIODE RECTIFIER BRIDGE
$0.09 - 100uF 25V 105C Electrolytic Capacitor
$0.98 - DC-DC Converter 5V to 3.3V Step-Down Buck AMS1117










There were a couple of coincidences here that allowed me to build this with minimal fuss. First, the plus and minus outputs from the bridge rectifier are on the same sides as the inputs to the larger step-down converter. I straightened the legs and soldered them across the pads on the front of the converter. Then I soldered the capacitor through the converter's input holes, ensuring the capacitor matches the plus and minus sides of the input. At this point you want to connect track voltage (up to 23VDC) to the two free legs of the rectifier and measure the output voltage from the converter. Since it is adjustable, you need to dial it down to approximately 5V. The components I will be using actually accept an input between 4.5v and 7.0v, so I don't have to be too critical, but it's still nice to get it close. I was able to adjust this module to 5.10v.

Once you have the output set, put a little paint on the adjustment pot to lock it in place. You will need to remove the connector pins from the 5v-3.3v converter. Now take a piece of wire with about 1/2" length of insulation and connect one side to the + output of the larger converter (note that on my large converter boards, both outputs are marked as negative - the positive side is actually on the same side of the board as the positive input). This gets routed in an 'L' shape to go around the body of where the smaller converter will be positioned, then the other end of the wire is soldered into VIN on the small converter. Finally, take another piece of wire and run it straight through the GND pad of the small converter, and through the - output of the large converter.

When you power up the completed unit, you'll notice the 5v-3.3v converter has a red LED on it -- a nice addition that lets you know when the entire module has power. You should now be able to measure ~5v on the output of the large converter, and ~3.3v on the output of the smaller converter (mine read 3.29v), regardless of the track polarity. The one thing to watch out for once this module is providing power to a motor is the heat on the bridge rectifier. 1 amp is a lot of power for such a small component, however every loco I've looked at generally has a large metal weight in it, which can handily double as a heatsink for us.

I generally buy these components in bulk packs, and you'll note most of the links above are not even sold individually because of the low costs. The entire cost for this project based on current ebay pricing came out to a measly $2.26 and about half an hour of time to put together the first one. One more thing I plan on doing is adding a drop of hot glue between the base of the capacitor and the bottom side of the bridge rectifier. As it sits now, there is very little holding the bridge in place so I had to be careful while hooking up my test leads.

As for usage... All of the arduino boards I have worked with will accept an input of up to 9V, and have their own step-down converter built in. However other small computer boards do not. I am currently working with an ESP8266-12E which has it's own WIFI radio, an 80Mhz cpu, and 4MB of flash memory, and is half the size of the smallest arduino boards I have. However this board only accepts a regulated 3.3v input, and I also need a 5v supply for the motor driver chip. The finished module presented here should satisfy all of my power needs for computerizing my trains, however I will probably also add a large capacitor across the 5V output leads to act as a short backup power supply for the computer, since the loco may lose power for a brief moment when going over frogs and such.


----------



## gunrunnerjohn

An important tip for this power source. There is NO common ground on the output from the input due to the bridge rectifier Given that fact, make sure no output is ever connected to either side of the input power, or anything circuit that shares a common with either side of the input power.


----------



## Shdwdrgn

Right, the two pins on the top side of the bridge rectifier connect ONLY to the track, and nothing else. But once you get past that, the voltage supply to the motor, 5v, and 3.3v lines all share a common ground.


----------



## gunrunnerjohn

Shdwdrgn said:


> Right, the two pins on the top side of the bridge rectifier connect ONLY to the track, and nothing else. But once you get past that, the voltage supply to the motor, 5v, and 3.3v lines all share a common ground.


Right, I was just noting for someone that doesn't understand what happens when you use a bridge rectifier to create DC power. 

This is a bigger issue with O-scale and TMCC electronics as the electronics shares it's DC ground with frame ground. That being the case, using a bridge rectifier for anything that has to interface with the existing electronics is a bad idea.

I'm assuming that someone with O-gauge may be interested in using the Arduino for rolling stock or engines.


----------



## ogaugenut

So if we want to put an Arduino into an AC 3 rail car, what is the proper power supply?

Bill


----------



## Shdwdrgn

This would actually do the trick, but you would want a much larger capacitor across the input pins. The bridge rectifier forces the voltage to a specific polarity with AC, just like it does with DC, however because AC voltage swings back and forth, a large capacitor will smooth it out enough to give a clean output.

Also it is doubtful this circuit can handle the current needed to run an O-gauge loco motor, and I'm not really sure what you would need to control an AC motor.


----------



## gunrunnerjohn

ogaugenut said:


> So if we want to put an Arduino into an AC 3 rail car, what is the proper power supply?
> 
> Bill


It would depend on how you were going to use it. If it was going to interface in any way with the existing electronics, you'd have to evaluate the options. When I do power supplies for 3-rail O-gauge, I typically go with a single diode and a common frame ground for the reasons I previously stated. That ends up requiring a larger filter cap, but the tradeoff is I have a common ground throughout all the electronic modules. For power supplies that don't have to have ground reference on the output, such as my LED passenger car lighting module, I use a bridge rectifier as it offers balanced power draw.


----------



## fcwilt

Hi,

Interesting unit.

Are you judging the ripple on the output with only a meter?


----------



## Shdwdrgn

fcwilt said:


> Are you judging the ripple on the output with only a meter?


So far, yes, I have not had a chance to hook it up to an arduino and check if it works reliably (I'm also still waiting on delivery of some larger capacitors). I don't have a scope so I can't really give any indicator other than whether the arduino runs reliably without restarting itself.

I put in an order for some more caps yesterday that I think will fit in nicely with this project. The first is a 47uF that is 5x7mm, which I think will work well on the input side. For the output, I found some 3300uF caps that are only 10x16mm. That capacity is large enough to provide about 1/2 second of run time on the arduino circuit I was using previously, and I know the new ESP chip uses even less power. I need to clean up my test track and try to start programming the new ESP to see how it works out...


----------



## fcwilt

You may find this interesting:

http://www.eetimes.com/document.asp?doc_id=1273282

You can also get some idea of the ripple if you have a true RMS meter with a suitable AC range.


----------



## Shdwdrgn

Sorry for the poor lighting, but here's some pics of the completed power supply. The new capacitors came in today, so now I have two 47uF/25V caps in parallel across the input, which still fit within the same original dimensions. I don't think I can pack any more into this small of package. 



















The next step is putting together the new computer components and see how much horsepower I can get into a similarly small area.


----------



## gunrunnerjohn

That's a pretty small little package.


----------



## Shdwdrgn

gunrunnerjohn said:


> That's a pretty small little package.


Especially considering the tip on my iron is completely shot. It's rather difficult to do pin-point soldering with a bowling ball. :dunno:


----------



## gunrunnerjohn

I have a problem doing any soldering with my bowling ball!


----------



## Shdwdrgn

You just have to throw them hard enough to generate heat. Here's what I use...










(Yes, that really is my contraption, although it looks like it will be torn down this Summer)


----------



## gunrunnerjohn

Why not take it to Delaware for Pumpkin Chunkin?


----------



## Shdwdrgn

I've been doing pumpkin chunkins and festivals here in Colorado since 2004... I love showing it off, but I'm burnt out on trying to get people to help. Everybody tells me how much they want to do it all year long, then suddenly can't take time off work when they've had all year to plan for the date. I especially love the ones who commit to the dates, then never show up or call. I've actually been trying to sell it as it stands, thought I had a buyer, and now they're not answering my emails... So screw it, I'll tear it down, see what money I can get for the materials, sell the trailer separately, and go from there.


----------



## Shdwdrgn

So after all these months I finally got around to trying to run a board with this power pack... And it fails! Basically I'm running an ESP8266-12E from the 3.3v pin. It runs long enough to get a little bit of serial output, but quickly overheats.

I *think* the problem is that the 3.3v regulator is a dc-dc buck converter which is being supplied from the 5v output -- and the 5v regulator is ALSO a buck converter. I don't really know how they work, but I have this feeling that they're not meant to be placed in serial like that. Unfortunately at the time I couldn't find any small 3.3v regulators that would take more than a 5v input. The only thing I can think to try is adding a capacitor across the output of the 5v regulator to dampen out any rippling that might be affecting the 3.3v regulator.

A perusal of ebay this morning netted me two new devices. The first is an adjustable regulator even smaller than the one I'm using for the 5v source above, so maybe I could just wire a couple of these back-to-back, set one for 5v and the other for 3.3v output. Not ideal though.

The second unit I found looks *very* promising though. It is a single unit that puts out regulated 5v AND 3.3v sources. It's a bit larger, at 15x20mm, however it looks like this unit actually has proper filter caps on it within that space, while I had to add my own caps to the other devices.

Both of these items take an input of up to 36VDC, and I'll still have to add a bridge to control the voltage direction picked up from the track. Still fairly simple to work with, and the device with the dual output is a complete package which eliminates having to mess around with putting together a bunch of other parts (meaning other folks here can make use of it without needing to know much about electronics).

In addition, I found some really cheap adjustable regulators with a built-in display. I ordered three of them, thinking I could set them at 3.3v, 5v, and 12v outputs, and use them to test the arduino setups on the bench. Considering the price, I'm sure I'll need to throw a large capacitor across the output of each of them, but at least I'll have some fixed outputs that I can easily plug in to.

Oh, I also ordered a camera and a miniature LCD display to play with. Maybe this Winter I'll be able to get some live video going from the test track.


----------



## gunrunnerjohn

Running an arduino board should be a piece of cake with just a linear regulator.

I have this little project that I just finished... It will supply 1.5 to 12V from track power. You have the option of half-wave rectification if you need a common DC ground or full wave rectification if isolated DC ground is OK. I've tested it up to around 100ma with no heatsink, higher currents will require some sort of heatsink.


----------



## Shdwdrgn

Isn't the LM317 from the same line as the 7805/7812/etc? I always thought those were horrible just for the amount of waste heat they put off. You get almost no heat dissipation from a dc-dc converter though.

FWIW, this is one of the boards I just ordered: http://www.ebay.com/itm/272253756552
All of the options I'm playing with use a common ground (in case that's a problem), but this little guy takes an input of up to 40V and supplies an output between 0.9 to 30V, up to 2A continuous. This auction doesn't mention it, but it will supply up to a brief peak of 3A. The whole board is only 10x15mm. Of course, like I mentioned, there's no decent caps to smooth the output, and other similar boards I've worked with require a cap on the input side or they won't provide a reliable output. 

You mention full vs half rectification... the only thing I can think of is your track runs on AC and you're using a bridge rectifier to switch it to DC? Even if that's the case, I'm not sure how a common ground is a problem. Aren't all the onboard electronics isolated from the AC source anyway?


----------



## gunrunnerjohn

Yep, but at low currents, who cares about the overall efficiency? I use the tool for the job. Every power supply doesn't have to be the most efficient on the planet. If it fits the application, then I use it.

For O-scale TMCC, there is a common DC ground for many signals, so anything I do has to consider that being a requirement.

For the board you reference, remember that you'll need caps added to that board.

I also did another board that used a switcher in a sandwich, actually two different versions. Here's the slightly larger one. It's a board sandwich, the eBay switching board is below it, you can see the hole in the PCB for the adjustment pot.


----------



## Shdwdrgn

Actually I'm not worried much about efficiency since it's all powered by the house anyway... however I don't like the idea of all that heat inside a small enclosed plastic shell (remember I'm working in HO), so that's a big reason for me to stick with the dc-dc converters.

Where are you getting your boards made at? Those look real professional quality! One of these days I need to find a low-cost service where I can have a small handful of boards made for my own projects.


----------



## gunrunnerjohn

I get the boards from Bay Circuits. I use DipTrace for my schematic capture and PC layout, and they have a direct order link to buy the boards. The minimum order is $30 + $6 shipping. For that they sell you about 18-20 sq/in of boards. For this board, I could get 29 of them for the $30 minimum, and they typically send you about 20% more, I probably got 36-37 for that order.

The boards have silkscreen and solder mask on both sides, they're 2-layer boards on .062 FR4.


----------



## Shdwdrgn

Wow that's a pretty good deal. It's been a looong time since I hand-laid and etched a board, I don't think I've worked with any pcb cad software in a decade because I wasn't willing to put in the time to make the boards. Glad to see these services available these days. Once I get my circuit figured out for the arduino I need a double-sided board to drop parts on, will be nice to just have the boards made for me.


----------



## gunrunnerjohn

If you haven't used any PCB software lately, it's improved a lot. There is, of course, a learning curve to anything, but I found DipTrace to be pretty easy. The thing I really like about it is their component editor is a lot easier to use than something like Eagle PCB. I found the Eagle component and pattern editor to be totally obtuse! If you do any quantity of layouts, you'll be making some of your own components. Unless the board is really dense, the autorouter works pretty well, and you can "tweak" the results to your liking once it completes.


----------



## Shdwdrgn

Hmm I wish I could remember the name of the last software I used, but I don't even remember which OS it was on. I do remember the component editor was pretty easy though -- basically laying down whatever pads you needed, or incorporating existing components into the new layout. I think the worst part of what I'm working with now is that I have parts with 0.1" headers, and other parts with 2mm headers, so I'll need a designer that flips between units easily. And the new ESP32 will have only 0.05" between solder pads... yikes!


----------



## gunrunnerjohn

I work with metric and inch parts all the time, no issues there with DipTrace. I looked at a few PCB layout packages before finding DipTrace. A nice bonus was the ease of ordering boards, a couple of clicks and they're on the way. There are a handful of places where you can order three or four boards and end up paying around $15-20 with shipping, but the convenience and the greater quantity of boards for just a little more money swings the deal for me with DipTrace.


----------



## Shdwdrgn

*sigh* But no native package for Linux. Ah well, one of these days I'll see what my options are.


----------



## Shdwdrgn

Well I should be set with parts to play with once the cold weather sets in. Ordered a bunch of different battery boxes and power supplies, plus I have a camera coming. This one isn't small enough to hide inside an HO cab, but it could still be sat on top of the tender... I've never worked with video before, so I figured I needed one with a full processing chip behind it to get my feet wet, then I can try moving to smaller units later.


----------



## gunrunnerjohn

What camera did you get?


----------



## Shdwdrgn

It's an Arducam based on an OV2640 camera. It uses the SPI interface to send data. Just like this one, only from ebay...

https://www.amazon.com/Arducam-Module-Megapixels-Arduino-Mega2560/dp/B012UXNDOY


----------



## Shdwdrgn

YAY! I got in the three-pack of large adjustable power supplies today. Set one for 3.3v (measured to confirm the reading), then reprogrammed the esp-12e, and it's working again! Now I can finally start working on some programming... I need to see if I can run a web page from the device, then start talking to all these various pieces of hardware I've been collecting. I have SD memory cards, a 3-axis compass, an RFID reader and tags... And for a garden project I also have a temperature/humidity sensor and a ground moisture sensor. Yeah I'll be doing a lot of programming over the Winter.


----------



## Shdwdrgn

Spent some time this weekend working on a new regulator board I got in. The first time I hooked it up, I couldn't get it to power the computer chip, so it's sat on the desk for awhile now. Based on what I'd learned from working with the previous boards, I tried putting a capacitor across the output, but that didn't help. Then I put one across the input and suddenly everything lit up! Now there are a couple electrolytics on the board already, so I was a bit surprised that it needed anything more, but after checking the traces I noticed the smaller cap was indeed across the input legs. The value was missing on both of the boards, making me wonder just what it was they put on there, however the 47uF that I had experimented with is exactly the same size. I removed the old parts, soldered in the 47uF's, and everything has been working perfectly. This pic compares the size between this unit and the very first one I experimented with on my train, with the new one being a full 1/3 the size of the original.










The next step was adding the bridge rectifier, and there happened to be a nice flat area on the back, next to the header pins, and with a convenient ground trace on the board. I scraped away the mask and soldered down one pin of the bridge, then soldered a second pin directly to out of the header pins. The other side of the bridge is for input from track power, and I added some temporary wires to hook up to my power pack.










What makes this board better than the original is that it puts out dual voltages -- 3.3v @ 500mA AND 5v @ 2500mA. (The bridge is rated for up to 1000mA total, well within my needs.) I need the 5v line to run the motor driver chip, and the current for the motor is taken directly from the bridge. Overall this board measures 19x15mm, and is 13mm tall. The footprint is actually smaller than the computer board. I do still want to include a very large capacitor for smoothing out areas of dirty track or short jumps across frogs and such.

Next step is wiring up one of the motor drivers and hook it to the 0-4-0's motor, then I can test the overall functionality compared to my previous circuit. And these parts will actually fit inside the tender, with room to spare!


----------



## gunrunnerjohn

I will tell you that there's no way that board is going to reliably put out 15 watts or more of power, it'll get VERY hot at those levels. The efficiency of most of those is in the 80-85% range, two to three watts in that size package gets fairly toasty.


----------



## Shdwdrgn

No, certainly not without a decent heatsink. The spec sheet on my computer chip says it only pulls a max of 250mA @ 3.3v, and the 5v line is only used for digital switching of the motor driver, so a fairly insignificant amount of additional pull. Overall I should be pulling less than 1W for the computer circuitry, plus the bridge chip will be pulling whatever the motor draws. I'm going to try and mount the regulator board so that the bridge is in direct contact with the weight plate in the tender, and hopefully I can do the same with the motor driver chip.


----------



## gunrunnerjohn

That makes sense. I have a couple of the little switching modules that I've made track powered "supplies" from. These are all various flavors of power modules. All power from track power, have DCS chokes to avoid DCS signal issues. Some are half-wave for a common AC and DC ground, some are selectable between half-wave and full-wave. The two piggyback modules use eBay adjustable voltage switching modules and wrap the rectification, choke, and filter capacitors around to make a track power supply. The 78xxT modules are all configured so the regulator can be folded under and bolted to a heatsink or straight and at the edge of the PCB to allow a heatsink or surface connection.


----------



## Shdwdrgn

Whew, you've been busy! Isn't it crazy what we'll go through to get a lot of power in a tight space?


----------



## gunrunnerjohn

I have varied power requirements, depending on the application. Sometimes I just need 10-15ma of DC, the tiny slim one is used for that task. The variable LM317T one if the flexible model, but it's a bit harder to assemble and parts are a bit more. The simple LM78xxT one can give me up to around 100ma if I heatsink the regulator. The TO220 form factor regulators are mounted so I can fold them over to reduce the footprint and also bolt them to a chassis or heatsink.

The two little switchers are based on two different eBay switcher modules, the slightly larger one is a bit more flexible and I tend to use it more.


----------



## Shdwdrgn

Well now I'm just kicking myself... The original information I had, including the spec sheet, all claimed that the L293D motor driver required 5V to power it, even though it could run with 3.3v signals. This was the entire reason I've been spending so much time working on a suitable power supply.

While looking for a reference pinout to hook up a test circuit tonight, I found something that said the chip would work on 3.3v power, so I decided to try it... Lo and behold, it actually worked just fine! GRRRRRR! This chip was the *only* reason I needed a 5v output.

Well, at least that simplifies things. I can run the whole circuit on a single 3.3v source, which means I can switch over to a regulator that is under 1/2 the size of the board I had pictured above (and maybe smaller, depending on what other options I can find).

Well the good news this evening is that I had my first live test using the new wifi-enabled computer and some tricks I learned. I can control the motor speed and direction now with a single digital output for direction and a pwm output for speed... previously I was using three outputs to control the motor. Tomorrow I'll get started soldering together some pieces to fit into my 0-4-0 and see just how small I can get this reduced.


----------



## gunrunnerjohn

One issue with running high power stuff and signal stuff on the same supply is cross coupling of the noise. I am working on a sound module that has an MP3 module that draws quite a bit of power, 150-200 ma peaks. When it was sharing power with the RF receiver, it was killing the range of the RF receiver. I had to separate the power supplies to solve the problem.


----------



## Lemonhawk

Old switching power supplies were notorious for generating noise right where you didn't want it. You would also think that filtering would be the answer but some if the noise generated is wide band noise and seems to blast thru any filter. Separate seems to be a good solution especially if a TX/RX is involved - nice to isolate it.


----------



## Shdwdrgn

So apparently you can't supply power through a chip without the ground hooked up? Who would have guessed??? 
[EDIT] I was fighting with the motor output for about 20 minutes before I realized I have never hooked up a ground line -- it gave the right voltage output when it was floating, but almost no voltage when I hooked up the motor.

I have a loose circuit assembled, with all the components mounted either directly on the cpu or on the motor driver chip. I added a plus and some extras for programming the computer, then loaded up the same code I'm running on the breadboard. Checking the voltage output from the motor driver looks great, but when I hooked up a loco motor, the code would get far enough to turn on the motor forward, then freeze up for several seconds before resetting itself. I let it do this for a few minutes, and it never got past turning on the motor. This is the first time I've had to troubleshoot motor noise, but no time left to poke at it tonight. I have a bin full of filter caps though, just have to figure out where to add them. Putting one over the power leads into the computer didn't help, so my next guess is the I/O lines controlling the motor driver chip. Shouldn't take too long to get it figured out though.


----------



## gunrunnerjohn

It may take more than filter caps, I had to actually create an isolated power supply.


----------



## Shdwdrgn

We'll see, but I didn't have any problems with the previous computer board, so I have this feeling it's something fairly simple...

By the way John, one of my improvements here is with the motor controller. Basically to control the motor direction, I need to drive two lines. One is always high and the other is always low, so it seemed such a waste to have to use two I/O ports on the computer to drive this. I found a real simple circuit last week using a 3904 and a pair of resistors to provide exactly the output I needed -- a single I/O port outputting both states to control the motor driver.

More importantly, I can use this same transistor circuit for common 4-wire stepper motors, reducing the I/O ports to only 2 pins (or 3 if I want to include an enable line to cut power to the motor between steps). This puts me in a good position to use an ATtiny85 chip from driving steppers, leaving two input lines free for momentary signals to indicate which direction to move the stepper in. I have all the hardware on hand now, one of these days I'll get around to programming one of the attiny's so I can test out the idea... (This is also what I was considering for the remote decouplers.)


----------



## Shdwdrgn

Ugh, it seems this may NOT be such an easy thing to solve. I finally found some caps suitable for decoupling across the computer power rails, need to get that soldered on tonight. In the meantime, I played with a larger 100uF electrolytic across various locations. The one thing that DID allow it to run for a few cycles was when I accidentally put the cap across the 5v and 18v positive leads (the ones feeding the motor driver chip). I don't know how I kept from blowing the cap in my hand, but it got very warm very quickly, so I had it running for less than 10 seconds. It ran perfectly through all of its cycles that way though.

So I'm thinking I'll add decoupling caps across both power legs of the motor driver, along with the one across to cpu, and see if that reduces the noise. And the problem is definitely from the motor, because when I unplug it from the circuit everything runs fine.


----------



## gunrunnerjohn

Yep, same issue I had with the MP3 module when it was playing music, it had a Class-D amplifier and the supply currents vary a lot during playback. That equals noise in the power supply.

The ground is actually more critical, so having a really good ground (plane if possible) helps a lot.


----------



## Shdwdrgn

Hmm the ground hadn't occurred to me... Looking at it now I see I daisy-chained the ground line from the motor driver, across the cpu to the power supply. I'll re-do that directly to the power supply when I add the caps and see if that helps clean it up.


----------



## gunrunnerjohn

It may not be enough, but everything helps.


----------



## Shdwdrgn

Got it solved. The bypass caps on all the voltage lines helped, but adding a 470uF across the input voltage (right after the diode bridge) cinched it. 330uF wasn't enough, so I'm guessing 470 may be borderline. Will see what I can find in a larger capacity and smaller package. In the meantime, more experimentation before I wrap it up and try to cram it all inside the tender...

[EDIT] Oh yeah, and the circuit is once again working correctly with the motor driver running on the 3.3v supply, so I'm back to a single voltage source again. Over the long weekend I'm going to try getting it to work from a smaller module (which surprisingly puts out a higher amperage than the regulator I'm currently using). Oh, and the reason the original circuit worked with the arduino board is because I had also put a rather large cap across the input voltage on that regulator.


----------



## gunrunnerjohn

Clearly, you need sufficient bulk capacitance on the input. The value really depends on the incoming waveform and the amount of current you're drawing from the supply.


----------



## Shdwdrgn

Well the current draw isn't that great. I'm using a surface-mount bridge rated at a peak of 1A, and it's not even getting warm running this old loco from the 70's. However my Tyco power pack is also from the early 70's, and I cannot imagine the output from it is anywhere close to what could be considered 'clean', which is probably why I've had to increase the built-in capacitors on the regulators I've been working with.

Even though I plan to eventually build my own fixed-voltage power supply for the track, I think it's still a good idea to set up the locos for worst-case conditions. Honestly I still need to add another capacitor as a storage cell for the 3.3v output because picking up power from the rails will be noisy and I'd like to be able to handle up to about 1/4-second power drops.


----------



## gunrunnerjohn

Maybe it's time to consider a supercap. You can have a lot more storage in a lot smaller space. I've done a design of a battery replacement for TMCC locomotives, it ends up having two sets of regulators. One regulates track power down to 5V for a SuperCap, and the switcher stage boosts it to around 8V for the RailSounds board. The goal is to replace the 9V primary battery with a track charged device that will never need to be replaced. It all fits into the 9V battery outline. The end goal will be to put the 9V connector on the end and heat-shrink the whole mess. The package is smaller than the battery, so that part is done.


----------



## Shdwdrgn

So a few things learned... First off, if you accidentally plug in a large capacitor backward and catch it before it pops, DO NOT immediately plug it back in the right direction without discharging it first. Thing had enough juice in it to destroy the voltage regulator I was working with. Ah well, at least I had another one. Second, when trying to troubleshoot mysterious computer resets, consider looking at any dumb things you're doing in the code. I had a simple loop set up that drove the motor off-forward-reverse-off... and that sudden reversal was apparently throwing some juice up the power lines. I added a 1/4-second off delay between steps, and now it's running solid again.

Last night I was playing with the idea of a large capacitor to maintain power to the computer chip if the track connection is dirty. To do this properly, you need a diode between the power supply and the capacitor, which drops the voltage slightly. OK great, I can work with this! The smaller power regulators I have are all adjustable, so I dialed one in to about 4.2V, and after it drops through the diode I end up with a 3.6V output which is great for the computer chip. The motor driver wants a 5v source, but works perfectly fine on the 4.2v side, and if the power drops out, the capacitor is *only* feeding the cpu. In theory this is perfect, but in practice, even using a pair of 3300uF caps, it's barely enough juice to keep the cpu running for a noticeable amount of time (it might provide as much as 1/10th of a second). So I started looking at supercaps again, and found something real promising... a coin-style package that is 3/4" diameter and maybe 3/16" thick, works at up to 5.5v (remember I'm working with only 3.6v), and has a capacity of 4 friggin' farads!!! I ordered a pair of them for $2, that'll be fun to play with when they arrive.

So I've been playing with various power regulators today. Was getting really frustrated with some of the setups because things just didn't work that should have. For example, trying to read voltage across the diode bridge and frequently getting nothing. And regulators that were working fine and suddenly stopped. Well it turns out that while troubleshooting, I skipped over something that seemed obvious it couldn't be the problem -- the jumper wires hooking up the components. Yes I had not one, not two, but THREE jumper wires fail on me through the course of the day. Since I'm still working on a breadboard, I was using some male-male jumpers and cutting them in half so I could solder one side to my regulators and plug the other side into the breadboard. Apparently the connection between the wire and the jumper pin breaks really easily. Ah well, got it figured out now. And I now have the smallest size regulator board (15x10mm) supplying power to the loco... and generating much less heat that the larger board was. I think I'm about ready to wrap up this circuit and drop it into the tender.


----------



## wvgca

Shdwdrgn said:


> To do this properly, you need a diode between the power supply and the capacitor, which drops the voltage slightly. OK great, I can work with this! The smaller power regulators I have are all adjustable, so I dialed one in to about 4.2V, and after it drops through the diode I end up with a 3.6V output which is great for the computer chip. The motor driver wants a 5v source, but works perfectly fine on the 4.2v side,
> .


If you wanted to, you can put two normal silicon diodes in series, rather than just the one, then you could have 5V in, 3.6 past the diodes


----------



## Shdwdrgn

Actually I found another board on ebay that is almost identical to the smallest board I'm using now, except instead of a pot they have a fixed-value resistor. They offer the board in a number of different voltages, and I've found that some of these sellers are making their own boards, so I sent them a message asking if they could make a few for me in a 4.4V version (that's where the last regulator ended up to give me 3.6v on the output). Figure it never hurts to ask, and it'd save me some effort if they came pre-set to the right voltage.


----------



## gunrunnerjohn

Shdwdrgn said:


> So I started looking at supercaps again, and found something real promising... a coin-style package that is 3/4" diameter and maybe 3/16" thick, works at up to 5.5v (remember I'm working with only 3.6v), and has a capacity of 4 friggin' farads!!! I ordered a pair of them for $2, that'll be fun to play with when they arrive.


Sadly, I think you will be disappointed. The internal resistance of the coin style supercaps is typically very high, so they can't deliver much current at all. I faced the same thing with the battery eliminator I posted previously, and I had to go for the larger and lower capacity unit to get the internal resistance down to a reasonable level. I needed to source around 200ma from the cap, and with an internal resistance of around 20-30 ohms, that precludes getting more than a 20-30 milliamps out of them without excessive internal voltage drops.


----------



## Shdwdrgn

Resistance in a capacitor? What is this world coming to?!? Next you'll be telling me there's capacitance in my breadboard and inductance in my jumper wires.  Besides, the description on ebay said these could be used to start a _car_, so it must be true! :bs:

Well that's a real shame. Still might be able to do something with them though, we'll see. I've never heard of internal resistance in these before, good info to have. And of course I checked back on ebay and they don't say a thing about resistance or maximum output current.


----------



## Shdwdrgn

Hmm I'm finding some caps rated at 4F with an internal DC resistance of 25 ohms, and they're claiming an output of around 450mA. How do you make the calculations to determine what current output to expect? And do you know what "low ESR" means?


----------



## wvgca

gunrunnerjohn said:


> The internal resistance of the coin style supercaps is typically very high, so they can't deliver much current at all.


The coin style do vary on internal resistance, with an ESR of up to 200 Ohms, depending on intended usage, you can get decent ones, but seldom off of eBay, and the cost is quite a bit higher for low ESR and greater current output..


----------



## Shdwdrgn

Yeah the ones that claim low ESR are slightly larger (about 25mm diameter) and are going for $3 each (2 for $6)... so triple the price of the ones I ordered. Maybe I'll put in an order for those too, it'll at least give me some comparison between different styles.


----------



## gunrunnerjohn

Shdwdrgn said:


> Hmm I'm finding some caps rated at 4F with an internal DC resistance of 25 ohms, and they're claiming an output of around 450mA. How do you make the calculations to determine what current output to expect? And do you know what "low ESR" means?


Well, if the internal resistance is 25 ohms and the current is 450ma, you can expect the internal drop would be around 11.25 volts, so it's kinda' hard to see how they're getting 450ma out of them!  .45 amps * 25 ohms = 11.25 volts, simple Ohm's Law.

There are lies, damned lies, and statistics.


----------



## wvgca

gunrunnerjohn said:


> There are lies, damned lies, and statistics.


How soon you forget about _*"Facts"*_


----------



## gunrunnerjohn

wvgca said:


> How soon you forget about _*"Facts"*_


True, but I think we're talking about advertising copy here, very few facts manage to make it into most of it.


----------



## Shdwdrgn

I ended up spending the weekend working on the code rather than fitting the electronics into the tender. Maybe I'll give it a shot tonight...

Basically my configuration now is a web server providing the bulk of the web page code (and allowing a single page to create the same interface for all of the future locos). Through javascript, the page queries the loco you specified for basic stats -- minimum speed to get the motor running, plus maximum forward and reverse speeds (defined and enforced by the computer on each loco). Also there is a variable for who is controlling the loco -- multiple viewers are allowed, but only a single person can be in control at one time. The web page will show what speed you have set, and the actual current speed of the loco. And I made it really easy to connect to the loco -- you basically put in an address like http://drgw3179/ and the page gets loaded.

The code on the loco's computer is tasked with answering queries about current values (speed, direction, etc), but more importantly it manages changes to the values to prevent damaging conditions and a more realistic operation. For instance, if you are sitting at a dead stop and throw the throttle to 100%, it doesn't simply take off, but rather slowly builds up speed. Similarly, if you are going full speed and hit the reverse button, it slowly backs down to zero before changing direction. It also manages who is currently controlling the loco and won't accept commands from anyone except the operator, however if the operator's browser hasn't responded in the past 5 seconds, the train will slow to a stop and then accept another operator to take over.

One of the biggest problems I was fighting with was constant timeouts trying to read the data from the loco. The code was supposed to request updates 3 times a second, but when I added some debugging, I discovered it was actually pulling 20-30 times a second! Turns out my time variable wasn't getting set right, so it was just grabbing data as fast as it could, and swamping out all over tasks. Got that fixed now, and it's running smoothly at 5 times per second.

Oh yeah, one other thing I figured out this weekend... The computer chip has a PWM output that runs on a 1khz frequency, but the motor didn't seem to respond well to that. I figured out how to change the PWM to 200hz, and now the motor is responding at slower speeds and with more power. All in all, a very productive weekend on this project!


----------



## wvgca

Shdwdrgn said:


> Oh yeah, one other thing I figured out this weekend... The computer chip has a PWM output that runs on a 1khz frequency, but the motor didn't seem to respond well to that. I figured out how to change the PWM to 200hz, and now the motor is responding at slower speeds and with more power. All in all, a very productive weekend on this project!


1Khz should have been okay, that is more than enough time for the coils to reach a fairly high percentage of saturation ..
You can calculate maximum recommended frequency if you know the armature coil resistance and inductance ..

as an example, resistance 3.4 ohm, inductance of 19uh, should give a time constant of 5.6us, so for a minimum PWM resolution of 1% the minimum pulse width would be 280us, [ten times the calculated frequency at 1% duty cycle], and a maximum frequency of 3571Hz for linear response..

Basically too low of a PWM frequency will give a 'choppy' drive, in this example it's around 20Hz, and too high will not allow time for high percentage saturation voltage ..and hopefully keep it in a range where the is little noticeable 'whine'

Cheap motors with large inductance values can tolerate a lower switching frequency because the large L/R time constant can filter out the low frequency PWM. The low switching frequency has the benefit of lower heat dissipation in the switch device, but the PWM will probably be audible and really annoying. Expensive motors, such as Maxon, Escap, Faulhaber, etc, often have very low inductance values so they work well with a higher PWM frequency. 

If you can adjust the PWM frequency 'on the go' as the motor is running it's much easier to find the 'smooth spot'


----------



## Shdwdrgn

At some point I will probably create some simple code for a debug mode, where the web interface can make adjustments to everything on the fly. Finding things like the stall point for the lowest possible speed of the motor could benefit from such a thing when testing out new locos.

In my case, very low speed at the 1khz value were producing an audible whine, but when set at 200hz there's no sound at all. Of course the test loco is an 0-4-0 from the 70's, while my other loco (as yet untested with this circuit) is a Bachmann 0-6-0 from the 90's. Even running on pure DC there are obvious differences between the motors in each, so I've tried to be careful in setting up parameters in the code for everything that could vary between different models. There's a pretty large block of variables at the beginning which set up the I/O pins for each feature, the wifi info, and controls for the motor. Later on down the road all of these values will be stored on the web server rather than written into the loco code, making it much easier to tweak the values rather than having to re-write the flash chip every time (and then the debugger will also be able to directly update the parameters).

Been playing with the code more in the last couple hours, found some more pieces I forgot to update, so now if the loco goes offline, the web page reflects that immediately. I still need to finish testing it through for all possible failures, but it's getting really close now.


----------



## Shdwdrgn

I finally got around to rebuilding the circuit on the bed of the tender...










On the right we have an L293D driving the motor. Underneath that is a 1x8 header to connect to the loco (I have some 0.005" headers on order). Above the chip are two headers, a 2-pin male and a 4-pin female. These are both used for rewriting the flash on the MPU. Moving to the right is the ESP8266-12, and underneath that is the power regulator and capacitor.

At the moment the whole bundle is twist-tied to the bed of the tender. It's good enough for testing for now, and I still need to add wiring for the loco lights and IR LEDs. I also still have to do some troubleshooting with my web code, as it only runs the train for a few minutes before losing connection. But at least I have something back on the tracks again.


----------



## gunrunnerjohn

Progress, that's what's important.


----------



## Shdwdrgn

Hmm so I'm definitely having a connectivity issue... Seems like it will run on the track for about 2-3 minutes, then the computer resets. That's not happening on the bench, so I thought I would increase the 5v capacitors. Even with 3 x 3300uF, I still run for the same amount of time before a reset, and it doesn't seem to matter what speed I run the loco at. Perhaps I need to increase the 330uF cap I have across the 18v input? I'm not sure, but I'll play around with it. In the meantime, I have some supercaps on order, that's what I hope to put in place of the 3300uF caps.

I think there's a couple of possibilities here. Of course the power pickup from the track is going to be noisy, thus the need for all the caps, and it may be that the supercaps provides enough of a buffer to get past that. The other thought is that all the noise on the line is causing the resets, because when I directly connect the 18v source (still allowing the motor to run with the loco on its side), I don't seem to have any problem with resets. That's why I thought maybe a larger cap on the input would help, but I'd be open to any other suggestions.


----------



## gunrunnerjohn

Well, I think I already mentioned that I had to do some serious P/S isolation for my sound board in order to lick the crosstalk issue that was killing the RF reception. I think you may be experiencing similar issues, the noise may be coming into the computer side do to the electrical noise of the motor driver.


----------



## wvgca

when the loco runs on the track, there may be intermittent voltage drops that may give some spiking on the input, but 330uf should be more than sufficient ..
there may be interference from the motor driver that is being picked up due to the way the components are laid together on the tender, did you have them wrapped like that during bench tests or spread out??? 
twisting connector cables may help ..or installing choke rings


----------



## Shdwdrgn

Currently running on the bench, the circuit is still twist-tied to the tender exactly as in the previous picture. The only difference is the loco is laying on its side. I did confirm the pickup wheels have been recently cleaned, and the reset is happening in random places on the track so it's not an issue with a particular spot.

At the same time I'm also having a code issue... occasionally the browser will freeze up for a few seconds so the train's computer registers a signal loss. I'm trying to make it so if the same browser picks back up again (easily reproduced by just reloading the page), it should see the same identifying key and resume control. I only had to add a couple lines of code to the loco, but it's a lot more complex on the browser side.


----------



## Shdwdrgn

Yeah the larger cap on the input made a noticeable difference. I added to 680uF to the 330uF, and ran for 7 minutes before getting a reset. Oh, and it just occurred to me that I forgot to plug the 3x3300 pack back in again. About time for dinner now, but I'll play with it some more tonight.


----------



## Shdwdrgn

I decided I better re-write my software to eliminate the stability problems there before trying to dig any deeper into the electronics issue, so I've been working on that since last week. Some folks I know online suggested I look into MQTT, and I really liked what I saw. I've pretty much gutted and re-written all of the web page and arduino software around this.

Basically MQTT is a transport protocol for very small packets of information. Since the majority of the information I'm sending is just small number for direction and speed, this works well. Also MQTT is a push-type protocol, meaning that instead of constantly querying to see if a value changed, it sends you the information when an update occurs which helps minimize the amount of network traffic needed. There are also other features which work really well with what I'm doing, but I won't go over all of that here.

So I almost have the web and arduino code back to the functionality I had before. I wrote in some blocks of code for actually controlling the train this morning, and will get them tested out tonight. The whole thing really needs to be tested from scratch, but the new code actually allows running a train from the internet -- fun idea, but not really useful until I get a camera set up. Oh and I also rebuilt the web page so it will size itself to different devices, even my cell phone... which is real handy since my test track and the computers are in different rooms in the house now.

I picked up a power pack off ebay that puts out 18VDC @ 3.5A (supposedly). It actually sparks when I plug it into an outlet, which makes me think the thing was made incredibly cheaply. I haven't tried using it yet other than checking the output voltage, but I'm thinking I should pull the thing apart and make sure it's not going to burn down the house.


----------



## gunrunnerjohn

Actually many powerpacks spark when you plug them in, they're typically switch mode supplies and they have a high inrush current to initially charge the input filter caps. Even a large number of laptop power supplies exhibit this behavior.


----------



## Shdwdrgn

Hmm true enough. Maybe I'll try hooking it up to the track and see what happens.


----------



## Shdwdrgn

In other news... Digikey is now selling ESP-32S boards! I put in an order for two and shipping was only $3.02. The software tools for this new board are still rough, but the capabilities of this board are really exciting...

Just some high points, multiple 12-bit ADC's, two 8-bit DACs, several SPI and I2C buses, touch sensors, temperature sensors, hall effect sensor, a real-time clock, a new bluetooth radio plus the standard wifi radio, a dual-core CPU running at 160Mhz... It runs from a 3.3V supply and has around 30 physical IO pins, and the whole chip is only about 18x26mm. This is the puppy that is going to allow me to add onboard cameras and a multitude of sensors to each of my locos.

Did I mention that the initial run of these chips are selling for a measly $6.95, and they're only going to get cheaper next year? Did I mention that I'm excited?


----------



## gunrunnerjohn

That's a lot of functionality for $7, no doubt about it.


----------



## Shdwdrgn

All right John, I'm running out of ideas here. I added three 0.1 caps on the motor (one from each terminal to the case, and one across the two terminals), thought for sure that would cut down the noise. Also realized I was taking the power lead for the MCU directly off the motor driver chip, so I moved that lead directly to the regulator. I also added another 0.1 cap at the regulator between ground and the +3.6v lead, and of course I already have one of those on the MCU itself. I'm still generally only getting about a minute of run time (varies anywhere from a few seconds to about 3 minutes at most). I did read something about adding a choke to the power line, but I don't know anything about chokes...

So, any suggestions I can try without completely rebuilding the whole circuit? It's next to impossible to try taking any measurements while it is running -- the circuit runs perfectly on the bench when I feed in power through clips, so it must be something about picking up power from the tracks, but I would think the 9900uF (total) caps across the 3.6v source would smooth that out.

[UPDATE] I thought of adding a 0.1 cap right at the input of the regulator and it seems to have made a little difference. Also I've discovered that running the loco backwards, or running forwards at about half the speed makes a huge difference in the run time, getting as much as 12 minutes. I'm thinking something in the power pickup may be causing the power regulator to reset (I remember something about buck converters running on a certain frequency?) but again it's hard to measure that. Wish I had a car with pickups handy, it would be interesting to see the difference from having more wheels on the track.


----------



## wvgca

You can make a small inductor with, ? 24ga magnet wire wrapped around a 1/8 metal screw, maybe am inch long for a test, to input of regulator ..
there's a formula to calculate desired effective frequency, but can't remember it right now


----------



## Shdwdrgn

That sounds more like an electromagnet. Isn't a choke wrapped around a non-active center? Yeah I do fine with digital electronics, but the analog stuff just goes right over my head.


----------



## gunrunnerjohn

Like I said, I ended up with a separate regulator, and you also need to make sure the ground is REALLY ROBUST for all the circuitry. Any ground noise will drive things crazy.


----------



## wvgca

Shdwdrgn said:


> That sounds more like an electromagnet. Isn't a choke wrapped around a non-active center? Yeah I do fine with digital electronics, but the analog stuff just goes right over my head.


well, kinda.. any choke with a ferromagnetic core is more effective than an open or air core ..
any time you have DC power pulses or reversals, there is some spurious RF emission .. most of the time not noticeable ..
that's why some people recommend using twisted pair for DCC buss lines for example ..

and any time there are physical 'loops' in signal, power, and especially ground lines, these can be similar to radiant antennas, keeping [especially ground] these lines relatively straight, and of a larger size than required can help ..

I don't remember much about this, it's been twenty years since I've done any RF stuff.. sorry ..


----------



## Shdwdrgn

No problems, any help is better than none at all, I just have to keep playing with it until I find the answer. Obviously from what you're both saying, I would benefit by replacing all my 30awg ground lines with the 24awg I have here, so I'll give that a try. I didn't notice before, but the regulator I'm using actually has a small choke on it already, so the only thing I can think of to help there might be adding another choke right at the V+ line on the arduino. In general my wiring isn't very long, but the way I have it laid on the tender right now created some folding in the wires. Could be interesting to see what happens just by unfolding the whole setup.


----------



## gunrunnerjohn

Good ground, better isolation of the VCC coming to the Arduino is what I suggest.


----------



## Shdwdrgn

Went to a small train show here in town today. Among other things, I picked up someone's attempt at a hand-laid HOn3 turnout for a couple bucks. While it doesn't fit in anything I have, it inspired me to start trying my hand at building one today. I figure it's a good time to step away from the arduino for a little while before I get frustrated with it. Got the notches files into the stock rails and the points are mostly done, just warming up the iron to start soldering the stock rails to some pc ties...


----------



## Lemonhawk

Making your own turnouts can be habit forming, so be careful. I use a 1" belt sander to make the frogs, points and remove the flange for the points. I use a homemade wooden jig to get the right angle for the frog - I just make the V part and solder it together. Use a paste flux (https://www.amazon.com/gp/product/B017RSGPI8/ref=oh_aui_detailpage_o02_s00?ie=UTF8&psc=1)
It will make less messy solder joints to the PC ties. Search for the Joe Fugate method of using CV ties to make turnouts! USE THE TRACK GAUGE, this is vital especially to se the V of the frog! If you use CV ties (which I don't think you can because of the track gauge) you need to put a couple layers of making tape on the bottom of the PC ties to make them slightly higher than the CV ties. For better points, try the Proto87 stores to get points that are more realistic and that do not require filing off the flange of the stock rails. Once you've done a few you'll fine a place where a custom curved turnout is needed, and then you will never go back to commercial turnouts!


----------



## Shdwdrgn

Thanks, and I didn't mean to turn this into another thread about turnouts as I've already had this discussion in other threads. I'll probably start a new discussion and post some progress shots as I go since I know there are some other folks here who are interested in doing the same thing.


----------



## mtfrizzell

gunrunnerjohn said:


> Good ground, better isolation of the VCC coming to the Arduino is what I suggest.




I would like to know more about the programming used in the Raspberry Pi to control things.


Sent from my iPad using Tapatalk


----------



## Shdwdrgn

mtfrizzell said:


> I would like to know more about the programming used in the Raspberry Pi to control things.


At the moment I don't actually have a Pi set up yet. I have several servers set up to run internet services here, so I created a virtual machine to work from...

With that said, the requirements on the machine are fairly low, but dependent on how many people you would expect to connect simultaneously. Under typical personal usage, I see no reason why a Pi Zero couldn't work for this setup. Since I run debian on my servers, I plan on using raspbian on the Pi. At the moment I am only running apache2 and mosquitto (plus mosquitto-clients for command-line testing). You would also need to set up the Pi as a wifi access point, and install dnsmasq to handle the connections.

On the ESP8266 I am running the async-mqtt-client library (you can find it on github) which is built to run on the ESPAsyncTCP library. I had originally planned to let each loco run as it's own web server, but if I were to take this setup to a show, it could be quickly overwhelmed by a lot of people trying to connect to one loco (especially once the video data is added), plus if I wanted to change the html code I would have to reload all of the locos.

I've started putting together a web page at http://wifitrain.link/ to provide information and the source code for this project, but I don't have any of the server-side information posted yet. I'll get there eventually though...


----------



## gunrunnerjohn

I have a Pi in the closet, I was given the little guy, but I've never used it.


----------



## Shdwdrgn

I have several kicking around, I use one as a media center on our TV to play shows from the computer. They're quite a powerhouse for such a little thing.


----------



## mtfrizzell

I was actually referring to using the Pi to control train operations. I currently have a Pi to support my wife's website for her Physical Therapy. I have been dealing with Unix for 30 years. Maybe I should hang out at a Raspberry Pi forum too.


Sent from my iPad using Tapatalk


----------



## Shdwdrgn

Ah... sorry, got my threads crossed.  Using a Pi as the controller, you would use similar hardware, but much different software. The biggest problem you're going to run in to is that the Pi has much higher power requirements than an arduino, which means correspondingly larger power regulators, and more trouble fitting it all inside of the train.

I have run across some examples of folks using python to control the I/O ports on a Pi. Most likely you would also start with raspbian for your project, and just hit up google for programming examples. As with the arduino, you can start with a simple motor driver chip like the L293D to control speed and direction, and then expand your program from there to incorporate more sensors and more complex routines. You'll probably want to incorporate things like collision detection and some way for the Pi to know where exactly it is at on your layout, and then give it tasks to perform like making stops between stations or loading docks.

Sorry I can't help with the programming part, but the hardware should be almost identical to what is used on an arduino. Just make sure you are aware of whether your Pi requires 5v or 3.3v signals on the I/O lines.


----------



## Shdwdrgn

So I've made some progress tonight... After some suggestions from other folks online I've made two improvements. First off, I had left the reset line floating so I used a pull-up resistor to keep it stable (didn't have much effect on the running time though). Second, I replaced my little power pack (I think it actually came from an N-scale train set?) with the 3.5A power pack I bought awhile back.

Huge difference! I initially ran for half an hour, until I bumped the speed up to max and the tender came off the track. Oops... Anyway I've reduced the cap across the buck converter inputs to a tiny 220uF (only 8x7mm!) and reduced the caps across the computer itself to a single 3300uF, but this one I want to replace with one of the 4.0F supercaps eventually.

I've run in to another problem now. The pickup from the 0-4-0 drivers are so unreliable that half the time when I try starting the loco, the wheels lose contact. I think the next step here is to add contact to the tender wheels, doubling the number of power pickups on the track. Not only should this help with power loss at startup, but I think it will also greatly improve the consistency of the power being fed to the buck converter. Then I think I'll have better luck testing at lower speeds.

So... progress is being made, I just keep flipping between different aspects. Eventually I'll get back around to the motors for the hand-laid turnouts as well.

Whew, that's enough testing for tonight. Sounds like the poor little loco needs a serious lube job, I'm starting to hear squeaking.


----------



## gunrunnerjohn

Be very careful when spec'ing out your supercap, many of the smaller ones with high capacity also have very high internal resistance and can only deliver very small currents. If you have an internal resistance of 20 ohms and a 5V charge, by the time you get to 100ma out, you are already down to 3 volts output from the battery!


----------



## Shdwdrgn

Eesh... well it'll be interesting to play with. Can I just hook it straight in, directly replacing the 3300uF electrolytic that I have in there now? If so, easiest thing is to just add it in and see what it does.


----------

