Starting from Scratch
OK, letās get at it. These projects need an Arduino Pro Mini Board (At last check US$2.94 each with free shipping off ebay see: http://tinyurl.com/oamynj5 ) and a USB to TTL cable to set up the programs on the little board (Now US$8.60 off ebay see: http://www.ebay.com/itm/262042386245). While you are waiting to get these download the Arduino IDE (Integrated Development Environment) free software off the net from: http://arduino.cc/en/Main/Software or http://arduino.googlecode.com/files/arduino-1.0.5-windows.zip (for Windows specifically) which has an editor, a library, and examples for you to use. Note this IDE will run on Windows, MACs, and Linux machines, so pick the right one for your computer. When you unzip the package, write down the full path name to the folder, like: C:\arduino-1.0.5 or wherever you put it. This will be important later.
Now take a glance at the Getting Started info: http://arduino.cc/en/Guide/HomePage and the info at http://arduino.cc/en/Guide/ArduinoProMini page. Just a quick read to give you some context. I had people get lost at this point, so Iāll step you through the rest. The accelerated learners among you can also glean more info from: http://arduino.cc/en/Tutorial/HomePage and there are a lot of topics there for search for a subject or browse or http://www.instructables.com/files/orig/F3J/MTJN/FVW22MXN/F3JMTJNFVW22MXN.pdf
or http://www.richardvannoy.info/arduino.php or http://arduino-info.wikispaces.com/TUTORIALS
These offer info at different learning levels so pick one you are comfortable with.
Now you should have at least one Pro Mini Board, a cable, and the IDE software loaded.
Arduino Pro Mini
USB to Serial TTL Programming Cable
If you ordered the Pro Mini I referenced before it came with a set of header pins. So cut off a six pin group, and either solder it into the six holes on the end of the Pro Mini Board (either side will do, I prefer the header to stick out the component side with the button on it. In some model setting you may prefer not to solder the header on at all. Iāll show you later how to deal with this. Notice that ends of the six holes are either labeled BLK and GRN, or GND and DTR. The black wire on the six pin USB to TTL Serial cable will connect to the BLK/GND pin, and the other end of the cable connector will connect to the GRN/DTR pin. (If you didnāt want to solder the 6 pin header to your board for some reason, insert the long end of the header pins into the 6 pin cable connector. When you are ready to load a program onto the board, insert the connector with pins into the top of the board, observing proper orientation I described above, and hold placing side pressure during the programming download.) Plug the USB side of the cable into your computer. In all likelihood Windows will need to load a driver. For Windows Xp, here: http://arduino.cc/en/Guide/UnoDriversWindowsXP is a good detailed, step by step. The drivers you want to install are in the Arduino folder (from my example above) C:\arduino-1.0.5\drivers\ You might also benefit from reading http://arduino.cc/en/Guide/Windows For other operating Systems go to http://arduino.cc/en/Guide/HomePage and poke around there. Remember the serial port number for the serial cable installation. Now start up the Arduino IDE software you loaded, and you should get a window like this: (All my examples will be MS Windows based)
This is the window for the Arduino Editor, where you can recall programs from libraries or create your own. Go to the top menu bar, mouse click on Tools, then Board, then Arduino Pro Mini (5V, 16MHz) w/Atmega328. This will place a black dot next to your selection, and corresponds to the Pro Mini Board I referenced before. Note well that there are many variations of Arduinos. They all can run the same examples we will use. The Arduino Pro Mini is small, low power, cheap, fast, and comes with a large program memory.
Now go back to the top menu bar, mouse click on Tools, then Serial Port. Select the Serial Port corresponding to the USB cable you set up before. All that weāve done so far only needs to be done ONCE.
OK, now we are ready to do something with the Pro Mini. In the open window of the Arduino IDE, click on File, then Examples, then 01 Basics, then Blink:
And the following window should open:
This is the editor screen in which you can load, edit, save, and download your programs, called sketches, for the Arduino. The program shown is from the list of examples which are great starting points for you to learn just how much you can do. With NO modification, making sure your Pro Mini Board is connected and selected properly, click on the circled right arrow button below the edit menu pick, to the right of the circled checkmark. These two screens should appear in succession:
and
You will also see the LEDs on the Pro Mini Board blinking along. After a short time, a LED connected to Digital Pin13 will blink one second on, one second off. You have now successfully set up your Pro Mini Board! To prove a point, go back to your computer, and in the IDE window with the Blink program, highlight and change both of the delay(1000); lines to delay(90); that is change the 1000 to 90. Hit the right arrow to download the now modified program and watch the change. Now the blink rate is 90 milliseconds (0.09 seconds) on and off. This is how simple it is to change the behavior of the Pro Mini.
Back to Model Railroading
While blinking a LED was instructive it is not particularly useful. So here are some small projects that might be of interest to modelers:
We do Windows!
One of the neatest animations I use is relatively simple to set up with a Pro Mini. This was built as an example for my animation clinics. This sketch (program) randomly turns on 16 LEDs used for room lights in my model structures. It can turn background buildings from lifeless shadows into hives of activity. Here is the sketch:
#define numleds 16
byte ledpins [ ] = { 0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17 } ;
void setup( ) {
for ( int i=1; i < = numleds; i++ ) {
pinMode ( ledpins [ i ], OUTPUT) ;
digitalWrite ( ledpins [ i ] , HIGH) ;
}
}
void loop ( ) {
digitalWrite ( ledpins [ random ( 0, numleds+1 ) ], lightsw ( ) ) ;
delay ( 900 ) ;
}
boolean lightsw ( ) {
if ( random (0,100)> 40 ) return LOW ;
else return HIGH ;
}
Copy, paste , and save it as a text file, but name it with a ā.inoā suffix like ābuilding.inoā
Then open the file with the Arduino IDE and load it into your Pro Mini. You can also copy and paste the text directly into the Arduino editor window.
Now letās set up the Pro Mini Board. Since this will be part of a freestanding model, we need to power the board independently. A cheap and easy alternative is a āwall wortā 5 Volt DC power adapter commonly available. I cut off the connector at the end. Strip the two wires exposing the bare wires, not allowing them to touch. Connect a LED in series with a 1000 to 3000 ohm resistor. Typically the longer length LED wire is the positive side. Touch the resistor/LED combination to the exposed power adapter wires. When the LED lights, you know which of the wires is positive and which is negative. Connect the Negative wire to GND on the pro Mini and the Positive wire to the hole on the Pro Mini marked VCC. Note this works for the Pro Mini mentioned before. There are other variations for which this will NOT work. Only use a 5 Volt DC adapter here, rated 400 milliamps or more. Place you LEDs in building rooms or where ever you want them, connecting all LED anodes (Plus or positive sides) together and to the positive side of your power source (in my case the 5 Volt wall wort). For each LED connect a 1/8-1/4 Watt resistor of somewhere between 330 and 2000 Ohms depending on your LED and the LED brightness you desire (experiment a little here) to the LED cathode (Negative side). The other side of the resistor connects to one of the Arduino Pins Labeled 2-13 and A0-A3 on the Pro Mini Board. These are referred to as Arduino Digital Pins 2-17. The assembly pictured below is my demo of this very project. The LEDs will come on randomly, and, on the average, stay on for 60% of the time.
This is exactly the technique used in this Building animation:
Nowā¦ Do You Want a Rooooooooom? (With apologies to Peter Sellers)
I have mentioned before that one of the great values in using the Arduino is in the availability of existing libraries and examples to get going quickly. Below is a Pro Mini connected to a 1.8 inch LCD display available from Adafruit ( http://www.adafruit.com/products/358) , together with graphic libraries for the display. The little board also has a socket for a Micro-SD memory card, and, as you might guess, thereās a library to use the SD card too! In this particular case, we can start by using the Adafruit display ($19) and libraries (Free) and follow their tutorials for connectionsāthey are actually straightforward. Other, cheaper 1.8 inch displays are available, but they have a few design quirks that are not for the impatient, or faint of heart!
You can see the Micro SD card socket on the back of the display. The display is connected to the Pro Mini directly:
Wiring from the 1.8inch Display to Pro Mini :
Lite to VCC +5 Volts
MISO to 12
SCK to 13
MOSI to 11
TFT_CS to 10
Card_CS to 4
D/C to 9
RESET to 8
VCC to VCC +5 Volts
GND to GND
Then download the libraries:
https://github.com/adafruit/Adafruit-ST7735-Library/archive/master.zip
and
https://github.com/adafruit/Adafruit-GFX-Library/archive/master.zip
Download and Unzip, and rename the folders: Adafruit_ST7735 and Adafruit_GFX and put them in your
Documents/Arduino/libraries/
folder. If the folder doesnāt exist, create it for the libraries. You can verify everything works by running sketches in the Examples/ST7735/ menu in the Arduino IDE. You should note that one of the examples is: spitftbitmap.ino which will display a 160 X 128 Color BMP picture. By finding or creating an appropriate photo in perspective, you can resize and convert it to a BMP type 24 bit color picture and load it onto your Micro SD card ā remember that little socket on the back of the display? If you position and glue the display towards the rear of a room, facing a clear window to the front, you can build this:
or or
orā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦.Grrrrrrrrrr!!!!
My rough estimates indicate the Pro Mini doesnāt quite have enough processing power to generate video without a hardware assist, but some of you might recall the āflicker comicsā that used to come in a package of āCracker Jacks.ā We can create an animation of sorts by rapidly repainting the display with multiple images. And with the additional help of the image editor, you can finish off our āvirtual roomā with a little animation, randomly activated, and with changing speed of movement:
No sound of courseābecause the doors and windows are closed! While itās possible to drive the little display with other, more powerful processors, you probably canāt beat this little animation added to your structure for less than $25.
I hope you enjoyed this! As always, suggestions and new ideas are always welcome!
Have fun!
Best Regards,
Geoff Bunza