I'm considering writing up my little dual servo controller once I get the design and software finalized, but I think it may be too complex for MR - it still uses the Arduino and the Arduino IDE but the process is a bit more complex than directly using an Arduino plus you need to build a little circuit to attach to the Arduino - it's really just connecting wires from a pin on the ATTiny85 to the specified Arduino pin, except for the 10uF cap that needs to go across gnd and reset.
Software-wise it's really pretty simple other than the routine I cam eup with to stor the last position (so it can always position each turnout at the right spot on power up). The EEPROM in the AT micros is only rated for 100,000 writes (seems like a lot, but if you update the setting every time you push a button to throw a switch, and you like to run trains, you blast through that in no time). I came up with a routine that will stagger the writes throughout the whole memory, with one location used as a pointer to whatever block is being used currently - every other memory location hits the 100K writes long before the pointer gets written anywahere near 100K times. Since I am writing 3 bytes and the Tiny85 has 512K of EEPROM, I worked it out such that if you run trains 4 hours per day 4 days a week and for that 4 hours you change that one specific turnout 20 times a minute (warp speed switching, I guess), it would take 20 YEARS before any memory location accumulated 100K writes.
I just have to get the details down to make it work as a proper sketch. The nested counting loops are the easy part, getting it to work with the EEPROM library and loading the initial values at startup is the tough part. But in the end - $5 of parts plus servos that are under $2 each means less than $10 to remote control 2 turnouts.
--Randy
Modeling the Reading Railroad in the 1950's
Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.
I hadn't been getting any parts at Radio Shack for years, way too expensive, unless it was an absolute need to have right then and there. And now there are none. The last independent electronics shop disappeared over 20 years ago, so it's been mail order for me for a long time. Since the shipping on a small order is so much, I always ordered multiples, like the last time I ordered parts to build a LocoIO, I ordered enough parts for 4 of them even though I only had 1 PC board - because of some bulky components, going to 5 of each jumped the shipping costs. Likewise with model stuff, I never buy a single strip or sheet of styrene, if I need a given size, I will always buy a full pack of it. If I organized my stuff better I'd need a lot of storage cubbies and drawers, like the bank of mailing tubes to keep styrene and stripwood, and way more of those little drawers I have for electronic components. I don't have the space my friend, also an EE, but a practicing one, has - he has one full wall of his shop space in his basement lined with storage cabinets that reach from the floor to over 6 feet tall. Some of these things that I buy in qunatity, like the 100 packs of IC sockets, I should probably put like a dozen in a drawer and the rest keep in the bags and put in a plastic tote stored elsewhere - until I forget about them and order another 100 after I use the dozen. One thing at least is that once I actually get started on my layout, I will have much increased storage space since my plan is to use as few legs as possible, leaving the under layout space clear to handle 2 or 3 high stacked plastic totes for organized storage - labels on all of them. If I get really ambitious about it I might even make a map of the room and mark the general category of items under various parts of the layout - not holding my breath on that one.
The application of Arduinos to model railroads is really taking off - a few articles and tons of web information from Geoff Bunza over at MRH, several articles now in MR, including the most recent issue (December), and plenty of posts here. I'm kind of curious why Detlef hard wired the BOD-8's to his Arduino instead of sticking a compatible 10 pin connector on his shield and just using a piece of 10 conductor ribbon cable for the connection - most all of the RR-CirKit accessory boards are equipped with the common 10 pin connectors which is a perfect size since the Tower Control was grouped in 8 bits of I/O per port, so you get _ and - plus 8 bits in a nifty 10 pin connection.
I purchased an Anduino Proto/Screw shield on line and will run 12 leads to the structures LEDs via resistors, and RCA plugs/sockets in the structures for easy removal as you suggested Randy. Then return to the 12 block 5 volt common.
I also ordered a number of Barley Twist gas street lamps and will feed them via a toggle switch direct to power. (Random lit street lights would give the town a bad name!) So with the help of all you good men, I think I've sorted the lighting problems out. Thanks guys. I notice we sure had a lot of hits on this subject.
Ron from down under.
That's sort of what I was thinking, although 8 leads to each structure is probably more than he needs - I was thinking maybe RJ11 jacks and cables for 4 wires to each structure. The other alternative would be 2 and/or 3 pin connectors although those may be too small - I don't mean the ones use inside locos for lights so you can take the shells off, or for between steam locos and tenders, those are definitely too small to work with easily, I'm talking things like the 3 pin connectors used for RC servos. The cables are readily available, and the male end is just 3 of those same pins that are used on those proto shields to make it plug into the socket on the Arduino. You buy them in strips of 40 or more and just break off however many you need. Servo cables of course are 3 conductor but the same style and spacing of connectors are available in everything from a single wire to 6 or more. If you don't want to go through the trouble of PC mounting the male end, you can take a servo extension cable, which has a male connector on one end and a female on the other, cut it in half, and solder the wires of one half to the Arduino shield and solder the wieres of the other half to the LEDs in the building. Another extension cable will then connect the two ends, allowing you to unplug either the Arduino or the building.
My ordering of 10 when I need only 1? That's the trick to having a supply of components - if you need 1 of something, order 10, use 1, have 9 left for the next project(s). I have surprisingly few parts saved up over the years so recently I've bought resistor assorments and capacitor assortments, and when I bought the ATTinys it was too cheapo to pass up so I bought a bag of 50 8 pin sockets. Based on each ATTiny controlling 2 turnouts, I'll probably need MORE than 50 to build all the circuits I will need, but 50 is a good start. And of course the one thing I just throught of that I should have added to my last order, those header pins are also available in a female version, as an alternative to IC sockets, or for non-standard size things, or to make disconnects when combined with the male ones. The Arduino Nano is a non-standard size dual inline device, so to socket them I need those female header pins to make my own socket. Those I do not have.
This looks interesting:
https://www.adafruit.com/products/256
It uses standard cat 5 cable to go between the connectors on the patch panel shield and the connectors on the remote boards.
rrinkerRight now I just have it cobbled up on a solderless breadboard but one bump and a wire will come out, or the capacitor will get popped off, so I want to build a soldered together version.
Any time I have something on a solderless breadboard that I want to make more permanent, I've started using these:
https://www.adafruit.com/products/591 (also available from Digi-Key and Mouser)
These reproduce the breadboard layout so you can easily move the circuit over and they have plated through-holes with pads on both sides.
There are so many possible connectors, you can do pretty much whatever you want. I o like the idea of putting connectors at each end, so you can lift off a structure without disconnecting a bunch of wires and so forth. If they are all close together, then I guess a single 5V common run between them all would work fine, but my thought was to make each structure independent of any other, unplug one without affecting anything else, replace it, or just take it off the layout to clean, or to clean or work on part of the layout without damaging the structure, that sort of thing. It may seem counterproductive, but if each cable from the Arduino to the structure includes the power and the signal line, it actually makes it easier. I'll see if I can draw something up, Fritzing has most of the components we're talking about and makes nice pictorial diagrams as opposed to plain schematics.
I just ordered a 10 pack of the proto shields, mostly because a pack of 1 was not valid for Prime shippign on Amazon but a 10 pack was. I'll eventually use them. Right now I just need 1 to build up a permanent programming adapter for the ATTiny85's. Right now I just have it cobbled up on a solderless breadboard but one bump and a wire will come out, or the capacitor will get popped off, so I want to build a soldered together version.
I'm blinded with science Randy!
I was thinking of two x 6 male connector for the digital pin holes on the Arduino with 12 separate leads from them to 12 structure LEDs via 12 resistors, and from the Leds back to a common 12 block of 5v. But I don't know the nomenclature for the connectors. By the way, I found a 7.5v x 100ma Dc power supply in my box of tricks today, so could probably use that for the lighting.
Ron from way down under.
I guess it depends on how those LEDs are split up - if all 12 go into one structure then a large connector might be ok, but if they are split up, I would use seperate connectors per building. As many as 12x 2 pin connectors, where one pin goes to the Arduino pin and the other to the +5. RC servo connectors are 3 pin, that would give you 2 pins plus the 5V. You could use telephone jacks and plugs, there are PC mount versions of the jacks, so you could put a row of jacks on the Arduino board and put jacks in the structures and then wire them all up with telephone cables. With a standard 4 position jack you could have 3 lighting circuits plus the +5, or hook the +5 to the two outer pins and 2 light circuits to the two middle pins - that way if you have a backwards cable it just means the LED connected to Arduino pin 2 will come on when you expected the LED connected to pin 3.
You'll want to mount the Arduino to some sort of perf board so you have room for all your connectors, with a common line from +5 to the common pin of each connector, and then the individual lines to the Arduino outputs. You MIGHT fit 6x 4 wire phone jacks on what's called a Proto Shield - they have connections to each Arduino pin plus a +5 and GND bus, the rest is holes where you can build your circuit.
Looking for plugs to connect to 12 digital pins and the 5v pin on the Arduino Uno. What do you recommend?
I may use a model of these rocks on my layout, but would need to change the trees to US western types.
If you are using Mel's sketch, then yes, this is how you would wire them. The pin being LOW turns on the LED. The cathode of the LED (- side) goes toward the Arduino pin, the anode (+) side goes to the 5V common.
Doesn;t really matter which side of the LED the resistor is on, as long as there is one. Whichever makes the wiring more convenient.
+5V-------<resistor>----->|------ Arduino pin
is exactly the same as
+5V------->|------<resistor>---- Arduino pin.
Thanks Mel for the sketch and everyone for your help.
I assume the circuit goes; 12 serial pins to 12 resistors to 12 LEDs to a common block of 5v powered from the Arduino?
As to LEDs, I will be looking for dim mellow yellow in keeping with the 1860s-80s.
DOn't worry too much about libraries. If you buy some add-on hardware that is not supported by one of the buitl in libraries, you will need to download and install the library for that hardware, but your own stuff you generally won't be building libraries at this point, just creating sketches that use existing libraries. Those get saved seperately from libraries. Unless there is something non-standard on your computer, best to let the IDE save things hwere it wants to, at least at first. Mine's a little more complicated, I save my stuff on my OneDrive so I can open them on any of my computers but for just one computer I'd let the IDE save sketches where it wants to when you click save. Once you get more comfortable you can experiment with saving files in different places. The IDE is very picky about everything having a folder though, and libraries in particular are expected to conform to a specific layout of folders where each of the files lives.
Ron:
EBay is a great source for LEDs of all kinds. If you want some pointers on what types are suited to structure lighting let us know.
By the way, congratulations on your rapid advancement in Arduino technology!
Dave
I'm just a dude with a bad back having a lot of fun with model trains, and finally building a layout!
Randy,
It appears the Arduino library was misplaced, fixed that and hey presto! My sketch works. Haven't found how to place the sketch into the library yet, but I guess I will eventually work it out. Time to purchase lots of LEDs!
How do you know it's connected to COM3? Are you seeing COM3 appear and disappear in Device Manage when you plug and unplug the Arduino? If so, then COM3 it is. Next, with the Arduino plugged in, go into the Arduino IDE and under Tools you need to select the proper board and the port, If the board is the one you pictured, select Arduino/Genuino Uno for the board type. And under port it should list COM3 is that's the one being used. Just checking here on my laptop, which with nothing plugged in has a COM1 (it has a real serial porton it, not just USB) and that's all that shows up until I plug an Arduino into one of the USB ports. I don't have one with me but whatever port it gets shows up there along with the COM1 that is always there. Most of the cheap clones use a USB chip that doesn't register with the computer in any way, so if you plug it in to a different USB port it will likely be a different COM port - so always use the same USB port if possible so you don't have to keep changing the settings in the IDE.
COM3 is fairly common. My workbench computer has a bunch of USB cables plugged in (my Uno and Mega use the big 'B' plug, the Nano uses a microUSB) so depending on which Arduino I plug in I have to swap the com port in the IDE, one gets COM4 and the other gets COM5 (I have a whole bunch of stuff connected to this computer - I think my oscilloscope gets COM3)
In the meantime Randy, a more pressing problem.
I connected the Uno to my computer and it began blinking right away. I copied a sketch ok without errors, but had a problem when the sketch wouldn't download to the board. Computer shows it's connected to COM3 but I don' think it knows that, because when I request board details, it asks to specify a COM port. Any clues?
Tried changing port from 3 to 2 as suggested in troubleshooting but no go.
Also, "This device is working properly".
Get "Can't work with USB 3.0"
You just have a link to trains.com in front of the picture URL. If I take that out I can get to your pictures - so when you paste the link in your message make sure you erase the cs.trains.com/ part in the URL and it should work.
You have: http://cs.trains.com/i44.photobucket.com/albums/f34/ronhume79/Alice%20Rocks_zpsc2fjqhc1.jpg
SHould be:
http://i44.photobucket.com/albums/f34/ronhume79/Alice%20Rocks_zpsc2fjqhc1.jpg
The 'How To Post a Photo to the Forums' thread is the very first thread in the General Discussion category.
Simplistic explanation: PWM, at least in digital circuits like the Arduino, is usually based on a square wave. As opposed to the sine wave in your household AC power. Squar wave is exactly what it sounds like, looks like a series of squares (leaving off some highly technical stuff that causes the edges to never be nice perfect right angles like a square you would draw because, it doesn;t really matter here)
So, if you have a square wave that is on 50% of the time and off 50% of the time, you have a 50% duty cycle (how long it's on). In the case of an Arduino output, off is 0V and on is 5V. The peak voltage is 5V. But the AVERAGE voltage is determines by the peak and the duty cycle. This is the voltage 'seen' by most types of loads would in this case be 50% of the peak, or 2.5 volts. The duty cycle can vary from 0% (off) to 100% (full on - 5V). All the crazy timing stuff to generate this is taken care of by the Arduino. In place of the digitalWrite command (which just has 2 states, HIGH or LOW for on or off), there is the analogWrite command which takes a value from 0 to 255, where 0 is 0 % duty cycle and 255 is 100% duty cycle. There's yet another technical explanation for why the range is 0-255 and not 0-100 but suffice to say having more than 100 steps means each increment is less than 1%, so the control is fairly fine. Like the difference between one throttle that goes from stop to full speed in 90 degreees vs one that has a range of 320 degress.
And the cool thing about Arduino being so popular - if you search you can probably find that someone has already written a setch that makes an LED behave like a gas light.
Wow! lots of info to take in. The PWM (what is that?) effect sounds ideal for some of the lighting. I,m going to need help with THAT sketch when the time comes.
I have some 1k ohm 1/2 watt resistors left from my LED toggle swiches on the control panel, I could try a couple of those in series to see what happens, but at present I'm wrestling with turnout positions for motors to avoid the framework lurking beneath. As to the request to post any outcome with pictures, I can't seem to find the instructions to post pictures. Saw them when I first joined, but they are now lost in the ether somewhere...
The Arduino can use up to 12V because there is a 5V regulator on board. If you are going to low current gas light effects witht he LEDs, you should be fine with 10-12 LEDs connected to the Arduino. The voltage on the Arduino lines will be approximately 5V when on so Dave's resistor selection may be a little too high, since those are operating at 12V+. It's a good starting point though.
Another example to look at is the one that dims the LED using one of the PWM outputs on the Arduino. Get the parameters right and instead of just a dim LED you get perceptable flickering - just the thing to simulator oil lamps and candles. Keep in mind that while a 10K resistor may be fine for the nicely glowing LED at a full 5V, it may be too mig for the LED to light under PWM especially when set for very low duty cycles for the dim/flickering appearance - what's happening is that when PWM is enabled, the voltage is varying between 0 and 5V at a rate you can control with the program, and the ratio betrween the on and off times determines the average voltage the LED sees. So some experimentation is in order before you wire things to your layout for good. If you get no resistors less than 1K, you won;t be able to blow any of the LEDs up/ They might be too bright for your application but even if connected to 12V instead of 5V, 1K limits the current to well within what the LED can handle. Go up from there to get the brightness level that works for you. And remember that LEDs are polarity sensitive, so if you hook one up and your program doesn't turn it on, check that the LED is connected the right way as well as checking for a mistake in the program.
Ron!
Well sir, you certainly seem to have jumped in both feet first!
Seriously, for that level of lighting you will want to experiment with some fairly high value resistors.
I used 10,000 ohm resistors for the light over the conductor's desk in these cabooses (middle window). They look fine in daylight but they are a bit too bright at night:
I used 30,000 ohm resistors in this McKeen Motor Car and the LEDs are still too bright at night:
This picture was taken in a pitch black room but the LEDs are still a bit too bright when viewed in a night scene with normal lighting levels:
For your purposes I would suggest trying something around 48,000 ohms and maybe higher.
Mike Lehman is an expert in LED lighting. Hopefully he will chime in.
The nice thing about getting your resistance right is that resistors are cheap.
Good luck! Please show us your results.
Description: This is Arduino Uno R3. In addition to all the features of the previous board, the Uno now uses an ATmega16U2 instead of the 8U2 found on the Uno (or the FTDI found on previous generations). This allows for faster transfer rates and more memory. No drivers needed for Linux or Mac (inf file for Windows is needed and included in the Arduino IDE), and the ability to have the Uno show up as a keyboard, mouse, joystick, etc.
The Uno R3 also adds SDA and SCL pins next to the AREF. In addition, there are two new pins placed near the RESET pin. One is the IOREF that allow the shields to adapt to the voltage provided from the board. The other is a not connected and is reserved for future purposes. The Uno R3 works with all existing shields but can adapt to new shields which use these additional pins.
Note: The Arduino Uno R3 requires the Arduino 1.0 (or any other recent version)drivers folder in order to install properly on some computers. We have tested and confirmed that the R3 can be programmed in older versions of the IDE. However, the first time using the R3 on a new computer, you will need to have Arduino 1.0(or any other versions) installed on that machine.
Features:
These are the specs for my Arduino Uno clone. It appears I can use my 12 volt 500 ma power source to fire it up. That being so, what size resistors do I need for a low light effect? Modelling in the Civil War era, candles, gas lights etc. And maybe a variable resistance on the main to control overall brightness.
Ron Hume from down under.