In this project I'm going to connect a GPS module and use it as a GPS tracker.
Hardware
For this project I'm using:
-
Onion Omega 2 plus
-
U-BLOX NEO-6M GPS module
-
PL2303HXD Serial to USB cable
-
Battery case with USB in and out (5V/2.1A max)
-
4x 18650 (3.7V/6000mA) batteries
-
Breadboard and some cables
The GPS module can be used on 3.3V or 5V. Connected to the battery pack it can be used for approximately 4.5 hours (not bad I think).
Connect the GPS module as follow to the PL2303HXD:
GPS - PL2303HXD
VCC - 5V
GND - GND
TX - RXD (white)
RX - TXD (green)
Connect PL2302HXD to Onion Omega 2+ USB
Installation
Step 1
Use the latest firmware
oupgrade
Device Firmware Version: 0.1.10 b160
Checking latest version online...
Repo Firmware Version: 0.1.10 b160
Comparing version numbers
Device firmware is up to date!
Step 2
Update packages
opkg update
Step 3
I prefer nano as an editor, but there is no default installation
opkg install nano
Step 4
I want to expand the filesystem so I can write large tracker files. So I need the following utility:
opkg install e2fsprogs
Step 5
To use the USB to serial I need the following installations:
opkg install coreutils-stty kmod-usb-serial-pl2303
Step 6
Add a SD card (I use a 2GB SD card)
Look for SD card:
dmesg | grep mmc
[ 4.786320] mmc0: new high speed SD card at address 1234
[ 4.803969] mmcblk0: mmc0:1234 SA02G 1.85 GiB
[ 4.896881] mmcblk0: p1
...
Format and mount SD card
root@Omega-5101:~# mkfs.ext4 /dev/mmcblk0
root@Omega-5101:~# mkdir /mnt/mmcblk0
root@Omega-5101:~# mount /dev/mmcblk0 /mnt/mmcblk0/
Edit fstab
root@Omega-5101:~# /sbin/block detect > /etc/config/fstab
root@Omega-5101:~# uci show fstab
fstab.@global[0]=global
fstab.@global[0].anon_swap='0'
fstab.@global[0].anon_mount='0'
fstab.@global[0].auto_swap='1'
fstab.@global[0].auto_mount='1'
fstab.@global[0].delay_root='5'
fstab.@global[0].check_fs='0'
fstab.@mount[0]=mount
fstab.@mount[0].target='/mnt/mmcblk0'
fstab.@mount[0].uuid='5417dc6b-0135-4f71-8ea0-f81d0666989c'
fstab.@mount[0].enabled='0'
Enable mount
root@Omega-5101:~# uci set fstab.@mount[0].enabled='1'
root@Omega-5101:~# uci commit fstab
root@Omega-5101:~# uci show fstab
fstab.@global[0]=global
fstab.@global[0].anon_swap='0'
fstab.@global[0].anon_mount='0'
fstab.@global[0].auto_swap='1'
fstab.@global[0].auto_mount='1'
fstab.@global[0].delay_root='5'
fstab.@global[0].check_fs='0'
fstab.@mount[0]=mount
fstab.@mount[0].target='/mnt/mmcblk0'
fstab.@mount[0].uuid='5417dc6b-0135-4f71-8ea0-f81d0666989c'
fstab.@mount[0].enabled='1'
Make it permanent
root@Omega-5101:~# /etc/init.d/fstab enable
root@Omega-5101:~# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 5.5M 5.5M 0 100% /rom
tmpfs 61.4M 216.0K 61.2M 0% /tmp
/dev/mtdblock6 25.1M 1.2M 23.9M 5% /overlay
overlayfs:/overlay 25.1M 1.2M 23.9M 5% /
tmpfs 512.0K 0 512.0K 0% /dev
/dev/mmcblk0 1.8G 5.5M 1.7G 0% /mnt/mmcblk0
Step 7
Expand filesystem (overlay)
root@Omega-5101:~# mount /dev/mmcblk0 /mnt ; tar -C /overlay -cvf - . | tar -C /mnt -xf - ; umount /mnt
Edit fstab
root@Omega-5101:~# nano /etc/config/fstab
config 'global'
option anon_swap '0'
option anon_mount '0'
option auto_swap '1'
option auto_mount '1'
option delay_root '5'
option check_fs '0'
config 'mount'
option target '/mnt/mmcblk0'
option uuid '5417dc6b-0135-4f71-8ea0-f81d0666989c'
option enabled '0'
Change to:
config 'global'
option anon_swap '0'
option anon_mount '0'
option auto_swap '1'
option auto_mount '1'
option delay_root '5'
option check_fs '0'
config 'mount'
option target '/overlay'
option uuid '5417dc6b-0135-4f71-8ea0-f81d0666989c'
option enabled '1'
Ctr+X --> Y
Reboot
root@Omega-5101:~# reboot
root@Omega-5101:~# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 5.5M 5.5M 0 100% /rom
tmpfs 61.4M 104.0K 61.3M 0% /tmp
/dev/mmcblk0 1.8G 6.7M 1.7G 0% /overlay
overlayfs:/overlay 1.8G 6.7M 1.7G 0% /
tmpfs 512.0K 0 512.0K 0% /dev
Step 8
Set timezone.
I'm living in the Netherlands so I choose the timezone for Amsterdam.
The timezones list is on: Timezones
We also need the corresponding NTP-servers. I'm using the dutch (nl) pool servers.
The pool servers list is on: NTP pool
Change timezone en ntp-servers to your choices
root@Omega-5101:/# cd /etc/config
root@Omega-5101:/etc/config# nano systemconfig system
#option timezone 'GMT0'
option timezone 'CET-1CEST,M3.5.0,M10.5.0/3'
option ttylogin '0'
option log_size '64'
option urandom_seed '0'
option cronloglevel '8'
option hostname 'Omega-5101'
#
config timeserver 'ntp'
option enabled '1'
option enable_server '0'
list server '0.nl.pool.ntp.org'
list server '1.nl.pool.ntp.org'
list server '2.nl.pool.ntp.org'
list server '3.nl.pool.ntp.org'
Ctrl+X + Y
root@Omega-5101:/etc/config# reboot
Check date / time
root@Omega-5101:~# date
Fri Mar 10 17:15:02 CET 2017
Step 9
Install Python
root@Omega-5101:~# opkg update
root@Omega-5101:~# opkg install python
root@Omega-5101:~# opkg install python-pyserial
Step 10
Check if GPS is connected
root@Omega-5101:~# dmesg | grep pl2303
[ 10.664492] usbcore: registered new interface driver pl2303
[ 10.670369] usbserial: USB Serial support registered for pl2303
[ 10.676466] pl2303 2-1:1.0: pl2303 converter detected
[ 10.703003] usb 2-1: pl2303 converter now attached to ttyUSB0
Getting data from GPS
root@Omega-5101:~/gps# stty -F /dev/ttyUSB0 ispeed 9600 && cat </dev/ttyUSB0
$GPRMC,154105.00,A,5315.64610,N,00601.92077,E,0.092,,030317,,,A*72
$GPGGA,154105.00,5315.64610,N,00601.92077,E,1,08,1.00,-7.0,M,45.6,M,,*77
...
Ctrl+Z
Step 10
Make tracker source
root@Omega-5101:~# cd ~
root@Omega-5101:~# mkdir gps
root@Omega-5101:~# cd gps
root@Omega-5101:~# nano tracker.py
Source:
tracker.py
Step 11
Test the tracker
root@Omega-5101:~/gps# python tracker.py
Start reading: /dev/ttyUSB0
[1] Wait for GPS data 2017-03-10 17:22:37
[1] GPS tracker alive at 2017-03-10 17:22:39
[2] GPS tracker alive at 2017-03-10 17:22:44
[3] GPS tracker alive at 2017-03-10 17:22:50
[4] GPS tracker alive at 2017-03-10 17:22:55
...
Ctrl+Z of Ctrl+C
Show ublox file
root@Omega-5101:~/gps# nano t20170310172237.ubx
$GPGLL,5315.64852,N,00601.92650,E,162238.00,A,A*65
$GPGGA,162239.00,5315.64882,N,00601.92671,E,1,06,2.13,1.6,M,45.6,M,,*59
...
Step 12
So I connected the GPS tracker to the battery pack and went for a bike ride and recorded the result.
The ublox fileformat can be used with u-center
This is the result: