All posts by Mark Williams

Why does it take so long to get a GPS fix?

Have you ever wondered why it sometimes takes your GPS module 10-20 minutes to get a GPS fix?   This post will explain why.


Each satellite sends a message every 30 seconds.  This message consists of two main components;

  • Ephemeris data, used to calculate the position of each satellite in orbit
  • Almanac , which is information about  the time and status of the entire satellite constellation.

Only a small portion of the Almanac is included in a GPS message. It takes 25 messages (12.5 minutes) to get the full Almanac. The full Almanac is needed before a GPS fix can be obtained.  This is Time To First Fix (TTFF).

TTFF is a measure of the time required for a GPS receiver to acquire satellite signals and navigation data, and calculate a position solution (called a fix).

The above happens during a cold start, this is when the GPS module has been off for some time and has no data in its memory. A full Almanac download is required to get TTFF. If the GPS module has clear line of sight to all satellites, the shortest time for TTFF is 12.5 minutes.

In a warm start scenario,  the GPS module has valid Almanac data,  is close to its last position (100km or so) and knows the time  within about 20 seconds. This approximate information helps the receiver estimate the range to satellites.  The TTFF for a warm start can be as short as 30 seconds, but is usually just a couple of minutes.

A receiver that has a current almanac, ephemeris data, time and position can have a hot start. A hot start can take from 0.5 to 20 seconds for TTFF.


Smarts phones use Assisted GPS (aGPS), this allows them to download the Ephemeris data and Almanac over the cell network which greatly reduces the TTFF.

BerryGPS Raspberry Pi GPS




Raspberry Pi Embedded Cap With GPS & 10DOF

In this post we will show you how to geotag and capture the "attitude"  of photos taken with the Raspberry Pi camera and record these values within the photo itself using EXIF metadata

We used a modified (hacked?) cap to take the images in this post. The cap took photos, geo-tagged and recorded attitude as we walked around Sydney Harbour.

Components used were;

  • Raspberry Pi Zero W
  • BerryGPS-IMU
  • Raspberry Camera V2
  • A cap

The BerryGPS-IMU was used to capture the GPS coordinates as well as "attitude".   No external antenna was needed as the BerryGPS-IMU includes an internal antenna.

The "attitude" would include values such as pitch, roll, direction. Some of this data you can see annotate in the image below.

raspberry pi camera gps

Other programs can use some of this data to plot the image on a map and even show the direction of the camera at the time the image was taken.  A good example of this is seen in  GeoSetter

Camera attitude


The Cap

The cap has the BerryGPS-IMU sitting on top of the visor, with the Raspberry Pi sitting under the viso.  Some holes where made in the visor to allow connectivity between the BerryGPS-IMU and Raspberry Pi.
We also created a basic camera mount out of 3mm laser cut acrylic. M2.5 Nylon screws were used to hold everything in place.
Raspberry Pi GPS


Continue reading Raspberry Pi Embedded Cap With GPS & 10DOF

Navigating with Navit on the Raspberry Pi


Navit is an open source navigation system with GPS tracking.
It works great with a Raspberry Pi,  a GPS module and a small TFT with touch, jut like the official Raspberry Pi Display or PiScreen.


In this guide, we will be using;

Setting up the GPS

Navit can be installed without a GPS connected to your Raspberry Pi, but you will not be able to use the real-time turn by turn navigation. You will however be able to browse maps. If you are not going to use a GPS, you can skip to the next step.

As we are using the BerryGPS-IMU, we will be following the guide in the link below.  As most GPS modules use serial to communication, this guide can be followed for other GPS modules.

BerryGPS Setup Guide for the Raspberry Pi


The images below shows how we have connected the BerryGPS-IMU to the Raspberry Pi 3 whilst it is in the SmartPi Touch case.

Raspberry Pi Navit GPS

If you plan on testing this out in your car,  you need to be mindfully of where you place your BerryGPS. In my setup and I have placed it in the air vent as shown below, and BerryGPS gets a good strong signal.

Raspberry Pi GPS

If you are using an external antenna, then there is no need to worry about where your BerryGPS is placed.

Continue reading Navigating with Navit on the Raspberry Pi

BerryIMU running on Raspberry Pi running Windows IoT

BerryIMU also works great with Windows IoT Core on the Raspberry Pi.

Our Git repository contains the source files needed to get the BerryIMU up and running on Windows IoT.

The code will print out the following values to the screen;

  • Raw values from the gyroscope, accelerometer and magnetometer.
  • Accelerometer calculated angles.
  • Gyro tracked angles.
  • Fused X and Y angles.
  • Heading.
  • Tilt compensated heading.

Connecting BerryIMU to a Raspberry Pi

BrryIMU can connect via the jumper cables to the Raspberry Pi as shown below;
Raspberry Pi BerryIMU

IMU Raspberry Pi Accelerometer gyro

Or BerryIMU can sit right on top of the GPIO pins on a Raspberry Pi. The first 6 GPIOs are used as shown below.

IMU Raspberry Pi Accelerometer gyro

Get the Code

Download the BerryIMU code for Windows IoT from our GIT repository. The files you need are under the WindowsIoT-BerryIMU folder.

You will need to download the entire git repository as GIT doesn't allow downloading individual folders.

Once downloaded, double-click  the file WindowsIoT-BerryIMU.sln to open up the project in Visual Studio.


About the code

The project code outputs all of the needed values to the screen and a complementary filter is used to fuse the accelerometer and gyroscope angles.

We have a number of guides already documented on how to get the BerryIMU working with the Raspberry Pi.
These are based on Raspbian, however the principals and math are the same for Windows Iot.

The final values which should be used are the fused X &Y angles and the tilt compensated heading.

The sensor on the BerryIMU is the LSM9DS0 and all the I2C registers for this sensor can be found in LSM9DS0.cs

The main code can be found in MainPage.xaml.cs


BerryIMU Raspberry Pi Gyroscope Accelerometer

Complementary Filter

A complementary filter is used to fuse the angles. Is summary, the complementary filter trusts the gyroscope for short periods and trusts the accelerometer for longer periods;

CFangleX = AA * (CFangleX + (rate_gyr_x * DT / 1000)) + (1.0f - AA) * AccXangle;
CFangleY = AA * (CFangleY + (rate_gyr_y * DT / 1000)) + (1.0f - AA) * AccYangle;

Changing how much trust is given for each of the sensors can be changed by modify the complementary filter constant at the start of the code.

const float AA = 0.03f;     // Complementary filter constant

Loop Speed

The loop speed is important as we need to know how much time has past to calculate the rotational degrees per second on the gyroscope.
A time delta is set at the start of the code.

const int DT = 100;         //DT is the loop delta in milliseconds.

This is then used to specify a new timer method.

periodicTimer = new Timer(this.TimerCallback, null, 0,DT);

Here you can see where DT is used to keep track of the gyroscope angle. You can also see it in the above calculation for the complementary filter.

//Calculate the angles from the gyro
gyroXangle += rate_gyr_x * DT / 1000;
gyroYangle += rate_gyr_y * DT / 1000;
gyroZangle += rate_gyr_z * DT / 1000;

BerryIMU orientation

The calculations in the code are based on how the BerryIMU is orientated. If BerryIMU is upside down, then some of the angles need to be reversed. It is upside down when the skull logo is facing up(or to the sky).
If it is upside down, set the below value to true. Otherwise, set it to false.

bool IMU_upside_down = true;





BerryIMU Code for Teensy

Our BerryIMU GIT repository has been updated with code for the Teensy, specifically Teensy 3.6.
teensy accelerometer gyroscopeNow you can have access to an accelerometer, gyroscope, compass, temperature and pressure sensor on your Teensy.

Here you can see the angles displayed using the Serial Plotter in the Arduino IDE which is connected to a Teensy 3.6.



Teensy 3.6  Hookup

teensy accelerometer gyroscope

Connect SCL on the BerryIMU to PIN 19
Connect SDA on the BerryIMU to PIN 18
Use 3.3v pin on the Teensy to power the BerryIMU.




Download the BerryIMU code from our GIT repository. The files you need are under the Teensy-BerryIMU folder.

We use the Arduino IDE to program the Teensy.  You will need to install Teensduino so that your Arduino IDE supports Teensy.

You can download it from this link;


BerryIMU Raspberry Pi Gyroscope Accelerometer


Arduino Serial plotter

The latest version of Arduino IDE includes a Serial Plotter. This is great to show angles in a sliding graph.

The below image shows how to access the Serial Plotter.

Arduino Serial Plotter

The Serial Monitor will have to be closed as both cannot be opened at the same time.

The Serial Plotter expects the values to be separated with a space. To show the X and Y angles on the plotter, comment out the print statements in the existing code and insert the code below.


Continue reading BerryIMU Code for Teensy

Record Temperature and Pressure with ESP8266 and BerryIMU

In this guide, we will be using the ESP8266 and BerryIMU to record temperature and pressure and display the output onto a web page.

Google charts is used to display the data in an easy to read format.

ESP8266 Record temperature
ESP8266 Record temperature

Adafruit Feather Hazzuh! and BerryIMU
Adafruit Feather Hazzuh! and BerryIMU

Components used are;


  • NTP is used to get the correct time of day.
  • The free available RAM is calculated to work out how much data we can store,
  • Google charts is used to display chart data.
  • 4 web pages are created:
    "/" - home page which is used to display the gauges.
    "/chart.html" - Is used to display chart.
    "/table.html" - Is used to display the data in a table.
    "/data.json"- Is used by the home page to update the the gauge values.

Hook Up

The below diagram shows how to connect a BerryIMU to an ESP8266 microcontroller, in this case it is the  Adafruit Feather Huzzah .

Adafruit Huzzah IMU
Adafruit Huzzah and BerryIMU


Prepare Arduino IDE

The Arduino IDE needs to be updated with the board packages for the ESP8266.  This is very easy to do and both Sparkfun & Adafruit have detailed guides on how to do this;
Sparkfun Arduino IDE and ESP8266
Adafruit Arduino IDE and ESP8266

Continue reading Record Temperature and Pressure with ESP8266 and BerryIMU

GPS Data logger using a BerryGPS

This post explains how to log GPS data from a BerryGPS or a BerryGPS-IMU and then how to plot this data onto Google Maps and many other maps E.g. OpenStreet, WorldStreet, National Maps, etc..

Raspberry Pi GPS

1. Setup GPS

Follow the instructions on this page to setup your Raspberry Pi for a BerryGPS. Ensure GPSD is set to automatically start and confirm that you can see the NMEA sentences when using gpsipe;

pi@raspberrypi ~ $ gpspipe -r


2.  Automatically Capture Data on Boot.

We will be using gpspipe to capture the NMEA sentence from the BerryGPS and storing these into a file. The command to use is;

pi@raspberrypi ~ $ gpspipe -r -d -l -o /home/pi/`date +"%Y%m%d-%H-%M-%S"`.nmea

-r = Output raw NMEA sentences.
-d = Causes gpspipe to run as a daemon.
-l = Causes gpspipe to sleep for ten seconds before attempting to connect to gpsd.
-o = Output to file.

The date the file is created is also added to the name.

Now we need to force the above command to run at boot. This can be done by editing the rc.local file.

pi@raspberrypi ~ $ sudo nano /etc/rc.local


Just before the last line, which will be 'exit 0', paste in the below line;

gpspipe -r -d -l -o /home/pi/`date +"%Y%m%d-%H-%M-%S"`.nmea

Reboot and confirm that you can see a .nmea file in the home directory.

Continue reading GPS Data logger using a BerryGPS

New Products : BerryGPS and BerryGPS-IMU

We have released two new products:

BerryGPS - GPS for the Raspberry Pi

BerryGPS-IMU - GPS and IMU for the Raspberry Pi

Both GPS modules use the  M10478-A2 from Antenova, which is a high quality GPS module which is able to track 22 satellites and has an internal antenna. This means no external antenna is needed if the module has clear access to sky.  Both feature a SuperCap to store ephemeris data for up to four hours. This and many more features are included.

Raspberry Pi GPS




Both have been specifically designed for the Raspberry Pi Zero, however they will work with any version of Raspberry Pi.


The BerryGPS-IMU also includes all the components found on the BerryIMU.  And is compatible with the existing code in our repository. The BerryGPS-IMU present a lot of sensors in a very, very small package.



Raspberry Pi GPS




Raspberry Pi GPS
BerryGPS-IMU on a Raspberry Pi Zero


BerryGPS-IMU on Raspberry Pi 2


ESP8266 and a BerryIMU - simple web server

The ESP8266 is another good microcontroller which can be used with the BerryIMU.

The ESP8266 is small and includes Wifi.


In this guide we will setup of the ESP8266 to provide a web page which we can then use to read the  accelerometer, gyroscope and compass values from the BerryIMU. We will also force this webpage to refresh every 1 seconds.

Accessing the ESP8266 from an iPhone



The ESP8266 Arduino core to program our ESP8266. This allows you to use the Arduino IDE to program and upload to the ESP8266.

We have used the Adafruit Feather Huzzah and the Sparkfun Thing Dev board in this guide. Both are excellent boards with included USB to serial converters. Just plug in and upload. This guide can also be used with other ESP8266 boards, just take note of the pins used.

Sparkfun Thing and BerryIMU
Sparkfun Thing and BerryIMU
Adafruit Feather Hazzuh! and BerryIMU
Adafruit Feather Hazzuh! and BerryIMU

Hook Up

The below diagrams show how to connect a BerryIMU to an ESP8266 microcontroller, in this case the  Adafruit Feather Huzzah and the Sparkfun Thing Dev board.


Adafruit Huzzah IMU
Adafruit Huzzah and BerryIMU
Sparkfun Thing IMU
Sparkfun Thing Dev and BerryIMU


Prepare Arduino IDE

The Arduino IDE needs to be updated with the board packages for the ESP8266.  This is very easy to do and both Sparkfun & Adafruit have detailed guides on how to do this;
Sparkfun Arduino IDE and ESP8266
Adafruit Arduino IDE and ESP8266

BerryIMU Raspberry Pi Gyroscope Accelerometer

The Code

The code can be found here . Download the entire Git repo. The code for this guide can be found under the directory
The file you load into the Arduino IDE is BerryIMU_ESP8266_simple_web.ino.

This guide will only cover the specific to the ESP8266. There is another guide here which covers the code used to calculate the angles and heading from the BerryIMU.

The first thing to do is update the code with your wireless network settings.

const char* ssid = "******";
const char* password = "***************";

Further down you can see where we define the web server and what port to listen on

ESP8266WebServer server(80);

There is then a function called handleroot(). This is what builds the web page and sends it to the client when the client requests it E.g. When a web browser requests for a page.
Looking at the line which contains the meta tag, you can see where the refresh timer is set to 1 seconds.

I have also hilighted the variables which store the angles and heading from the BerryIMU.

void handleroot()
  //Create webpage with BerryIMU data which is updated every 1 seconds
  server.sendContent("HTTP/1.1 200 OK\r\n"); //send new p\r\nage
  server.sendContent("Content-Type: text/html\r\n");
  ("<html><head><meta http-equiv='refresh' content='1'</meta>"
  "<h3 style=text-align:center;font-size:200%;color:RED;>BerryIMU and ESP8266</h3>"
  "<h3 style=text-align:center;font-size:100%;>accelerometer, gyroscope, magnetometer</h3>"
  "<h3 style=text-align:center;font-family:courier new;><a href= target=_blank></a></h3><hr>");
  ("<h2 style=text-align:center;> Filtered X angle= " + String(<strong><span style="color: #ff0000;">CFangleX</span></strong>));
  ("<h2 style=text-align:center;> Filtered Y angle= " + String(<span style="color: #ff0000;"><strong>CFangleY</strong></span>));
  ("</h2><h2 style=text-align:center;> Heading = " + String(<span style="color: #ff0000;"><strong>heading</strong></span>));
  ("</h2><h2 style=text-align:center;> Tilt compensated heading =  " + String(<strong><span style="color: #ff0000;">headingComp</span></strong>));

Within setup(), we define what pins are used for I2C to communicated with the BerryIMU.


The first value is the SDA pin and the second specifies the SCL pin. Any pin on the ESP8266 can be used for I2C.

Wireless is then enabled  and then we try and connect to the wireless network. The IP address is then printed to the serial console.

  WiFi.begin(ssid, password);

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED)
  Serial.print("Connected to ");

  //Print IP to console
  Serial.print("IP address: ");

And finally, the web server is started and match on root of the web server and then run handleroot().

server.on("/", handleroot);

You need to add the below line in the main loop to handle web requests.

server.handleClient(); //Handler for client connections

Boot Raspberry Pi from USB - in Beta

The Raspberry Pi 3 can now be booted from a USB drive or from over the Network.  It is still in beta and somewhat complicated to setup.

Raspberry Pi Network Boot


However, once the Raspberry Foundation has ironed out some of the bugs and have made it easier to configure, I think these two features will be used more frequently, specifically booting from USB.


Raspberry Pi USB



Info here;
Raspberry Pi boot modes

And below;

Pi 3 booting part I: USB mass storage boot beta