GoRobotics - Robotics news, robot projects

Archive for the ‘Microcontrollers’ Category

Arduino 5 Minute Tutorials: Lesson 2 – Basic Code & Blink LED

Posted on April 17th, 2012 in Microcontrollers

Lessons Menu:

Lesson 2 Hardware:

  1. Computer / Laptop or Netbook
  2. Arduino Microcontroller
  3. USB to Serial Adapter (if your microcontroller does not have a USB port)
  4. Appropriate USB cable (Arduino boards draw power from the USB port – no batteries yet)

The Arduino language is CASE SENSITIVE: a capital letter is not the same as a lower case letter. The following code represents the minimum in order for a program to compile:

Arduino 5 Minute Tutorials

The “void setup()” section is widely used to initialize variables, pin modes, set the serial baud rate and related. The software only goes though the section once.

The “void loop()” section is the part of the code that loops back onto itself and is the main part of the code. In the Arduino examples, this is called “Bare Minimum” under File-> Examples -> Basics. Note that you are free to add subroutines using the same syntax:

void subroutinename() {}

Almost every line of code needs to end with a semicolon ‘;’ (there are a few exceptions which we will see later). To write single line comments in the code, type two back slashes followed by the text:

//comments are overlooked when compiling your program

To write multi-line comments, start the comment with /* and end with */

/* This is a multi-line comment and saves you having to always use double slashes at the beginning of every line. Comments are used used to explain the code textually. Good code always has a lot of comments.*/

Serial Communication

The Arduino board can communicate at various baud (“baud rates”). A baud is a measure of how many times the hardware can send 0s and 1s in a second. The baud rate must be set properly for the board to convert incoming and outgoing information to useful data. If your receiver is expecting to communicate at a baud rate of 2400, but your transmitter is transmitting at a different rate (for example 9600), the data you get will not make sense. To set the baud rate, use the following code:

void setup() {

Serial.begin(9600);

}

9600 is a good baud rate to start with. Other standard baud rates available on most Arduino modules include: 300, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, or 115200 and you are free to specify other baud rates. To output a value in the Arduino window, consider the following program:

Arduino 5 Minute Tutorials

Verify the program by pressing the “verify” button (looks like a “play” button in order version or a check sign in Arduino 1.0); you should not get any errors at the bottom of the screen. If you get errors, check that only the two numbers in the code are black, the rest of the text should have been automatically recognized and assigned a color. If part of the text is black, check the syntax (often copy/pasting text from another program can include unwanted formatting) and capitalization.

Next, upload the sketch to the board using the “Upload to I/O Board” button (arrow pointing right). Wait until the sketch has finished uploading. You will not see anything unless you then select the “Serial Monitor” button (rectangle with a circle that looks like a TV in the old software, or what looks like a magnifying glass in the new software). When you select the serial monitor, make sure the baud rate selected is the same as in your program. If you want to save all your programs, we suggest creating a new folder called “reference” and save this program as Hello World.

Blink LED Program

Connect the board to the computer if it is not already connected. In the Arduino software go to File ->  Examples -> Basics -> Blink LED. The code will automatically load in the window, ready to be transferred to the Arduino. Ensure you have the right board chosen in Tools -> Board, and have the right COM port as well under Tools -> Serial Port. If you are not sure which COM port is connected to the Arduino, (on a Windows machine) go to Device Manager under COM & Ports.

Press the “Upload” button and wait until the program says “Done Uploading”. You should see the LED next to pin 13 start to blink. Note that there is already a green LED connected to most boards – you don’t necessarily need a separate LED.

Understanding Blink LED Code

From Lesson 2 you will recognize the basic code void setup(){} and void loop(){}. You will also recognize the green commented sections. The three new lines of code you have not seen before are:

pinMode(13, OUTPUT);

This sets pin 13 as an output pin. The opposite, being INPUT, would have the pin wait to read a 5V signal. Note that the ‘M’ is capitalized. A lower case ‘m’ would cause the word “pinmode” to not be recognized.

digitalWrite(13, HIGH); and digitalWrite(13, LOW);

The line digitalWrite(pin, HIGH); puts a specified pin high to +5V. In this case we chose pin 13 since on the Uno, the LED is connected to pin 13. Replacing HIGH with LOW, the pin is set to 0V. You can attach your own LED using a digital output and the GND pin. Note that the ‘W’ is capitalized.

delay(1000);

The delay(1000); line causes the program to wait for 1000 milliseconds before proceeding (where 1000 is just a convenient example to get a 1 second delay). Note that during a delay, the microcontroller simply waits and does not execute any additional lines of code.

Special Note

Pin 13 incorporates a resistor with the LED, whereas none of the other digital pins have this feature. If you want to connect one or more LEDs to the other digital pins, you need to add a resistor in series with the LED.

Arduino 5 Minute Tutorials: Lesson 1 – Software

Posted on April 11th, 2012 in Articles, Microcontrollers

Lessons Menu:

Lesson 1 Hardware:

  1. Computer / Laptop or Netbook
  2. Arduino Microcontroller
  3. USB to Serial Adapter (if your microcontroller does not have a USB port)
  4. Appropriate USB cable (Arduino boards draw power from the USB port – no batteries yet)

The popularity of Arduino is steadily increasing and it is fast becoming the microcontroller of choice for students, hobbyists and smaller companies. Many different electronics PCB manufacturing companies are jumping on the bandwagon and producing their own variations of the boards, as well as “shields” (additional circuits that fit directly on top of many Arduino boards to increase their functionality) and accessories. The Arduino website offers free resources and tutorials as well as a language reference to help you understand the code and syntax. In order to get started, you will at the very minimum need an Arduino board. Note that all the Arduino (and most of the clone boards) can use the Arduino software. If you are unsure what hardware to get, the Arduino USB is currently the most popular model, and these 5 minute tutorials are based around it.

Downloading / Installing Arduino Software

  1. Go to www.arduino.cc to download the latest version of the Arduino software (Direct link: http://arduino.cc/en/Main/Software and select your operating system; in this case we are using Windows)
  2. Save the ZIP file to your desktop (you can move or delete it later)
  3. It is convenient to create a new folder called “Arduino” under “Program Files”. To do this, go to “My computer” -> “C:” (or the drive where the operating system is installed) -> “Program Files”, then left click once on “program Files” folder, then select “New”->”Folder” from the main Explorer menu.
  4. Extract the entire ZIP folder to this new “Arduino” folder
  5. To run the Arduino software, open Windows Explorer by pressing the windows key (usually between the Ctrl and Alt keys on your keyboard) and the ‘E’ character at the same time (there are other ways to access explorer as well).
  6. Go to “My computer” -> “C:” (or the drive where the operating system is installed) -> “Program Files” -> “Arduino” In this folder you will see an executable file (blue colored icon named “Arduino”), you can left click (once) and then right click and select “send to” -> Desktop (create shortcut) to have Arduino more easily accessible.
  7. Double click the icon on the desktop to start the software.

The Arduino Software Interface

The Arduino interface is pretty “bare-bones”. When you load the software, the first screen you will see is a white window (shown below) with several different shades of blue and blue-green as border.  Arduino projects are called “sketches” and when you start a new sketch, several additional files are also created.

“Newest: Arduino Interface (as of Q1 2012)

The main headings are “File” “Edit” “Sketch” “Tools” “Help” and several shortcut icons beneath “Verify”, “Upload”, “New”, “Open”, “Save”, and at the far right, the “Serial Monitor”. Note that all these icons are also available from the main menus.

“Older” Arduino Interface

The main headings are “File” “Edit” “Sketch” “Tools” “Help” and several shortcut icons beneath “Verify”, “Stop”, “New”, “Open”, “Save”, “Upload” and “Serial Monitor”. Note that all these icons are also available from the main menus.

Arduino 5 Minute Tutorials

To connect to your board,
  1. Launch the Arduino software by double-clicking the Arduino icon
  2. Plug one end of the USB into the Arduino and the other end into your computer.
  3. Your computer should detect the new device and tell you if it has installed correctly. At this time, two things can happen; if you have an older board using an FTDI chip (ex. Duemilanove based), Windows should detect it and you’re good to go to the next step. If you have a board which uses an ATMega chip to convert USB to serial (for example the UNO), you will need to install the drivers manually.
  4. Take a look at your board’s main processor chip (usually found between the pin headers) to see which you have. It will likely be the ATMega168, ATMega328, or a more powerful ATMEga640. ATMega1280 etc
  5. In the software, select “Tools” -> “Board” -> You will get a list of possible boards. If you have a different board, select it from the drop-down list; if you have purchased a compatible board, that manufacturer should indicate which board to choose.
  6.  In the software, select “Tools” -> “Serial Port” -> COM # (note that if you have several COM ports, you will need to go to Device Manager to see which COM port is assigned to your board.
You’re now ready to start coding!  

Carlitos’ Projects: Speech-Controlled Arduino Robot

Posted on March 1st, 2011 in Microcontrollers, Projects, Robotics Projects, Robots

We all dream of having appliances and machines that can obey our spoken commands. Well, let’s take the first step towards making this happen.  In this second iteration of Carlitos’ Projects, we are going to build a speech-controlled Arduino-based robot.

Speech Controlled Arduino Robot

You may be thinking that making such a robot must be a very complex task. After all, humans take many years before they can understand speech properly. Well, it is not as difficult as you may think and it is definitely lots of fun. The video below illustrates how to make your own speech-controlled Arduino rover.

After watching the video, read below the detailed list of parts and steps required to complete the project.

Materials

  • A DFRobotShop Rover kit. It constitutes the robot to be controlled.
  • A VRbot speech recognition module. It processes the speech and identifies the commands.
  • Two Xbee RF communication modules. They create a wireless link between the speech recognition engine and the robot.
  • An Arduino Uno. Controls the speech recognition module.
  • An IO expansion shield. Allows to connect the Xbee module to the DFRobotShop Rover
  • An Xbee shield. Allows to connect an Xbee module to the Arduino Uno.
  • Male headers. They are required by the Xbee shield.
  • A barrel jack to 9V battery adaptor. Allows to power the Arduino Uno trough a 9V battery.
  • An LED. It is not required since the IO expansion shield already has one but it can provide a more visible activity feedback.
  • An audio jack. It will be used to connect the microphone. This is optional
  • A headset or a microphone (a microphone is included with the speech recognition module).

Tools

  • Wire Cutter. It will be used to cut the leads off components.
  • Soldering Iron. In order to solder all the (many) connections, a soldering station might be preferable since it provides steady and reliable temperature control that allows for easier and safer soldering (you have less risk of burning the components if the temperature is set correctly).
  • Third Hand. This is not absolutely required, but it is always useful for holding components and parts when soldering.
  • A Hot-glue gun in order to stick the components together.
  • A computer . It programs the DFRobotShop Rover and the Arduino Uno using the Arduino IDE.

Putting it Together

  1. Assemble the DFRobotShop Rover and mount the IO expansion shield, an Xbee Module and the LED. Se the picture above or the video for further information.
  2. Solder the headers onto the Xbee shield. Also solder four headers on the prototyping area as shown below. Do not like soldering? Then keep reading since there is no-solder-required version of the project.
    Speech Engine - 2
  3. Connect the four headers to the corresponding pins as shown below.
    Speech Engine - 3
  4. As shown above, you can also mount the headphone jack and use the cable included with the microphone in order to connect it to the VRbot module microphone input.
  5. Put the shield onto the Arduino and connect the battery.
    Speech Engine - 4
  6. Connect the VRbot speech recognition module wires and the microphone.
    Speech Engine - Back
  7. Program the DFRobotShop Rover and the Arduino Uno with these programs respectively:
    dfrobotshop_serial.zip and VRbot.zip
  8. Start talking to your robot! Say “forward”, “backward”, “left”, or “right” in order to make the robot move in the desired direction. The word “move” shown in the video has been removed from the program in order to improve the performance.

Go Further

Now that you have the basic program you can create new commands in order to build upon this project. For instance, it would be nice to program a “dance” command that would make the rover execute a predefined choreography. It is also possible to use this knowledge to control other devices such as lamps, TV sets, and more.

You can find more information about using the VRbot speech recognition module here:

In our case, we used two of these robots in order to create a ball-fetching challenge at the CRC 2011 with high-school and CEGEP students. As shown below, the students and general public loved the game.


CRC - Robot Fun

CRC - More Robot Fun


Get your own

RobotShop put together a full kit that you can buy in order to get started with speech control. This kit is a bit different than the project shown and does not require any soldering and uses the microphone included with the VRbot module:

DFRobotShop Rover – Speech Control Kit

Carlitos’ Project: RGB LED Mood Cube

Posted on January 14th, 2011 in Microcontrollers, Miscellaneous, Projects, Robotics Projects

This is the first in a series of electronic or robotic DIY projects. These projects are accompanied by instructional videos that will help you trough the many steps involved in completing the task at hand. For this first iteration, we are making an RGB LED Mood Cube.

Glowing colour-changing objects are always cool. So why not make your own? Mood lights have been around for some time and, while it is cool to have a colour changing light, it would be even cooler to have something more complex and geekier. An RGB LED Mood Cube seems to be the way to go.

RGB LED Mood Cube Fully Assembled

In this project, we are going to build a 4x4x4 RGB LED cube that can be used to display cool colourful patterns. This project should be straight-forward and the most significant difficulty will be soldering all the connections for the cube structure and the 64 LEDs (since they are RGB, this means 256 joints for the LEDs alone!). In short, if you are looking to have a cool mood-light and get razor-sharp soldering skills, this is the right project for you.

Below you can see the video of the LED cube being put together and the final result.

If you need more information or you simply prefer written instruction, here you will find the full list of materials, tools, instructions and documents required for the build.

Materials

  • An LED Cube Kit. Provides the LEDs and all the structure required to create an LED cube.

  • A Rainbowduino. It is a special Arduino built to control up-to 192 LEDs.

  • A UartSB (USB-to-serial adaptor). A USB to serial interface that is used to program the Rainbowduino (or for serial communication in general) trough a USB port.

  • A USB Cable. A cable to hook-u the UartSB to the Computer

  • A 9V Wall Adapter. A power supply that will power the cube once the assembly and programming are done.

Tools

  • A Wire Cutter. It will be used to cut the leads off components.

  • A Soldering Iron. In order to solder all the (many) connections, a soldering station might be preferable since it provides steady and reliable temperature control that allows for easier and safer soldering (you have less risk of burning the components if the temperature is set correctly).

  • Third Hand. This is not absolutely required, but it is always useful for holding components and parts when soldering.

  • Flat Head Screwdriver. This will be used for un/tightening terminal blocks

  • A computer . It programs the Rainbowduino using the Arduino IDE.

Putting it Together

  1. The first step is to assemble the LED cube kit. This kit is much easier to put together than the more common way of constructing an LED cube using the LED leads as the supporting structure.

    The kit includes all the parts required to hold the LED together and takes care of all the complex wiring. Full instruction on how to put the cube together are available in PDF format.

  2. Once the cube is assembled, we need to drive it in order to display cool stuff in it. For this, we use the Rainbowduino, an Arduino clone created specifically for driving massive amounts of LEDs. The cube fits directly on top of the Rainbowduino, and can provide power to it by using the included JST cable. When connecting both modules together, it is important to make sure the “Green” male headers from the LED cube match the “Green” female headers on the Rainbowduino. Also, it is important to set the Rainbowduino switch to “JST”.

    RGB LED Cube and Rainbowduino Power Connected

  3. Now that all electrical connections are done, we need to write some software in order to make it display cool stuff in our new cube. We took the liberty of modifying, cleaning and updating the plasma code readily available for the Rainbowduino. This new code should display a nice smooth wave as of colours that propagates softly though the cube. The code can be downloaded from here: Rainbowduino-RGB-LED-Matrix-Plasma.zip.

    In order to upload this code to your Rainbowduino, you will need to use the Arduino software, so, if it is not already done, it has to be installed. Also you will need to install the USB-to-Serial adaptor drivers.

  4. Once the code and the Arduino software are downloaded and installed, simply unzip the code and open the .pde sketch file found inside of the unzipped folder using the Arduino software. Then, upload the sketch to the Rainbowduino using the USB-to-serial interface.

    Rainbowduino with Serial Interface (UartSB) and USB Cable

  5. Now that the Rainbowduino is programmed, simply remove the USB interface, plug-in the power adapter and admire the light show!

    RGB LED Mood Cube Connected to the Power Supply

Additional Programming and Hacking

Of course, colourful lights are pretty and everything, but for those of you who would like to program your own patterns and animations, there are functions in the provided code that allow you to set the LEDs individually. You could also add some sensors and make the cube interactive. There are even some Xbee headers that could be used to send information to the cube remotely from a nearby computer Using an Xbee module.

On the physical side, you can make a cover for your cube out of paper, plastic, fabric or whatever other materials you have on hand (make sure the material is translucent though)

Finally, at the end of the construction, you will have many RGB LEDs and a bunch of male and female headers left-over. Make sure you put them to good use in your next project.

Getting Your Own LED Cube

RGB LED Mood Cube Full Kit

For those of you wishing to make their own cube, you can use your own parts and buy the missing materials separately or you can get all the components in a convenient kit at RobotShop.

RGB LED Mood Cube - 1

You are also invited to share your results and experience in the RobotShop Forum and by simply leaving a comment below.

Arduino + Toy = Robot!

Posted on December 14th, 2010 in Microcontrollers, Projects, Robots, Sensors

This is a nice video from a while ago describing how to quickly and cheaply put together a robot by using an old RC toy, an Arduino (actually a Seeeduino), a Ping distance sensor and a couple of other components.

More in-depth videos of the construction below.

We are eager to see our readers go crazy and build their own robots from old toys.

Via DinoFab.

Subscribe to the RobotShop Blogs RSS feed!

Enter your email address: