Using CellLocate with OzzMaker SARA-R5 LTE-M GPS + 10DOF

What do you do if you have a poor or no GNSS signal, such has being indoors, inside a parking garage or in urban canyons? You could try CellLocate.

CellLocate

In a nutshell

CellLocate provides an estimated location based on visible network cell information reported by the cellular module. When CellLocate is activated, a data connection to the CellLocate server is established and the network cell information is passed to the server which provides an estimation of the device position based on the cell information.

CellLocate is fully integrated into the SARA-R5 which is on the OzzMaker SARA-R5 LTE-M GPS 10DOF board. The technology enables stand-alone location data based on surrounding mobile network information as well as hybrid technology that works in conjunction with GNSS. Through the single AT command interface, it is possible to define all the location settings for optimized performance.

When using CellLocate, the position accuracy is not predictable and is determined by the availability in the database of previous observations within the same area. CellLocate does not require a GNSS receiver to be present or active.

CellLocate requires a data connection (PDP) from the SARA-R5 module to the carrier.

 

Getting started

Connect to the SARA-R5 cellular module

pi@raspberrypi ~ $ minicom 115200 -D /dev/serial0

Setup the Packet Data Protocol (PDP) context.

First task is to setup the connection parameters for the PDP context using AT+CGDCONT. Any setting applied with this commend is persistent over power cycles. This means it only needs to be done once. You will however need to enter it again if you do a factory reset.

First, turn off the radio

 AT+CFUN=0

Then set up a connection profile with the APN for your network operator, using the AT+CGDCONT  command (Packet Switch Data configuration). In this example we are using a Hologram SIM, so the APN would be hologram.

AT+CGDCONT=1,”IP”,””hologram”

Now turn the radio back on;

 AT+CFUN=1

Once your SARA-R5 connects to the carrier, you can use AT+CGDCONT? to get your current IP address

AT+CGDCONT?
+CGDCONT: 1,”IP”,”hologram.mnc050.mcc234.gprs”,”10.170.92.244″,0,0,0,2,0,0,0,0,0,0,0

Now active the PDP context

AT+CGACT=1,1

Set the PDP type to IPv4

AT+UPSD=0,0,0

Profile #0 is mapped on CID=1

AT+UPSD=0,100,1

Activate the PSD profile

 AT+UPSDA=0,3

 

Your SARA-R5 should now have internet access. If you want to test the data connection, you can use AT+UPING

AT+UPING=”www.google.com”
OK
+UUPING: 1,32,”www.google.com”,”142.250.179.228″,113,617
+UUPING: 2,32,”www.google.com”,”142.250.179.228″,113,637
+UUPING: 3,32,”www.google.com”,”142.250.179.228″,113,636
+UUPING: 4,32,”www.google.com”,”142.250.179.228″,113,637

 

Using CellLocate

When using CellLocate, There are two modes to choose from:

normal scan: the cellular module reports the serving cell and the neighboring visible cells designated by the network operator, which are normally collected by the module during its “network” activity. This configuration is suggested for a quick update of location

deep scan: the cellular module scans and reports all visible cells providing in addition to serving and neighboring cells by the serving network operator, also the cells of all other available (visible) network operators, thus increasing the probability of obtaining a successful position estimation. Although this takes a bit longer (approximately 30 sec to 2 minutes is needed to perform a deep scan), uses more data (each reported cell requires a few bytes), and more power, coverage and reliability are potentially better in corner cases.

Continue reading Using CellLocate with OzzMaker SARA-R5 LTE-M GPS + 10DOF

New Product: OzzMaker SARA-R5 LTE-M GPS + 10DOF

We have released a new product ; OzzMaker SARA-R5 LTE-M GPS + 10DOF

OzzMaker LTE-M GPS IMU 10DOF

This is an all in one module which can provide location tracking and LTE-M services such as data, text and SMS to your project. It comes in the same form factor as a Raspberry Pi Zero, which makes it nice and compact when used with a Raspberry Pi Zero.

It is a feature packed board, which includes the  following components;

  1. LTE-M cellular modem
  2. GPS  receiver (including assisted GPS)
  3. Accelerometer
  4. Gyroscope
  5. Magnetometer (Compass)
  6. Barometric/pressure sensor (altitude)
  7. Temperature sensor

 

This board includes a SARA-R510M8S  module from uBlox,  this module can be used for LTE-M connectivity and includes an integrated GPS receiver. Using both these features together results in obtaining a GPS fix in seconds, using Assisted GPS.

The below video shows a comparison between assisted and normal GPS.

  • Asisted GPS takes 19secs to get a fix
  • Normal GPS takes 8min 22Sec to get a fix


 

Typically, a GPS module can take a few minutes to get  Time To First Fix(TTFF), or even longer if you are in  built up areas.  This is because the Almanac needs to be downloaded from  satellites before a GPS fix can be acquired and only a small portion of the Almanac is sent in each GPS update.

Assisted GPS speeds this up significantly by  downloading  ephemeris, almanac, accurate time and satellite status over the network, resulting in faster TTTF, in a few seconds. This is very similar how to GPS works on a smartphone.

 

 

Accessing GPS via I2C on a BerryGPS-IMU

The BerryGPS-IMU uses a  CAM-M8C U-Blox GPS module, this GPS module includes a DDC interface which is fully I2C compatible.

This guide will show how to read NMEA sentences from the GPS module via I2C, using a Raspberry Pi. This leaves the serial interface on the Raspberry Pi free for other uses. You can also use a QWIIC connector to connect the BerryGPS-IMU to the Raspberry Pi

We will create a virtual node where we will send the NMEA sentences, we will then configure GPSD to read this virtual node.

 

Caveat: There is a well know I2C clock stretching bug on the Raspberry Pi which will be encountered when trying to communicate with the  uBlox module via native I2C.  This results with random characters appearing in the retrieved data.
We will cover two methods of how to get around this;

Method 1 – Include a lot of checks to ignore NMEA sentences with corrupt data.
The overall amount of NMEA sentences which will be corrupt is very small(20 out of 1,000), which still makes this method very usable.

Method 2 – Using bit banging to overcome the clock stretching bug. This will result in zero errors, but requires I2C to be disabled on the Raspberry Pi.

 

I2C Jumpers

By default, the GPS module on the BerryGPS-IMU is not connected to the I2C bus.  This can be fixed by placing a solder blob on the jumpers JP11 and JP10 on the back of the PCB.

BerryGPS-IMU I2C GPS

 

Method 1 – Using native I2C

Enable I2C on your Raspberry Pi and set the speed to 400Khz.

pi@raspberrypi ~ $ sudo nano /boot/config.txt

Near the bottom, add the following line

dtparam=i2c_arm=on,i2c_arm_baudrate=400000

Now reboot.

You can confirm if you see the GPS module by using the below command.

pi@raspberrypi ~ $ sudo i2cdetect -y 1

 

Here is the output when a BerryGPS-IMU is connected. 42 is the GPS module

pi@raspberrypi ~ $ sudo i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: — — — — — — — — — — — — —
10: — — — — — — — — — — — — 1c — — —
20: — — — — — — — — — — — — — — — —
30: — — — — — — — — — — — — — — — —
40: — — 42 — — — — — — — — — — — — —
50: — — — — — — — — — — — — — — — —
60: — — — — — — — — — — 6a — — — — —
70: — — — — — — — 77

 

Create the python script which will read the data via I2C from the GPS module

pi@raspberrypi ~ $ nano i2c-gps.py

Copy in the below code;

#! /usr/bin/python
import time
import smbus
import signal
import sys
BUS = None
address = 0x42
gpsReadInterval = 0.03
def connectBus():
    global BUS
    BUS = smbus.SMBus(1)
def parseResponse(gpsLine):
  if(gpsLine.count(36) == 1):                           # Check #1, make sure '$' doesnt appear twice
    if len(gpsLine) < 84:                               # Check #2, 83 is maximun NMEA sentenace length.
        CharError = 0;
        for c in gpsLine:                               # Check #3, Make sure that only readiable ASCII charaters and Carriage Return are seen.
            if (c < 32 or c > 122) and  c != 13:
                CharError+=1
        if (CharError == 0):#    Only proceed if there are no errors.
            gpsChars = ''.join(chr(c) for c in gpsLine)
            if (gpsChars.find('txbuf') == -1):          # Check #4, skip txbuff allocation error
                gpsStr, chkSum = gpsChars.split('*',2)  # Check #5 only split twice to avoid unpack error
                gpsComponents = gpsStr.split(',')
                chkVal = 0
                for ch in gpsStr[1:]: # Remove the $ and do a manual checksum on the rest of the NMEA sentence
                     chkVal ^= ord(ch)
                if (chkVal == int(chkSum, 16)): # Compare the calculated checksum with the one in the NMEA sentence
                     print gpsChars
def handle_ctrl_c(signal, frame):
        sys.exit(130)
#This will capture exit when using Ctrl-C
signal.signal(signal.SIGINT, handle_ctrl_c)
def readGPS():
    c = None
    response = []
    try:
        while True: # Newline, or bad char.
            c = BUS.read_byte(address)
            if c == 255:
                return False
            elif c == 10:
                break
            else:
                response.append(c)
        parseResponse(response)
    except IOError:
        connectBus()
    except Exception,e:
        print e
connectBus()
while True:
    readGPS()
    time.sleep(gpsReadInterval)

 

You can test the script with python i2c-gps.py. If you have a GPS fix, you will get output similar to below.

pi@raspberrypi ~ $ python i2c-gps.py
$GNRMC,071423.00,A,3254.18201,S,15243.27916,E,0.252,,110721,,,A*72
$GNVTG,,T,,M,0.252,N,0.466,K,A*3C
$GNGGA,071423.00,3254.18201,S,15243.27916,E,1,10,1.01,29.0,M,22.6,M,,*63
$GNGSA,A,3,30,14,07,17,13,19,15,,,,,,1.66,1.01,1.31*17
$GNGSA,A,3,73,74,72,,,,,,,,,,1.66,1.01,1.31*1C
$GPGSV,3,1,12,01,21,124,,06,13,009,20,07,11,048,21,13,47,286,34*70
$GPGSV,3,2,12,14,54,143,27,15,25,253,31,17,84,132,28,19,70,328,31*7D
$GPGSV,3,3,12,21,09,139,,24,08,225,18,28,,,29,30,49,052,26*45
$GLGSV,3,1,10,65,14,243,16,71,00,330,,72,15,287,21,73,39,099,22*65
$GLGSV,3,2,10,74,53,176,19,75,16,227,,80,00,070,,83,24,149,*64

 

Create a virtual node, this is where we will send the NMEA sentences from the GPS module to.

pi@raspberrypi ~ $ mknod /tmp/gps p

 

Now run the python script and redirect the output to the virtual node we just created.
We will also use stdbuf so the output from the script is sent to the virtual node one line at a time. Without this, the output is buffered and only sent to the virtual node when the buffer is full.

pi@raspberrypi ~ $ stdbuf -oL python i2c-gps.py > /tmp/gps
Configure GPSD to use the virtual buffer

No you can configure GPSD to point to the virtual buffer.

pi@raspberrypi ~ $ sudo nano /etc/default/gpsd

Look for
DEVICES=””
and change it to
DEVICES=”/tmp/gps”

Restart GPSD so the new settings take effect.

pi@raspberrypi ~ $ sudo systemctl restart gpsd.socket

 

You can now start using your GPS module with your Raspberry Pi

Method 2 – Bit Bang I2C

Confirm that you do not have I2C enabled. There should be no i2c devices under /dev/

pi@raspberrypi ~ $ ls /dev/i2c*
ls: cannot access ‘/dev/i2c*’: No such file or directory

 

If you do have I2C enabled, the above command will return a file under the /dev/ directory.
You can disable I2C in /boot/config.txt

pi@raspberrypi ~ $ sudo nano /boot/config.txt

 

Look for the below line and comment it out by adding a “#” in front.

dtparam=i2c_arm=on

Now reboot.

Create the python script which will read the data by bit banging I2C from the GPS module

pi@raspberrypi ~ $ nano i2c-gps.py

 

Copy in the below code;

import time
import signal
import sys
import pigpio
address = 0x42
gpsReadInterval = 0.03
SDA=2
SCL=3
pi = pigpio.pi()
pi.set_pull_up_down(SDA, pigpio.PUD_UP)
pi.set_pull_up_down(SCL, pigpio.PUD_UP)
pi.bb_i2c_open(SDA,SCL,100000)
def handle_ctrl_c(signal, frame):
        pi.bb_i2c_close(SDA)
        pi.stop()
        sys.exit(130)
#This will capture exit when using Ctrl-C
signal.signal(signal.SIGINT, handle_ctrl_c)
def readGPS():
    c = None
    response = []
    while True: # Newline, or bad char.
        a=pi.bb_i2c_zip(SDA, [4, address, 2, 6, 1])  # Bit bang I2C read. 2 = Start, 6 = read, 1= How many bytes to read
        c = ord(a[1])
        if c == 255:
            return False
        elif c == 10:
            break
        else:
            response.append(c)
    gpsChars = ''.join(chr(c) for c in response)  #Convert list to string
    print gpsChars
while True:
    readGPS()
    time.sleep(gpsReadInterval)

 

Create a virtual node, this is where we will send the NMEA sentences from the GPS module to

pi@raspberrypi ~ $ mknod /tmp/gps p

 

Now run the python script and redirect the output to the virtual node we just created.
We will also use stdbuf so the output from the script is sent to the virtual node one line at a time. Without this, the output is buffered and only sent to the virtual node when the buffer is full.

pi@raspberrypi ~ $ stdbuf -oL python i2c-gps.py > /tmp/gps
Configure GPSD to use the virtual buffer

No you can configure GPSD to point to the virtual buffer

pi@raspberrypi ~ $ sudo nano /etc/default/gpsd

Look for
DEVICES=””
and change it to
DEVICES=”/tmp/gps”

Restart GPSD so the new settings take effect.

pi@raspberrypi ~ $ sudo systemctl restart gpsd.socket

 

You can now start using your GPS module with your Raspberry Pi

Using the BerryIMUv3 on a Raspberry Pi Pico with MicroPython

In this guide we will show how to get the a BerryIMUv3 working with a Raspberry Pi Pico, using MicroPython. This code example supports I2C and SPI.

Hook up Guide

The two images below show how to hook up the BerryIMUv3 via I2C or SPI. (If using SPI, you will need to place a solder “blob” on JP7 on the BerryIMUv3 to complete the SPI connection, as shown here)

 

Raspberry Pi Pico and BerryIMU
Raspberry Pi Pico and BerryIMv3 via SPI

 

Raspberry Pi Pico and BerryIMU
Raspberry Pi Pico and BerryIMv3 via I2C

Thonny and the MicroPython code

The MicroPython code can be downloaded from our GitHub repository. The code for this example can be found under the PicoMicroPython directory.

We will be using Thonny to program the Raspberry Pi Pico.

If you are new to the Raspberry Pi Pico and Thonny, we suggest viewing these excellent tutorials from our friends at Core Electronics;
1. Getting started with Raspberry Pi Pico
2. Pico and Thonny

 

The sample code supports both I2C and SPI communications.  Comment out the protocol which will not be used as shown below. Below we have commented out I2C as we will be using SPI

import utime
import math
from LSM6DSL import *
import machine
#Comment out one of the below lines
import IMU_SPI as IMU
#import IMU_I2C as IMU

 

BerryIMU Pico Thonny
BerryIMU Pico Thonny

 

Connecting BerryIMUv3 via SPI to a Raspberry Pi

The accelerometer and gyroscope on the BerryIMUv3 can output data at a rate of 6,664 times a second!  I2C is too slow to read the output at this rate, this is where SPI comes in.

Buy default, BerryIMUv3 is setup to use I2C.  You can complete the SPI interface by placing a solder blob on jumper 7 (JP7).

BerryIMU SPI
Blob on jumper 7

 

SPI uses 4 pins,  and depending on what device you are using these pins could be named differently, which causes confusion.

The most common pin names are;

  • MOSI  (Master out Slave In)
  • MISO  (Master In Slave Out
  • SCLK (Serial Clock)
  • CS (chip select)  This is CE0 or CE1 on the Raspberry PI.

These pins have been highlighted below

Raspberry Pi SPI pins
Raspberry Pi 40 pin header

 

On the BerryIMUv3, they are called;

  • SDI (Slave Data In)
  • SDO (Slave Data Out)
  • SPC (Serial Port Clock)
  • CS (Chip Select)

When we connect a BerryIMUv3 to a Raspberry Pi using SPI, the Raspberry Pi will be acting as a master and the BerryIMUv3 will be acting as a slave. This is how they are connected logically.

BerryIMU SPI
BerryIMU and Raspberry Pi SPI

Here is the physical wiring

Raspberry Pi BerryIMU SPI
Raspberry Pi SPI and BerryIMUv3

 

You can enable SPI on the Raspberry Pi using raspi-config

pi@raspberrypi ~ $ sudo raspi-config

Raspberry Pi SPIGo into “Interfacing Options”

Raspberry Pi SPI
Then select “SPI”

When asked if you want to enable SPI, select “yes”

 

The code for SPI can be found here https://github.com/ozzmaker/BerryIMU/tree/master/python-BerryIMUv3-SPI

Double tap detection with BerryIMUv3

The accelerometer(LSM6DSL) on the BerryIMUv3 has built in double tap detection, which makes it very easy to detect double taps without the need for any fancy code.

double tap IMU

When the LSM6DSL detects a double tap, it can fire an interrupt pin on the BerryIMUv3.  We will use a Raspberry Pi to monitor the interrupt pin and turn a LED off and on when a double-tap is detected.

 

Double-Tap event recognition has special registers which control tap recognition functionality, these are the tap threshold and the Shock, Quiet and Duration time windows

Double-tap event recognition
Double-tap event recognition

 

The Raspberry Pi will configure the BerryIMUv3 for double tap recognition. It will also monitor for double taps, which will be used to turn a LED on and off.

 

INT1 On the BerryIMUv3 will go high when a double tap is detected.


GPIO18
(physical pin 12) on the Raspberry Pi will be used to monitor INT1 , using an interrupt.

GPIO20 (physical pin 28) will be used to drive the LED.

The resister below is 330 Ohms

Here is the hock up diagrams

BerryIMU double-tap using QWIIC cable
BerryIMU double-tap using QWIIC cable
BerryIMU double-tap
BerryIMU double-tap
import signal
from LSM6DSL import *
import sys
import RPi.GPIO as GPIO 
import smbus
bus = smbus.SMBus(1)
LED_ON = 0                                                           #Used to track of the current state of the LED
INTERRUPT_PIN = 12                                                   #The interrupt pin which will be connected to the IMU
LED_PIN = 38                                                         #The pin which will be driving the LED
#Used to clean up when Ctrl-c is pressed
def signal_handler(sig, frame):
    GPIO.cleanup()
    sys.exit(0)
    
#Used to write to the IMU
def writeByte(device_address,register,value):
    bus.write_byte_data(device_address, register, value)


def LEDnotification(channel):
	global LED_ON
	if LED_ON:
		GPIO.output(LED_PIN,0)
		LED_ON = 0
	else:
		GPIO.output(LED_PIN,1)
		LED_ON = 1

writeByte(LSM6DSL_ADDRESS,LSM6DSL_CTRL1_XL,0b01100000)                 #ODR_XL = 416 Hz, FS_XL = +/- 2 g
writeByte(LSM6DSL_ADDRESS,LSM6DSL_TAP_CFG,0b10001110)                  #Enable interrupts and tap detection on X, Y, Z-axis
writeByte(LSM6DSL_ADDRESS,LSM6DSL_TAP_THS_6D,0b10001100)               #Set tap threshold
writeByte(LSM6DSL_ADDRESS,LSM6DSL_INT_DUR2,0b01111111)                 #Set Duration, Quiet and Shock time windows
writeByte(LSM6DSL_ADDRESS,LSM6DSL_WAKE_UP_THS,0b10000000)              #Double-tap enabled 
writeByte(LSM6DSL_ADDRESS,LSM6DSL_MD1_CFG,0b00001000)                  #Double-tap interrupt driven to INT1 pin
        
GPIO.setmode(GPIO.BOARD) # Use physical pin numbering
GPIO.setup(INTERRUPT_PIN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(LED_PIN, GPIO.OUT)
GPIO.output(LED_PIN, 0)
GPIO.add_event_detect(INTERRUPT_PIN, GPIO.RISING, callback=LEDnotification, bouncetime=300)

while True:
    signal.signal(signal.SIGINT, signal_handler)
    signal.pause()

We will cover specific code which relates to double-tap recognition.

Line 37 , LSM6DSL_TAP_CFG is used to enable tap recognition on the X, Y, Z directions.  It is also used to enable the interrupt function for double-tap recognition.

Line 38 , LSM6DSL_TAP_THS_6D is used to set the tap thresholds. a lower value will result in softer taps being detected.

Line 39 , LSM6DS_INT_DUR2 is used to set the duration, quiet and shock time window.  A larger duration will result in a longer time between 1st and 2nd tap.

Line 40, LSM6DSL_WAKE_UP_THS. Set the left most bit to enable double tap recognition.

Line 41,  LSM6DSL_MD1_CFG is used to set which interrupt pin ont he BerryIMUv3 is used. In this instance, it is set to INT1.

 

 

 

 

 

 

 

New BerryIMU version

We are now selling version 3 of the BerryIMU.

BerryIMU Raspberry Pi

 

BerryIMUv3 has been updated with the latest sensors, resulting in lower noise and a faster output rate (up to 6,664 times a second!).

We have also included level shifters for 5V MCUs. Which means you can safely connect the BerryIMUv3 directly to an Arduino.

 

BerryIMU Arduino

 

BerryIMUv3 is compatible with the SparkFun QWIIC echo system.

 

We sell a QWIIC connector and cable for the Raspberry here.  This does away with the need to solder headers onto the BerryIMUv3 when connecting to a Raspberry Pi.

QWIIC connector Raspberry Pi

Some of the features.

  • Gyroscope and accelerometer output rates of 6.7KHz (6,664 times a second!)
  • Detect tilt, tap and double tap
  • Pedometer, step detector and step counter
  • Interrupt pins
  • Read temperature
  • supports both 3.3V and 5V
  • I2C and SPI
  • “Always-on” experience with low power
    consumption for both accelerometer and gyroscope

 

BerryIMU

 

 

GPS Position accuracy and how to tell if you have a good fix?

One of the main contributing factors to GPS position accuracy is the geometric configuration (the position in the sky) of the satellites used to obtain a position.
The best position fix is given when a satellite is directly overhead and another three are equally spaced around the horizon.

This aspect is called the ‘geometry’ of the system and is measured as DOP (Dilution of Precision).

The influence of satellite geometry on imprecision is demonstrated in the image below. When both satellites are widely separated (figure left) the position error (area in red) is smaller. If the satellites are close to one another (right figure), then the area of error is more spread out. This is valid when the uncertainty for determining the position,
known as the Range Error (R-E: yellow and blue areas), is the same for both satellites. R (R1 and R2) refers to the
measured distance of the satellites to the user (pseudorange).

HDOP overlap
Satellite precision error

 

There are a number of different DOP elements which can be used, we will focus on HDOP (Horizontal-DOP).

The HDOP can be seen when using gpsmon. The image below has HDOP highlighted;gpsmon HDOP

The HDOP can also be found in the GSA sentence.  Below it is shown as 1.3;

$GPGSA,A,3,04,05,,09,12,,,24,,,,,2.5,1.3,2.1*39

A HDOP value of 1 or below would give you an accuracy of about 2.5 meters.

When in mountainous areas, forests and urban canyons, you can experience high HDOP values as  some of the available satellites will be obstructed. The satellites used will be closer together creating a large area of error as the signal from each satellite have a larger intersect.

Low accuracy in a city
Low accuracy in a city

Out on the open sea, you should be able to see a low HDOP value as the satellites used would be spread out and has less area of a intersect.

HDOP
Good accuracy

Using u-Center to connect to the GPS on Raspberry Pi

u-Center from u-Blox is a graphical interface which can be used to monitor and configure all aspects of the GPS module on a BerryGPS-IMU or BerryGPS-GSM.

u-Center from uBlox
U-Center

 

u-Center only runs on Windows. It can connect over the network to a Raspberry Pi.  This will require us to redirect the serial interface on the Raspberry Pi to a network port using ser2net.

Pi Setup

Do an upt-get update and then install ser2net;

pi@raspberrypi ~ $ sudo apt-get update
pi@raspberrypi ~ $ sudo apt-get install ser2net

Edit the ser2net config file and add the serial port redirect to a network port. We will use network port 6000

pi@raspberrypi ~ $ sudo nano /etc/ser2net.conf

And add this line at the bottom;

6000:raw:600:/dev/serial0:9600 NONE 1STOPBIT 8DATABITS XONXOFF LOCAL -RTSCTS

This is a breakdown of the syntax for the line above;
TCP port : connection type : timeout : serial port : serial port speed : serial options

you can now start ser2net using;

pi@raspberrypi ~ $ sudo ser2net

And you can use the below command to check if it is running by seeing if the port is open and assigned to the ser2net process;

pi@raspberrypi ~ $sudo netstat -ltnp | grep 6000

If it is running, you should see something similar to the output below;

check result of ser2net

Windows PC Setup and Connecting to the GPS module

You can download u-Center from here.

Once installed, open u-Center. You will get the default view as shown below.  No data will be shown as we are not connected to a GPS.

u-Center default view

The next step, is to create a new network connection and connect to the GPS which is connected to our Raspberry Pi. You can create a new connection under the Receiver and then Network connection menus.

u-Center connect to Raspberry Pi
In the new window, enter the IP address of the Raspberry Pi and specify port 6000. This is the port we configured in ser2net on the Raspberry Pi.
u-Center Raspberry Pi Address

This is what the default view looks like when connected and the GPS has a fix.u-Center connected

 

u-Center

Below I will list of the more useful windows/tools within u-Center.
You can also click on the images below for a larger version.

Data View
This window will show you the longitude, latitude, altitude and fix mode. It will also show the HDOP, which is the Horizontal Dilution of Precision.  Lower is better, anything below 1.0 means you have a good signal.

u-Center Data View
u-Center Data View

Ground Track
This window will show you where the satellites are as well as what time.

u-Center Ground Track
u-Center Ground Track

Skye View
Sky view is an excellent tool for analyzing the performance of antennas as well as the conditions of the satellite observation environment.

u-Center Sky View
u-Center Sky View

Deviation Map
This map shows the average of all previously measured positions.

u-Center Deviation Map
u-Center Deviation Map

Continue reading Using u-Center to connect to the GPS on Raspberry Pi

Control the GPIO of a Raspberry Pi using SMS from a mobile phone

In this guide we will show you how to control the GPIO pins of a Raspberry pi by send a SMS to the Raspberry Pi from a mobile phone.

 

For this guide, the GSM modem we are using to receive the SMS is the  BerryGPS-GSM.

On the software side, we will be using Gammu, which is specifically designed to control  phones and GSM modules. It also has a daemon which will monitor the GSM modem for incoming SMSs.

We will configure Gammu to trigger a python script when a new SMS is received. We will use the contents of the SMS to control what happens in Python

LEDs are used here as an example, but you can do anything you like Eg. Open a garage door, turn on some lights, etc..

 

Wiring

Raspberry PI GPIO SMS

 

We will be using the three bottom right GPIO pins on the Raspberry Pi header. These are GPIO 16, 20 and 21.
Each is connected to a different color LED as shown above. The
The resistors used are 330 Ohm  and the GND pin (shorter pin) of the LEDs is connected to the GND power rail.

 

Setup

Install Gammu and python bindings;

pi@raspberrypi ~ $ sudo apt-get update
pi@raspberrypi ~ $ sudo apt-get install gammu-smsd python-gammu

Edit the config file;

pi@raspberrypi ~ $ sudo nano /etc/gammu-smsdrc

Find the below lines and add port and speed.
For the BerryGPS-GSM, use /dev/ttyACM1 for port and at115200 for speed

port = /dev/ttyACM1
connection = at115200

At the bottom of the file, add the line below. This is the python script which will run when a new SMS is received.

RunOnReceive = sudo python /home/pi/smsReceived.py

We will do a quick test. Restart the gammu service so the new config takes effect;

pi@raspberrypi ~ $ sudo /etc/init.d/gammu-smsd restart

Send a test SMS to a mobile number. The mobile number below is an example, you will need to update this;

pi@raspberrypi ~ $ echo “This is a test from a Raspberry Pi” | /usr/bin/gammu –sendsms TEXT +614123456789

 

Python Script

This python script will run every time a new SMS is received.

pi@raspberrypi ~ $ nano ~/smsReceived.py

Copy in the below code

import RPi.GPIO as GPIO
import time
import sys
import re

RED_LED =  21
GREEN_LED =  20
BLUE_LED =  16
GPIO.setmode(GPIO.BCM)
filename=str(sys.argv[1])                               #Gammu will pass the filename of the new SMS as an argument
complete_filename="/var/spool/gammu/inbox/"+filename    #we create the full path to the file here
GPIO.setup(RED_LED , GPIO.OUT)
GPIO.setup(GREEN_LED , GPIO.OUT)
GPIO.setup(BLUE_LED , GPIO.OUT)
sms_file=open(complete_filename,"r")
#read the contents of the SMS file
message=sms_file.read(160) #note that a not-parted SMS can be maximum 160 characters
#search the contents and perform an action. Rather than use 'find',
# we will use regular expression (re) so we can ignore case.
#Most smartphones will have the first letter capitalised
if re.search('red', message, re.IGNORECASE):
        GPIO.output(RED_LED , GPIO.HIGH)
        time.sleep(2)
        GPIO.output(RED_LED , GPIO.LOW)
elif re.search('green', message, re.IGNORECASE):
        GPIO.output(GREEN_LED , GPIO.HIGH)
        time.sleep(2)
        GPIO.output(GREEN_LED , GPIO.LOW)
elif re.search('blue', message, re.IGNORECASE):
        GPIO.output(BLUE_LED , GPIO.HIGH)
        time.sleep(2)
        GPIO.output(BLUE_LED , GPIO.LOW)

GPIO.cleanup()

To troubleshoot you can view the syslog

pi@raspberrypi ~ $ tail -f /var/log/syslog

Blip, blop, bloop…