BeagleBone and USB GSM Stick

More sysadmin than electronics today!

I have an O2 USB modem and I was wondering about getting the BeagleBone hooked up to it.  It would be cool to have the BeagleBone “phone home” if is was out in the field logging, or whatever.

Front side of my USB GSM modem

As you can see form the photo of the back-side it’s a Huawei Mobile Broadband E1752C USB modem.

The back side of the Huawei Mobile Broadband E1752C USB stick

It turns out to be really easy to use this (or any other USB GSM modem) with Ubuntu.  It a little “old school” without a GUI to work in, but hay, command line is king after all!.. It brings back memories of using pppd and chat scripts when I used Linux to connect over a copper phone line to the “Internet!”.

On the O2 network here in Ireland my /etc/ppp/peers/o2 file looks like this:

debug
connect "/usr/sbin/chat -v -f /etc/chatscripts/o2"
lock
local
user "o2"
password "o2"
ttyUSB0
noauth
defaultroute
noipdefault
usepeerdns
ipcp-max-failure 5
lcp-echo-failure 5
lcp-echo-interval 30
persist

#auth
refuse-chap
refuse-mschap
refuse-mschap-v2
refuse-eap

# compression
novjccomp
nobsdcomp
noaccomp
nopcomp
novj
noccp

And my chat script looks like this:

ECHO ON
TIMEOUT 10
ABORT 'BUSY'
ABORT 'NO ANSWER'
ABORT 'ERROR'
ABORT 'NO CARRIER'

""    AT
OK    AT+CPIN=XXXX
TIMEOUT 5 ERROR-AT-OK
AT+CGDCONT=1,"IP","open.internet"
OK    "ATD*99#"
CONNECT    ""

Nice little trick here for the PIN entry.. You need it the first time the modem boots up, but not for re-connecting the “TIMEOUT 5 ERROR-AT-OK” will allow the PIN code to fail (because it already been entered) and not stop the script.

As I want to remote connect to BeagleBone, I’ve got it to send it’s IP address back to base (every time the PPP interface comes up).  You will need to set up shared SSH keys between your server and the Bone to get this to work without a password.

Then I created the following little script ( /etc/ppp/ip-up.d/001updateIP ):

#!/bin/sh
#
# scp the current IP address back to base...
# (MMcK 2012-11-19)
#

/sbin/ifconfig -a \
    | awk '/inet addr/ { print $2 }' \
    | awk -F: '{ print $2 }' \
        > /tmp/bone.ipaddr

/usr/bin/scp -q /tmp/bone.ipaddr <me>@<my server>:

Now every time the Bone comes online over the PPP interface I can connect to it by looking up it’s new IP address.

BeagleBone and GPS

Tonight brings us to GPS’s and how to get the BeagleBone to know where it is in the world.

I had a request during the week for a unit that would track and monitor a refrigerated truck.  So first thing that sprung to mind was a BeagleBone, I’ve already looked into the 1-wire network and setting up a DS18B20.. That is the temperature monitoring out of the way.

Now on to position… I know I could just get an off the shelf USB GSP module, but I’ll need the Bone’s one USB port to hook up a GSM modem, and sure I could put a USB hub in and connect both to the one port. But there has to be a nicer solution that can make use of one of the other UARTS on the Bone.  A dig around in my parts box and I found this old skool GPS receiver. Back in the day when I have a Palm Treo “Smart” phone.This unit has bluetooth (yepee!), but without a USB dongle won’t be much use… unless there is an internal serial line I can hack into.  Time to crack this bad boy open and see what is inside.  Turns out it is a re-badged Holux GPS receiver called the GPSlim236.

The GPSlim236 GPS module (with bluetooth)

What are the connectors on the left? Looks like these might be worth a poke at with the scope, see what is going on.

Cool.. Pin 3 (up from the bottom left pin) we see some serial data, and it even sweeter, it looks like it’s at 3.3V levels too.

The GPS serial data on the DSO (measured on pin 3)

A little more poking around with the DSO, I find the three pins needed.. 1) Gnd, 2) Data out and 3) +5V

The pinouts for the GPSlim263 module

So now I can hook up the GPS module to the BeagleBone on a spare UART and get the GPS data in that way.  Much easier that trying to get Bluetooth working!  I was already testing my RFID module out on UART1, so time to config UART2. UART2 Rx comes in on header P9, pin 22 [MUX pin spi0_sclk] and needs to be set up (along with TX).

echo 1 > /sys/kernel/debug/omap_mux/spi0_d0
echo 21 > /sys/kernel/debug/omap_mux/spi0_sclk

With a dig around I found the default serial config for the GPS data is 38400,n81.  Drop into Minicom and config the port (/dev/ttyO2), and bingo:

$GPGGA,220514.000,5311.xxxx,N,00607.xxxx,W,1,06,1.3,28.7,M,54.7,M,,0000*70
$GPRMC,220514.000,A,5311.xxxx,N,00607.xxxx,W,0.00,163.13,151112,,,A*7C
$GPVTG,163.13,T,,M,0.00,N,0.0,K,A*0B
$GPGGA,220515.000,5311.xxxx,N,00607.xxxx,W,1,06,1.3,28.7,M,54.7,M,,0000*71
$GPRMC,220515.000,A,5311.xxxx,N,00607.xxxx,W,0.00,163.13,151112,,,A*7D
$GPVTG,163.13,T,,M,0.00,N,0.0,K,A*0B
$GPGGA,220516.000,5311.xxxx,N,00607.xxxx,W,1,06,1.3,28.7,M,54.7,M,,0000*72
$GPGSA,A,3,05,26,07,08,15,10,,,,,,,2.2,1.3,1.7*3D
$GPGSV,3,1,11,05,70,211,23,08,67,082,15,26,61,275,34,07,32,054,30*7D
$GPGSV,3,2,11,28,24,132,,15,24,274,27,10,24,147,18,21,15,322,*7A
$GPGSV,3,3,11,02,07,206,,03,04,024,,06,03,007,*4B

We have position data now… cool..!

BeagleBone and RFID

The BeagleBone has 6 UARTS on it.. (OK well 4 that are easy to use.) I thought it might be cool to look up a RFID reader I got a while ago. The reader caught my eye while I was ordering a few parts form Watterott.com, the part is a Electronic brick – 125Khz RFID Card Reader.  I had played about with it on my Arduino, but again without good ethernet connectivity I did not get too far.  Sure you could make a selfcontained door entry system, but a networked one give one many more options!

Electronic brick – 125Khz RFID Card Reader

Back into the world if pin decoding and mux’ing on the BeagleBone.. A quick search found this great page with all the info I needed: http://www.gigamegablog.com/2012/01/22/beaglebone-coding-101-using-the-serial-and-analog-pins/

The RFID module works off 5V… Ummm need to do something about the levels! As the “brick” only outputs data I only have to worry about level shifting from 5 to 3.3V.  What could be easier? A simple resistor based voltage divider should do it the trick. A 10K from the output of the RFID module, to the UART1_RXD pin (P9_26) and another resistor from P9_26 to ground.

The wires above are: White – Data, Red – +5V, Black – 0V (hidden from view!)

Check the levels on the scope…

Vertical scale is at 1V/div… so we are getting 2.5V or there abouts.  Should be OK to drive the UART on the BeagelBone.

On my Ubuntu distro I had to install the python-serial package before running this code. Now time for some Python:

import serial, os
import sys

# -------------- configurable settings ---------
PORT = '/dev/ttyO1'     # set tty port
                        # NOTE: ON BEAGLE BONE O1 is the Letter O
BAUD_RATE = 9600        # set baud rate
RX_PIN = 'uart1_rxd'    # port pin for RX
MUX_MODE = 0            # MUX mode for PIN
MODE_EXT = 32           # Enable receive on pin too!

open('/sys/kernel/debug/omap_mux/' + RX_PIN, 'wb').write("%X" % (MODE_EXT + MUX_MODE))

ser = serial.Serial(PORT, BAUD_RATE)   # open serial port
have_tag_data = 0

while True:
        a = ser.read()                 # read byte
        if ord(a) == 3:
                print "Tag stop!"
                have_tag_data = 0
        if ord(a) == 2:
                print "Tag start!"
                have_tag_data = 1
        if have_tag_data>1:
                print (have_tag_data-1), ord(a)         # print byte and count
                have_tag_data += 1
        if have_tag_data==1:
                have_tag_data += 1

Run it and watch the numbers change for different tags:

root@bbone1# python rfidtest.py

Tag start!
1 51
2 68
3 48
4 48
5 52
6 55
7 53
8 56
9 66
10 53
11 57
12 55
Tag stop!
Tag start!
1 48
2 49
3 48
4 48
5 48
6 66
7 57
8 52
9 66
10 55
11 50
12 57
Tag stop!

So 2.5V can drive the UART no problems… All good!