Skip navigation
2014

 

Next Guide:

Getting to Know Arduino : Part 3 : Taking your Temperature

 

Previous Guide:

Getting to Know Arduino : Part 1 : Hello, World!

 

In part 1 of my Getting to Know Arduino, I blogged about flashing an LED (light emitting diode) with the Arduino UnoArduino Uno and how to get started with it using an A to B USB cableA to B USB cable. However, we only flashed the LED that was on the circuit board of the Arduino and we didn't actually get to building any circuitry with it, but in the blog post we did look into the code behind the flashing of the LED.

 

Now, what we can do is the same again, only this time, a little differently. You will need the following, or a variant there of:

 

 

Along with the Arduino IDE installed onto your computer. When you have your parts, you will want to plug them into your breadboard and there is a specific way to plug them in to complete the circuit.

 

The Arduino's input/output (IO) pin sockets is where we then connect from digital pin 13 (D13) through a resistor to the LED to ground (GND). It is important to have a resistor in the circuit to prevent damage to your LED, some Arduino boards have an on board resistor in series with the IO header for pin 13 but it is safer not to take that risk else you'll let the magic blue smoke out and your LED will become an FED (fire emitting diode).

 

If you're unsure as to what resistor to use, you could take the unorthodox approach of using the highest value resistor you can find and scaling down until you find the right one, or you can calculate it. If you're uncomfortable with this, typically a 1Kohm resistor will do, but I often cheat and use an online calculator, if you do not use an online calculator then you will want to use Ohms Law to work it out. Once you've read the specifications of your LED and you know the forward voltage (or just voltage) and the forward current (or just current) in mA (milliamperes) and the source voltage (you can find out from the specifications on the Arduino, but I can easily tell you it is 5volts) then you can work out the required resistor.

 

It is important to get used to being aware of the requirements of the components and not just LEDs you're using and what resistors are required.

 

Here is an example of a completed setup:

 

arduino_part2.jpg

 

 

On a typical breadboard there is a grid referencing system. As you can partly see in the photograph it is labelled A to J along the columns across the top and numbered from 1 downwards for the rows.

 

Here we connect our LEDs positive pin to the digital IO pin socket (from row 2 on the breadboard to pin 13 on the Arduino) while we then connect a resistor (row 1 on the breadboard to row 5) and ground (GND from the Arduino to row 5 on the breadboard).

 

It is also worth to note that the LED is 'keyed' as to its orientation from positive to negative (or anode/cathode). Typically the shorter leg on the LED which also has a flat side to the plastic casing is the negative/ground/cathode side.

 

It has been known that cheap LEDs you can acquire have been manufactured incorrectly and that the casing on the LED has been rotated. So sometimes it is a lucky dip as to whether or not it will turn into a FED depending on the build quality.

Now you can connect your Arduino up to the computer and upload the example Blink program, if you still have the Blink example program uploaded to your Arduino then we will see that the LED will blink in unison with the on board LED 'L'.

 

Equally if we connect the LED to pins 1 or 0 on the Arduino, we would see it blink in unison when there is data sent to/from the Arduino.

 

Since you've now got an external LED connected to the Arduino, you can try connecting a few of them in line with one another, in series. Or, you can alter your sketch so that it will blink an LED from more than just the one pin depending on what variable values you use.

 

Have a go and experiment, if you have any problems then please leave a comment. There's also the element14 Arduino community group!

This is the third post in the blog post series celebrating Arduino day 2014..

 

This post is about a low-cost mobile lab experiment kit put together by the talented folks at Minseg. This is an excellent example of the contribution Arduino has made to the field of engineering education. Experiment kits such as Minseg not only make control and mechatronics labs more engaging, but also make them accessible to a large student population. 

 

minSeg 3.png

 

The Minseg website has a number of resources including simulation models, video tutorials etc. With these resources, you can create a miniature version of a Segway using a lab experiment kit that includes an Arduino and Raspberry Pi. You can develop and simulate balancing algorithms for the robot using Simulink. Then deploy these algorithms on an actual robot to see the robot in action.

 

Here are a set of links to specific resources:

 

 

and yes - wish you a very happy Arduino day!

This is the second blog post in a series of posts celebrating 10 years of Arduino! This series highlights how Arduino has powered a number of innovations in the field of education and engineering.

 

Robotic arms are used extensively  for numerous tasks from car assembly to picking up rocks on Mars. This video illustrates how you can build your own autonomous robotic arm using Arduino Mega with Simulink. You can learn how a robotic arm can be programmed to identify an object placed in front of it, pick it up and place it elsewhere.

 

One of many ways Arduino is making industrial applications accessible to the Maker community:

 

Happy Arduino day!!!

 

Do you remember racing a car in a video game, bumping into your opponent, your joystick happens to vibrate and you could feel the collision? This is the science of haptics. Haptic devices provide users a sense of physical interactions with real or simulated systems. The haptic paddle was originally developed and used as a teaching tool for dynamic systems at Stanford University. 

 

You may be wondering how this is related to Arduino?

 

Arduino has been used to power the development of such an inexpensive, portable haptic device at Vanderbilt University. The Arduino-powered haptic paddle is used with Simulink to teach system dynamics in Mechanical Engineering courses. Students can apply the theoretical concepts in feedback control systems by simulating the haptic paddle in Simulink and then experiencing the forces generated in the virtual environment with the haptic paddle.

 

Here's a link to the university website for more details on this project. You can also download the course materials from the website here.

 

NewSchematic_small.jpg

Every second and fourth Thursday of each month, I teach a class at my local makerspace, theClubhou.se that centers on STEM Education. Youth between the ages of 8 and 17 attend the class and we strive to teach them how to create fun projects that will hopefully inspire them to embark onto larger projects in the future.

 

During our November and December sessions this past year, we decided that we would teach the YoungMakers how to index strands of LED Christmas lights using nothing but an Arduino, a few Relays, and some LEDs as a proof of concept. After some research, we decided that the best route to take would be to use a program called Vixen Lights to simplify the sequencing process as much as possible. This was necessary because we only had a total of about six-hours spread out over 2 months to complete everything.

 

While I have documented the process we took for the curriculum we wrote around this project, I have yet to take the time to document it online. That is the purpose of this posting and by the end of this post I hope you will be able to use Vixen Lights to sequence some LEDs of your own. Below is a list of materials you will need to complete this tutorial, and almost everything can be bought from Newark.com. You can find all of the necessary code, and related files in my GitHub Repository for this project.

 

 

So to kick this off, we need to plug our LEDs into the breadboard. To simplify things, I like to plug the cathode of each LED into the GND rail of the breadboard, and place the anode into the five-position strip that is in line with the GND hole you plugged the cathode into.  This will allow us to use a jumper wire to connect the anode to the PWM pins on the Arduino, and let us only utilize a single GND port on the Arduino as well.

 

IMG_3306.jpg

 

Make sure to space the LEDs far enough apart to ensure that the ping pong balls will have enough room to fit. To get an idea of how much room you will need, six ping pong balls will take up the entire surface area of a standard breadboard. Once you have all of your LEDs in place, push the ping pong balls onto the 5mm LEDs.

 

IMG_3292.jpg

 

With the LEDs now in position, we can move on to wiring everything up. Starting from the left, attach the first LED anode to digital pin 11 on the Arduino. Follow this up by attaching the next LED’s anode to digital pin 10. The third LED attaches to digital pin 9, with the fourth, fifth and sixth attaching to digital pins 6, 5, and 3 respectively.

 

IMG_3294.jpg

 

Once everything is attached, we can move on to importing and adjusting the code for this project to our specific needs. Head over to my Github repository to download all of the files used in this tutorial, or you can copy and paste the code I have listed below.

 

IMG_3295.jpg

 

Base Code (Needs Modifying)

/*
The purpose of this code is to allow the Arduino to use the
Generic serial output of vixen lights to control 5 channels of LEDs.
Author: Matthew Strange
Created: 14 October 2010

*/

// Output
int Chan1 = 5; // green LED, connected to digital pin 5
int Chan2 = 6; // white LED, connected to digital pin 6
int Chan3 = 9; // red LED, connected to digital pin 9
int Chan4 = 10; // green LED, connected to digital pin 10
int Chan5 = 11; // red LED, connected to digital pin 11

int i = 0; // Loop counter
int incomingByte[8]; // array to store the 7 values from the serial port

//setup the pins/ inputs & outputs
void setup()
{
  Serial.begin(9600); // set up Serial at 9600 bps

  pinMode(Chan1, OUTPUT); // sets the pins as output
  pinMode(Chan2, OUTPUT);
  pinMode(Chan3, OUTPUT);
  pinMode(Chan4, OUTPUT);
  pinMode(Chan5, OUTPUT);
}

void loop()
{ // 7 channels are coming in to the Arduino
  if (Serial.available() >= 5) {
  // read the oldest byte in the serial buffer:
  for (int i=0; i<8; i++) {
  // read each byte
  incomingByte[i] = Serial.read();
  }

  analogWrite(Chan1, incomingByte[0]); // Write current values to LED pins
  analogWrite(Chan2, incomingByte[1]); // Write current values to LED pins
  analogWrite(Chan3, incomingByte[2]); // Write current values to LED pins
  analogWrite(Chan4, incomingByte[3]); // Write current values to LED pins
  analogWrite(Chan5, incomingByte[4]); // Write current values to LED pins
  }
}




 

With the code now open in the Arduino IDE, we need to make some adjustments to it to better match our setup.  The first thing we need to do is adjust the output to follow the schematic on how we hooked up our LEDs on the breadboard. Edit the output to match the code below. What we are doing is telling the Arduino that channel 1 on the breadboard equals pin 11 and so on. This is important because Vixen will tell the Arduino later which channel to turn on during the sequence.

 

Adjust Output Pin Definitions

// Output
int Chan1 = 11; // green LED, connected to digital pin 11
int Chan2 = 10; // white LED, connected to digital pin 10
int Chan3 = 9; // red LED, connected to digital pin 9
int Chan4 = 6; // green LED, connected to digital pin 6
int Chan5 = 5; // red LED, connected to digital pin 5
int Chan6 = 3; // red LED, connected to digital pin 3




 

Up next we need to adjust the set up to match the settings of our output. Again make the code in your sketch match the code below. Basically this tells the Arduino that all six channels defined above should be treated as outputs.

 

Adjust Setup Code

void setup()
{
  Serial.begin(9600); // set up Serial at 9600 bps

  pinMode(Chan1, OUTPUT); // sets the pins as output
  pinMode(Chan2, OUTPUT);
  pinMode(Chan3, OUTPUT);
  pinMode(Chan4, OUTPUT);
  pinMode(Chan5, OUTPUT);
  pinMode(Chan6, OUTPUT);
}





Vixen will utilize the serial communication port to tell our Arduino which channels to turn on and which to turn off and as such, we need to adjust the number of channels that are coming into the Arduino from the serial port.  The original code specifies 5 channels, but since we are doing 6 channels, we need to adjust this to match.  As we did before, make your code match the code I have pasted below.

 

Adjust Loop Code Part 1

void loop()
{ // 6 channels are coming in to the Arduino
  if (Serial.available() >= 6) {
  // read the oldest byte in the serial buffer:
  for (int i=0; i<7; i++) {
  // read each byte
  incomingByte[i] = Serial.read();
  }




 

Now we are almost finished. We now need to add once analogWrite line to the last part of our code. Since the original code was written for 5 channels, we just need to add one more channel to the loop. The correct code is pasted below. Match your code to this.

 

Adjust Loop Code Part 2

  analogWrite(Chan1, incomingByte[0]); // Write current values to LED pins
  analogWrite(Chan2, incomingByte[1]); // Write current values to LED pins
  analogWrite(Chan3, incomingByte[2]); // Write current values to LED pins
  analogWrite(Chan4, incomingByte[3]); // Write current values to LED pins
  analogWrite(Chan5, incomingByte[4]); // Write current values to LED pins
  analogWrite(Chan6, incomingByte[5]); // Write current values to LED pins




 

With that complete, your code should now look like this. If you see any mistakes, please go back and correct them before continuing on with this tutorial.

 

Final Code

/*
The purpose of this code is to allow the Arduino to use the
generic serial output of vixen lights to control 5 channels of LEDs.
Author: Matthew Strange
Created: 14 October 2010
Adapted for 6-PWM-Channels by Charles Gantt on November 14th 2013.

*/

// Output
int Chan1 = 11; // green LED, connected to digital pin 11
int Chan2 = 10; // white LED, connected to digital pin 10
int Chan3 = 9; // red LED, connected to digital pin 9
int Chan4 = 6; // green LED, connected to digital pin 6
int Chan5 = 5; // red LED, connected to digital pin 5
int Chan6 = 3; // red LED, connected to digital pin 3

int i = 0; // Loop counter
int incomingByte[8]; // array to store the 7 values from the serial port

//setup the pins/ inputs & outputs
void setup()
{
  Serial.begin(9600); // set up Serial at 9600 bps

  pinMode(Chan1, OUTPUT); // sets the pins as output
  pinMode(Chan2, OUTPUT);
  pinMode(Chan3, OUTPUT);
  pinMode(Chan4, OUTPUT);
  pinMode(Chan5, OUTPUT);
  pinMode(Chan6, OUTPUT);
}

void loop()
{ // 7 channels are coming in to the Arduino
  if (Serial.available() >= 6) {
  // read the oldest byte in the serial buffer:
  for (int i=0; i<7; i++) {
  // read each byte
  incomingByte[i] = Serial.read();
  }

  analogWrite(Chan1, incomingByte[0]); // Write current values to LED pins
  analogWrite(Chan2, incomingByte[1]); // Write current values to LED pins
  analogWrite(Chan3, incomingByte[2]); // Write current values to LED pins
  analogWrite(Chan4, incomingByte[3]); // Write current values to LED pins
  analogWrite(Chan5, incomingByte[4]); // Write current values to LED pins
  analogWrite(Chan6, incomingByte[5]); // Write current values to LED pins
  }
}




 

1.jpg

Once the code is complete, its time to verify and upload the code to your Arduino. You can do this by simply clicking the “Play” button which is second from the left at the top of the Arduino window. If everything uploads correctly and no errors arose, it is time to move onto installing and configuring Vixen. Head over to VixenLights.com and grab the latest version of Vixen Lights 2.

 

2.jpg

 

Installing Vixen is fairly simple as it comes already unpacked into its directory. Make sure to place it somewhere you will remember to find it such as the desktop, or in your documents folder. To begin, launch Vixen and let’s set up a sequence. This is a very important step and very close attention should be paid and every step should be followed exactly for things to work properly. To start, click on the sequence tab and navigate to New Event Sequence > Vixen Standard Sequence.

 

3.jpg

 

Once you click on Vixen Standard Sequence the New Sequence Wizard will pop up and prompt you with a few configurable options. The first major thing you will need to set up is the Event Period. This value determines the period of time that each LED will stay lit. You can adjust this time down to 25-miliseconds and up as high as 1 second. For the purpose of this tutorial, we are going to keep it simple at 100-miliseconds, giving us 10 events per channel, per second.

 

4.jpg

 

Up next is where most of the configuration happens. To make things simple, we are going to create a profile that we can save and re-use in the future.  Click Profile Manager and then click the Add icon that is highlighted in the image above.

 

5.jpg

 

Give the new profile a name and then click OK. At this point the Edit Profile screen will pop up, and you need to add six channels.

 

6.jpg

 

Once the six channels have been added click the Output Plugins button and you will see the Sequence Plugin Mapping configuration window pop up. Under Available Plugins, select Generic Serial, and click the Use button. Set the channels from 1 to 6, and click the Plugin Setup button.

 

7.jpg

 

Set the Com Port to 4 (also make sure your Arduino is set to Com Port 4) and set the Baud Rate to 9600 and then click OK.

 

8.jpg

 

The Profile window will once again pop up, and you will need to select the profile you just created, and then click next. Since we are not adding any audio to this sequence, click next on the Audio and Event Patterns window.

 

9.jpg

 

Finally we are presented with the Sequence Time configuration window. For this tutorial I have set it to 1-minute, but you can set this to any length you desire. Once you have your time set, click the Create It button and you will be prompted to save this sequence. Give it a name, and click Save.

 

16.jpg

 

The PC will take a few moments to process and create your sequence, but when finished, a sequence configuration window will open and the sequence will be represented in a timeline that is sectioned into a grid-like pattern. Each one of these little blocks represents a single event period, and can be used to turn that channel on, off, or set a brightness value.

 

17.jpg

 

To keep things organized and easy to configure we need to assign a color to each channel. To do this we must right click on the channel list, and select Channel Properties.

 

18.jpg19.jpg

 

When you click Channel Properties, a small window will pop up and will have several configurable options. For the purpose of this tutorial, we will just be changing each channels color. Set the first one to red, and then click the channel dropdown and select channel two.

20.jpg


Continue doing this until each channel has a unique color. I color coded the channels in my sequence to reflect the LED colors on my breadboard.

 

21.jpg

 

So let’s begin building the sequence. Click and highlight the event periods you wish to enable, and then click the solid square button in the control bar as seen highlighted in the image above. You can also enable the event periods by pressing the spacebar. Play around with the rest of the buttons on that row for some cool effects. I don’t want to dive too deep into building advanced sequences as that is an entire article on its own, and this tutorial is already long enough.

 

 

Now we can run the sequence. Make sure the Arduino is plugged in and is set to Com Port 4 in the Device Manager. If everything is correct, click the play button located at the top left of the Vixen Sequence. You should see the LEDs begin to light up and follow the sequence you just built. If you get a router / com port error, simply save your sequence, close Vixen and Arduino and reopen Vixen and load your sequence. Things should work now.

 

You can adapt this same setup to trigger relays to control 110v circuits that can activate LED Christmas Lights, Halloween Lighting, or pretty much anything that runs on mains voltage. Below is a video of a 4-christmas tree setup I built with my Makerspace that sequenced 32 channels of LED Christmas Lights.

 

 

Next Guides:

Getting to Know Arduino : Part 2 : Hello, Again!

Getting to Know Arduino : Part 3 : Taking your Temperature

 

I recorded a video to introduce the Arduino UnoArduino Uno and how to get started with it. The premise was that you didn't need to add anything extra, except for an A to B USB cableA to B USB cable (always check the type you need for the Arduino you have) because although you can connect an external power supply it can be powered purely from the USB, and you could get code running with a few simple steps on Microsoft Windows to make an LED (Light Emitting Diode) start to flash on your board.

arduino_uno_components.jpg

The Arduino I showed in the video was a revision 3 board, there have been a few versions so far, in the image (from zenbike.co.uk) you can see an earlier version, but it nicely maps out the connectors on the board. I think in the recent version the reset button has moved, but that makes little difference overall. What it doesn't note on the image is that any socket with the ~ (tilde) symbol next to it can be used as a Pulse Width Modulation output. This is a way of having a digital signal pretend that it's analogue but typically you don't need to worry about this until you've got some hardware that you need to output to which needs it.

 

The first instruction we can make the Arduino perform is to flash an LED, which is often considered the "Hello, World!" of getting started. The example code 'Blink' will do this for you, it flashes the LED marked 'L' on the board. This LED is also linked up with the breakout pin '13' like many connections on the board, some go through components and others do not, but they ultimately connect to the ATMega328 micro-controller processor on the board, which is the brains of it all.

 

We'll need to tell the Arduino what we want it to do and for that we can use the Arduino Integrated Development Environment (IDE), this environment contains a text editor and a console window which shows you any error messages and how successful the software has been when communicating with the Arduino. You can get the IDE for more than just Microsoft Windows, there are Mac OS and Linux variants. You might want to check your package manager and software repository for whether or not there is a version pre-packaged for your version of Linux. For example you can use apt-get on Ubuntu to "apt-get install arduino" from a terminal.

 

It's often best to get the latest non-beta version of the Arduino IDE, but if you have a board that is newer then usually this isn't supported in the 'stable' builds and a beta or nightly build is required.

 

After installing the Arduino IDE in Microsoft Windows, you'll need to connect your Arduino Uno if you haven't already. It may help to reconnect it so that it re-detects the device and installs the driver. Then you can run the IDE. To be able to upload code to the device you will need to know what COM port it is running on.

 

To do this, open your Start menu, navigate to Control Panel, once the window appears, open System and then navigate around the tabs/options until you find Device Manager. With this window open, click the + symbol next to "Ports (COM & LPT)" and the Arduino should be listed along with its COM and a number.

 

In the IDE, go to the Tools menu and then expand Board and choose your Arduino, then do the same, but go to Serial Port and choose the one that it stated in Device Manager.

 

Now to get the LED flashing, choose the File menu, go to Examples and then 01.Basics, under this menu navigate to Blink. To get this running on your Arduino you can now either click on the arrow next to the tick icon or choose the Sketch menu and click Verify/Compile. Now the 'L' LED on your board should be blinking!

 

Feel free to change the code, copy and paste bits to see what works and what doesn't.

 

This will open a new window with the following code in it:

 

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  This example code is in the public domain.
*/

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {        
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}
        

 

This is what is referred to as a 'sketch' in IDE terms, however it is actually using a low level programming language called C++ which has been around for a notable amount of time, most of the software you use is written with C++ including Microsoft Windows and parts of Linux.

 

Line 01 and 06 in the code uses text that the IDE recognises as a special arrangement so that it knows to ignore anything typed between them (it denotes that whatever is between them is a comment. On line 08 it shows the line starting with a similar arrangement that means to ignore that entire line as a comment.

 

int led = 13;
        

 

This line is literally mathematical, it could be said that programming is inherently mathematical because processors are just doing calculations and moving numbers around. So this line in particular is declaring that the english word, led is a certain type of variable (kinda like a bucket that can only contain something of a particular thing and its contents can vary) and that is called an integer, which means a whole number. As opposed to a number with a decimal (or a real number). We're then making the contents of the variable (or bucket) equal to the number 13. What then terminates the line is a semicolon and this is required by the IDE to know that we're finished putting commands on the line.

 

The IDE, or specifically the part of it that changes our near-english (sketch/programming) into a language that the Arduino can understand typically operates on a line by line basis, which is like how old typewriters used to work where by you normally couldn't go back and change what you had just created/read and had to continue (probably a bad analogy).

 

void setup() { }
       

 

The setup declaration is called a function, anything within { } is processed by the IDE, 'setup' is a reserved name for the function and it means that it is ran before anything else within the sketch. Like the variable led is of a type int, the setup function is of a type void. We don't have to worry about that for now. pinMode() is another function that is referred to and you can read up about it.

 

void loop() { }
       

 

The loop function is another reserved name that means anything within { } is ran again from the first { when it reaches the last line or instruction before the final }. The speed of this is governed by how fast the microprocessor, for example the ATMega328 can get through the instructions per second. The digitalWrite() and delay() functions can also be read up about on the Reference section of the Arduino site.

 

Hopefully you have found this useful to get started with your Arduino and it has introduced you to some new concepts for programming for micro-controllers. The best way to learn is trial and error, so don't be afraid to mess around with the code or read up about it.

 

If you have any questions, problems or otherwise please leave a comment! You can also find more information in Arduino community group!

Behold the Winners of the Arduino Anniversary "Give Me 10" Contest!

 

We are announcing 10 Arduino Uno winners, one for each day of the Contest.

 

It's easy to join the fun!

 

Here are the winners:

 

1) March 24th: Saudin Dizdarevic suggests "An Arduino Gmail Notifier with servo controlled flag indicator"

 

2) March 25th: sam clemmons suggests "RFID Doggie door with in/out indicator and time lock"

 

3) March 26th: hunt333r suggests "robotic arm, that copy human arm movement, saves it ,wireless"

 

4) March 27th: ralphjy suggests "arduino based and android based path finding mobile robot"

 

5) March 28th: zatamite suggests "Talking plants: Arduino+SpeakJet+Moisture Sensor. "Hey Bud Water Me"

 

6) March 31st: himanshu2590 suggests "Arduino Controlled Ambilight for TVs for better movie experience"

 

7) April 1st: danielmcgraw suggests "Low cost Arduino analyzer using DDS and ADC"

 

8) April 2nd: sandeepdwivedi suggests "arduino as universal chip programmer"

 

9) April 3rd: neeraj2604 suggests "accelerometer based gesture controlled wheelchair for physically handicapped"

 

10) April alfredbrock suggests "control motion sensors for cameras monitoring empty real estate"

 

 

 

 


I recently picked up a new hobby that involves custom building muti-rotor helicopters and during this journey I have found a strong desire to map the flights of my quad copter. Unfortunately, a full sized handheld GPS is much too heavy to add to the payload of the quad copter and still retain respectable flight times. So I began searching for a small, lightweight GPS data logging solution that I could build myself with readily available, off the shelf components.

 

After a few days of research I settled on an Arduino and GPS shield combo with a cusom 3D printed case. Around the time I ordered the hardware I would need, a company called TinyCircuits contacted me and asked me if I would be interested in reviewing their products, and writing a few tutorials around their Tinyduino line of micro-development boards. I agreed and a few days later I had the company’s entire Tinyduino line sitting on my workbench.

 

1.jpg

 

Included in this kit was a fully functional micro-GPS shield that was not much larger than a quarter, an SD card shield, and an ArduinoArduino. When stacked together, the entire package is about 1-inch cubed, which makes the stack the perfect size for attaching to RC aircraft.  With everything I needed to develop my GPS logger I sat down at my bench to get the party started. I began researching and looking for sample code to help me speed up the build process, and during that search, I found a GPS data logger project that was built using the same TinyCircuits hardware I had on hand.


2.jpg

 

The GPS data logging project I found on Make.com was designed to track the author’s cat, but the code I needed to get my project off the ground would do the job whether it was tracking a cat or tracking the flight path of my quad copter. I realized that this project would be the perfect opportunity to write an article on how easy it is to build a project using the Arduino development environment and how easy it is to find, adapt and utilize existing code in your projects.

 

The TinyDuino series is pretty cool in the fact that you have a full Arduino Pro / Pro Mini packed onto a board the size of a quarter. I won’t go into great detail about the boards and what makes them so special, but if you would like further information on them, check out the full overview I wrote on TweakTown.com. Below is a list of everything you need to create a simple GPS Data Logger of your own using the Tiny Circuits hardware.

 

TinyCircuits PartsAlternate Arduino Parts From Newark
  • TinyDuino
  • TinyShield microSD
  • TinyShield GPS
  • TinyShield USB & ICP
  • TinyDuino Mounting Kit
  • 3D Printed Case
  • Code
  • Class 4 or higher 4GB microSD Card

Arduino Uno R3Arduino Uno R3

Arduino GPS ShieldArduino GPS Shield

 

 

IMG_3290.jpg

 

There really is not much to building the GPS Data Logger other than stacking the shields in the correct order, uploading the code to the Arduino, and then getting outside and logging some data. The stack should be built in the following order.  The bottom most board should be the TinyDuino, which should then be followed by the TinyShield microSD board. Up next would be the TinyShield GPS which is followed by the TinyShield USB and ICP.

 

IMG_3287.jpg

 

I chose to power my GPS Logger using a 18650 powered USB cellphone charger instead of the CR2023 or JST methods that the TinyDuino also supports. If you chose to go this route, you will need to arrange your stack with the TinyShield USB & ICP board placed between the TinyDuino and TinyShield GPS, I chose this route because I had several spare USB cellphone chargers laying around.

 

IMG_3288.jpg

 

With everything stacked together, let’s prepare the TinyDuino for coding. Plug a microUSB cable into the TinyShield USB & ICP board, then select the appropriate USB port that the TinyDuino is now connected to. Once the correct port has been selected, we need to set the Arduino IDE to recognize the correct Arduino-compatible board. Since we are using a TinyDuino, we need to select Arduino Pro or Pro Mini (3.3V, 8MHz) w/ ATmega328. Once finished we should be ready to import some test code to the TinyDuino to test that everything is working correctly.

 

Before we upload any code we will need to make a minor change to the SoftwareSerial library in the Arduino IDE. You will need to replace the SoftwareSerial.cpp and SoftwareSerial.h Library files with the ones found in the GitHub repo for this tutorial. Replacing the files is quite easy and you simply need to navigate to Arduino>libraries>SoftwareSerial and rename the existing files to SoftwareSerial_cpp.bak and SoftwareSerial_h.bak and then download the new files into this directory.


Now that that is complete, lets upload some test code to make sure that everything was configured correctly and the TinyShield GPS module is sending raw NMEA data to the Tiny Duino. Upload the code that is embedded below (also found in the Git repo titled GPS_Test_Firmware.ino) and then open the serial terminal in Arduino and set the baud rate to 9600. You should see some weird strings that look like the pasted code below the GPS Test Firmware code.

 

GPS_Test_Firmware

/**********************************************************
* TinyCircuits Test Procedure
* Tiny-Circuits.com
*
* This is the test program for the GPS TinyShield (ASD2501)
*
**********************************************************/


#include <SoftwareSerial.h>


static const int GPS_ONOFFPin = A3;
static const int GPS_SYSONPin = A2;
static const int GPS_RXPin = A1;
static const int GPS_TXPin = A0;
static const int GPSBaud = 9600;
static const int chipSelect = 10;


// The GPS connection is attached with a software serial port
SoftwareSerial Gps_serial(GPS_RXPin, GPS_TXPin);


int led = 13;


void setup()
{
  // Init the GPS Module to wake mode
  pinMode(GPS_SYSONPin, INPUT);
  pinMode(GPS_ONOFFPin, OUTPUT);
  digitalWrite( GPS_ONOFFPin, LOW );
  delay(5);
  if( digitalRead( GPS_SYSONPin ) == LOW )
  {
     // Need to wake the module
    digitalWrite( GPS_ONOFFPin, HIGH );
    delay(5);
    digitalWrite( GPS_ONOFFPin, LOW );  
  }

  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  pinMode(led, OUTPUT);
  Gps_serial.begin(9600);
}


void loop()
{
  if (Gps_serial.available())
     Serial.write(Gps_serial.read());
}



RAW GPS NMEA DATA

$PSRF150,1*3E
$GPGGA,,,,,,0,00,,,M,0.0,M,,0000*48
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPGSV,3,1,12,01,0error opening gps.txt
0,000,,02,00,000,,03,00,000,,04,00,000,*7C
$GPGSV,3,2,12,05,00,000,,06,00,000,,07,00,000,,08,00,000error opening gps.txt
,*77
$GPGSV,3,3,12,09,00,000,,10,00,000,,11,00,000,,12,00,000,*71
$GPRMC,,V,,,,,,,,,,N*53
$GPGGA,error opening gps.txt
,,,,,0,00,,,M,0.0,M,,0000*48
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPGSV,3,1,12,01,00,000,,02,00,000,,03,0error opening gps.txt
0,000,,04,00,000,*7C
$GPGSV,3,2,12,05,00,000,,06,00,000,,07,00,000,,08,00,000,*77
$GPGSV,3,3,12,09error opening gps.txt
,00,000,,10,00,000,,11,00,000,,12,00,000,*71
$GPRMC,,V,,,,,,,,,,N*53
$GPGGA,,,,,,0,00,,,M,0.0,M,,0error opening gps.txt
000*48
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPGSV,3,1,12,01,00,000,,02,00,000,,03,00,000,,04,00,000,*7C
error opening gps.txt
$GPGSV,3,2,12,05,00,000,,06,00,000,,07,00,000,,08,00,000,*77
$GPGSV,3,3,12,09,00,000,,10,00,000,,11error opening gps.txt
,00,000,,12,00,000,*71
$GPRMC,,V,,,,,,,,,,N*53
$GPGGA,,,,,,0,00,,,M,0.0,M,,0000*48
$GPGSA,A,1,,,,error opening gps.txt
,,,,,,,,,,,*1E


If the data that appears in the serial terminal does not look like this, then you will need to re-upload the SoftwareSerial files and upload the test code again.

 

Now that everything is working fine, we need to upload the actual GPS Data Logging code to the TinyDuino. I have pasted the code below, and remember to insert a properly formatted microSD (Read how to do this here ) card into the TinyShield microSD.

 

GPS Data Logger Code

/*
   This Arduino sketch will log GPS NMEA data to a SD card every second
   This code was written by Ken Burns, founder and CEO of TinyCircuits
*/


#include <SoftwareSerial.h>
#include <SD.h>




// The Arduino pins used by the GPS module
static const int GPS_ONOFFPin = A3;
static const int GPS_SYSONPin = A2;
static const int GPS_RXPin = A1;
static const int GPS_TXPin = A0;
static const int GPSBaud = 9600;
static const int chipSelect = 10;


// The GPS connection is attached with a software serial port
SoftwareSerial Gps_serial(GPS_RXPin, GPS_TXPin);




void setup()
{
  // Init the GPS Module to wake mode
  pinMode(GPS_SYSONPin, INPUT);
  pinMode(GPS_ONOFFPin, OUTPUT);
  digitalWrite( GPS_ONOFFPin, LOW );
  delay(5);
  if( digitalRead( GPS_SYSONPin ) == LOW )
  {
     // Need to wake the module
    digitalWrite( GPS_ONOFFPin, HIGH );
    delay(5);
    digitalWrite( GPS_ONOFFPin, LOW );  
  }


  // Open the debug serial port at 9600
  Serial.begin(9600);

  // Open the GPS serial port
  Gps_serial.begin(GPSBaud);

  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);

  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
}




int inByte = 0;         // incoming serial byte
byte pbyGpsBuffer[100];
int byBufferIndex = 0;


void loop()
{
  byte byDataByte;

  if (Gps_serial.available())
  {
     byDataByte = Gps_serial.read();

     Serial.write(byDataByte);
     pbyGpsBuffer[ byBufferIndex++ ] = byDataByte;

     if( byBufferIndex >= 100 )
     {
       byBufferIndex = 0;   
       File dataFile = SD.open("gps.txt", FILE_WRITE);

       // if the file is available, write to it:
       if (dataFile) {
        dataFile.write(pbyGpsBuffer, 100);
        dataFile.close();
      }
      // if the file isn't open, pop up an error:
      else {
        Serial.println("error opening gps.txt");
      }    
     }  
  }
}


 

Once the code is finished uploading, you should see the LED on the TinyDuino blink once every second. This is an indication that the TinyShield GPS is doing its job and polling its location every second and writing that point to the microSD Card. Now is the time to venture out unto the world and capture some data. Do this by unplugging the GPS Data Logger stack from your PC, and powering up the board by a CR2023, JST connected battery, or via the TinyShield USB & ICP like I have done. If you placed the TinyShield USB & ISP board on top of the stack you will need to remove it now to ensure that the GPS antenna gets a stong signal. If you need this board to power your stack, then move it to a position between the TinyDuino and TinyShield GPS.



Unfortunately I have not hand a chance to take my TinyCircuits GPS Data Logger outside and gather data yet as we have had some fairly bad weather over the last few weeks. Every chance I get to venture outside on a sunny and nice day, I get caught up with another article, breaking news, or some other task that eats up my free time.  But for you, this tutorial will continue on and I will explain how to take the data that has been written to the SD card and show you how to import it into Google Earth for viewing.

 

When you are finished recording data, head to your nearest PC and open the SD card to view the filed stored inside. If you correctly formatted the SD card then you should only see one file that is titled gps.txt. Make sure you have extensions visible if using Windows, and then rename the file to gps.nmea. The current SD library can only write extensions up to three characters in length and is why the file is saved as a .txt instead of nmea.


Once you have the file renamed, open Google Earth and navigate to Tools>GPS and click GPS. There will be an option to upload a gps file. You can simply browse to the gps.nmea file you renamed, upload that file and Google Earth will plot the exact path that your GPS Logger took when it was gathering data. There are several other programs that can be used to visualize this data, but I will not list them here as a simple Google Search will give you pages of information on them.

 

26.jpg

 

Now that we have the GPS Data Logger working, we need to secure the stack together using the TinyDuino Mounting Kit. This will ensure that the stack stays securely connected during any impacts that might occur during flight.


IMG_3291.jpg

 

With everything secure, we also need to enclose the stack inside the case so that it is safe from static discharges, moisture, and debris. You can head over to Thingiverse , or Github to download the custom enclosure I designed to house this project. It is designed to be affixed to a quad copter or any other ½” surface using nothing but Velcro straps that are commonly used to bind computer cables together. It could also be secured using zipties as well.


Video Here


GPS-Logger-Image.jpg

 

I will update this post with video and tracking data from the first flight as soon as I get the final few parts in for the quad-copter I am currently building. They should be here within a week, so please check back for updates! Not much of any part of this project is of my own design except for the 3D printed case, and that is completely OK. I wrote this tutorial to demonstrate how easy it is to build almost any project with just a little knowledge, some pre-existing code, and a little creative design skills. I hope you enjoyed this project as much as I did, and I can not wait to update it with video and GPS data from some of my first flights with my new scratch-built quad-copter.

Join the Arduino Anniversary “Give Me 10!” Contest & Win an Arduino Uno

arduino-uno-r3-free-usb-cable.jpg

 

Help us celebrate Arduino’s 10th birthday! Share your best Arduino project idea in 10 words or fewer between March 24th and April 4th, 2014!


It's Simple to Join:

                • Register or log on to the element14 Community.
                • Select "Add Your Comment" at the bottom of this post to submit your idea.

 

What Happens Next?

  • The element14 Team will choose an entry every business day between March 24th and April 4th to win an Arduino Uno.
  • A winner will be announced every day on the Community on the Arduino section.

 

Important Note:

By submitting an entry you will automatically start receiving notifications of other responses to this post. If you do not wish to receive notifications, select "Unfollow" at the top right of this page. If you have any questions, please let us know in our Feedback & Support area.

 

Detailed Prizing Info:

There are 10 Arduino Unos to be given away, one to each winner over the period of the contest. Preference will be given to entries describing projects that we would like to see featured on the Community.

 

See the full Terms and Conditions
________________________________________


Timeline:


During the period from 9am CDT (United States Central Daylight Time) on March 24th 2014 until 5pm CDT (United States Central Daylight Time time) April 4th 2014, any community member can participate in the competition.
________________________________________

daemon

Hi all

Posted by daemon Mar 6, 2014

Hey everyone.

Just joined up here.

I have all sorts of interests. I am building a diy cnc machine, a self steering kontiki, automated christmas display and salt water marine tank which includes lots of automation.

I was recommended to this forum as it has helpful members who are willing to help you learn and grow.

 

Will be asking a few questions now and again definitely as I am still learning a lot about coding for the arduino.

 

Look forward to meeting you all.

Filter Blog

By date: By tag: