Tuesday, September 16, 2014

Intermediate: u-blox Neo-6M GPS Module (Revisited)

Previously, I've posted about this module which you can find here. This time around I'm going to share with you another library that I wrote specifically for this module.

If you've tried my code from the tutorial, you might notice that sometimes it is hard to change the baud rate of the module. Most of the time, the module failed to change the baud rate to 9600. Note that the module runs by default, at 38400 baud rate. I notice that it is easier to change to this baud rate, but the Arduino Uno or Nano that I'm using can't keep up with the speed, thus, loosing some bytes. However, it still managed to give you some of the important information. I manage to get about 63 bytes of data for each reading. This data is actually enough to extract the location data, latitude, longitude, altitude and the UTC. You won't get to verify this data however, of cause, due to the missing checksum, but still, for me it is fine. Unless your project requires you to be extremely cautious, you might want to try out this library.

You may download the library here.

The sketch could end up pretty huge, but can be reduced if you remove all the Serial print statements in the library. I just leave it there so that we can see what happen. The following is the short code to print the available information.


#include <CustomUBlox.h>
#include <SoftwareSerial.h>

CustomUBlox gps(2, 3); // RX, TX, Baudrate, mode, datarate

void setup() {
  Serial.begin(19200);
  Serial.println("Initializing...");

  gps.init();
}

void loop() {
  gps.processData();
  
  if(gps.available() && gps.isFixed()) {
    Serial.print("\nLocal time : ");
    Serial.println(gps.getLocalTime());
    Serial.print("Latitude : ");
    Serial.print(gps.getLatitude(), 4);
    Serial.println(gps.getLatitudeHeading());
    Serial.print("Longitude : ");
    Serial.print(gps.getLongitude(), 4);
    Serial.println(gps.getLongitudeHeading());
    Serial.print("MSL Altitude : ");
    Serial.print(gps.getAltitude(), 4);
    Serial.println("m");
    delay(1000);
  }
}

The functions available in the library are as follows:
Constructor:
CustomUBlox(int rx, int tx, int baudrate = 38400, int mode = 2, int rate = 3)
  • Baud rate can be: 4800, 9600, 19200, 38400 (default), 57600, 115200 or 230400
  • Mode: 0 (Portable), 1 (Stationary), 2 (Pedestrian - Default), 3 (Automotive), 4 (Sea), 5 (<1G), 6 (<2G), 7 (<4G)
  • Data rate: 0 (1Hz), 1 (2Hz), 2 (3.33Hz), 3 (4Hz)
Functions:
void init() : to initialize the GPS module.
void showStatus(bool status) : Show Serial messages (true - default) or hide Serial messages (false)
void processData() : Checks and updates new data from the GPS.
double getLatitude() : Return the latitude.
char getLatitudeHeading() : Return 'N' for North or 'S' for South.
double getLongitude() : Return the longitude.
char getLongitudeHeading() : Return 'W' for West or 'E' for East.
double getAltitude() : Return the altitude.
bool available() : Return true if new data is available. Otherwise, false.
bool isFixed() : Return true if the GPS got a fix.
String getLocalTime(byte offset = 8) : Return UTC time + offset (default=8) in form of HH:MM:SS
byte getHour() : Return hour.
byte getMinute() : Return minute.
byte getSecond() : Return second.

Monday, September 1, 2014

Basic: HC-06 Bluetooth Module


Hi. It has been a while since my last post. I was busy with the Eid preparation, getting my driving license, babysitting, etc. Finally I have some free time to write a short post about a Bluetooth module, HC-06. As always, this module is purchased from GI Electronic which you may view here. It's considerably cheap and easy to use.

Living in advance technology era, I believe all of you have at least heard about Bluetooth technology before. Contrary to some belief, this module is actually very simple to use; programming-wise speaking. The only drawback is that you'll need to attach 2 resistors (1kΩ and 2kΩ) on the module's RX pin. This is because the module is working at 3.3V. We'll see this later. The module will allow you to perform simple serial communication from/to your computer, smartphone, tablet, etc. There's just a lot of things that you can do with it due to its flexibility. In fact, I'm currently working on reviving my brother's RC car using this module. Now, I can control the RC car using my smartphone and my computer. Now, let's get down to business.

Connection

I actually use 2kΩ for R1, but I think 2.2kΩ should also works just fine. Make sure the connection is correct. Triple-check it!


You can actually use the hardware RX (0) and TX (1) pins on Arduino (like diagram above), but I use the pin 2 and 3 instead because pin 0 and 1 will be used for serial monitor. Using pins other than hardware RX and TX pins requires us to use SoftwareSerial library instead. If you are using the hardware RX and TX pin, simply write Serial.begin (baud rate);
How to connect to the device, then? In the following examples, I'm going to connect to the module using my computer and my Android phone. I simply search for the available device and connect to it. The default password is: 1234.
To connect and send/receive messages from/to Android phone, go to Play Store and search for Bluetooth Terminal. There should be a bunch of them. I've tried using "ArduDroid" and "ArduinoRC". Both works just fine.
If you want to change the device's name, password, and others, refer to the product's guideline.

Programming
If you are used to writing programs to display messages in the Serial Monitor, this would be a walk in the park. The coding is almost similar. If you're using the hardware RX and TX pin, the coding should be exactly the same, but you wouldn't be able to use the Serial Monitor.
btmodule.read () will return whatever the Bluetooth module is receiving from the connected device.
btmodule.write ("message") will send the message to the connected device.
Simple, isn't it?

#include <SoftwareSerial.h>

SoftwareSerial btModule(2, 3);

void setup() {
  Serial.begin(19200);
  btModule.begin(9600);
}

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

Using the code above, you may send and receive messages from computer to an Android phone or other bluetooth devices with Arduino as the middleman. What you need to do is, install a bluetooth terminal on your smartphone and connect to the bluetooth module, not the computer's bluetooth device. I use ArduDroid. You may find more information about it here. The LED on the bluetooth module should stop blinking after connected to a device. While the Arduino still connected to the computer, open the Serial Monitor. Type something and press "Enter". The message should be sent to the device connected to it. You can also try to type something and press "Send Data" in the ArduDroid application and you receive a line with symbols, numbers, and finally your message. We'll discuss what those numbers mean later. But now you should understand how easy it is to do it, right?

Alright. Now, let's discuss a little bit about ArduDroid. The message that you receive is in form of *number|number|number|message# when sending message and *number|number|number# when pressing the Digital Write and changing the value for Analog Write. It is actually like this. * marks the beginning of the message. # marks the end of it. | separates the values of message code, pin number and value, respectively. To simplify the usage of it, I wrote a rather simple library which you may download here.

After extracting it to the Arduino's library folder, run the following code:

 
#include <SoftwareSerial.h>
#include <ArduDroid.h>

ArduDroid btModule(6, 7);

void setup() {
  Serial.begin(19200);
  Serial.println("Starting...");
}

void loop() {
  if(btModule.available()) {
    if(btModule.getMessageCode() == 12) {
      Serial.print("Message Received: ");
      Serial.println(btModule.getMessage());
    }
    else {
      Serial.print("Setting value of pin ");
      Serial.print(btModule.getPinNum());
      Serial.print(" to ");
      Serial.println(btModule.getValue());
      btModule.executeCommand();
    }
  }
  
  if(Serial.available()) {
    char message[50] = "";
    int i = 0;
    
    while(Serial.available()) {
      message[i++] = (char) Serial.read();
    }
    
    btModule.sendMessage(message);
    Serial.print("Sent Message: ");
    Serial.println(message);
  }
}

The code above will allow 2-ways communication between your Android phone to the Arduino. I guess the code is quite self-explanatory. Still, if you have any question, do comment below.
I hope this tutorial may help you develop more interesting things and increase you creativity and functionality of your project. Until next time, good bye.

Saturday, July 5, 2014

Basic: HMC5883L (Digital Compass)

Hi, everyone. I am actually waiting for the time for breakfast. I'm writing this post to take my mind off the meal. So, this time, it's about a digital compass; HMC5883L which I bought from GI Electronic.


When I first played around with it, it was quite complicated, but soon enough, I manage to understand most of the important part of it. I wrote a library to make it even simpler to use, which can be found here or here.

Introduction

This module is actually a digital compass, which probably means that you've understand what it should do. It is a compass, which measures the magnetic strength around it in 3 axis; X, Y and Z. This module is using I2C communication. It is a famous type of communication and I really like it as it basically uses only 2 wires, SDA and SCL, and multiple devices could be connected on the same pin at the same time.

Connection

In the following diagram, notice that the pins listed aren't really accurate as the sketch is using a product by Adafruit, not the one sold by GI Electronic. The pins are equivalent as:

VIN = VCC
GND = GND
3vo = -
SDA = SDA
SCL = SCL
RDY = DRDY




Code

The following code simply prints the output or the degree based on X and Y axis.

#include <HMC5883L.h>
#include <Wire.h>

HMC5883L compass;

void setup(){
  Serial.begin(19200);
  compass.init();
}

void loop(){
  if(compass.available()) {
    Serial.println(compass.getHeading());
  }

  delay(100);
}

Important Note

By observing the serial monitor, turn the digital compass until the value move closer to 0 or 360. When you manage to get that value, you are actually finding the magnetic north. However, relying on the magnetic north alone is unwise especially when it comes to navigational use. At long distance, 1 degree difference could end up quite far. Be sure to deduct or add the declination angle according to where you are situated at to get the true north.

Look for your declination angle here: http://magnetic-declination.com/

About the library


Constructor (HMC5883L)
  • Prototype:
    • HMC5883L::HMC5883L(int address = 30);
  • Description:
    • Create the HMC5883L object and set the address of the module.
  • Arguments:
    • address: The address of the module with default value of 30 or 0x1E.
  • Returns:
    • None
  • Usage:
    • Outside any function. (Global)


init
  • Prototype:
    • void HMC5883L::init();
  • Description:
    • Begin the data transmission and selecting the continuous measurement mode.
  • Arguments:
    • None
  • Returns:
    • Void
  • Usage:
    • Inside setup() function.

available

  • Prototype:
    • bool HMC5883L::available();
  • Description:
    • Check if the data is available.
  • Arguments:
    • None
  • Returns:
    • true: if data is available.
    • false: if data is not available.
  • Usage:
    • Inside if block.

getHeading

  • Prototype:
    • double HMC5883L::getHeading();
  • Description:
    • Get the angle from North calculated between X and Y axis.
  • Arguments:
    • None
  • Returns:
    • Angle calculated between X and Y axis.
  • Usage:
    • Inside if block after ensuring data availability.

getAngleXY

  • Prototype:
    • double HMC5883L::getAngleXY();
  • Description:
    • Get the angle from North calculated between X and Y axis.
  • Arguments:
    • None
  • Returns:
    • Angle calculated between X and Y axis.
  • Usage:
    • Inside if block after ensuring data availability.

getAngleYZ

  • Prototype:
    • double HMC5883L::getAngleYZ();
  • Description:
    • Get the angle from North calculated between Y and Z axis.
  • Arguments:
    • None
  • Returns:
    • Angle calculated between Y and Z axis.
  • Usage:
    • Inside if block after ensuring data availability.

getAngleXZ

  • Prototype:
    • double HMC5883L::getAngleXZ();
  • Description:
    • Get the angle from North calculated between X and Z axis.
  • Arguments:
    • None
  • Returns:
    • Angle calculated between X and Z axis.
  • Usage:
    • Inside if block after ensuring data availability.


Intermediate: QC12864B (128x64 LCD using u8glib.h)

Hi, everyone. Today, I have some time to kill. So, I decided to play around with my 128x64 pixels LCD. This is also a product distributed by GI Electronic which can be found here.


There are some sample code written in C attached on the product page, but for me, it's not very helpful as I'm more familiar with Arduino. So, this tutorial will be about interfacing Arduino and the LCD.

Introduction

This LCD comes with build-in ST7920 controller chip which will handle the data sent to it. The attached user manual somewhat tells you how it should work and what command you should send, but it is still blurry, isn't it? It's just look too complicated. But, there's an easy solution for that. An external library makes our life so much easier. The library is called U8glib and it supports wide range of LCD.  However, this tutorial will focus on this LCD only. You can see the list of supported LCD here.

Usually, you need to send 8 bits of data to make the LCD display what you want it to display. So, basically, there'll be 8 wires going from Arduino to the LCD. Imagine how complicated that would look like. However, here's the sweetest part of all. The library allows you to program the LCD using 3 methods.

1. Using 8 bits of data as mentioned above. (Parallel Bus Mode)
2. Using hardware/built-in SPI port on Arduino. (Serial Bus Mode)
3. Using software SPI port.

Personally, I'd choose the second method in case where the SPI ports are available. It uses less port, making the connection far simpler and also leave the other ports available for other applications. For your information, SPI ports are on pin 10 (Slave Select), 11 (MOSI), 12 (MISO), 13 (SCK) on Arduino Nano and Arduino Uno. Using the software SPI port may slow down the refresh rate.

Connection

This product comes with 20x1 header, which really helpful to shove the LCD into a breadboard. I'll show you how to connect using the first and second methods as mentioned above. The third one is almost the same as the second one, but it is actually depends on what port you want to use.

Note that the pin in the following photo is equivalent as follows:
D/I = RS
CS1 = PSB
CS2 = NC

First method:

Second method: (Special thanks to this website for showing this method)
IMPORTANT! For this LCD to work using this method, you need to de-solder R9 and R11 at the back panel of the LCD.
The reason is, VDD is actually connected to PSB through the 0Ω resistors (R9 and R11), making PSB always HIGH, putting the LCD always in parallel bus mode. Connecting GND to this could end badly to your LCD and Arduino as you are basically connecting 5V to GND directly. So, just de-solder it. Don't worry, you can still connect it in parallel bus mode by connecting PSB to 5V.


Testing the LCD

To test the LCD, simply copy the U8glib library/folder into Documents > Arduino > libraries.
Start Arduino IDE. Goto File > Examples > U8glib > GraphicsTest.


The next step depends on the method that you choose.

If you choose the first method, un-comment the line:
U8GLIB_ST7920_128X64_4X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16);   // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16

If you choose the second method, add the following line:
U8GLIB_ST7920_128X64_4X u8g(10);

If you choose the third method, modify the following line as you needed to:
U8GLIB_ST7920_128X64_4X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17

If you choose the first method but using different pin numbers, make sure you also change the pin numbers in the declaration above.

If the LCD is showing various shapes and text, that means your LCD is working correctly. Now, you may go on and program your own graphic or anything that you want on the LCD. You may refer to more functions and explanation about the U8glib library on their official page and user reference page. Check out this page as well. There are links to the explanation of the examples on that page.

I've shown you the basics, so you should be able to explore more by yourselves. Just comment down here if you do not understand any step. Until next time, good bye. Have fun!

Saturday, June 28, 2014

Advance: u-blox Neo-6M GPS Module


(UPDATE: I made another tutorial on this module which addresses the problem that you might encounter after trying out the method below. It still works, but not always. Read more if you are interested.)

Hi! Hopefully all of you are in high spirit because today we are going to explore a very exciting component, which is a GPS module! Well, I know this is actually an advance tutorial and probably too sudden for the second post of this blog, but this is what I'm currently working on. So, it is fresh on my mind and I'm very excited to share it with all of you.


This is a product that I bought from GI Electronic. You may view the product page here.



Introduction
GPS stands for Global Positioning System. It's in your phone, tablet, car and almost everywhere nowadays. Learning how to use this may also help you to find some ideas for your Final Year Project. It can help us to determine where the module's exact location in terms of latitude and longitude. We can also get some other information like the altitude, speed, time and so on.

The module that we are going to program is using a very reliable and powerful chip, the u-blox Neo-6M. I love how this module works because it is very easy to hook up to the Arduino as it is using UART interface.
There's also no need for an antenna as it is already built-in on the module, unless you are going to use it indoor where there's many floors above you or you want to increase the gain. In that case, you'll need to attach an external active antenna to aid the connectivity.

What you need
  1. u-blox Neo-6M GPS Module
  2. Arduino Board (I'm using Arduino Nano for this one)
  3. Jumper wires
  4. Breadboard

Connections

This module is operating at 3.3V but if you refer to the datasheet provided (Below), you may notice that there's already a voltage regulator to convert to 3.3V and there's also a resistor connected to both RX and TX pins, so there's no worry in connecting this module directly to the Arduino.


The required connections:


Above: Required connection. PPS pin is optional. RX and TX pins on the Arduino may change according to your preferences.

Below: Connections that is possible to be made on the module.

What is the purpose of PPS pin?
The PPS pin can be connected to a digital pin to detect when the GPS module obtain a fix. Just make sure to put a 10kΩ resistor as well in between the PPS pin and the digital pin. I don't know if it is really necessary, but one more step to protect your module and Arduino board won't hurt, right. The PPS pin will go HIGH for 900±1 milliseconds and LOW for 100±1 milliseconds when it gets a fix and will go LOW for as long as the module didn't get a fix. So, there'll be some extra condition for you to check. But, the good thing is, you'll be able to tell your program when the module get a fix. (However, in GPGGA NMEA message, there's already a Position Fix Status Indicator to tell you the position fix status.)
You may also connect this pin to an external LED to easily see the status. Let say your project's circuit board is quite complicated and obstructing the built-in LED on the module, this feature will be helpful. Just connect an LED and a suitable resistor to 3.3V and PPS pin like in the picture above.

The following code can be use to test out the input from the PPS pin according to the picture above.
#include <UBlox.h>
int input = 4;
bool last;
long lastTime;

void setup() {
  Serial.begin(19200);
  pinMode(input, INPUT);
  lastTime = millis();
}

void loop() {
  bool current = digitalRead(input);
  long currentTime = millis();
  
  if(current != last) {
    Serial.print(current ? "HIGH" : "LOW");
    Serial.print(F(" for "));
    Serial.print(currentTime - lastTime);
    Serial.println(F(" msec"));
    
    last = current;
    lastTime = currentTime;
  }
}



Code [Setting up the module and getting the raw data using library]

You should take a look at the tutorial that is attached on the product page first. The following code is derived from the tutorial. What I did was just compiling it all together into a library.
In the following code, I'm changing the setting from the default baud rate, 38400 to 9600 as it is too fast for the Arduino Nano to catch up. I'm also using pin 2 and 3 as RX and TX respectively. The module runs at 4Hz data rate in pedestrian mode. (More on this later)
*NOTE: This library is using SoftwareSerial, so you need to import it in the main sketch. The limitation of SoftwareSerial also applies here.

Download "UBlox.h" library here.


#include <UBlox.h>
#include <SoftwareSerial.h>

UBlox gpsModule(2, 3, 9600);

void setup() {
  Serial.begin(19200);
  Serial.println("Initializing...");
  gpsModule.init();
}

void loop() {
  if (gpsModule.available()) {
    Serial.print(gpsModule.read());
  }
}


About the library
Constructor:

UBlox(byte rx, byte tx, unsigned int baudrate, [byte mode], [byte rate]);

rx = RX pin
tx = TX pin
baudrate = GPS baudrate
mode = optional, see Navigation Mode below
rate = optional, see Data Rate below

NAVIGATION MODE
Value
Description
0
Portable
1
Stationary
2 (Default)
Pedestrian
3
Automotive
4
Sea
5
Airborne < 1G
6
Airborne < 2G
7
Airborne < 4G




DATA RATE
Value
Description
0
1Hz
1
2Hz
2
3.33Hz
3 (Default)
4Hz


Functions:
init() : To initialize the GPS module with the settings provided.
getBaudrate() : Return the GPS baud rate.
available() : Returns 'true' if the GPS has new data. Else, returns 'false'.
read() : Returns a character from the serial communication.
sendUBX_Msg(byte *UBXmsg, byte length) : To set more UBX command. Return 'true' if command successfully sent and 'false' otherwise.
UBXmsg is the UBX command string in form of array of byte.
length is the sizeof(UBXmsg).

Example to use sendUBX_Msg:
byte msg[] = {0xB5, 0x62, 0x06, 0x16, 0x08, 0x00, 0x01, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2D, 0xC9};
if(gpsModule.sendUBX_Msg(msg, sizeof(msg))) {
    Serial.println("Successfully set SBAS setting...");
}
else {
    Serial.println("Failed to set SBAS setting...");
}


Code [Process data using TinyGPS]

TinyGPS is well known for making it easy to process GPS data. You can download it from the following website: http://arduiniana.org/libraries/tinygps/

The following code is the integration of the UBlox.h library and TinyGPS.h library:

#include <UBlox.h>
#include <SoftwareSerial.h>
#include <TinyGPS.h>

UBlox gpsModule(2, 3, 9600);
TinyGPS gps;

void setup() {
  Serial.begin(19200);
  Serial.println("Initializing...");
  delay(1000);
  gpsModule.init();
  
  byte msg[] = {0xB5, 0x62, 0x06, 0x16, 0x08, 0x00, 0x01, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2D, 0xC9};
  if(gpsModule.sendUBX_Msg(msg, sizeof(msg))) {
    Serial.println("Successfully set SBAS setting...");
  }
  else {
    Serial.println("Failed to set SBAS setting...");
  }
  
  byte msg2[] = {0xB5, 0x62, 0x06, 0x09, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1D, 0xAB};
  if(gpsModule.sendUBX_Msg(msg2, sizeof(msg2))) {
    Serial.println("Successfully saved all setting...");
  }
  else {
    Serial.println("Failed to saved all setting...");
  }
}

void loop() {
  bool newdata = false;
  unsigned long start = millis();

  // Every 5 seconds we print an update
  while (millis() - start < 5000) {
    if (gpsModule.available()) {
      char c = gpsModule.read();
      Serial.print(c);  // uncomment to see raw GPS data
      if (gps.encode(c)) {
        newdata = true;
        // break;  // uncomment to print new data immediately!
      }
    }
  }
  
  if (newdata) {
    float latitude, longitude;
    unsigned long age;
  
    gps.f_get_position(&latitude, &longitude, &age);
    Serial.print(F("Latitude: "));
    Serial.println(latitude, 6);
    Serial.print(F("Longitude: "));
    Serial.println(longitude, 6);
    Serial.print(F("Age: "));
    Serial.println(age);
    Serial.print(F("Altitude: "));
    Serial.println(gps.f_altitude(), 4);
  }
}


Changing the Settings
You should change the settings according to your needs. In the example above, I'm using Pedestrian mode, 4Hz data rate at 9600 baud rate. It is probably a good time now to open the protocol file attached on the product's page. Yes, it is a 222 pages document.

But, do not worry. For me, either I don't understand or I just don't read 85% of the document. You just need to understand a few things, unless you really want to make the best out of your GPS module, go for it! Read ALL of them. For me, it is good enough to know a few things. Below are a few things that I think you should read about in the protocol documentation.

1. You should know all of the different types of navigation modes provided to set the most suitable setting for your project. They are listed in the Navigation Mode table above and you can also find the descriptions on page 1.
2. You should also read about some of the UBX protocols. UBX protocols are very important as they are the one responsible in setting up most of the settings for the GPS module. I recommend you to read about UBX structure, ACK, CFG-MSG, CFG-NAV5, CFG-NMEA, CFG-PRT, CFG-RATE, and CFG-SBAS.
3. When dealing with GPS, you should also know about NMEA messages, and the most important one you should know is about GPGGA. (Page 56).
Now that you've read about those things, let's try to change some of the settings.

If you pay attention and read about the UBlox library, you may notice of the example for using the function sendUBX_Msg(byte *UBXmsg, byte length). However, how would you know the command string that you should supply to the function? Well, the answer is, use the software provided by u-blox, which called u-center.

The software is quite powerful. You can analyse your GPS data in one place. You could even set the GPS settings directly. After you've installed the software, launch it and press F9 or go to View > Messages view.


Let say we want to change the SBAS settings. Expand UBX > CFG > SBAS (SBAS Settings)
Change the settings using the interface on the right. When you've finished making your changes, copy the HEX code below it. Make sure that you only copy the ones in range as shown below:


Paste it in the setup function of the Arduino. Make some changes so that it turns from:

B5 62 06 16 08 00 01 07 01 00 00 00 00 00 2D C9

into array of byte like the following:

byte msg[] = {0xB5, 0x62, 0x06, 0x16, 0x08, 0x00, 0x01, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2D, 0xC9};

You can change the array name as you like. Next, we can call the function sendUBX_Msg(byte *UBXmsg, byte length). I'm assuming that we've already created a UBlox instance called gpsModule:

byte msg[] = {0xB5, 0x62, 0x06, 0x16, 0x08, 0x00, 0x01, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2D, 0xC9};
gpsModule.sendUBX_Msg(msg, sizeof(msg));


What if you wanted to change the data rate or the navigation mode? Simple. Just add two more parameters in the constructor like below. Refer to the tables above for the code.

UBlox gpsModule(2, 3, 9600, 1, 3);

The code above will results in stationary navigation mode and 4Hz data rate.

Conclusion

The GPS module that we used in this tutorial is very easy to be used now, with the existence of the libraries. However, the UBlox.h library is still under Beta development stage. There might still be some bugs somewhere. If you find it, please let me know. Also, if you have any question you want to ask, please comment below.
I'm still learning and if you find something that is worth sharing, please do so. I may not be able to solve all of them, but someone might shed some light. I think that is all for now, have a nice day.

Friday, June 27, 2014

Basic: Getting Started [Arduino]



Well, actually, I don't have time for this kind of post. There's a lot of information in getting started with Arduino already. I'm more excited to get on the real stuff. Here's one of the getting started stuff, brought to you straight from the official website.

Make sure you install the Arduino IDE. You can download the installer here.

But, of cause, there's no use of installing the software if you do not have any Arduino board. You can buy original Arduino board from Cytron Technologies. Yes, there are a lot of boards. Need some guides to buy the best board for you? Here's a good one. Usually, beginners will go for Arduino Uno as it is easy to play around with, and not so expensive.

Better yet, just buy a starter kit as they comes with many extra components that you can play with. It is a good thing to buy the original one because if your board had some problem, you can send them back to the factory. They may replace it if your board is beyond repair; that's from what I heard, at least. You should be careful with counterfeit ones. Some says that they are not as durable as the original one and may cause you some problems in the long run. How to identify them? Here's how.

Now that you have installed the software and bought the board, let's bring them together. You might run into some troubles when connecting your Arduino board for the first time. This page might help.

After you've settled all those problems, we can finally test the board.
Follow the following instructions:

1. Go to File > Examples > 01.Basics > Blink

2. Go to Tools > Board > (Choose your board)

3. Go to Tools > Port > (Choose your COM port)

4. Press Upload button or Ctrl+U for shortcut.

5. Wait until the progress bar at the bottom right corner fully loaded and disappear. Look at your board. Notice that there's an LED labeled as L blinking. If you see it blinking, congratulation! You've successfully uploaded your first sketch. Oh, yes. We call your code as sketch.

Now that we've set up the stage, let's work on the show, then. There'll be a lot of fun stuff coming up. Be sure to come around soon. Till then, good bye.