itbrainpower.net
THE ALPHABET PROJECT - professional Arduino, BeagleBone & Raspberry PI shields



Read our last post: Modems and RaspberryPI 5. RaspberryPI OS [Debian 12 bookworm] notes.. Order u-GSM modems.

Who's barking? BBB meets h-nanoGSM. [BeagleBone Black gsm how to]

 

About the project

Twenty to thirty minutes guide lines about connecting BeagleBone Black with the ITBP h-nanoGSM shield.

 

Needed parts

  • BeagleBone Black
  • h-nanoGSM - GSM shield [nano] or
  • any other ITBP modular modem,
  • 1pcs. one cell LiPo battery [3.7V, > 250mA], or
  • 1pcs. super-capacitor, bigger than 1F, rated for more than 5V and having ERS lower than 250mOhm [we've tested SCMT22C505MRBA0 from AVX and PM-5R0H105-1 from POWERSTOR/EATON].

 

Knowledge and skills required

  • BeagleBone Black previous experience is quite welcome,
  • some entry level Python and Linux knowledge are required,
  • soldering

 

About BeagleBone Black

Folks, finding BBB was a pleasant surprise for me! This BeagleBone Black it is f....g awesome piece of s..t- very powerful engine!
Just watch/listen Jason, the co-creator of beagleboard.org discuss the BeagleBone Black, bellow.

 

About h-nanoGSM shield

h-nanoGSM - became commercially available in 2016, August. It is a quad band GSM only(world wide compatible) + Bluetooth 3.0 nano shield, packed in an compact format 1.25"x1.16"(31.75x29.46mm) and with weight around 8g. Same as his bigger brothers (c-uGSM and d-u3G), it is not only a break-board, but a full shield having powerful features embedded, as: USB support (communication and powering), auto level 2.8V-5V digital interfaces and Lithium Polymer charger integrated.

h-nanoGSM - worldwide GSM + BTH 3.0 nano shield  

 

Some hardware hints

The BBB board it's really a quite big engine embedded in a small format. Having 5 UART ports gave us lot of alternatives for interfacing.

BeagleBone Black pinout

Keep in mind that almost all BBB logic pin have several functions accessible trough the PinMUX [mode0 ==> mode7]. Take a look in following pdfs [very important resources]:
BBB P9 pins table [pdf] and BBB P8 pins table [pdf]

In our example, we will use BBB UART1 for data interfacing with the modem and P9_14[EHRPWM1A], P9_16[EHRPWM1B] and P9_18[I2C1_SDA] as modem control interface.

 

Prepare your h-nanoGSM shield. Solder the pinheader; see how here. Connect the LiPo battery [take care at polarity!] or the super-capacitor, the antenna to the GSM uFL connector. Insert the SIM card [remove PIN code checking before].

 

Hardware connections

In the picture bellow you can observe all the needed connections.

BeagleBone Black GSM wiring

 

Let's reveal the connection details from image uphere:

BeagleBone Black GSM wiring datasheet

Above, the h-nanoGSM shield is powered in the "WITH Lithium Polymer" configuration [powered from 5V], but using one 1F super-capacitor instead the LiPo battery.
IMPORTANT: In our tests, the BBB was powered from the USB. In this case the h-nanoGSM powering was made connecting the BBB SYS_5V with the modem Vin[5V] pin! If the BBB is powered via the 5V barrel connector, we recomend to you to power the modem from the BBB VDD_5V [wire the BBB VDD_5V with the modem Vin[5V] pin].

For other h-nanoGSM shield / ITBP modular modem powering options, read c-uGSM, h-nanoGSM and d-u3G how to start.


 

Let's do the magic [Software]

SOFTWARE ASSUMTIONS

The real target it is to prepare the BeagleBone Black to be compatible with our RPI support files for h-nanoGSM[code examples] and with the PPP examples, making as little changes as possible.

BBB Debian distribution is used in this how to. We assume you will start from a out of the box BBB [if you used your BBB before, some steps may be skiped].

BBB SETUP TASKS

a. Connect the BBB to the USB. Download the BBB USB driver from http://beagleboard.org/getting-started. Follow the instructions found on that page and install the USB driver. Connect to the BBB using SSH service [initial username is root, no password].

DEBIAN SETUP [MAINLY BBB PORTS CONFIGURATION, BUT GATHERING SOME PACKAGES TOO]

b. Connect the the BBB ethernet to your lan. Check the connectivity to the internet. Enter following commands to the shell:
apt-get update
apt-get install python-serial
and, optional:
apt-get install mc

c. Using your preferred editor [I like mcedit, this is the reason I've installed the mc package, but you may use vi, vim...] edit the /etc/rc.local file:
mcedit /etc/rc.local
and insert following lines at the bottom, but before exit 0:
/etc/rc.config-itbp-modem > /dev/null 2>&1
Save.
d. Make/Copy the following file as /etc/rc.config-itbp-modem [right click & save as]

/etc/rc.config-itbp-modem

1#!/bin/sh -e
2#
3# rc.config-itbp-modem v0.11
4#
5# This script configs the BBB ports for usage with the ITBP modular modems; Eg.: c-uGSM,  
6# h-nanoGSM, d-u3G. More details can be found on http://itbrainpower.net
7#
8# This SOFTWARE is distributed is provide "AS IS" in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 
9# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10#
11# Dragos Iosub, Bucharest 2017.
12# http://itbrainpower.net
13#
14
15# next line loads the universaln cape [no IO port mapped over BBB HDMI] 
16# reference: https://github.com/cdsteinkuehler/beaglebone-universal-io
17/usr/local/bin/config-pin overlay cape-universaln #> /dev/null 2>&1
18
19# next 3 lines, config P9_14, P9_16 and P9_18 as input pins WITHOUT pullings. 
20# Those pins will be used as CONTROL interface for the ITBP modular modems.
21/usr/local/bin/config-pin P9_14 in
22/usr/local/bin/config-pin P9_16 in
23/usr/local/bin/config-pin P9_18 in
24
25#next four lines, config the P9_24 and P9_26 ports to be internally connected to UART1
26cd /sys/devices/ocp.*/P9_24_pinmux.*/
27echo uart > state
28cd /sys/devices/ocp.*/P9_26_pinmux.*/
29echo uart > state
30
31#next line, enable the UART1 [will be available under linux as /dev/ttyO1]
32/usr/local/bin/config-pin overlay BB-UART1 #> /dev/null 2>&1
33
34
35exit 0
36

Make it executable:

chmod 777 /etc/rc.config-itbp-modem

 

We are almost there...this was the Linux part. Just reboot your BBB [shutdown now -r or reboot will do this job].

 

PYTHON ITBP MODEM AND PPP SUPPORT FILES

a. Keep in mind that Python ITBP modem and PPP support files was written to compatible with the RPI and Debian distribution. There are three major differences when porting the code to the BBB [Debian]:
a1. The serial port names, /dev/ttyAMA0 for the RPI and /dev/ttyO1 for the BBB [we assumed that UART1 will be used]. We will address this later.
a2. The RPI.GPIO python class it is not present and compatible with BBB python. We will address this later.
a3. The BBB port addressing it is different from the RPI port addresing under python.
For all a1, a2 and a3 will apply some simple patches, later.

b. Download the GSM python and PPP support files from the download page. You will need to register using your name, email address and with the IMEI of your h-nanoGSM [the IMEI can be found on the top of the M66FA chip, or you may find using AT+CIMI command].

c. Decompress the archives. This archive contains, along with other files, the following files: "hnanoGSM1_08_hw_control.py", "hnanoGSM_Serial_Lib.py" and "globalParVar.py", related to python modem control and serial communication.

d. Copy the code bellow and make a file called "ITBP_gpioBBB.py" in the very same folder where the "mdmname_ver_hw_control.py" [in this case "hnanoGSM1_08_hw_control.py"] it is located. Alternate, you can download from here [right click & save as]: ITBP_gpioBBB.py

ITBP_gpioBBB.py : BBB GPIO python helper file

1###############################################################################################################################################
2#ITBP_gpioBBB.py v01 - RPI.GPIO helper for ITBP modular modem - port for BBB[debian] 
3#COPYRIGHT (c) 2017 Dragos Iosub / R&D Software Solutions srl
4#
5#You are legaly entitled to use this SOFTWARE ONLY IN CONJUNCTION WITH ITBP MODULAR MODEMS DEVICES USAGE [c-uGSM, h-nanoGSM and d-u3G shileds]. Modifications, derivates and redistribution 
6#of this software must include unmodified this COPYRIGHT NOTICE. You can redistribute this SOFTWARE and/or modify it under the terms 
7#of this COPYRIGHT NOTICE. Any other usage may be permited only after written notice of Dragos Iosub / R&D Software Solutions srl.
8#
9#This SOFTWARE is distributed is provide "AS IS" in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 
10#warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11#
12#Dragos Iosub, Bucharest 2017.
13#http://itbrainpower.net
14###############################################################################################################################################
15import subprocess
16ports   = ['P9_14','P9_16','P9_18']
17mapping ={'P9_14':'gpio50','P9_16':'gpio51','P9_18':'gpio4'}
18
19#some definitions, do not change
20OUT     ='out'
21IN      ='in'
22HIGH    = 1
23LOW     = 0
24BOARD   = 1 #just 4 compatibility with RPi.GPIO
25dirmap = {'out':1,'in':0}
26
27def output(port, value):
28    p = subprocess.Popen('echo '+str(value)+' > /sys/class/gpio/'+mapping[port]+'/value', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
29    out, err = p.communicate()
30    #print str(out)
31    #print str(err)
32
33def setup(port, direction, initial=-100):
34    p = subprocess.Popen('/usr/local/bin/config-pin '+str(port)+' '+str(direction), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
35    out, err = p.communicate()
36    #print out
37    #print err
38    if (initial > -100):
39        output(port, initial) #write initial state
40
41def input(port):
42    p = subprocess.Popen(['cat','/sys/class/gpio/'+mapping[port]+'/value'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
43    out, err = p.communicate()
44    #print out
45    #print err
46    try:
47        return int(out)
48    except:
49        return -100
50    #print str(out)
51    #print str(err)
52
53def cleanup():
54    global ports
55    for port in ports:
56        setup(port, 'in', -101)# force input float[no pull up or pull down]
57
58
59#just 4 compatibility with RPi.GPIO
60def setmode(whatever):
61    return
62
63#just 4 compatibility with RPi.GPIO
64def setwarnings(whatever):
65    return
66
67

 

e. Fixing a1, a2 and a3 differences
e1. Edit the "hnanoGSM1_08_hw_control.py" file [mcedit hnanoGSM1_08_hw_control.py] and replace the line 17":
import RPi.GPIO as GPIO with:
import ITBP_gpioBBB as GPIO

e2. Edit the "hnanoGSM_Serial_Lib.py" file [mcedit hnanoGSM_Serial_Lib.py] and replace the line 40":
agsm = serial.Serial("/dev/ttyAMA0", serialSpeed, timeout=1) with:
agsm = serial.Serial("/dev/ttyO1", serialSpeed, timeout=1)

e3. Edit the "globalParVar.py" file [mcedit globalParVar.py] and set the "CONTROL interface for the ITBP modular modems" as bellow:
RESET = "P9_14"
POWER = "P9_16"
STATUS = "P9_18"

 

TEST THE SETUP

You may run any ITBP modem python example file [Eg. python sendSMS.py].

 

Ready. Enjoy!

 

VARIANTS. REFERENCES.

You may try the setup using other UART ports as /dev/ttyO2 or /dev/ttyO4, or using other BBB I/O pins for modem CONTROL.

First of all, check the pins are free [config-pin utility can gave you valuable information], but guide after following references:
- https://github.com/cdsteinkuehler/beaglebone-universal-io
- http://www.armhf.com/using-beaglebone-black-gpios/
- http://derekmolloy.ie/gpios-on-the-beaglebone-black-using-device-tree-overlays/
- CAPE, what's about: http://elinux.org/Capemgr
- BBB pins definition: https://github.com/jadonk/bonescript/blob/master/src/bone.js
- and last, but not least http://www.ti.com/product/am3359

 

Keep calm, understand what's under the BBB blanket and write your own cape [best approach]....and share with us.

 

TUTORIAL & SOFTWARE ARE PROVIDED WITHOUT ANY WARRANTY!!! USE IT AT YOUR OWN RISK!!!!

 

 

Dragos Iosub & itbrainpower.net team original how to.

 

 

 

 

document version 0.921 / 2017-04-12 © R&D Software Solutions srl