How to Stream GPS Data Using Raspberry Pi

In this post, I’ll show you how to stream GPS data using a Raspberry Pi. To make it more fun, I actually strapped the GPS receiver and Raspberry Pi to a quadcopter and streamed the data via Wifi to my laptop computer. I’ll walk you through all the steps below.

Requirements

Here are the requirements:

  • Using a GPS receiver/dongle connected to the Raspberry Pi, capture GPS data, stream via WiFi to my laptop computer and display on my laptop computer.

Prerequisites

The following components are used in this project. You will need:

Implementation

Hardware

I began by opening a terminal window and typing the following command:

ls /dev/tty*

I looked at the devices, then plugged in the GPS unit into the USB port of the Raspberry Pi. I then looked at the terminal again to check for the difference.

Before:

gps_data_raspberry_pi

After:

gps_data_raspberry_pi

I saw the new entry is /dev/ttyACM0.

Next, I made sure the tty port is set to a baud rate of 9600.

stty -F /dev/ttyACM0
gps_data_raspberry_pi

Next, I installed the daemon. The purpose of this step is to install software on the Raspberry Pi that understands the serial data that the GPS module is providing via /dev/ttyAMA0.

sudo aptitude install gpsd gpsd-clients python-gps

I then invoked the daemon using -nN so it doesn’t try to set the baud rate itself.

sudo gpsd -nN /dev/ttyACM0 /var/run/gpsd.sock

I then ran the basic test program to verify gpsd is working.

cgps -s

I jump started the service.

sudo service gpsd stop
sudo gpsd -nN /dev/ttyACM0 /var/run/gpsd.sock

I got a lot of error messages.

gps_data_raspberry_pi

I then placed the GPS device on the windowsill to have a clear view of the sky.

I opened another terminal window, and typed the following command:

cgps -s
gps_data_raspberry_pi

I typed the following command to get a more visual display of the GPS data.

xgps
gps_data_raspberry_pi

I ran the following command to get a more detailed look at the live-streaming GPS data.

gpsmon 
gps_data_raspberry_pi

I typed the following command to shutdown the GPS stream:

sudo killall gpsd

To restart the GPS stream I typed

sudo gpsd /dev/ttyAMA0 -F /var/run/gpsd.sock

I then typed the following command to shutdown the GPS stream:

sudo killall gpsd

I then mounted the Raspberry Pi and GPS on the quadcopter.

gps_data_raspberry_pi
gps_data_raspberry_pi

I then flew the quadcopter and streamed the GPS data via WiFi to my host computer.

Software

No extra software was necessary.

Video

How to Stream Live Video Using Raspberry Pi

In this post, I’ll show you how to stream live video using a Raspberry Pi. To make it more fun, I actually strapped the camera and Raspberry Pi to a quadcopter, captured video, and streamed that video via Wifi to my laptop computer. I’ll walk you through all the steps below.

Requirements

Here are the requirements:

  • Using a USB Webcam connected to the Raspberry Pi, capture video, download via WiFi to my laptop computer (Windows 10) and display on my laptop computer.

Design

The following components are used in this project. You will need:

Here is the diagram of the hardware setup:

No diagram necessary.

Implementation

Hardware

First, I updated the packages. It is good practice to update all the Raspberry Pi software before installing new software. I went to the terminal inside Raspberry Pi, and I typed the following commands in order to make sure that I am using the latest version:

sudo apt-get update
stream_live_video_8
sudo apt-get upgrade

I waited several minutes for the upgrade to perform.

I then restarted the Raspberry Pi using the following command:

sudo reboot

Then, I typed the following command to start the installation:

sudo apt-get install motion

I typed in the following command and pressed Enter to see if the system is recognizing my USB web camera.

lsusb
stream_live_video_9

The name of the USB web camera is GEMBIRD as seen in the above screenshot.

I made edits to the configuration file, motion.conf, using the following command:

sudo nano /etc/motion/motion.conf
stream_live_video_10

I made sure the settings were as follows:

  • daemon on
  • framerate 100
  • stream_localhost off
  • stream_port 8081
  • stream_quality 100
  • stream_maxrate 100
  • width 640
  • height 480
  • webcontrol_localhost off
  • quality 100
  • post_capture 5

I pressed ctrl + x to exit.

I typed y to save.

I typed enter to confirm.

I typed the following command and pressed Enter:

sudo nano /etc/default/motion

I changed the following line:

start_motion_daemon=yes

I saved and exited by pressing ctrl+x then y

I restarted the service to make sure the web page would load:

sudo service motion restart

To start the service, I typed the following command:

sudo motion

Next, I checked the webcam stream at the IP address of the Raspberry Pi:

192.168.0.17:8081
stream_live_video_11

To stop the service, I ran the following line:

sudo service motion stop

To start the service again, I ran the following line:

sudo service motion start

I then typed the following command:

sudo motion

Next, I checked the webcam stream at the IP address of the Raspberry Pi:

192.168.0.17:8081

I then mounted the Raspberry Pi, battery, and webcam on the quadcopter.

stream_live_video_raspberry_pi (4)
stream_live_video_raspberry_pi (5)
stream_live_video_raspberry_pi (6)
stream_live_video_raspberry_pi (7)
stream_live_video_raspberry_pi (2)
stream_live_video_raspberry_pi (3)

I then flew the quadcopter and streamed the video via WiFi to my host computer. See the video below in the next section.

Software

No software was necessary.

Video

How to Capture Temperature and Humidity Using the ESP8266 Weather Kit

In this post, I’ll show you how to set up the ESP8266 and how to capture temperature and humidity data using this device. For this project I followed the Uctronics user guide. To locate that, just type into Google, “UCTRONICS ESP8266 pdf user guide”, and it should be the first result.

Requirements

Here are the requirements:

  • Set up the ESP8266 and capture temperature and humidity data using this device.

Hardware Design

The following components are used in this project. You will need:

parts_for_esp8266

Here is the diagram of the hardware setup:

hardware_setup_esp8266PNG

Software Design

Software to read temperature and humidity comes from:
https://github.com/supprot/ArduCAM_esp8266- dht-thingspeak-logger.

Hardware Implementation

First, I did a test project to see if I can use an API to capture weather forecast data from the web on my OLED.

I downloaded and installed the Serial Driver available here: https://www.silabs.com/products/mcu/Pages/USBtoUARTBridgeVCPDrivers.aspx

device_driver_8266PNG

I installed the ESP8266 toolchain.

esp8266_toolchain

I selected the correct board NodeMCU 1.0 (ESP-12E Module): In the Arduino IDE, I went to Tools > Board: * > NodeMCU 1.0 (ESP-12E Module).

I set the correct port by going to Tools > Port and looking for a COM port labelled COM# (where # is a number).

I tested the setup of the Wifi Scanner. In the Menu of the Arduino IDE, I went to to File > Examples > ESP8266Wifi and select WiFiScan.

wifi_scan

I installed the libraries for the weather station: Sketch > Include Library… > Manage Libraries…

  • ESP8266 Weather Station Library
  • Json Streaming Parser Library
  • SSD1306 OLED Library

I opened the WeatherStationDemo example: Went to File > Examples > ESP8266 Weather Station >WeatherStationDemo and saved the new sketch with a new name.

I got the OpenWeatherMap API.

open_weather_map

I configured the weather station.

wx_station_demo

I connected the hardware.

esp8266_breadboard

I uploaded the firmware and ran the WeatherStation. The weather forecast and current weather outside were displayed on the OLED display as seen below.

Next, I collected and displayed temperature and humidity data in my home office. Here are the steps I took:

I set up Thingspeak.

thing_speak

I went to https://github.com/supprot/ArduCAM_esp8266- dht-thingspeak-logger and downloaded the code as a Zip file.

I adapted the settings to my needs.

I set up the hardware.

humidity_logger

I ran the temperature and humidity logger. Here are the results I got.

temp_results
humidity_results

Software Implementation

Here is the source code that you will need to load to your ESP8266 board. Where it says “xxxx”, that is where you enter your own values:

/**The MIT License (MIT)

Copyright (c) 2015 by Daniel Eichhorn

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

See more at http://blog.squix.ch
// Modified by Addison Sears-Collins
*/

#include <ESP8266WiFi.h>
#include <DHT.h>


/***************************
 * Begin Settings
 **************************/


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

const char* host = "api.thingspeak.com";

const char* THINGSPEAK_API_KEY = "xxxx";

// DHT Settings
#define DHTPIN D6     // what digital pin we're connected to. If you are not using NodeMCU change D6 to real pin


// Uncomment whatever type you're using!
#define DHTTYPE DHT11   // DHT 11
//#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

const boolean IS_METRIC = true;

// Update every 30 seconds. Min with Thingspeak is ~20 seconds
const int UPDATE_INTERVAL_SECONDS = 60;

/***************************
 * End Settings
 **************************/
 
// Initialize the temperature/ humidity sensor
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(115200);
  delay(10);

  // We start by connecting to a WiFi network

  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");  
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {      
    Serial.print("connecting to ");
    Serial.println(host);
    
    // Use WiFiClient class to create TCP connections
    WiFiClient client;
    const int httpPort = 80;
    if (!client.connect(host, httpPort)) {
      Serial.println("connection failed");
      return;
    }

    // read values from the sensor
    float humidity = dht.readHumidity();
    float temperature = dht.readTemperature(!IS_METRIC);
    
    // We now create a URI for the request
    String url = "/update?api_key=";
    url += THINGSPEAK_API_KEY;
    url += "&field1=";
    url += String(temperature);
    url += "&field2=";
    url += String(humidity);
    
    Serial.print("Requesting URL: ");
    Serial.println(url);
    
    // This will send the request to the server
    client.print(String("GET ") + url + " HTTP/1.1\r\n" +
                 "Host: " + host + "\r\n" + 
                 "Connection: close\r\n\r\n");
    delay(10);
    while(!client.available()){
      delay(100);
      Serial.print(".");
    }
    // Read all the lines of the reply from server and print them to Serial
    while(client.available()){
      String line = client.readStringUntil('\r');
      Serial.print(line);
    }
    
    Serial.println();
    Serial.println("closing connection");


  // Go back to sleep. If your sensor is battery powered you might
  // want to use deep sleep here
  delay(1000 * UPDATE_INTERVAL_SECONDS);
}

Video