}

10/24/2012

Arduino Due vs the Arduino Mega 2560 and TI Stellaris Launchpad

ARM powered Arduino Due

Where can you buy an Arduino Due?

The Arduino site itself shows 'SOLD OUT' on their Arduino Due page.  I ordered an Arduino Due this morning from Mouser electronics.  The Due's are being sold at Mouser for $39.95, which is $10 cheaper than the $50 price I've seen in press releases so far.  They are being shown on backorder, so I don't know how long it will take for me to actually get my hands on one.

Why in the world did they name this board the Arduino Due?  Won't there be confusion between the Arduino Due and the Arduino Duemilanove?  I've seen the Duemilanove shortened to Due many times in the past.  Could be a source of confusion...

Arduino Due specs

The Due is powered by a 32 bit Atmel ARM Cortex M3 microcontroller.  Here's a quick rundown of the Arduino Due's specs:

ARM Cortex M3 microcontroller running at 84 MHz
54 digital I/O pins
12 PWM pins
12 Analog input pins
2 Analog Output pins (digital to analog converters or DAC)
512K Flash storage (program storage)
96K RAM
Operating voltage 3.3V
4 UARTS (serial ports)
USB port can act as a host for devices like mice, keyboards, etc.

For more info, go to the Arduino Due page at Arduino.cc

What's so good about the Arduino Due?

Obviously, a much more powerful 32 bit processor is a huge upgrade from the 8 bit chips.
Tons of I/O, program storage and ample RAM
The DAC's provide for easy playback of music and voice, using the Audio library.  WAV file playback right away, with other formats supported later.
12 bit resolution on analog inputs and DAC's.  This gives 4096 levels of resolution versus the 8 bit resolution of the Arduino UNO, et al, which only had 256 levels of resolution.
Open source!  The Eagle files are already posted at Arduino.cc.  Stay tuned for cheap eBay knockoffs.

What's missing from the Arduino Due?

No floating point unit.  Still has to use emulation, although it will be much faster.  TI's Stellaris Launchpad, by comparison, has a hardware floating point unit.
An Ethernet port would have been really nice.
5.0 Volt device support - I know there was no getting around this, but it's going to cause lots of problems with all of the 5 volt devices and shields already in the Arduino ecosystem.

Comparing the Arduino Due to the Arduino Mega 2560

I currently own an Arduino Mega 2560 clone ($22 on eBay).  Some quick specs vs. the Arduino Due:
54 digital I/O pins on both.
12 PWM pins on both.
16 analog inputs on Mega 2560, 12 analog inputs on Due
256K program storage on Mega 2560, 512K program storage on Due

If you need a faster, more powerful processor than the Mega 2560, DAC's, 12 bit resolution on ADCs and DACs, USB 2.0 host support...then the Arduino Due is the clear choice.

I'm still a beginner, and I can't fathom needing more than the Mega 2560 at this point.  The processor is plenty fast enough, there's virtually infinite I/O on the board, and I like the fact that it can support both 3.3 and 5 volt devices.  

As far as price goes, the Mega 2560 is currently selling for $58.95 at the retailer Sparkfun, while the Arduino Due is listed for $49.95, although it is not in stock.  Realistically, Mega 2560 clones can be had on eBay for $22 shipped.  We will have to wait and see what the Arduino Due knockoffs sell for.

I can imagine applications where the Arduino Due would shine vs. the Arduino Mega 2560.  CNC and 3d printing are two such applications.  Complex robotic systems are another, especially talking robots, or robots with advanced mapping and navigation systems.  I'm not building these types of systems yet, so the advantage to me would be nil at this point.

At what point would you jump from using a Mega 2560 to just using a full fledged mini-PC instead of a microcontroller?  The jump to the Arduino Due almost seems incremental to me.  I do have one on the way, so I'll reserve judgment for when I get my hands on one.  It might end up knocking my socks off.

Comparing the Arduino Due to the TI Stellaris Launchpad

The only reason I am making the comparison of the Arduino Due vs. the TI Stellaris Launchpad is because of the Energia IDE.  Energia allows you to program TI microcontrollers (currently just the MSP430 value line) using Arduino sketches.  I've used Energia with the TI MSP430 Launchpad, and can attest that it works very well.  The developers of Energia announced a few weeks ago that they are working on Stellaris Launchpad support and it should be ready 'soon'.

The Stellaris Launchpad had a promo price of $5 at it's launch, but the price is now $12.99.  This is not really a fair comparison with the Arduino Due, since TI is undoubtedly selling the Stellaris Launchpad at a loss, or at best break-even.  But, you can buy it for $12.99, shipped.

Let's compare the specs of the Arduino Due vs. the Stellaris Launchpad:
Stellaris has an ARM Cortex M4F microcontroller running at 80Mhz vs. the Due's M3 running at 84 Mhz
Stellaris has 35 digital I/O vs 54 on Due
8 UARTS on Stellaris, 4 UARTS on Due
2 12 bit DAC's on both Stellaris and Due
16 PWM outputs on Stellaris, 12 PWM outputs on Due
Hardware FPU on Stellaris, Due relies on software emulation
Stellaris has 256K flash memory program space, Due has 512K program space
Stellaris has 32K RAM, Due has 96K RAM

The TI Launchpad Stellaris beats the Arduino Due in every category except for total amount of I/O available and Flash memory/SRAM.  The two boards are close enough hardware wise to be very comparable for most applications I think.

The real question is when and how good will the Energia support be for the Stellaris Launchpad?  There are plenty of chips and dev boards that are better than the Atmel based Arduino boards, but the Arduino almost always holds the edge in ease and speed of development.

Stay Tuned!

I'll be posting more when I get my Arduino Due from Mouser.

10/23/2012

How to set up an electronics lab for the beginner

Setting up an electronics lab for beginners

Why did I make this list?

When I first started really getting into electronics experimentation back in December (about 10 months ago), I found it very confusing and difficult to know exactly what I needed to buy.  What tools would I absolutely have to have?  What components would I need to get started?  What microcontrollers are best when you are starting out?

I ended up buying a lot of stuff I didn't really need.  I also ended up buying things I needed, but I bought the wrong model or type.  I also ended up not buying a lot of things that I did need.  The net result was that everytime I started to try and build any kind of simple project, I found myself lacking a key ingredient.  It was a very frustrating, and sometimes expensive, learning experience.

In this post, I will try to make a list of tools and components you will need if you are just getting started in electronics.  This is a general-purpose list, meant to give you a good supply of commonly used items.  You will be able to build a wide assortment of projects using the tools and components in this list.

This list is not all-encompassing.  I'm assuming you have ordinary tools like screwdrivers, wrenches and pliers on hand already.  You will also need to provide your own means to organize and store all of this gear.

Total cost of the starter electronics kit

The total cost of all the tools and components listed below is $343.69.  It might sound a little pricey, but if you look at the list you can see that you will be getting a TON for your money.  Compare it to electronics kits like the Mindstorm NXT 2.0 that costs $280.  I really wish I would have come across a list like this when I first became interested in electronics.  For me it hasn't been the cost of the hobby, it's been the frustration of not having what I needed on hand.

Shopping for hobby electronics

There are several places I usually buy hobby electronics.  The cheapest for components is almost always eBay, as long as you can wait a couple of weeks for them to ship it to you from China.  I have provided links below to all of the recommended components.

A disclosure - I do have an affiliate account at Amazon.  If you buy through one of the Amazon links below, I will earn a small commission.  I make no money on the eBay links.  If you buy on Amazon - be careful with the shipping.  If you try to buy items that say 'Free super saving shipping on orders over $25' you will save a ton on the shipping costs.  Be careful not to buy a $5 item from one seller only to pay $5 in shipping.  Most of the Chinese sellers on eBay have free shipping to the US.

Tools 

Multimeter - Extech EX-330 Autoranging Multimeter - $59 at Amazon
I put this multimeter on the list because it was the best meter in Dave Jone's $50 multimeter shoot-out at the EEVblog.  The meter I actually own is the Equus Innova 3320, and it's served me fairly well.  I do wish I had bought at more expensive one now, though.  One of the bigger down-sides to the really cheap meters is the speed at which they are able to switch ranges.

Soldering iron - Hakko FX-888 65W Soldering Station - $80.72 shipped at Amazon
This is one of the more important tools in your arsenal.  I had a constant temperature iron that came from radio shack for about $9 when I first started.   I wasn't able to control the temperature and it took too long to warm up.  I later bought a $25 dollar cheap-o soldering station on eBay.  This was ok, but it also took forever to heat up, and it eventually broke.  Take my word on this one item - buy a decent soldering iron!  It is hard enough for a beginner to solder correctly, and damn near impossible if you are using a shitty iron.  My recommendation - Hakko FX-888 Soldering Station.  It heats up quick, is ergonomic, does a great job, and has a really sexy design.

Needle nose pliersKlein standard long nose pliers - 6 inch - $21.71 at Amazon
Your needle-nose pliers are going to spend a lot of time in your hands and you will depend on them to work smoothly and accurately.  I love these Klein needle-nose pliers.  I like the simple handles that give you really good feedback with whatever you are gripping, bending, etc.  The cheap pliers have bulky handles that feel disconnected from the working end of the pliers.  Get yourself a good pair of needle-nose.  We'll save money on other items later, I promise.

Side cutting pliers - Channellock 6-inch diagonal pliers - $16.39 at Amazon
You'll be spending a lot of time snipping leads and cutting wire.  I like this pair, but you should be able to get away with a little cheaper pair if necessary.

Solder sucker - Vacuum desoldering pump - $6.07 at Amazon
You'll need this kind of tool for pulling solder off of pads when removing components from a board.

Microcontrollers

Arduino - Meduino Nano - $11.66 on eBay
Arduino is the most popular hobby electronics microcontroller platform out there.  The Meduino Nano is compatible with the Arduino Nano, easy to use on a breadboard, and it is CHEAP.  Buy a couple of these.

MSP-430 - TI Launchpad MSP-430 - $4.30 at Texas Instruments
The MSP-430 is a low-power, super low-cost microcontroller offering from TI.  The TI Launchpad MSP-430 is a dirt-cheap development board that TI sells for $4.30.  When you buy a Launchpad, you get the board, two microcontrollers and a USB cable.  You may choose to use TI's Code Composer studio to program the chip if you like, or you might choose Energia, which allows you to program an MSP-430 just like you would an Arduino.At this price, you should buy 2.

Boards and cabling

Breadboards - 830 point solderless breadboard - $5.79 on eBay
Use a solderless breadboard to easily build a circuit by simply pushing wires and components into the holes. Buy 2!

Perfboard - Prototyping PCB perfboard - $2.25 on eBay
Perfboard is good when you want to make your connections more sturdy than using a breadboard.   Buy two of these.

Jumpers - 65 piece male to male jumpers - 2.85 on eBay
These are pre-made jumper wires so you can quickly make connections on your breadboard.

Dupont jumpers - 40 piece female to male jumpers - 3.22 on eBay
These jumpers are made so you can plug a pin or wire into one end, then plug the male end into a breadboard.  These are perfect when you need to connect a male header pin to a breadboard.

22 gauge hookup wire - 25' solid 22 gauge hookup wire - $3.39 on Amazon
Buy 3 spools of this.  You will be using this wire for almost every electronics project you ever do.  This wire is even good for breadboarding, since you can cut your jumpers to the proper length and make them lay flat. Anytime you have more than 10 standard jumpers on a breadboard, things start getting very spaghetti-like.

Test clips - 10 piece alligator clip test leads - $3.30 at Amazon
Great for making temporary connections or using with your multimeter to make measurements.

Components and other 'stuff'


Electrolytic capacitors - 160 pc, 23 value electrolytic capacitor assortment - $12.00 on eBay

Ceramic capacitors - 250 pc, 25 value ceramic capacitor assortment - $2.98 on eBay

Diodes - 25 pcs. 1N4001 1A 50V diodes - $0.99 on eBay

NPN transistors - 50 X 2n3904 NPN transistors - $0.99 on eBay

PNP transistors - 50 X 2N3906 PNP transistors - $2.59 on eBay

555 timers - 10X TI NE555 IC - $3.49 on eBay

3.3V voltage regulators - 10pcs EX1084CT 3.3 volt fixed regulators - $3.99 on eBay

5.0V voltage regulators - 10X LM7805 voltage regulators - $3.99 on eBay

Potentiometers - 12 potentiometer assortment - $8.25 on eBay

9V battery clips - 5 X 9V battery clips - $0.99 on eBay

2 AA battery holders - 5 2AA battery holders - $2.22 on eBay

4 AA battery holders - 2 4AA battery holders - $0.99 on eBay

LCD displays - 16X2 HD44780 LCD display - $2.25 on eBay
Easy and cheap way for your projects to give output.  Buy two.

Distance ranger - HC-SR04 Ultrasonic Sensor - $2.29 on eBay
Give your projects 'vision'.  Buy two.

Speakers - 2X piezo buzzers - $1.89 on eBay


Switches and button - Switch and button assortment 10 PCS - $6.39 on eBay

Servos - Towerpro SG90 9g Micro Servo - $3.50 on eBay
Buy two.

Solder - MG Chemicals 37/63 .032 solder - 1/2 pound - $16.75 on Amazon

Flux - Oatey flux, 4oz. - $5.36 on Amazon



10/19/2012

Using the TI Launchpad MSP430 as an in system programmer (ISP)

Using TI Launchpad MSP430 as an in system programmer (ISP)

One of the really nice things about the TI Launchpad MSP430 is the ease with which you can transfer the MSP430 chip from the development board to your project board.  Just program the chip in the launchpad, take it out, then put it in your project.  Very easy.

But, what if you want to program your chip in circuit?  Each time you move the microprocessor, you run a risk of bending or breaking pins.  Not to mention, you may want to reprogram a chip that is already soldered to a PCB.

That's just as easy, and only requires 4 wires.  There are 5 jumpers between the Emulation and MSP430 side of the board, right where the dashed line is.  Pull the three jumpers from VCC, TEST and RST.  Connect jumpers from the VCC, TEST, and RST pins on the Emulation side of the board to the corresponding pins on your chip.  Use one more jumper wire to connect the ground on the launchpad to the ground pin on your MSP430 chip.

Hit the upload button, as usual.  In the video, you will notice I am using Energia - it programs the MSP430 chip as if it is in the Launchpad board.

In the video I program 3 MSP430G2553 chips and 1 MSP430G2452.  Each chip is programmed with the same code, which just blink an LED on and off on pin 8 at a 100ms rate.

To connect the MSP430 chips directly on the breadboard, you just need to hookup VCC and GND.  You will also need to tie the RST pin HIGH.  The datasheet says to use a 4.7k ohm resistor on the RST pin, but I didn't.

Don't forget to replace the jumpers on your TI Launchpad MSP430 board when you are done.  Hope this was helpful for someone.


10/18/2012

TI Launchpad MSP430 i2c communication with Arduino using Energia



This is the second part in an i2c demo I have been working on.  In the first part, I had an Arduino Mega communicating with an Arduino Uno.  Now we are going to add a TI Launchpad MSP430 to the i2c bus.

First, we need to connect the TI Launchpad MSP430 to the i2c bus.  Simply connect pin 1.6 on the Launchpad to the SCL channel on the breadboard and pin 1.7 to the SDA channel on the breadboard.

Second, we need to change the voltage of the i2c bus.  The MSP430 is a 3.3 volt device, so I just moved the +5 feed to the i2c bus on the Arduino Mega 2560 to the 3.3 volt pin.

Next, I connected a speaker to the TI Launchpad MSP430.  I have the red lead of the speaker going to pin 1.4 on the Launchpad and the black lead connected to ground.

Now for the code.  The Arduino Mega will first tell the Uno to turn it's LED on, wait 3 seconds, tell the Launchpad to play a 1900 Hertz tone using the tone() command, wait 3 seconds, then turn the LED and speaker OFF.

The code for the Launchpad is almost exactly the same as the code I previously used for the Arduino.  The only difference is that we are now playing a tone instead of lighting an LED.  The other difference is the i2c ID # of 6.

Below is the code for the Arduino Mega 2560 and the TI Launchpad MSP430.  I used the Energia IDE to program the MSP430 using Arduino code.  The Launchpad is using a M430G2553 microcontroller, although a 2231 should work just as well.

i2c master code - Arduino Mega 2560


//i2c Master Code(MEGA)
#include <Wire.h>

void setup()
{
  Wire.begin();
  delay(2000);
}

void loop()
{
      
      Wire.beginTransmission(5);
      Wire.write('H');
      Wire.endTransmission();
      
      delay(3000);
      
      Wire.beginTransmission(6);
      Wire.write('H');
      Wire.endTransmission();
      
      delay(3000);
      
      Wire.beginTransmission(6);
      Wire.write('L');
      Wire.endTransmission();

      Wire.beginTransmission(5);
      Wire.write('L');
      Wire.endTransmission();
      
      delay(3000);
     
}

i2c slave code (TI Launchpad MSP430 with MSP430G2553 installed)


//i2c Slave Code(LAUNCHPAD)
#include <Wire.h>

void setup()
{
  Wire.begin(6);
  Wire.onReceive(receiveEvent);
  
  pinMode(6,OUTPUT);

}

void loop()
{
}

void receiveEvent(int howMany)
{
  while(Wire.available())
  {
    char c = Wire.read();
    
    if(c == 'H')
    {
      tone(6,1900);
    }
    else if(c == 'L')
    {
      noTone(6);
    }
  }
}

I'd like to thank the Energia folks for creating the Energia IDE.  If you haven't heard of it, it allows you to program an MSP430 chip using the same code as you would an Arduino.  For more information on Energia, you can go to the Energia website, or the Energia forum at 43oh.com.

i2c communication between an Arduino Uno and an Arduino Mega 2560



I've never worked with i2c before, except to connect an i2c LCD.  In this video, I get an Arduino Mega 2560 and an Arduino Uno to talk to eachother over an i2c bus.

The Arduino Mega 2560 is set up as the master device.  I connect pin 20 (SDA) to a negative power rail on the breadboard, and pin 21 (SCL) to a positive rail.  On the Arduino Uno, I have A4(SDA) connected to the negative power rail and A5 (SCL) connected to the positive.  The SDA and SCL channels from each Arduino are now connected to eachother.

I must now provide power to the SDA and SCL channels of the i2c bus.  I use the +5VDC pin on the Mega 2560 to power the SDA and SCL channels, going through a 4.7K ohm pull-up resistor first.

The last connection I make is to connect an LED up to digital pin 8 of the Arduino Uno, going through a 510 ohm current limiting resistor on the ground side.

Below is the code I used for each Arduino.  The master, the Mega 2560, sends an 'H' to i2c device #6.  When the Uno receives the 'H', it turns the LED on pin 8 ON.  The Mega waits 3 seconds, then sends an 'L' to the Uno.  The Uno reads the 'L', then turns the LED OFF.  Pretty simple code.  Note that the receiveEvent() routine is basically an interrupt handler.  This way the Uno will stop whatever it is in the middle of whenever i2c traffic is received.

First the Master - the Arduino Mega 2560


//i2c Master Code(MEGA)
#include <Wire.h>

void setup()
{
  Wire.begin();
  delay(2000);
}
void loop()
{      
      Wire.beginTransmission(5);
      Wire.write('H');
      Wire.endTransmission();
      
      delay(3000);
      
      Wire.beginTransmission(5);
      Wire.write('L');
      Wire.endTransmission();
      
      delay(3000);     
}

and now the code for the slave, the Arduino Uno


//i2c Slave Code(UNO)
#include <Wire.h>

void setup()
{
  Wire.begin(5);
  Wire.onReceive(receiveEvent);
  
  pinMode(8,OUTPUT);
  digitalWrite(8,LOW);
}

void loop()
{
}

void receiveEvent(int howMany)
{
  while(Wire.available())
  {
    char c = Wire.read();
    
    if(c == 'H')
    {
      digitalWrite(8,HIGH);
    }
    else if(c == 'L')
    {
      digitalWrite(8,LOW);
    }
  }
}

10/14/2012

How to build a robot #9 - connecting the i2c serial LCD, HC-SR04 ultrasonic sensor, and an LED



Todays 'How to Build a Robot' video is pretty simple.  I'm simply hooking up the i2c serial 16X2 LCD, multiple HC-SR04 ultrasonic sensors (four), and a power indicator LED.

The power indicator LED is real easy.  I just hook it up to the breadboard power rails across a 100 ohm resistor and I'm done.  The power rail on the breadboard won't get power until the red switch is hit, so this works out perfectly.

The four HC-SR04 ultrasonic sensors are easy to hook up too - just make damn sure you get your power and ground connections right.  A few weeks ago I wired one up backwards and the entire sensor got VERY hot.  I was surprised I didn't see smoke pouring out.  One of the 4 HC-SR04's on this robot didn't work at all, and I think it might be that one.

So each HC-SR04 sensor has a power, ground, TRIG and ECHO pin.  That'll be 16 connections total, just for the ultrasonic sensors.  As I hook each sensor up, I write down where the pins are going and keep the paper folded up in the robot for future reference.

Now it's time for the i2c LCD.  Power and ground again, of course.  Then two IO pins.  If you are using an Uno or Nano type Arduino, you will need to use A4 and A5 for SCA and SDL.  These are the two i2c pins on your Arduino.  If you have some other flavor of Arduino, just Google i2c for your device and find out what pins you need to hook up to.  If you are using the same i2c LCD as me, there is a small pot on the back you can adjust with a small screwdriver to set the contrast.

Now it's time to make all these systems talk to eachother!

10/12/2012

How to build a robot #8 - Using an IDE cable to bring I/O to the second deck



In this installment of 'How to Build a Robot' I'll be using an IDE cable to bring 16 I/O pins, 5VDC and ground pins from the bottom level to the top level of Boxx-E.

I already know that I will have 4 HC-SR04 ultrasonic sensors and a serial LCD display on the top level of the bot.  I am also going to add a power-indication LED to the top of the bot too.  After thinking about it, each HC-SR04 will have 4 wires - 1 for trig, 1 for echo, 1 for power and 1 for ground.  The serial LCD has 4 wires - SCL,SCA, power and ground.  The LED will have power and ground also.  That's a total of 22 wires!

It's a lot easier to bring the wiring up to the second deck on another breadboard than it is to run 22 individual wires between the two levels.  Especially if I can use one pre-built cable to do it.  The answer is an old-school IDE hard drive cable.  The IDE hard drive cable has 40 conductors - I only need 18.  The other cool things about the IDE cable is that my jumper wires are a perfect fit for the female connectors.

I punch out holes for the IDE cable between the two levels, then fasten it with zip-ties.  Then comes the job of making the connections between the cable and the Arduino on the bottom and a new breadboard and the cable on the top.  On the first few I used my multimeter's continuity tester to tone out the pins to make sure I was hooking up the right ones.  Once you are sure you have the sequence down you won't need it anymore.

This is a time where it will pay to keep good records.  Each time I make a connection to the breadboard on the second level, I write down the Arduino I/O pin # and the corresponding breadboard row number on a small sheet of paper.  When done, I fold the paper up and keep it with the bot at all times.

10/11/2012

How to build a robot #7 - A big red switch and a nine volt



I spend almost an hour installing a switch in the robot.  To be sure, it is a nice switch, and a pretty decent wiring job.

I found a cool switch with a red plastic throw.  There are two sets of contacts on the switch, so I am able to wire both the 9V battery to the VIN of the Arduino and the motor power pack to the switch.  So, with one throw of the switch, the battery pack is pumping juice to the motor driver circuit and the Arduino springs to life.

I was careful to provide proper strain relief and to secure the 4 switch wires firmly.  The switch wiring has to ride on the hinge of the top box.  I bring the positive side from each power source up from the bottom level to one side of the switch, then send it back down to the bottom level from the other side of the switch.

10/10/2012

How to build a robot #6 - battery pack hack, de-spaghettiizing, and another test run



The first order of business in this session is to correct my power problems.  In the last filming I was using the 6VDC from the battery pack to drive the motors and to provide 5VDC to the Arduino Nano.  I was wrong on both counts!  The motors are rated for 3VDC and the Nano really either needs a regulated 5 volt power source, or a 7-12 volt input to VIN so it can regulate the power itself.

The first fix was to NOT power the Arduino from the battery pack.  I used a 9 volt battery instead, feeding into VIN.  The second fix was two-fold.  First, I used a piece of wire to delete one cell from the 4 cell battery pack.  I also used 1.3 volt  rechargeable batteries  instead of 1.5 volt alkalines.  So I went from giving the motors 6 volts to giving the motors 3.9 volts.  If I had kept feeding them 6 volts, they may have had an hour left in them if I was lucky.

The last issue to resolve for this session was to de-spaghettify the wiring on the first level breadboard.  I'm going to have a lot more wires connected to the breadboard, and it's already a mess.  Pre-made jumper wires are nice for quick connections, but they quickly turn into a real problem.  They are too long, so you end up with a big pile of spaghetti.  It's hard to tell where they are going and it's real easy to accidentally pull one out.

The fix is to simply cut proper length wires that can lay down flat.  It's tedious, but the end result is worth it.  I'm going to have enough problems to troubleshoot in this robot without having to worry about loose jumper wire spaghetti.

During this video I realized a couple of items that need to be taken care of.
#1 - I want a power button on the exterior of the robot.
#2 - I need a way to secure the 9 volt battery

10/09/2012

How to build a robot #5 - Adding sensors, an LCD display, and another box



In this episode of 'How to Build a Robot', I am making quite a few physical improvements to the robot.  I was going to call this bot Affordabot, but I've decided I don't like the name.  I'm looking for suggestions for a new name, so if you have one, please leave it in the comments below.

I decided the Launchpad box would be too crowded once I added the HC-SR04 ultrasonic sensors and LCD display.  I looked up at the shelf and spotted the box my new Stellaris Launchpad came in.  Why not just add another box?  If you can put two mobile homes together and call it a double wide, why can't I stack two boxes on my robot and call it a double stack?

Now it's time to add some sensors.  I'm installing four HC-SR04 ultrasonic sensors.  These are only about $3 apiece on eBay.  I'm putting two on the front of the robot, and one on each side.  I modded the HC-SR04's slightly.  I took the male header pins off of each sensor and soldered female headers instead.  This will make them much easier to hook up using regular wire instead of having to use female Dupont jumpers.

So, a simple slit in the box and a little hot glue and the HC-SR04's are attached.

With the growing pin count, I decided to use a serial LCD display instead of a parallel one.  The motor controller uses 6 I/O pins, the ultrasonic sensors are using 8 I/O pins total, and the serial LCD is using 2 pins.     Using the serial LCD I will only have 4 pins left.  If I had used a regular HD44780 LCD, I'd be out of I/O pins already!  There are still a few things I want to add, like a bump switch and a speaker, so the serial LCD is a must.

I simply cut a hole the size of the LCD screen and taped the LCD display down.

10/07/2012

How to build a robot #4 - Uploading the code and a first test run!



It is now time to upload code to test the operation of the motor driver, Arduino Nano and motors.  Here's the code I used.  This is very similar to the test code I used for ClusterBot.


#define PWMA 10
#define AIN1 6
#define AIN2 7
#define PWMB 11
#define BIN1 8
#define BIN2 9

void setup() 
  {  
  pinMode(PWMA,OUTPUT);
  pinMode(AIN1,OUTPUT);
  pinMode(AIN2,OUTPUT);
  pinMode(PWMB,OUTPUT);
  pinMode(BIN1,OUTPUT);
  pinMode(BIN2,OUTPUT);
  }

void loop() {    
  goForward();  
  delay(2000);  
  turnAround();  
  goForward();  
  delay(2000);  
  turnAround();  
  goBackward();  
  delay(2000);  
  rotateLeft();  
  delay(560);  
  rotateRight();  
  delay(560);  
  goForward();  
  delay(2000);  
  applyBrakes();  
  delay(2000);  
  }

void goForward ()
  {  
  digitalWrite (AIN1,HIGH);  
  digitalWrite (AIN2,LOW);  
  analogWrite(PWMA,234);  
  digitalWrite (BIN1,HIGH);  
  digitalWrite (BIN2,LOW);  
  analogWrite(PWMB,255);  
  }

void goBackward ()
  {  
  digitalWrite (AIN1,LOW);  
  digitalWrite (AIN2,HIGH);  
  analogWrite(PWMA,233);  
  digitalWrite (BIN1,LOW);  
  digitalWrite (BIN2,HIGH);  
  analogWrite(PWMB,255);  
  }

void rotateRight ()
  {  
  digitalWrite (AIN1,HIGH);  
  digitalWrite (AIN2,LOW);  
  analogWrite(PWMA,255);  
  digitalWrite (BIN1,LOW);  
  digitalWrite (BIN2,HIGH);  
  analogWrite(PWMB,255);  
  }

void rotateLeft ()
  {  
  digitalWrite (AIN1,LOW);  
  digitalWrite (AIN2,HIGH);  
  analogWrite(PWMA,255);  
  digitalWrite (BIN1,HIGH);  
  digitalWrite (BIN2,LOW);  
  analogWrite(PWMB,255);  
  }

void veerLeft ()
  {  
  digitalWrite (AIN1,HIGH);  
  digitalWrite (AIN2,LOW);  
  analogWrite(PWMA,190);  
  digitalWrite (BIN1,HIGH);  
  digitalWrite (BIN2,LOW);  
  analogWrite(PWMB,255);  
  }

void veerRight ()
  {    
  digitalWrite (AIN1,HIGH);  
  digitalWrite (AIN2,LOW);  
  analogWrite(PWMA,255);  
  digitalWrite (BIN1,HIGH);  
  digitalWrite (BIN2,LOW);  
  analogWrite(PWMB,190);  
  }

void applyBrakes ()
  {  
  digitalWrite (AIN1,HIGH);  
  digitalWrite (AIN2,HIGH);  
  analogWrite(PWMA,255);  
  digitalWrite (BIN1,HIGH);  
  digitalWrite (BIN2,HIGH);  
  analogWrite(PWMB,255);  
  }

void turnAround()
  {  
  rotateLeft();  
  delay(1370);
  }
The code is pretty simple.  I wrote a few functions to simplify the main portion of the program.  You may notice I am using different PWM values for each motor in the goForward and goBack functions.  For one of the motors I am using a PWM value of 233, while I'm using 255 for the other.  These were the values I found would provide a straight track on Clusterbot.  Whether because of physical difference between the cheap toy motors or alignment issues in the chassis - this was a quick and dirty way to have the bot track somewhat straight.

In the video, you will notice that when I remove the USB cable, the motors stop turning.  I think the problem was that I was supplying 6VDC to the VIN pin on the Arduino Nano.  The Nano needs an input voltage of 7-12VDC on VIN, because the voltage regulator apparenlty needs the input voltage to be at least 2 volts higher than the regulated 5VDC output.

My immediate solution was to simply swing the 6VDC to the 5VDC pin on the Arduino.  This is not the smartest thing in the world, but it worked.  I think the better solution will be to simply use a 9 volt battery for powering the Arduino Nano.

One other issue - I think I am providing too much voltage to the motors in the Tamiya twin motor gearbox.  I read the specs at Pololu, and the recommended voltage is 3VDC.  I am using 6VDC, which will result in a short lifespan for these motors.  I will either lower the voltage with a resistor divider, or I may switch out battery packs.

To read more about voltages with these Tamiya gear boxes, you can check out this research: http://www.pololu.com/docs/0J11.  After reading this, maybe I could get away with running 4 rechargeables...that would be 4.8 volts.  It's not like I would run these for hours at a time like Adam did with his test.  I'm looking at runs of ~10-20 minutes, with plenty of cool down time in between.

During my test run, I noticed the zip tie on the bottom of the motors was touching the floor instead of the wheel caster.  Going to have to trim this down.  Otherwise, I was happy to see the new bot in locomotion.

Now it's time to add some sensors!

How to build a robot #3 - Wiring up the robot



Now that we've got the main systems of Affordabot in place, it's time to wire the components up so they can work together.

The video goes into good detail, but a good source of info is an earlier post I made about the TB6612FNG motor driver - http://www.meanpc.com/2012/01/how-to-use-tb6612fng-motor-driver-with.html.

Between the Meduino Nano and the TB6612FNG motor driver, these are the connections I made:

PWMA - Digital Pin 10
PWMB - Digital Pin 11
AIN1 - Digital Pin 6
AIN2 - Digital Pin 7
BIN1 - Digital Pin 8
BIN2 - Digital Pin 9

It is starting to look like this robot is going to take a lot of pins!  I'm using 6 pins just for motor control.  I'm planning on using 3 ultrasonic sensors, each of which will use 2 i/o.  A speaker will use one more.  There will be enough IO pins, but I am starting to think I will use a serial LCD instead of a standard parallel one.

Don't sweat these messy jumper wires - I'll clean them up soon.  Going to custom cut short jumpers that fit flush on the breadboard.

How to build a robot #2 - Installing breadboard, TB6612FNG, Nano and battery pack


This step is pretty straightforward.  We now need to somehow attach the microcontroller, motor driver, breadboard, and battery pack in the robot chassis.

I decided that I had to install the components in the bottom.  The problem was the bottom of the box was full of tires and zip ties, so that I couldn't find a flat surface to mount the breadboard and battery pack to.  I decided to glue a couple of pieces of foam down, then mount on top of the foam.

I used Gorilla Glue to mount the foam and components.  Hot glue would have been easier and quicker, but I don't think it would have been near as solid as the Gorilla Glue.  It was my first time using Gorilla Glue, and I am impressed with how well it did.  I did allow the glue to dry for around 10 hours.

As far as the components that I added in this step:
400 point breadboard - $3.25 shipped on eBay
Meduino Nano - $12.79 shipped on eBay
TB6612FNG Dual Motor Driver Carrier - $8.45 at Pololu

Obviously, there are a wide range of breadboards / perfboards / stripboards, microcontrollers, and motor drivers out there.  Some may be a better choice for you.  I'm using these components for ease, costs and because I have them on hand.

Note that I only use one power rail on the breadboard.  Also, the Meduino Nano is a really nice implementation of the Arduino Nano, with the Atmega 328 chip.  The Meduino Nano is switchable between 3V and 5V operation, which also changes the operating speed between 8Mhz and 16Mhz.

When I get "done" with the first prototype of this bot I'll put a list of all the parts source and prices on the first page of this build series. I am trying to source a lot of stuff from eBay with free Chinese shipping.  The stuff I can't source there, I am trying to source all at Pololu. They have pretty good prices, and I'd like to keep the number of places you are paying shipping down to a minimum.

Expect the wire hookup and initial test run videos soon - they are already in the can and awaiting some quick editing before I post them tomorrow!

10/05/2012

How to build a robot #1 - cheap cardboard box robot chassis build

Affordabot's cheap TI Launchpad box chassis.
This is the first in a series of posts chronicling the building of Affordabot.  My goal with Affordabot is to build a powerful mobile robot platform as simply and as cheaply as possible.  Affordabot will have a microcontroller, motor controller, gear motors, several ultrasonic sensors, an LCD display, and a speaker.  The target cost for Affordabot is under $50.

In this first installment, I'll be constructing the basic chassis of Affordabot using a cardboard box, a Tamiya twin-motor gearbox, wheels and tires, a caster wheel and zip ties.

Watch the video for more detailed instruction, but construction is pretty simple.  Cut holes in your box for the tires. Zip tie the motor to the box.  Zip tie the caster wheel to the box.  Route your motor wires through holes in the bottom of the box.

Parts used in this step:
TI MSP430 cardboard box - obviously, you can use any suitable box of your choosing.
Tamiya twin motor gearbox - $8.95 at Pololu - You will have to assemble this.  I recorded assembly of the Tamiya twin motor gearbox a few months back here.
Tamiya ball caster kit - $5.99 at Pololu - You can substitute this with almost anything with low friction if you like.  The ball caster kit I bought comes with two casters for that price.
Tamiya truck tire set - $4.10 at Pololu - This set comes with 4 wheels and tires.  These are made to fit perfectly on the twin motor gearbox axles.




Wires routed into the interior of the box.


Closeup of the Tamiya twin motor gearbox zip-tied to the box.  Holes had to be cut in the box to make room for the tires.

Completed chassis, including rear ball caster assembly.

10/03/2012

Stellaris Launchpad - unboxing and a first look

Stellaris LaunchPad from Texas Instruments - EK-LM4F120XL
I just received my Stellaris Launchpad and wanted to show the unboxing and the latest evolution of the 'Hello World' blinking LED program that came preloaded.

The similarities between the Stellaris Launchpad and the MSP430 Launchpad are uncanny.  The boxes are almost exactly the same.  The boards themselves are exactly the same size, and I've read that the Stellaris can actually use Boosterpacks (the TI version of the shield) made for the MSP430 Launchpad.

The Stellaris Launchpad does have a cool feature - male and female headers, simultaneously   I wish all developments boards had this.  On the other hand, TI decided to use a micro USB connector instead of the mini-USB connector that was on the MSP430 Launchpad.  I'm not sure what advantage the micro-USB connector has over the mini, but now I will need micro,mini and type-B cables on my bench.

The specs on the Stellaris Launchpad are incredible, especially for a $4.99 board.  I looked up the Arm Cortex M4-F chip on Digi-key  and the chip costs around $9.00 in one-off quantities.  There are two of these chips in the Stellaris Launchpad eval board.

Stellaris Launchpad Specs:
Speed - 80 MHz
GP I/O - 35 - 5V tolerant
Flash - 256kb
i2c - 4
ADC - 12 analog-digital converters, each with 12 bits resolution
UART - 8

Going from an Arduino or MSP430 Launchpad to a Stellaris Launchpad is like going from a Honda Civic to a Ferrari.

It's important to note one distinction between the Stellaris Launchpad and the MSP430 Launchpad.  It's a distinction that even TI is sure to make.  The MSP430 Launchpad is labelled as a 'Development Tool', while the Stellaris Launchpad is labelled as an 'Evaluation Kit'.

What's the difference?  With the MSP430 Launchpad, you can program the chip in the Launchpad, then remove the chip and plug it directly into your project.  The Stellaris Launchpad simply cannot work like this. The Arm Cortex M4-F chip comes in a quad flatpack that is not as simple as plugging a DIP package chip into a socket.  You will either have to custom make a board, or use a breakout board of some sort.  I guess you can't expect to get this kind of power and I/O count without moving to an SMD device though.

There are already some good Stellaris resources available:

Stellaris at TI - This includes a series of "Getting Started with the Stellaris Launchpad' video
Stellarisiti - Forum for the Stellaris Launchpad by the same guys that bring us 43oh.com