RoverClaw: RoboClaw 2×5 Tracked Rover

   

 

 

For this project, you'll need a chasis, there are many fine choices. I'm using the arduino rover frame from Robotshop.

Though i don't use an Arduino, This frame is designed in a way the pre-drilled holes will line up with an Arduino or BasicAtom: Mad Hatter

 

You'll notice my frame is a bit messy, I use a lot of hotglue, which usually comes off clean in most projects when used with plastic parts, but with the frame's powder coat. The glue doesn't always come off clean.

Building up the frame is pretty straight forward, following the downloadable instructions, but since you may be using a different rover, i won't get into that.

The Motors:

I started with standard GM9 gear motors.  Which can be ran on just even a dual 1A motor controller, But they are slow, and not very strong.

So i kicked it up a notch and replace the actual motors with some high power Solarbotics RM2s from Pololu. These motors can really draw some current.

You can see in the pictures (click to enlarge) Each motor has three 0.1uF ceramic capacitors to help reduce EMI noise. Which can cause problems with just about everything robot related.

Soldering on the capacitors can be tricky. Solder 1 capacitor between the metal shell and each of the motor's connectors. and then 1 between the two motor connectors. The tricky part, is to make sure you heat the motor's shell enough so the solder will bind. I've read some suggestions of using a pocket torch for a few seconds, being careful not to melt the plastic.

With capacitors on, wires soldered down, go ahead and reassemble the GM9s. For these small motors, always use capacitors with the motors.

 

Mounting the hardware:

 The frame came with some mounting holes for the Arduino/Mad Hatter, but i use neither of those. So i knew i was going to be drilling into this thing before i even bought it.

 Mounting the GM9 gear motors is pretty straight forward, the only difficult part of the frame itself, is assembling all the tracks. the pins can be stuborn to get in.

Now i built this rover before Basic Micro offered their Tank-Track kits. Which is a major bummer, Basic Micro's track links are far superior to the ones i have. 

The problem with my tracks, is they are smooth. So they don't climb over obstacles very well. The treads just slip. BasicMicro's rubberized tracks would definitely win hands down. I may replace my tracks in the future, but short term i'll probably just use some rubber-foam tape and a little super glue. I'm often building on a tight budget.

 

Mounting the Botboard 2   

For this i had to drill a new hole, and using an old PC motherboard raise, mount the botboard free floating on just 2 screws, you must be careful at this stage. After making sure it was all set right, i went ahead and removed the botboard, and attacked the RoboClaw 2×5. Which has since been upgraded and overhauled. Hence why mine may not look the same as yours.

 

Wiring up the RoboClaw is very simple, the motors just connect to the intended lines. If you find your command is right, but your motor is going in reverse, you can either alter the command, or simply switch the wires around.

 

I'm using a Radioshack hobby enclosure to house my power switch and battery. The battery i'm using is a 2cell, 20C, 800mAh li-po, same kind used in my Universal controller. Again i made holes for the charging connector, (which is moved over from where it is in this photo) and a switch. And the power wires of course.

Now connecting the RoboClaw to the Botboard.

Using an IO line and Software Serial, controlling the RoboClaw is easier than ever. And you have many other options to choose from, From PWM, or even RC pulse. 

The Side of the enclosure is a large ferrite choke, I do not believe it is actually required, but due to my wireless camera system that i often play with, reducing noise where ever i can, is always important.  The power goes from the battery to the roboclaw, and then back up to the botboard.

 

 

 

Bluetooth control: Roving networks RN-41

Please Refer to my Roving Networks project page for more information on these adapters.

The adapter sits on top of my miniture TTL 5v <-> 3.3v converter. The RN-41 like many small scale bluetooth adapters use 3.3v, not the Basic Atom's 5v. The converter includes my standard converter, including it's own 3.3v regulator in a TO-92 package.

 

Here is a bonus image of my rover with it's DIY arm and my Universal Bluetooth Robot Controller.

 

TO BE Continued. The arm will be replaced with a proper arm. Also a 170* wide view angle camera will also be mounted to the bot on it's own pan-tilt setup.

The rover will also get a servo controlled mini RadioShack enclosure, which an item can be picked up and placed into, using the robotic arm.

 

I apologize for any grammar or typo mistakes. And even more so, i apologize for how late this is, almost a year late. Health issues stopped me pretty abruptly. But i'm fine now, and i'm back.

Universal Bluetooth Robot Controller

 

Introducing the Universal Bluetooth Robot Controller. This is not a tutorial or project guide. It's simply a, "What I made, and how I made it."

 

 

Specs:

Two, Dual Axis Thumbsticks with center buttons.

One, 4way+center, button stick.

4×4 keypad with values of 1 through 16.

16×2 White on black serial LCD.

A powerful  Roving Networks RN-24-E, Class 1 100meter bluetooth RS-232 module.

And at the heart of it all, The Basic Atom Pro 40.

 

This Post will be broken into Sections using the Expand Buttons. This is a bit more for convenience, so you can check out each section 1 at a time.

The orders at which things happen are a bit off. Since there was no real order in which I did everything. I make this up as I go. I barely preplan anything.

I only plan the parts, not the details. So I don't know exactly where something will go, until I’m ready to put it in.

Which means this will not be a step by step guide.

I'll be posting a bunch of pictures, and a little description about what's going on in each picture. Most images when clicked will open in a new window.

Bluetooth information can be found in its own post.

The Roving Networks RN-24, and RN-41 Class 1 Bluetooth adapters can be found here.

 

Let's start with the Keypad.

 

This is a short section. The keypad. Not the cheapest, but was the smallest, and with my controller. Size is a factor.

The modification to this keypad was simple, I removed the header, and replaced it with wires, and moved the Bussed Resistor network to the back.

The reason for this was I wanted it to sit as flush with the case as possible, and the parts were in the way.

The blue wire was my bad, the header pins they used were giving me trouble and sure enough I pulled up the solder pad. It's happened before, but nothing I can't fix.

BEFORE : Clicking images will open in new window.

 

 

AFTER:

 

I could have soldered the wires to the back, but for stronger solder joints, i decided to go through the holes.

The header prior to being incased in hot glue. The loose wire is the 5v, and it gets its own female header.

 

Next up the case.

 

I'm using the PacTec PPT-4081.

The case is sturdy, and high quality. The plastic is very strong, and if left unmodified, is water resistant, probably  water tight within reason of course. The black outer layer, is a rubber foam. Gives a good grip, with just the right firmness. This is also responsible for sealing out water and debris.

You'll notice in my pictures, the case is upside down. I did this for one main reason. Comfort. The case, when held with 2 hands, is far more comfortable upside down and used like a game controller, than right side up when used like a multimeter.

I have long slender fingers, so a wider grip is simply more comfortable. No overlapping fingers.

The front. (upside down.)

This next image is a very large one. It's the back half of the case. The 6 screws (included) fit well, and leave a nice snug fit. Very nice.

The face plate measurements aren't perfect due to the odd rounded design.

 

 

Cutting into it.

Well I don't have a whole lot of tools, and I can't say I’m proud of the job I did. I've cleaned up the edges pretty nicely, but they still aren't precision cuts.

I ended up using an old xacto blade, which I heated with a pocket torch until red. (smelled pretty foul) But it did cut it fairly well. Later holes I used a solder iron with an old oxidized head that I was going to toss otherwise. It smelled worse. But since it's below freezing outside.. what can you do.

 

 

Yup.. that's one seriously straight line. -sigh-

Jagged edges? Nothing a fresh Xacto blade can't fix.

 

Need a place for that keypad.

 

A bit of single sided foam tape to keep debris out. The holes at the top are for the Bluetooth adapter's SMA plug and it's LED's. The LED hole was just sealed with hot glue. It works fine, nothing fancy.

 

 

Below you see the 10k slide pot's hole. This wasn't originally planned, but I’m happy with how it turned out.

You can also see the holes for the thumb sticks. At first I thought I made them too large, but when I was done, I realized they were just right.

I originally intended a couple small round holes just for the joysticks to stick out, but then I decided to fit the whole thumb stick into the hole. Whatever, it works.

 

 

 

And now we're mounting! I used hot glue. It's cheap, easy to use, and can be removed if you mess up. Because of the size constraints, I couldn't fit special fancy brackets or breakout boards. Before you judge the project, thinking Hot Glue is amateurish, weak, or for the poor. Weigh your options. $60-$150 for special/custom brackets, or $0.25 in glue sticks. Also the hot glue keeps debris out, moisture, and adds a bit of flexibility. It'll bend rather than break.

Roving Networks RN-24-E, Class 1 100meter Bluetooth RS-232 module.

 

When gluing in the thumb sticks, I had to be very careful not to get any glue in the moving parts of the sticks. such as the center of the turquoise pots, or under the buttons. These sticks receive a lot more glue later on.. Let’s just say, they aren't coming out.

The keypad wires get trimmed later on. Those were just way to long.

 

 

 

That covers the case construction. There wasn't a whole lot to it. Just a lot of cutting. I would suggest anyone making one to use a Dremel, and a wet blade. 1 second on, 1 second off, just so you don't stink everything up, and you can get smoother edges.

PS, I’m getting a Dremel for Christmas, so future projects will look a lot cleaner.

 

 

First things first, we need an IC Socket for the MCU. Since I'll be using a 40 Pin MCU, I need a 40 pin socket. To allow for more user space, I've broken away and trimmed down the center bar for more user space in the center of the socket.

Now then, don't make the mistake I did by building the Main board first, in fact it comes last. I had to scrap the original board and start over.

You design the board to fit your case, not the other way around.

 

You need a PCB to attach all your goodies to right?  I've been using these. They are cheap and Flimsy, and they work fantastic. I bought 30 at once.

A Razor will trim the left over notches on the sides. Maximizing the user space without weakening it too much.

 

Ok, now we're going. I started attaching header pins and the socket. There are dozens of high quality guides on YouTube on how to solder, so I won't get into it.

 

The 3 pins in the lower left are separated and didn't solder straight as I use salvaged parts. But they work fine, and lead to the serial LCD.

Quick TIP: When soldering Right Angle Male Header pins, it's easy to use a 2×4 Female header to get the size and the angle just right. See the top of the aforementioned image. It holds the pins in place while I solder them, without burning fingers or having pins stick up.

 

This image here just shows the additional headers, including the 2 power pins to the Bluetooth adapter.

 

Now we need power. The regulator of choice? The Texas Instruments REG1117-5.

 

It's small, good current, and doesn't get to warm. Why more people don't use these is beyond me. I've ran it in my controller for 20 minutes straight and it barely got warm.

I like to trim off the fins for a few reasons. One being it makes it shorter, so you can actually fit it inside the IC socket. Like in my Bot Board Mini Pro 28 As seen by the lower orange arrow. Use a tool like needle nose pliers and try to straighten the pins the best you can.

 

The board now has regulated power.

What you're looking at here is two 10uF capacitors immediately above the 5v regulator.

The wiring is simple. 1 capacitor between the ground and Vin on the regulator, and one linking ground and Vout. This helps with various spikes, noise, and other power related issues.

The small 0.1uF (104) capacitor inside the IC socket is between the VSS and VCC. This is also to reduce noise.

The new 2 pin header above the regulator goes to the reset button. One pin to RES line on the MCU, the other to ground.

 

Next up, the underside. Definitely click the image to open in new window.

 

The pins of the IC socket are hard to see, and not all headers are soldered in. Just the corners and the needed pins.

The programming pins S_out, s_in, ATN, and GND, are all pretty straight forward, and thus use direct links using some scrap leads from trimmed resistors, capacitors etc.  The VCC and VSS have nice long leads for future links.

The capacitors and regulator has its own little mess over to the side. That Loop bit you see is the ground linking the second capacitor. It isn't pretty, but it works great.

A lot of the best things in life, aren't all that pretty.

 

Wiring: 2 images

 

 

Wiring, you can see I "stitch" through some of the holes. This is uncommon for me as I haven't done this in projects before. Usually I try to make the top sides as clean as possible, But since this board won't be open for display, I simply didn't care. So I did this to get the wires out of the way.

Wiring Part2:

Now it's getting hairy, we have a lot more wires going around.

 

 

The black loose wire is the ground to the controls. It's loose because I want to solder that on last, but I wanted a heavy enough wire so I didn't use my traditional kynar.

The wires inside the IC socket do go somewhere!

The larger male header at the bottom goes to the buttons and 5v, where the smaller one goes to the pots- the joysticks and slide pot

 

You can see I have the keypad header wired up now.

 

 

That's it for the MCU board. The only thing that you're not seeing is, the 4 analog pins, the ones immediately under the programming header, received some 0.1uF SMD capacitors. This was because I was getting a lot of noise and jumpy values.

The MCU pinout:

 

 

A bit of explanation is due.

P0-p3 goes to the 2 joystick Axis. P30 goes to the slide pot.

P31 despite being an analog pin is just being used as an input pin, should I ever need to use that analog pin, I’ll reroute the center select button to p8.

The _______ was from when I printed this out, should I need any extra notes to write down.

The 8 C/R pins are the keypads inputs/outputs. C1-C4 = column 1-4, and R5-R8 = Row 1 to Row 4, the colors are the wires of the keypad, just for personal reference. When coding, have it check if any of the columns are pressed, and then if any of the rows. Column 2, row 3, would be second button over, 3rd down.

VIN is not used, as I supplied my own 5v. But is listed for reference.

 

Now with the Keypad, Case and Mainboard out of the way, let’s put everything together.

 

 

Well more stuff is getting mounted.

A 4 +1 way button stick is placed between the joysticks, and our slide pot is in place. The slide pot, for the Rover is essentially a master speed control, which increases the speed up to a multiple of 10.l So speed 1 = 6, and speed 10 = 60. Very useful, like switching gears on a car.

 

The craft stick section in the center, is mostly so I have something to work on, and to secure the button down a bit.

Ya it sort of looks like a face. The glue looks really bad in how it refracts the light, but cost being a factor, well worth it. And the thumb stick toppers hide the glue.

 

Pay more attention to the top of the next image. The controller gets its programming connector. A Female DB-9 serial connector.

There's enough spacing around the connector for the male to fit comfortably. Giving you remove the screw headers from the male end. Else you'll need an adapter.

The ground of the thumb sticks and the center stick is getting wired up.

The wiring is done in a way so UP will = 1023, and down is 0, and Right is 1023, and left is 0.. on both sticks, despite one being upside down.

 

 

 

The end faze. The connections are simple. The SMA Bluetooth antenna, and under it, the black dot is the reset button.

The DB9 connector. The switch is a dual rail slide switch, which switches the RX/TX of S_in/out, between the DB9 connector and the Bluetooth. This means bluetooth and the programming header can use the same MCU S_in/S_out pins, just not at the same time.

This protects the Bluetooth adapter and the PC from signals interfering with each other.

 

 

Due to a wiring goof up, I had to redo that whole mess of red wires in the center near the sticks. I wasn't able to take as many pictures and I would have liked. All the hookups have been tested with the continuity test on the multimeter, and everything is good to go.

The battery is a 2cell, 20C, 800mAh li-po, if you look close at the bottom of the case, you'll see the 3 pin charging connector sticking out.

 

The controller… gets a heart.

 

 

And the controller construction.. Is done.

It works, the keypad puts out values 1-16, and The LCD looks good and is very legible even with the camera's flash.

 

 

Total time for construction? Roughly 30 hours. Even simple things take forever, and you should never rush yourself.

Programming… still working on that. But it's looking good so far.

I apologize for my poor grammar.

 

I will eventually include a schematic, but those are a bit time consuming to sketch up.

To-do list:

Add an internal speaker, just a simple one to use with the sound command.

Add a clip on, 3.5" or 4.3" video LCD to the blank gap on the top to be used with a wireless camera. It won't be part of the controller, just a clip on accessory.

Adding a hardware serial output header somewhere. This will connect to a slave MCU to be used with a 3D control arm. See Youtube

Roving Networks Bluetooth Adapters.

 

 

 

Let's talk about the Roving Networks RN-24 and RN-41. I am unbiased, and I tell it how I see it. And I can honestly say I’m very satisfied with the quality of these two products. And though one of them has a few small issues, It’s definitely not a deal breaker.

On the Left, the RN-41, and On the Right the RN-24.

 

 

You can see on the RN-24, there are many open solder pads from stuff that would normally be present in the RN-25 (RS-485 Parallel version).

Now then, Know that the RN-24 (right) includes its own 3.3v regulator, and supports input voltages between 5v and 24v. Or it can be powered directly with a 3.3v input. I'll be using 5v on pin 12, the lowest pin on the Right, when viewing the underside. Pin 3, the 3rd down on the right when viewing the bottom, is the 3.3v input. You can use one or the other, not both. When you use pin 12, 5v to 24v, you can use p3 as a regulated 3.3v output.

Now then, with the RN-24, by removing Resistor R7, the resistor immediately to the upper left of the regulator, and right above the IC, you disable the RS-232 pins, enabling TTL pins. This is where I had some problems. For the SP3232ECA, RS-232 to TTL converter has a few issues that will need to be worked out.

The problems we are facing are that it leeches power from the TX/RX pins even while the R7 resistor is removed. This causes voltage spikes and incompatibility with the TTL signals. This essentially makes using it as a TTL module, problematic at best. This can be solved by completely removing the SP3232ECA IC. Not an easy task, even for someone with a steady hand.

On the bright side, the RS-232 on it works perfectly.

RS-232? TTL? What are those you ask? They are the two primary standards for Serial Communication.

The RS-232 works on a -12v, 0v, +12v scale, where TTL just has 0v and +v, usually 0v and 5v, though it can be any voltage, such as 3.3v TTL or 24v TTL. In these Bluetooth adapters it would be 0v and 3.3v, meaning we need a converter to talk to the 5v lines of the Basic Atom Micro controllers. May it be the Original Atom, the pro or the nano; they would all need a logic level converter. Using 5v on a 3.3v device, could potentially damage the IC.

 

A TTL converter is required to drop, or raise the voltage. Press Expand for details.

 

Now then you can buy one at spark fun. Sparkfun Logic Level Converter, which if you do buy them, do yourself a favor and buy 4-5 of them. If you need 1, chances have it, you'll need 2 or 3 more. Since with multiple 3.3v modules and 5v MCUs, each pair would need a TTL converter.

Or you can make one. Schematics from Sparkfun

To make them a 3.3v to 5v booster, you'll need a few parts. You can buy such parts in bulk, if you happen to make a lot of converters as i do. Since i use them for every project.

A BSS138 N-Channel MOSFET SMD  Transistor: Datasheet Opens externally. Us this or something similar. These can be harder to find, but are cheap even in bulk. A few dozen shouldn't set you back more than a dollar or two.

2x 10k ohm resistors, again very cheap, i use SMD(surface mount) resistors, they are hard to solder, but i can make an entire converter in very little space.

1x 22k ohm

1x33k ohm.

Some headers and a PCB to put it all on.

When using the BSS138, which is very small, you need tweezers and a steady hand.

 

The TX in goes to the TX on the 3.3v powered adapter, and the TX-out goes to the RX on your 5v device.

As for dropping 5v TX down to 3.3v, you only need 2 resistors in what's called a voltage divider. Sparkfun uses 2x 10k resistors, I don't.

In this image, the RX_HV goes to the 5v TX, and will use the voltage divider to drop the 5v signal down to 3.0v, which is close enough to 3.3v.

A multimeter will confirm this. Put 5v into the RX_HV end of this picture, and ground.. to ground. And then test the voltage between ground and the RX_LV.

 

 

Two 10k resistors will work, but it'll halve the voltage from 5v down to 2.5v, by using a 2/3 ratio, you cut the voltage by 2/3rds so it brings 5v down to 3.33v

 

Now that we have the power levels out of the way, let’s get back to the adapters.

The RN-24.

I made a few modifications. Instead of just removing R7 which is just a 0ohm resistor, IE a fuse, I rerouted it to pins 22 and 23.

On the RN-25, Pins 22 and 23 are used for data signals, for the RN-24 they are not connected to anything.

I then use a jumper to enable or disable R7. This was so i can enable or disable TTL signals but due to the power leech problem listed above, this was no longer required, since RS-232 is required for my version of the adapter.

 

A picture is worth a thousand words.

I used 30 AWG solid kynar wire. that can be purchased at a RadioShack near you. The best wire I've found.

It handles heat really well, easy to trim, and great to work with. And you get a lot, for just a few dollars.

The Pros of the RN-24

-Very powerful Class1 100meter Bluetooth, I actually got about 400 feet LOS when paired with the RN-41, there was a tiny bit of lost data, still <1%

-And is very command friendly. I'll cover this later on.

-You can easily configure this device over UART or over Bluetooth remotely.

-0.100" hole spacing. So it can be made breadboard mountable, though it will be a bit wide, so better if you have a larger breadboard.

-Can use a wide range of voltages from regulated 3.3v or 5v to 24v.

-Uses an SMA (not RP-SMA) antenna, for some serious range. Can even be paired with a higher db gain antenna, even a directional one.

Cons:

-The TTL doesn't really work even with the R7 removed. This will no doubt be fixed in version 5 of the module.

-Can be a little expensive if you're on a tight budget.

Verdict:

One fantastic device. I absolutely love it. I can't imagine a better adapter for its size and price range, with so many features.

 

 

The RN-41

Now here’s a fantastic Module. At $25, the pricing on these modules is well worth it. Similar modules that range between $16 and $20 are class2, 10meter.

Where the RN-41 is a powerful Class1 100m module. With a fantastic Chip antenna. Unlike the smaller cheaper, and weaker modules that use a trace antenna.

For my projects, there are only 4 wires I need to worry about. TX/RX and 3.3v and GND, There are a lot of pins, but those are the only 4 I care about, with exception of 1 module, but I’ll get to that later.

To use these in my projects, I need only 3 parts.

The RN-41 module, a length of 30awg solid kynar wire, and a 4 pin male header.

The tools, wire snips, a soldering iron, and a hot glue gun… and of course a steady hand.

Step1:

Glue the header to the module, at the bottom. Front or back, doesn't matter. I prefer the back. Just a small dab of glue to hold the header in place. More glue is added when finished.

Step2: Cut 4 lengths of solid kynar wire, and attach them to the header pins. Or the points on the module first, whatever is easier for you.

Step3: Attach the wires to the proper pads.

NOTE I goofed a little and switched the RX and the TX. I was comparing the header output to a controller, but forgot the controller listed its RX and TX, and obviously RX to TX, and TX goes to RX.. so I had to switch them around. This only took an extra 30 seconds.

 

Step4: Test all points with the continuity test of your multimeter, and then once everything is good, seal in hot glue.

 

You can see here I have four RN-41's lined up, all wired up. And you'll notice #4 is a little… different. He has a sword! No it's a header pin connected to pin32 of the module. This happens to be an unused PIO. PIO9 to be exact. This is a special pin that will be used as a remote reset for an Atom Controller.

I will send a command to the module to pull that pin low, resetting the atom module. Or any device I need.

The backside of the modules.

 

I use wire scraps instead of wasting wire fresh off the spool. Hence the various colors.

The Pros:

-Very cheap compared to other modules.

-Small, I chose these over the RN-41-SM's which include a breakout board.

-Great data rates

-High power, Class 1 100m range.

-Uses the Roving Networks Command list. Which is very nice. Very easy to configure.

The Cons:

I didn't actually find any cons with these at all. I've used small modules like these before. So I’ve had experience with modules this size. At most, it would be how hard it is to solder to the pads, but even compared to other adapters I've used, these have great high quality pads.

Verdict: They did exactly what I wanted, and had the price tag I wanted to see.

For many people, a weaker class 2 10-20m module. such as the RN-42, will work fine. But with a $5 difference in prices, it makes sense to get one 5-10x more powerful.

The only improvement I could think of, would be an RN-41-ULF, that includes a ULF connect instead of a chip antenna.

I'd rather use a ULF to SMA adapter with a high gain antenna than the chip antenna. But having reached 400feet line of site, with <1% error rate, I’m in no position to complain.

 

Configuring the RN-24 and RN-41.

 

The command manual can be found here. PDF files open externally. But this is just a general run through.

No pictures here, but let’s talk about AT commands. Never buy a Bluetooth UART module that can't be configured by commands. I have a weak class2 module I bought from Sure Electronics, which works fine, but does not support commands at all. This means you need an SPI programmer to configure it. Something I did not enjoy constructing. (The SPI programmer that is)

The Roving Networks adapters ALL support commands either by direct UART and/or remotely over Bluetooth.

This is a fantastic feature. And though many modules like the Rayson modules support commands, the RN devices have very easy to use commands as well.

The Roving networks modules are the same ones used in the popular Bluesmirfs from sparkfun.

 

First things first. To get into command mode, send:

$$$     ; Initiates the CMD mode.

This will take you into command mode. Very simple. You can also change that to something else. For me I use %%% on my RN-24 and $$$ on the RN-41.

You can change the command symbol with C$,<new symbol>, so to change it to %, the command is "C$,%"

This was so I can configure the RN-24 or the RN-41 remotely, without affecting the host module.

Once in, you can get a readout of all the information.

with

D      ; Displays basic information

E       ; Displays advance Information

O       ; Displays special information.

SU,##     ; will set the baud rate. You only need the first 2 digits. so 115k is only "SU,11" Without quotes. I personally use 38.4k So that it's backwards compatible with the Atom Nano's Hserial. So my command was SU,38. The default speed is 115k.

 

The connect command "C,<mac address>" is one of my favorite commands. When used from Slave mode, you can trigger the host module to temporarily step into master mode and connect to another slave device. The mac address is the address of the remote module. This information is available from each module using the "D" command.

I took the liberty of checking all the information of all of my Bluetooth modules and storing it in a simple text file for easy reference when coding.

— +CR, to exit command mode, That's three dashes – , followed by a carriage return, such as ,13 in the atom.

 

So to connect to another module from the atom MCU, you need 3 commands.

For this, I’ll be using hardware serial as an example.

sethserial1 h38400     ; Or whatever baud rate your modules are configured for.

hserout ["$$$"]      ; My host module uses "%%%"

pause 5                  ; just give the serial time to transmit, pause 1 would work just fine.

hserout ["C,001D4300D2A1"]     ; An example using my Sure Electronics BT module's address

pause 500            ; you can probably get away with a shorter pause, but I notice using a longer one helps. 250 will probably work just fine. or even 100ms

hserout ["---",13]  ;Leaves command mode on the host module.

And that's it. It'll connect immediately after, and you can start transmitting commands.

The reason I do it this way, is because I have multiple modules, and I want to select which module my controller links to, depending on which contraption I want to control.

 

And there you go. How to use the RN-24 and RN-41 Bluetooth module from Roving Networks.

Some people like to use the Xbee, I prefer Bluetooth. The main reason… Using Bluetooth stack on a PC with a cheap USB Bluetooth Dongle, you can create a virtual serial port. Meaning you link your Bluetooth module to your PC without any additional hardware such as an Xbee breakout serial board or anything like that.

This makes controlling a robot from a PC using Bluetooth serial, easier, and cheaper.

The bluetooth stack of choice for me, is BlueSoliel, of all the stacks I've used, such as windows, toshiba, widcomm, and a few other generic stacks. Bluesoliel is the only one that hasn't given me issues with virtual serial ports.

I apologize for my grammar.

Fallentine’s Craft Stick 2DOF hexapod. Part 1

This isn't a tutorial, or a guide, it's just a project post. You will see a lot of these.

This uses my Botboard mini Pro 28. Please feel free to read the project guide on that.

This is a working project, so i still have quite a bit to do. Such as make a way to hold the botboard mini, and the battery in place. Maybe add some LED's or something.

 

Videos can be found here or on Youtube.

 

Lets get started. This is a simple 2 DOF hexapod, It wasn't very hard to make, though i did have to remake it a few times. It's design is pretty straight forward, you'll notice the middle row of servos are not directly in the middle, this was to compensate for the servos size and shape.

I use 7gram micro servos. And no matter how you look at it, these servos are fantastic. They are fast, strong, and cheap at $3.40 USD for a 2 pack. Thats $1.70 each.

My hexapod is controlled by a Gameboy Advance SP wirelessly using bluetooth adapters from sparkfun. It is configured using a terminal using AT commands. ATI? For example sends back all the current settings. command mode is set when the bluetooth is not connected. I also use a Sureelectronics bluetooth adapter that i got from ebay. But i suggest the sparkfun version as it is command configurable.

Update: best to use Roving Network's adapters, class 1 100m adapters.

Gameboy advance serial output guide. The gameboy advance SP puts out ~3.3v and uses TTL signals, so you can power the bluetooth adapters without any additional circuitry. But in order to use a GBA SP, you'll need a flash cartridge. They aren't illegal, but they walk a fine line, so getting one can be tricky. Yes, theres legitimate reasons to have one, this is one of them.

 

Well here are some pictures with notes for each. Click the pictures to open in a background tab.

A closeup, It looks curved for some reason, though i assure you this is not the case.

Hexapod closeup

It's using a 7 cell Ni-MH battery pack, essentially 7 rechargable AAA batteries.

Next is the botboard mini pro 28, with the Sure-Electronics UART Bluetooth adapter, This one requires an SPI programmer to reconfigure. The sparkfun uart adapter is better as it only needs simple serial commands. But the Roving Networks adapters are the best choices. But i didn't have access to those when i made this hexapod.

More pictures of the bot are coming.

 

Here we have 3 pictures of the gameboy advance, with EXT to header adapter, and the sparkfun bluetooth adapter.

 

Next we have the Sure Electronics, Bluetooth uart adapter. The header pins are ground, Vdd, RX, TX. The header pins are the same on the Sparkfun, but the wiring is different. This adapter includes a female header which goes to the SPI pins which i use to reconfigure this adapter. The sparkfun adapter does not need this, and is configurable remotely. The wires and the trace antenna are encased in hot glue. It's removable, but keeps it all secure. The wiring is 30 AWG Solid Kynar wire.

 

Click to enlarge

 

Heres the lovely Sparkfun BTM-182 bluetooth uart adapter, prior to being encased in hotglue.

Multimeters and Continuity Test

When making any DIY projects, before powering ANYTHING up, check all your connectors with a multimeter's Continuity test.

What the test does, is it checks for a complete circuit and will beep when a complete circuit is made. These can also be used to test surface mount LEDs but thats our little secret.

Never plug your micro controller into a DIY board without checking everything for unwanted bridges. Every pin must be tested. It doesn't take very long, and can save you a ton of hassle. You must make sure every pin is connected where it's supposed to be, and no where else. A bad connection will fry your micro controller, ruin a servo or sensor, or destroy every servo and sensor on your contraption.

Quick tips: Salvage everything!

If you're like myself, you may not be able to afford all the resistors or transistors, or even capacitors you would likely need for future projects.

This is why you should salvage as much as you can. Computer motherboards, and especially power supplies are a treasure trove of goodies. Electronics dating from the 80s to 90s are also a fantastic source of goodies. Just toss them in a box and stick them in a closet, you never know when you'll need them. Key note: Also set asside some thick gloves, some of those electronic boards are so prickly they can be hell on your hands.

Here is a decent link for resistor color/number codes. 

Here is a decent link for Capacitor number codes.

Don't just salvage standard capacitors and resistors, theres plenty of goodies that can be had from electronics. Computer motherboards often have ferrite chokes, which you can use to dramatically reduce interference on servo lines.

Computer power supplies often have standard resistors, capacitors, and even voltage regulators.

Computer dial up modems like the horrid 56k data fax modems are often overlooked, but often have some of the best goodies. Like small speakers or even high power  sealed relay switches.

You see this lovely little beauty? That black round thing, that's a tiny speaker, similar to the ones used on the Lynxmotion Botboard 2. See that black box near the plugs under the transformer? That little baby is a relay!

Like i was saying, don't limit yourself to standard components. Surface mount components are also very useful. Especially resistors.Using the color code tables linked above, you can find the resistance of a surface mount resistor. And there are 2 ways that I use to desolder them.

To desolder surface mount components, may they be resistors, capacitors, or even surface mount LEDs, I use one of two methods.

Method 1: If you have only 1 soldering iron, add additional solder to each side of the resistor, and switch the iron from one end to the other end until the resistor moves off of one of the solder points. Then using a pair of tweezers, heat the remaining attached side and dislodge the resistor.

Method 2: This one requires 2 soldering irons and very steady hands.

Using both irons, heat both sides of the surface mount components and simply lift it off. Be careful as not to damage the component by over heating. So remove 1 iron and the resistor will likely be held on by the other iron, then quickly wipe the resistor onto a wet soldering sponge. A pair of tweezers and a tiny storage container and you're set.

Breadboard jumper wires: The best place i've found breadboard jumper wires was actually using old PC networking cables. Often I have networking cables with kinks or damaged ends, and these cat5/cat6 cables contain usually 8 different colored nice thick solid copper wires. They are easy to strip, and fit quite nicely. And if you salvage them from a nice 25 foot cable like I did, you won't be running out of cable any time soon, so you'll always have plenty of wire to use on your projects, and you can always snip them to the right sizes.

 

Desoldering serial plugs and other I/O plugs from a computer motherboard. Ok theres no real easy way of doing these, but there are two methods.

While OUTSIDE use a butane torch and simply heat the solder on the underside of the board holding the serial ports upside down. If you're lucky you'll be able to melt the solder and dislodge the plug before the board burns and stinks, and boy do they stink.

Method 2, which is what i use 75% of the time, is using a heatgun, it's essentially a hair dryer on steroids. I picked up a variable heatgun with 2 speed settings at Ace Hardware for $32. With this, you can salvage parts by the masses. Using high heat, and the high fan speed setting, you can heat the entire corner of the board, and using some needle nose pliers, the plugs should come right off. Or you can heat more in the middle of the board, while wearing some light insulated gloves, and pick off surface mount components with tweezers very rapidly. You can just sit there and pick them off one after another.

The Botboard Mini Pro 28

I'm Fallentine, writer and one of the project creators for Basic Micro. This is my first real project post, it's very skimpy, wordy, and light on details. Don't worry, future projects will be overflowing with details and information, possibly even schematics.

As for this particular project, I will eventually be showing how to make your own using a larger prototyping board. So stay tuned for future post.

Today i'll be introducing you to a little project i did, which was to create a miniature version of the Lynxmotion BotBoard 2.

The reason behind this project was that my projects are becoming smaller and smaller, and thus i needed a smaller board. How small? Well this board is currently 45mm by 45mm. Or roughly 1.75" by 1.75". Many would consider this board redundant as there are many beautiful boards available, but more often than not, those boards are large, with added features that not everyone needs or wants to use. Such as buttons or user LEDs, Speakers or special controller connectors.

It offers a full array for the 20 user pins, each with their own power input jumpers to select between direct battery input, or by one of the two onboard 1.5A 5volt regulators.

Making one of these boards is no easy task, and it's not suited for just anyone. It took hours of planning, and even more time actually doing the work. It required a light touch, as it actually uses Surface Mount components. Also abbreviated as SMD or SMT.

Now then, i won't go into detail on how to make you own in this post. But i will give you general ideas on where to start.

As you can see this board is very simple in it's early stage.

It includes headers and a socket, as well as the reset switch in the corner, but much of the board is still largely unfinished.

You will notice there are jumpers inside the IC socket. This was done to save space. On many boards, the space under the IC sockets is left empty, while components are moved to the sides, extending the boards. This is fine for most, but for smaller boards, it's actually a problem. These pins when linked up as shown in the center red jumper, link power to a 5v regulator, or when connected down link power directly to the battery. And are connected to the center row of each header array.

The header pins from left to right are P0 to P3, P4 to P7, P8 to P11, then down, then P12 to P15, and P16 to P19 for the atom pro 28. The pro 24 does not have or use pins 16-19, so they could simply be used as power outputs.

The headers are standard signal,power,ground, compatible with all major servos.

 

We have power! I apologize greatly for the quality, my camera's manual lacked the info regarding macro photography, and i was unable to focus in, after spending 2 hours on the phone with the camera maker, they finally managed to tell me how to use macro photography.

As you can see in this picture at the top, theres a large T-220 regulator, it is a Texas Instruments 5v 3A LDO regulator, and it has been the bane of this project. They lack an internal safety diode, so before i installed power wires and a battery connector, i just used header pins. I've actually fried 2 of them accidentally, and 1 intentionally as testing. Burned my finger on one. I've since switched to using two, 1.5A regulators in a seperate array, Regulator 1 goes to the first 2 header arrays, and regulator 2 goes to the last 3 arrays.

You will notice a small orange arrow pointing inside the IC socket to something looking a little black, covering a few holes visible in the earlier picture, This is another voltage regulator. It is a 5volt 0.8A TI LDO regulator, which is dedicated to the Basic Atom Micro controller. It is small, low heat, and ideal for the micro controller, and tucks away nicely under the Atom. This regulator works fine with just 5.5v input, though i recommend at least 6v.

Wiring

Now then I didn't take many pictures while wiring. Once i get wiring i need absolute focus, and i can't stop every 5 minutes to snap a picture. If i lose concentration, it'll take me a good while to figure out where i left off.

Well, we can see here i started wiring the power up. This has since gone through a few modifications, which i was unable to photograph at the time.

You can tell all the ground pins are connected. A lot of the soldering doesn't look very clean, which i personally blame on the angle. But it's actually pretty neat.

Each array of headers has it's own 0.1uf ceramic disc capacitor. To link all the pins, i actually used the long wires of the capacitors and put them against the pins while soldering. This allowed me to cleanly bridge the power pins, and all the ground pins. I used female headers to hold all the pins in place while soldering. The easiest would be for a person to use a 40 pin computer IDE cable. plug your header pins into that to hold them in place while soldering. This will also help you keep them all lined up. The power wires are a bit heavier AWG wire than i like using on small projects, but i needed wire that could handle the current.

 

Theres no excuse for this one, it's a spider web mess of wires. I won't sugar coat it, or anything.

The wire i used to connect the pins is 30 AWG solid kynar wire. Which is more than enough for signals. Despite being solid wire, it's a bit trickier to strip. Because it's so fine, most wire strips end up cutting it. So i use my teeth, i suggest against it, but it's the only thing i've found that works. Plus With my teeth, i could strip 1mm, or 5mm accurately, like magic.

The wiring is connected in an array so P0 on the micro controller would connect to the first pin on the array. There are much neater ways of doing this, like double sided custom PCB's. That's if you have $100+ to spend. I actually do suggest doing this if you can afford, it, as you can actually make your boards smaller and neater than anything i could offer.

There really is no schematic required here. For anyone wanting to create this project, if you cant figure out how to arrange the wires, then this whole project is a bit over your head. I had to use tweezers in order to get these wires around, and quite frankly, i did a horrible job, i'm actually a bit ashamed of how it looks.

On the other hand, it works fantastic. No shorts or unwanted bridges.

When wiring this all up, you'll need to take into consideration, that everything is in reverse since it's upside down. P0 is no longer the first pin on the left. but now the first pin on the right. The pins of the headers are real easy, it's figuring out which pin on the IC socket that's the tricky part.

 

Now then, it was all a fun project, i had a lot of fun doing it.

There have been a few modifications which i won't go into details on, because they are very specific personal modifications, one being a TTL voltage converter, which amplifies 3.3v TTL signals to 5v, and from 5v down, making them safe for my 3.3v bluetooth adapter.

And a simple power LED. To connect a power LED, simply connect the ground of the LED to the ground lines on the board, and the positive voltage line to a 470ohm to 1kohm resistor. then connected to a +5v line.

A picture of it's red SMD power LED. I love surface mount components. Using tweezers they are easy to solder, and take almost no space. You can attach a resistor between 2 neighboring pins by just heating the solder and dropping it in.

 

Here are some recent pictures of the board, now that i know how to use the macro function on my camera.

The two T-220 regulators sharing a single soldered on heatsink, are 1.5A regulators, by Texas Instruments TL780-05C's

I'm still in the middle of looking for stronger power regulators. the 3A regulators i originally intended to use, failed on me. The TI-UCC382T and UCC283T's failed to output 400mA despite being rated for 3A.

The Female header on the Right, is where my bluetooth UART adapter plugs in, and the two jumpers next to it is connects the TX/RX pins of the bluetooth adapter to pins 14 and 15, the hardware serial pins, of the atom pro.

 

Here's the 90% finished underside. I say 90% because i still need to replace the regulators, and if you notice in the lower right corner, there are two 103 (10kohm) SMD resistors, one of those needs to be replaced by either a 15k, or a 6.6k resistor. It's a voltage divider that drops the 5v TTL signals of P15, down to 2.5v for my 3.3v bluetooth adapter. After i switch one of the resistors, i'll drop 5v down closer to 3v. I will go into detail when i do a DIY post on how to make your own servo board.

In the lower left corner, there's a SMD transistor, and a SMD resistor, this is a boost to up the voltage from 3.3v to 5v for the bluetooth adapter.

Schematics for the converter can be found here, but you'll only need 1 channel if you're using 1 device.

 

 

Here you can see my board next to the Lynxmotion Botboard 2.

I very much so like the Lynxmotion botboard 2, it's a fantastic full featured board, perfect for many users. Only things i didn't like, were, even though it's small, it's a bit to large for some of my projects, and it has features which most people use, that i personally didn't use. Such as the user LEDs and Buttons. The speaker i did use, but i would rather use a header plug'n'play speaker that uses a 3 pin header instead.

You will also notice i removed the very large DB-9 serial programming port on the botboard 2, in exchange for a 4 pin header. I'll give full details on how to do one of these yourself as well. The reason for this, is it reduces the space to the side, allowing the board to fit in a smaller housing enclosure. You could also use right angle headers or another setup.

The pins from RIGHT to LEFt on the header, are 5-ground, 4-DTR, 3TX, 2RX,

Pins 1, and 6-9 are not used while programming the Atom Pro. You can however use 7-RTS, instead of 4-DTR. The atom can use RTS or DTR. I prefer DTR simply because it's easier to make a header for.

 

Heres definitely a picture you'll get a kick out of.

This is my Botboard Mini Pro 28, next to my Botboard Nano 18. They are both 45mm by 45mm boards, you can see a lot more space on the nano board though.

The nano board came first, and is a bit messier, and it uses the faulty TI 3A regulators, So it'll actually be receiving new regulators soon. The nice thing about the nano board, is that it's small, compact, and offers servo compatible headers for all the output pins. But that's a whole post all together.

Quick Tips: Extend the life of Soldering iron tips.

You can double, triple, and sometimes even quadruple the life of soldering iron tips, by sanding off the oxidation.

Over time oxidation builds up on tips, and using your brass coil or wet sponge can only clean the tip so well. So when you feel it's time to replace the tip, STOP! Hammer time.

Don't throw it away.

Instead, take the tip and clamp it into a small hand held power drill. Then grab some 600+ grit sandpaper, wet it a little, and give it a spin.

Be careful not to clamp it in to hard or you can mishape the end that connects to your iron, or even damage the threads if the tip screws in like most Radioshack irons.

Wipe the tip regularly with a paper tower and continue to spin-sand the tip until it looks nice and shiny.

This wont make 1 tip last for ever, and a re-sanded tip won't be quite as nice as a brand new tip, but if you want to save money, you can definitely re-sand the tips to extend their life.

PS When i discovered this nice little trick, i went through my work station trash bin looking for discarded tips from months past. Tips now last me months.

 

A picture of a rough sanded tip, It's definitely not of "new" condition, but it'll last me weeks, before it needs another quick sanding.

This sanding job took roughly 30 seconds. I could have spent more time and got a cleaner tip. But this is fine.

Breadboarding With A Nano18. Part 1

What is Breadboarding?    Part 2   Part 3  Part 4

Back in the day (think turn of the 20th century), electrical components were large and unwieldy. Experimenters and hobbyists drove brass nails into handy kitchen breadboards and soldered components between them. Once you built a circuit you kept it forever or laboriously stripped all the parts off, drove new nails, etc. This chore was quickly alleviated by the Fahnestock clip, starting in 1907 (picture on left). This device allowed easy parts swapping and experimentation. You can still get these today. They are typically used in model train layouts.     Modern breadboards use tinned beryllium-copper clips inside their plastic bodies to “capture” wires and component leads (see picture on right).      

 

 Either way, breadboarding allows one to create temporary circuits quickly and conveniently. Parts replacement is possible, multiple wires can be tied to a single starting point, and entire circuits can be built up, disassembled, and new circuits built using the same components from earlier efforts. It is largely inexpensive and effortless, but not without its limitations. Rough handling leads to loose and sometimes intermittent wires, which can be bothersome, sometimes even destructive, for components that can’t take sudden loss of one or more power or signal connections. The user must watch that long bare components leads don’t touch. Frequencies above 30 MHz aren’t recommended, so most RF work is not possible. The RF limitation doesn’t apply to XBEE modules as they are self-contained boards.     
     Once a circuit is done to completion, the experimenter can purchase inexpensive circuit boards whose pads have the same layout and placement as on the breadboard and simply move the components and wires over to this and solder them in place. Violas, a tested permanent circuit ready for rugged use! 

Anatomy Of A Breadboard

Click images to open in new window.

Click to Enlarge

Typical Breadboard with Binding Posts

 

Details of Power Input Binding Posts – Notice wire insertion holes in shafts. These will also take banana plugs.

This is the deluxe way to go. This is actually a project station. Buying just the plastic block part is less expensive. However, the base has non-skid feet, and the binding posts ensure rock-steady wire installations for power wiring. The $5 to $15 you save now with a plain breadboard means nothing when a power wire pops loose and fries a $50 accessory module. Even though the Nano 18’s paltry $8 price seems bearable to replace, the week waiting for it to arrive will surely be annoying.

Nano18 Overview

The full data sheet for this is at http://downloads.basicmicro.com/downloads/datasheets/B0086_basic_atom_nano_18.pdf.

 

Click to Enlarge

Being an 18-pin DIP (Dual Inline Package) makes the Nano 18 perfect for breadboarding. There are two other Nano versions, a 28-pin and a 40-pin part. These of course give more RAM, EEPROM (forms of memory) and I/O, but the Nano 18 is only $8.

What lends this part so well to breadboarding is the fact that the user need not install a crystal and its support capacitors, or a resonator, for clocking. This frees two pins for I/O work.

    The Nano processor has an internal clock, set to run at the factory at 8 MHz. You’ll note that certain Baud rates are stated above for software and hardware serial ports, and a rate for the number of instructions per second (IPS). These are set largely by the 8 MHz clock rate. If higher speeds for these factors are needed, the user will have to switch to the Atom Interpreter IC processors, which are designed to run at 20 MHz. However, the user will have to add the crystal/caps or resonator to clock these parts and lose two I/O pins. Other than that, the chips are largely the same for other wiring.

 

Breadboarding With A Nano18. Part 2

Obtaining and Installing Studio  Part 1   Part 3   Part 4

BasicMicro’s Studio compiler/IDE (Integrated Design Environment) software package is needed to program any Nano, debug problems, and provide terminal windows for serial communications. The latest Beta version can be found in the BasicMicro forums at

http://forums.basicmicro.net

under the “News” section. Being Beta means it is prone to “bugs” (internal problems in the code). The new user is directed to using the company-sanctioned, tested version mentioned below.

Note:  This program must be run on 32-bit Windows operating systems, such as Windows 2000, NT SP4, XP Pro and Home, and Vista. MicroSoft’s OS7 has been tried and found compatible at present, but no large scale testing has been conducted yet.
Any exceptions to this, and their fixes, can be found on the forums or by contacting BasicMicro’s support department using support@basicmicro.com or by making inquiries on the forum at the .net address above. OS versions like Windows9x or earlier, or ME, are no longer supported.

To download the installer, go to

http://www.basicmicro.com/BasicATOM-Nano-Downloads_ep_56-1.html.

And click on “BasicMicro Studio” at the top of the selections. This will start the download process for the latest sanctioned version. Select “Run”, “Save” or “Cancel” in the download window and follow the directions that appear after. Eventually you’ll have the setup installer icon.

 The icon for the setup installer looks like:

 

Once you have it, follow these steps:

After left-double-clicking the setup icon, you will see the InstallShield Wizard window appear:

If you have a previous version of a Basic Micro IDE/compiler, you may see a window on top of this advising you of a conflict between this and the other compiler. It will announce the conflicting version and recommend you uninstall it. The user must uninstall the previous version before this installation can proceed. This is not true for all earlier versions.

Click
  to continue, or
 

  to stop installation at any time.

Note: If you see it active, the 

  button will let you return to a previous step and redo selections.

 
The License Agreement Window opens.

 

 Read the agreement carefully. This explains the rules governing users’ use and rights, as well as copyright and termination considerations, between user and Basic Micro. If you disagree, click  and end the installation.

 If you agree, click the “I agree…” button, then click   to go to the next step.
 

The installation choice window opens next.


You can select between either Complete or Custom. Complete will install all necessary files to the default folders, creating folders where needed. Custom allows the user to select a different folder to install to.

We recommend you leave it set to Complete.

Then click  .

You will get a “last chance to review” window (Not shown here).

Click  to start the file installation process.

 

The File Installation Window opens

The fuel gauge in the middle tracks the installation progress.
Eventually the InstallShield Wizard Complete window comes up.

Click  to end the process.

Find the Studio icon, , and left-double-click on it to start the program.

At this point you’ll want to download the online forum manual (up to v12 at this writing) for Studio at

http://forums.basicmicro.net/syntax-manual-f501/

and read the Studio overview portion of the “Quick Start” section. This will guide you through Studio’s features and how to use them to find, select and program your Nano.
Be aware, this manual is still a work in progress. Not all the commands available are covered. There are however several demo programs and app notes for the Nano in the Downloads section of the BasicMicro Home page and on the forums in the AtomNano section you can use as guides.

Basic Programming Concepts

Most complex programs contain six parts as a rule (sometimes less, some times more):

  1. Header
  2. Initialization(s)
  3. Setup(s)
  4. Main Routine
  5. Subroutine(s)
  6. Interrupt routine(s)

 

The following example shows a basic template to use for future user programs.

Don’t enter the numbers or numbered entries.

1. First is the header.

; A Basic Template for Programming, Rev1.0, 9June2010 By Name Here

; This can be followed by a program description, usage instructions, wiring guides, warnings, etc.

; Every line starts with a comment symbol, the semicolon (“;”) or apostrophe (“ ’ ”).

2. The Initialization(s) Section

; **** Initialization(s) ****

Enter your VARs, CONs, and TABLEs here; Initialize Liquid Crystal Displays (LCD) and other devices.

Although not mentioned in the list above, if you plan to use the LCD or any serial ports, add a PAUSE 500 after this to allow the LCD and Nano to initialize internal registers.

3. Setups

; **** Setup(s) ****

Here is where you define your interrupts and enable them; take first readings of digital pins and/or ADC pins to assign to MIN/MAX values and the like;

4. Main Routine

Start entering your program here. This contains the main body of code plus code for interrupts where the user does the bulk of the interrupt’s work. Avoid repeating the same code over and over here; make repetitive tasks into subroutines and put them into the next section.

5. Subroutine(s)

; **** SubRoutine(s) ****

Code you use over and over goes here. Subroutines have labels, which are used in GOSUBs to identify which piece of code to go to in this section. I use a trailing underscore (“_”) to identify a label in the program as belonging to a subroutine, such as “LCD_Report_”.

       Each subroutine ends with “RETURN”.

  1. Interrupt Routines

; **** Interrupt Routine(s) ****

After defining interrupts above, the user places his interrupt’s label here followed by short, concise code. Brevity is key, as interrupts running here are using stack space, and if interrupts take too much time in running there is a real chance several interrupts will overlap. This leads to using up all the stack space, which can lead to strange problems (Read: damn hard to troubleshoot) or even a complete reset. I try to identify an interrupt label by using a leading “i_”, i.e., “i_IntHandler”.

     All interrupt routines end in “RESUME”.

In short, the template looks like:

; Header

; **** Initialization(s) ****

; **** Setup(s) ****

MAIN

; **** SubRoutine(s) ****

; **** Interrupt Routine(s) ****

END   ; Last thing in the program, but optional. Always a good idea to have this here, though.

Just create a dummy program titled something like “Code Template”, based on the template above, and use it every time you set out to write code.

Some notes about commenting: A comment can start with either “;” or “ ‘ “. I commonly use the “;” as it stands out better in a crowded page of code. Comments can be standalone lines or entries at the end of lines of code. F’rinstance, the following first commented line lets you know what the routine does; the next ends in a comment that tells of the use of two characters, “0” and “13”.

; The following code line writes the ADC value to the serial port

SEROUT s_out, i9600, [0, dec ADC_Val, 13]  ; The “0” clears the screen, the “13” is a new-line.

Commenting is a must for good programming. Not only does it allow others studying your code to understand what you mean to do in your program, it can help the original writer refresh his/her memory about their intent several months, even years, after they finished the code originally.

    I submit programs to the forums a lot. All this code is heavily commented. I do this as a service to the beginners who are trying to learn how the code works.

Next we discuss white space and indenting. These help a user track the “sense” of the code. White space is typically using blank lines between routines, which consist of multiple lines of code, to aid in tracking logic flow. Indentation allows tracking logic within these routines.

      The following block of code is incomplete and meant only to illustrate the points above.

MAIN

LOW LED  ; “LED” is an LED attached to pin P10 of the ATOM, LOW turns it off

; Empty line inserted to show next block is unique

; This routine tests ADC value, blinks LED at P10 if value less than 512

FOR Loop = 1 to 128  ; Do this 128 times

PAUSE 350  ; pauses 350 milliseconds

           ; The IF-THEN-ENDIF indented yet again to show uniqueness

           IF ADC_Val < 512 then  ; If ADC reading less than 512 then

           TOGGLE LED                ; toggle (ON/OFF) the state of LED

           ENDIF                             ; We’re done

     NEXT  ; Increment Loop value

; Another empty line, end of indentation, to show end of previous routine(s)

…More code here…

END

Find, download and study the Nano demo codes on the BasicMicro forums to get a better idea of proper program layout.

   Part 2/4   Part 3/4  Part 4/4   Part 2/4   Part 3/4  Part 4/4   Part 2/4   Part 3/4  Part 4/4

Older posts «