Step 3: Software or Firmware?

The difference between "firmware" or "software" is slight. Your "sketch", or the program you load on to the Arduino could be considered "firmware", but the program you use to get it loaded is "software". To make it worse, people start calling the latter a "programming environment". Confusing, eh? Let's not start talking about "bootloaders", because I don't know squat.

Setting up an Arduino programming environment could be a whole Instructable by itself (I don't see one, so feel free to write it). For now, I'll point you to the "horse's mouth", Getting Started at the Arduino site.

With an Arduino "environment" in place, you are going to need a couple of extra's.
- The motor shield comes with a library called "AFMotor ". You need to down load it from LadyAda's website and place it in the "Arduino/hardware/library " folder. If you breadboarded your own controller, you know enough to write your own functions for it.
- My demo software "WiiChuck_Train_Controller " (attached below). My advice is to paste it into the Arduino environment and save it with a really, really clever name. You'll have to supply that yourself.
- The WiiMote adapter also has a library called "nunchuck_funcs.h " available here . This single file will have to be placed in the same folder as the sketch, something like "Arduino/WiiChuck_Train_Controller " folder. In the newer Arduino environment (0017), it shows both the sketch and the nunchuck_funcs.h on separate tabs (see image).

Update (December 2014):

I had compatibility problems with the newer Arduino versions and switched to a newer nunchuk library from:

Take a look at the demo sketch that comes with it.

<p>Dear ken.</p><p>Now is our code completed !! We are very happy about it. But the only problem is that our train doesn't move. Now we think it is because our train only drives with at least 100 V.</p><p>What kind of train do you use ? And if we want to buy a new train what kind of detail we have to look for ?</p><p>Kind regard,</p><p>Claire &amp; Chantalle</p>
<p>Hi</p><p>I have declared the wire but now we get these errors, I hope you can help us!</p><p>sketch_trein-nunchuk.ino: In function 'void nunchuck_init()':<br>sketch_trein-nunchuk.ino:35: error: 'class TwoWire' has no member named 'send'<br>sketch_trein-nunchuk.ino:36: error: 'class TwoWire' has no member named 'send'<br>sketch_trein-nunchuk.ino: In function 'void nunchuck_send_request()':<br>sketch_trein-nunchuk.ino:45: error: 'class TwoWire' has no member named 'send'<br>sketch_trein-nunchuk.ino: In function 'int nunchuck_get_data()':<br>sketch_trein-nunchuk.ino:65: error: 'class TwoWire' has no member named 'receive'</p>
<p>I would completely abandon my example code and start by going to <a href="https://github.com/GabrielBianconi/ArduinoNunchuk" rel="nofollow">https://github.com/GabrielBianconi/ArduinoNunchuk </a> and downloading his library (look for the &quot;Download Zip&quot; button).</p><p>Unzip the download and copy the 'ArduinoNunchuk' folder, located in the same folder as this 'README' file, to the Arduino libraries folder (Arduino/libraries).</p><p>Restart your Arduino IDE and then open the demo code [File]-&gt;[Examples]-&gt;[ArduinoNunchuk]-&gt;[ArdunioNunchukDemo]</p><p>Upload the sketch and see if you can get readings from your Chuk, and we'll work from there.</p>
<p>Sounds like it is time to update the sketch to get a working example again. </p><p>Shoot me an email at 648.ken@gmail.com and you guys can help me get one written and tested.</p>
<p>I hope somebody is still active. My friend and I are working on this for our assignment for school. But we are having struggles with some errors. I hope somebody can help us.</p><p>WiiChuck_Train_Controller.ino: In function 'void nunchuck_init()':</p><p>WiiChuck_Train_Controller:32: error: 'Wire' was not declared in this scope</p><p>WiiChuck_Train_Controller.ino: In function 'void nunchuck_send_request()':</p><p>WiiChuck_Train_Controller:43: error: 'Wire' was not declared in this scope</p><p>WiiChuck_Train_Controller.ino: In function 'int nunchuck_get_data()':</p><p>WiiChuck_Train_Controller:61: error: 'Wire' was not declared in this scope</p><p>We hope somebody knows these errors and can help us.</p>
Hey Guys!<br><br>Sounds like a fun class if you get to use an Arduino!<br><br>I had compatibility problems with the newer Arduino versions and switched to a newer nunchuk library from:<br>https://github.com/GabrielBianconi/ArduinoNunchuk<br><br>Take a look at the demo sketch that comes with it.<br><br>Let know how it goes!<br><br>Ken
<p>I love this and might try this myself.</p>
<p>I put this great controller into use several months ago. I wanted to build another one but adafruit has changed the controller design, is it still compatible with this? Here's the new controller. <a href="http://www.adafruit.com/products/1438" rel="nofollow">http://www.adafruit.com/products/1438</a></p><p>Thank You!</p>
<p>I haven't had a chance to use the new one yet, but it looks like it would work fine for driving a train. Let us know if you try it out!</p>
very nice project!! <br>I need some help with the program. <br>these are the errors that i get: <br> <br> <br>nunchuck.cpp:324:28: error: nunchuck_funcs.h: No such file or directory <br>nunchuck.cpp:325:21: error: AFMotor.h: No such file or directory <br>nunchuck.cpp: In function 'void nunchuck_init()': <br>wii_train_controller:152: error: 'Wire' was not declared in this scope <br>nunchuck.cpp: In function 'void nunchuck_send_request()': <br>wii_train_controller:163: error: 'Wire' was not declared in this scope <br>nunchuck.cpp: In function 'int nunchuck_get_data()': <br>wii_train_controller:181: error: 'Wire' was not declared in this scope <br> <br>Can some one help Please
It sounds like the sketch can't find the extra libraries. You need to download and install both the motor library from Adafruit and the Nunchuck library. Check the Arduino forum if you need help with that.
thanks! <br>when i go to get hub which of the files should i get(motor-shield)? it wont let me download all of them at once and how to i save them properly?
Have you thought about using magnetic reed switches to detect when a train is approaching the&nbsp;end of tracks? All you need is&nbsp;a couple of small bar magnets glued to the underside of the loco and trailing vehicle (for reverse operation). The reed switches, which are very cheap,&nbsp;can be easily disguised as 'between track' fittings and can be painted without affecting their operation. If you're using a common ground, just connect one side of the (normally open)&nbsp;reed switch to that and take the other side back to one of the Arduino pins, held at 5v by a 1k&nbsp;resistor. Poll that pin to detect when it's grounded and apply the brakes! The magnets should have the same orientation as the reed switches (don't have them at right angles to each other)&nbsp;otherwise you may get a double switching as the N and then the S poles move over the switch.<br> You can also use reed switches for train differentiation. Imagine two locos, one with two magnets spaced 1&quot; apart and the other with the magnets 2&quot; apart. With 3 reed switches spaced 1&quot; and 1&quot; you can detect if switches 1 and 2 are closed at the same time or if switches 1 and 3 are closed at the same time. Simply ground one end of switch 1 and connect the other end to both switches 2 and 3. The outputs of switches 2 and 3 will tell you which train is present.<br> My idea is for an automatic 'hump' shunting yard. The wagons would have a bar code stuck to the underside and a bar code reader in the hump would read the barcode and switch the points to the appropriate track. I don't yet know how to do this, but I'm sure that it could be done with an Arduino!<br> <br> <br>
Great Instructable Ken, and Dawson Station is an exceptional piece of craftsmanship.
Hello, this is a great project but I cant download the code! could you put another link up so I could get the code please? this link gives me a tmp file!? Regards Richard
I uploaded a zip file. Give it a try.
Works great, i've learnt loads already. cheers dude
Saw this layout on www.carendt.com. Realy nice job<br />
Has anybody used this with DCC?&nbsp; I wouln't want to burn out a lot of locos, turnouts,&nbsp; and other controlled stuff.<br /> <br /> On my DC&nbsp;garden layout, this might be perfect.<br />
you probaly will need the entire wii to get the parts cus you will need antennas...... and receavers
Neato -I like it! <br /> <br /> It would definitely be cool for slot cars. My little boys have a hard time controlling the car speed and keeping them on the track. One thing you could also do is have lane changing on a routed wood track (or track changing for trains) by using either a solenoid or servo motor to move the track by pressing one of the nunchuck buttons. I wrote some code a couple of years ago that allows access to all the nunchuck functions so I might have to try that out.<br />
You are one step ahead of me.&nbsp; Operating turnouts is the next step.&nbsp; I was going to use servos, but then I found this neat little circuit which will use the Atlas remote switches which I already have:<br /> <br /> http://www3.sympatico.ca/kstapleton3/751D.HTM<br /> <br /> I haven't put the accelerometer readings to use yet.&nbsp; Maybe I could use a throwing action to make the turnouts switch?<br />
I've set up a nunchuck so the accelerometer and joystick functions move servos and the buttons trigger transistors to turn on sounds/lights. I figured for slot cars I'd use the joystick to control acceleration/braking and the buttons could control two lane changers. Don't know what I'd use the accelerometer for....<br />
top speed? normaly shunting is a max speed of 15 mi.....
&nbsp;&nbsp;nice layout! heres a picture of mine (still in progress)
Has there ever been a layout that wasn't &quot;still in progress&quot;?<br /> <br /> Looks good.&nbsp; Nice low-angle action shot.<br /> <br /> Ken<br />
Yup,<br /> <br /> The last one.<br />
nothing is ever finished.
never. aways changing. random question, have you heard of Gn15?
did not know you wii-d dawson station. cool.
This is handy i hate derailing skelectric cars ! . <br /> <br /> will have to look into buying an arduino<br />
&nbsp;What a magnificent application of the Wiimote!<br /> <br /> I love how hackable the wiimote and nunchuck attachment are. &nbsp;They have tons of uses yet to be unlocked!<br />

About This Instructable


72 favorites


More by MakersBox: Using an Arduino Drawing Robot with Hour of Code Tutorials Arduino Drawing Robot Low-Cost, Arduino-Compatible Drawing Robot
Add instructable to: