Tutorial – Using Cellular Modems with the Raspberry Pi 4B

Tutorial – Using  Cellular Modems with the Raspberry Pi 4BCellular Modems Raspberry Pi

We have been asked numerous times to evaluate cellular modem technology for use in our SkyWeather2 series of products.   This article is the beginning of this process.  In this tutorial, we look at two general types of Cellular Modems for the Raspberry Pi.   The two types:

  • The more generic modems used by the Raspberry Pi with a variety of SIM Cards and systems.  These tend to be less expensive to operate but have about the same costs per MB of data (set by the carriers in general).    We use the SIM7600A-H modem for this example.
  • The second type is a more proprietary system (although using many of the same cellular modems) with a more full ecosystem as far as IOT and cellular modem connected devices.   We are using the Sixfab modem for this example.

After using both modems, we feel that the Sixfab modem family is probably a better fit for hobbyists and deserves a full on look by professionals wanting to build IOT devices.

Cellular Modems Raspberry Pi

Which Cellular Modems are we Testing?

Waveshare 4G / 3G / GNSS Hat for Raspberry Pi SIM7600-A-H  / $76

SixFab Raspberry Pi 4G/LTE Cellular Modem Kit – Quectel EC25-A (North America) / $109

Which SIM Cards are we Testing?

soracom.io Sim Card – purchased on amazon.com

SixFab Sim Card – purchased on SixFab.com

 

Waveshare SIM7600 Hat w/Soracom.io SIM Card

This is a medium price pretty generic cellular hat for the Raspberry Pi with the SIM7600A-H cellular modem and antennas.

Cellular Modems Raspberry Pi

 

Step by Step for Connecting your Cellular Modem

Step 1) Update your Raspberry Pi and install software

sudo apt-get update

sudo apt-get install libqmi-utils udhcpc

sudo reboot

Step 2) When you reboot your Pi, the SIM7600 module is OFF and needs to be turned ON before you can see the network.

sudo qmicli -d /dev/cdc-wdm0 --dms-set-operating-mode='online'

Step 3) gather the APN information for your SIM card.  For the Soracom.io card:

apn=soracom.io
username=sora
password=sora

Note:  Your APN information will vary according to the card you have.

 

Step 4) Shut the interface to down

sudo ifconfig wwan0 down

Step 5) Set the wwan0 interface to raw mode

echo 'Y' | sudo tee /sys/class/net/wwan0/qmi/raw_ip

Step 6) restart the interface

sudo ifconfig wwan0 up

Step 7) Start the qui network, replacing your apn, username and password in the following command:

 

sudo qmicli -p -d /dev/cdc-wdm0 --device-open-net='net-raw-ip|net-no-qos-header' --wds-start-network="apn='soracom.io',username='sora',password='sora',ip-type=4" --client-no-release-cid

You will get something similar to this:

[/dev/cdc-wdm0] Network started
Packet data handle: '3781840224'
[/dev/cdc-wdm0] Client ID not released:
Service: 'wds'
CID: '20'

Step 8) Now acquire an IP Number from your provider

sudo udhpc -I wwan0

You will get something similar to this:

udhcpc: started, v1.30.1
No resolv.conf for interface wwan0.udhcpc
udhcpc: sending discover
udhcpc: sending select for 10.165.xx.xx
udhcpc: lease of 10.165.xx.xx obtained, lease time 7200
Too few arguments.
Too few arguments.

 

Step 9) Check to see if you have an IP Number

ifconfig

You will get something like this:

...
wwan0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1500
inet 10.165.xx.xx netmask 255.255.255.252 destination 10.165.xx.xx
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 1000 (UNSPEC)
RX packets 2 bytes 612 (612.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 75 bytes 12478 (12.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Step 10) Verify the network is turned on

sudo qmicli -d /dev/cdc-wdm0 --dms-get-operating-mode

You will get something like this:

	Home network:
		MCC: '295'
		MNC: '5'
		Description: 'FL1'

Now:

sudo qmicli -d /dev/cdc-wdm0 --nas-get-signal-strength

You will get something like this:

[/dev/cdc-wdm0] Successfully got signal strength
Current:
Network 'umts': '-90 dBm'
RSSI:
Network 'umts': '-90 dBm'
ECIO:
Network 'umts': '-10.5 dBm'
IO: '-106 dBm'
SINR (8): '9.0 dB'

Finally:

sudo qmicli -d /dev/cdc-wdm0 --nas-get-home-network

You will get something like this:

[/dev/cdc-wdm0] Successfully got home network:

Home network: MCC: ‘295’ MNC: ‘5’ Description: ‘FL1’

If the first command shows in its output ‘Low Power’ or anything other than ‘online’ it means your radio is off and needs to be turned on.

The last of those commands should return the LTE network ID if your device successfully connected.

Step 11) Test network connectivity

ping -I wwan0 www.microsoft.com

You will get something like this:

PING e13678.dscb.akamaiedge.net (23.45.229.117) from 10.165.18.113 wwan0: 56(84) bytes of data.
64 bytes from a23-45-229-117.deploy.static.akamaitechnologies.com (23.45.229.117): icmp_seq=1 ttl=35 time=2589 ms
64 bytes from a23-45-229-117.deploy.static.akamaitechnologies.com (23.45.229.117): icmp_seq=2 ttl=35 time=1566 ms
64 bytes from a23-45-229-117.deploy.static.akamaitechnologies.com (23.45.229.117): icmp_seq=3 ttl=35 time=536 ms

Using the “-I wwan0” forces the ping to go through the cellular modem.   Don’t let this keep running!  It costs per byte $$$$

Starting the SIM7600A-H Cellular Network on Bootup

To start the Cellular Network Interface on boot up do the following:

Step 1) Before following this, reboot your Pi

sudo reboot now

Step 2) using your favorite editor (nano or vi for example), edit the following file

sudo nano /etc/network/interfaces.d/wwan0

Add this (replacing your apn, username and password in the qmicli command):

iface wwan0 inet manual
     pre-up ifconfig wwan0 down
     pre-up echo Y > /sys/class/net/wwan0/qmi/raw_ip
     pre-up for _ in $(seq 1 10); do /usr/bin/test -c /dev/cdc-wdm0 && break; /bin/sleep 1; done
     pre-up for _ in $(seq 1 10); do /usr/bin/qmicli -d /dev/cdc-wdm0 --nas-get-signal-strength && break; /bin/sleep 1; done
     pre-up sudo qmicli -p -d /dev/cdc-wdm0 --device-open-net='net-raw-ip|net-no-qos-header' --wds-start-network="apn='soracom.io',username='sora',password='sora',ip-type=4" --client-no-release-cid
     pre-up udhcpc -i wwan0
     post-down /usr/bin/qmi-network /dev/cdc-wdm0 stop

Step 3) reboot once again

sudo reboot now

Starting, Stopping and Testing the SIM7600A-H Cellular Network

Now you can start the network by

sudo ifup wwan0

and stop it with

sudo if down wwan0

and Check it with:

    route -n        
    ping -I wwan0 8.8.8.8 

 

 

 

 

Cellular Modems Raspberry Pi

  1. SIM7600E-H
  2. CP2102 USB to UART converter
  3. NAU8810 audio decoder
  4. TXS0108EPWR voltage translator
    translates 3.3V/5V into 1.8V
  5. MP2128DT power chip
  6. MP1482 power chip
  7. Raspberry Pi GPIO header
  8. SIM7600 control interface
    for connecting with host boards like Arduino/STM32
  9. SIM card slot
    supports 1.8V/3V SIM card
  10. TF card slot
    allows data storage like files, messages, etc.
  11. 3.5mm earphone/mic jack
  12. USB interface
    for testing AT Commands, getting GPS positioning data, etc.
  13. USB to UART interface
    for serial debugging, or login to Raspberry Pi
  1. MAIN antenna connector
  2. AUX antenna connector
  3. GNSS antenna connector
  4. Power switch
  5. Network status indicator
  6. Power indicator
  7. Operating voltage selection jumper
    configured via 0Ω resistor jumper
    VCCIO – 3.3V: set operating voltage as 3.3V
    VCCIO – 5V: set operating voltage as 5V
  8. UART selection jumper
    A: access Raspberry Pi via USB to UART
    B: control the SIM7600 by Raspberry Pi
    C: control the SIM7600 via USB to UART
  9. PWR configuration jumper
    PWR – 3V3: auto startup on power-up (default)
    PWR – D6: startup/shutdown by the Raspberry Pi D6 pin
    Flight mode configuration jumper
    NC by default, no flight mode control pin
    Flight – D4: flight mode is controlled by the Raspberry Pi D4 pin
  10. USB connector solder pads
  11. BOOT forced programming solder pads

Waveshare SIM7600 Hat Conclusion

Now you have successfully connected with the network.  Congratulations!    Shut down your wifi connection and unplug your ethernet, plug in a monitor, keyboard and monitor and surf the web and send data using the cellular modem!

Note:   There are still lots of potential issues left here depending on your service provider.  If you are using a soracom.io card, you can use their remote service system or by installing teamviewer, you can remotely log into your Raspberry Pi through the cellular service.  Remember that every byte of data costs you something so pay attention to data usage.

Some providers block lots of ports (like ssh port 22) so you can try the napter service at soracom.io but even that will require you to reconfigure you ssh.conf on the Raspberry Pi, which will be the subject of a future posting.

SixFab Raspberry Pi 4G/LTE Cellular Modem Kit – Quectel EC25-A (North America)

We chose the SixFab  modem kit to get a feel for a more proprietary solution.  This is available on Amazon, but it was really hard to figure out exactly what you were getting so we ordered on the SixFab.com website, especially because we wanted the SixFab Sim Card to test.

 

Cellular Modems Raspberry Pi

 

Sixfab is a more vertically integrated IOT Cellular Modem type of company.  Their offerings are designed to get you up and running quickly with your IOT project, but then you are pretty much Cellular Modems Raspberry Piwedded to their solution.   For this article, that’s a great second way to look at things.

Sixfab will allow you to get your Raspberry Pi prototype up and connected in minutes with their easy-to-use, developer friendly products.  And their backend will allow you to scale up if you decide to make it a product.   The Sixfab of adding a cellular modems to your Raspberry Pi projects.

OK, let’s get to work on this.

The SixFab site has good instructions so let’s begin with those:

Step 1)  Go to this site

https://docs.sixfab.com/docs/raspberry-pi-3g-4g-lte-base-hat-introduction

and follow the instructions for building and putting the hat on the Raspberry Pi

Step 2) Boot up your Pi and run the following command:

pi@SwitchDocLabs:~ $ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 2c7c:0125 Quectel Wireless Solutions Co., Ltd. EC25 LTE modem
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
pi@SwitchDocLabs:~ $

and then:

pi@SwitchDocLabs:~ $ dmesg | grep ttyUSB
[  104.822678] usb 1-1.3: GSM modem (1-port) converter now attached to ttyUSB0
[  104.823398] usb 1-1.3: GSM modem (1-port) converter now attached to ttyUSB1
[  104.826166] usb 1-1.3: GSM modem (1-port) converter now attached to ttyUSB2
[  104.826772] usb 1-1.3: GSM modem (1-port) converter now attached to ttyUSB3
pi@SwitchDocLabs:~ $ 

 

Step 3) Insert your SIM Card into the plug on top of the SixFab hat.  Don’t forget this!

Since we have decided to use the whole Sixfab solution, we are going to download and install SixFab core software and use the SixFab SIM Card.

Follow the directions at:

https://docs.sixfab.com/docs/sixfab-core-introduction

Note:  Right off the bat they leave off this link to register your SIM Card:   connect.sixfab.com

They will charge you $10 which goes to your starting balance.

When you go to the create device screen, of course it does not match the documents.  Select Global for your device, and then copy the code and run it on your Raspberry Pi in a terminal window.

PAY ATTENTION TO THIS WARNING and unplug the USB plug from the Cellular Modem:

 

sudo apt-get update Error

If you get the feared  error:

Reading package lists... Done
E: Failed to fetch https://packagecloud.io/headmelted/codebuilds/raspbian/dists/jessie/InRelease 401 Unauthorized [IP: 54.183.38.243 443]
E: The repository 'https://packagecloud.io/headmelted/codebuilds/raspbian jessie InRelease' is no longer signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.

edit your sources.list file:

sudo vi /etc/apt/sources.list

and comment out the sources line  (using a “#”) for the packagecloud.io repository

#deb https://packagecloud.io/headmelted/codebuilds/raspbian/ jessie main

The Sixfab Control Panel

Cellular Modems Raspberry Pi

OK, we have to say we are impressed.  Right off the bat I could do many things I wanted to do.   I could log in remotely:

 

Cellular Modems Raspberry Pi

I would have to say for the money and convenience, the SixFab solution is quite good.  Of course, they still are charging way too much per MB for ($0.10) for sending pictures, but sending small amounts of data and remote access?  They really rock.  Here is a list of other features you can access:

Internet Connection with Quectel EC25 using ECM Mode on the Sixfab Hat

For an active internet connection with the Quectel EC25, you can use PPP, QMI, or ECM.
ECM (Ethernet Control Model) is the easiest method in order to provide an internet connection to your single-board computer such as Raspberry Pi.

https://docs.sixfab.com/page/internet-connection-with-quectel-ec25-by-using-ecm-mode

QMI Interface Internet Connection Setup Using Sixfab Shield/HAT

When we were setting up the SIM7600-A-H, we used QMI.  Newer ways to present USB-connected LTE modems like QMI and MBIM have been developed. Quectel modules offer QMI(Qualcomm MSM Interface) which is established as a real network interface, such as ethernet(typically shows as wwan0). There is an open source Linux in-kernel driver supporting this interface called qmi_wwan.
The QMI is also counted among the non-AT protocols which are communicated over dev/cdc-wdm0 port. In order to establish a connection, proper qmi/gobinet proxy should be installed, which again depending on the chipset of the module/modem and the kernel of Linux, can get a bit complicated.

This stuff really works too!

https://docs.sixfab.com/page/qmi-interface-internet-connection-setup-using-sixfab-shield-hat

Conclusion

We were prepared to be somewhat dismissive of the Sixfab solution, but upon using both modems we were quite impressed.   If you just want to easily use the technology with your Raspberry Pi, then we would recommend purchasing the Sixfab modem and SIM card.  Getting your system up and running quickly has some real advantages.   As you get more comfortable with the technology, you can start using these other somewhat less expensive technology.

It’s great the that it is so easy to now use Cellular Modems on the Raspberry Pi.

 

Coming in the Future from SwitchDoc Labs about Cellular Technology

We will be writing additional articles in our series on Cellular Modems and the Raspberry Pi

  • Connecting the SwitchDoc Labs SkyWeather2 Weather Station to  a Cellular Modem
  • Hooking up 433MHz WeatherSense Sensors to a Cellular Modem
  • Using Cellular Modem Dongles on the Raspberry Pi
  • Reading out GPS Data from Cellular Modems
  • Minimizing Data Transfer from Cellular Modems