Connect Your Raspberry Pi to a Cell Network

Thanks to the Raspberry Pi’s small size, this single-board computer is highly portable. You may not always be in range of a Wi-Fi hotspot when you travel, though, so the option to connect to a cellular network is appealing if you want to keep your Pi online.

With a mobile data plan and an LTE HAT (Hardware Attached on Top) you will be able to connect your Raspberry Pi to a cellular network almost anywhere. Our step-by-step instructions will guide you through the process.

4

Equipment Needed

Before you are ready to connect your Raspberry Pi to a cellular network, you’ll need:

Connecting the Hardware

First, secure four stand-offs to the Raspberry Pi board. Next, with gentle pressure, place the HAT on to the Raspberry Pi’s GPIO pins, making sure it lines up correctly. You will then want to ensure a snug fit by screwing it down onto the stand-offs.

The modem should then be slid into the connector on top of the HAT, similarly to how an M.2 SSD connects. There are two screws at the other end of the modem that will need to be secured as well. The u.FL cables will need to be attached in order to connect antennas later. The M1 and D1 are antenna ports and the D2/G port is usually for GPS (if required).

raspberry pi and LTE hat

This is a good time to insert the SIM card from your carrier. It’s a good practice to do so before you connect the power from your Raspberry Pi to the LTE HAT and modem.

To ensure the new hardware receives power, plug in the USB cable into the HAT and the other end to a USB-A port on the Raspberry Pi—if using a Raspberry Pi 4, use one of the blue USB 3.0 ports for higher speed. Depending on your HAT, expect to see a bright light shining once powered on.

hardware required for LTE hat project

Installing the Software

Assuming that you knowhow to install Raspberry Pi OSon to your Raspberry Pi, let’s move on to configuring the connection to a cellular network.

Raspberry Pi OS should detect the USB device as soon as your HAT and modem are plugged in via USB cable. To confirm that your modem is visible to the system, type the following in the terminal:

LTE Hat for Raspberry Pi

You’ll see something like this:

This confirms that your modem is recognized by your Raspberry Pi. Next, you need to validate that your USB-connected modem registers an IP address. To do so, type:

find usb devices pi 4 (lsusb)

You’ll notice that4: usb0has an IP address. If your device does not have an IP address then try to reconnect your hardware and try the terminal commands again.

As you can see, there is aneth0connection registered. This output refers to an Ethernet connection that is up and running. If the Wi-Fi connection was enabled, you’d also see an IP address displayed nearwlan0.

To be certain that your modem will be able to connect to a nearby cell tower, type the following into your terminal:

As your modem is connected via USB, you’ll set up your modem in a mode called ECM (Ethernet Control Model). You will need an application, called minicom, to set up the modem. To install minicom, open a terminal and type the following command:

Once that is installed, go back to your terminal and key in this command (you may have to type thesudoprefix if you get an error):

This will open a serial connection using your USB modem with a baud rate of 115,200. If you start to type and cannot see the characters on screen, pressCtrl + AthenEto turn the echo on.

Use the following AT command to confirm the current USB mode:

If you received something withusbnet=0, then you will need to switch to “1.” This is also referred to as ECM mode. If that’s the case for you, type:

The modem should reboot automatically at this point. To confirm this action, look for “Cannot open /dev/ttyUSB2!” appearing on-screen within five seconds. If not, type this:

TypeATonce again, and you should receive “OK” in response. You will now need to tell the modem your APN information by entering the following in minicom:

Restart the modem one more time using the command:

You’ll see something like this after the modem finishes rebooting once again.

Exit minicom by pressingCtrl + AthenX. Ensure you’ve selected “Yes” and pressEnter.

Reboot your Raspberry Pi; in a terminal, enter:

After the reboot is complete, log in and open your terminal application. Type:

You’ll be looking for mention of thecdc_etherdriver. This confirms that your modem is working as expected.

As well, you can repeat thepingcommand shown earlier to confirm that you are able to connect to the internet through your nearest cell tower.

Should you require further troubleshooting, Sixfab has a terrific guide explaining theECM modem setupfor a Quectel modem.

Where Will You Take Your Raspberry Pi?

Now that you have the ability to connect your Raspberry Pi to a nearby carrier-supported cell tower, you can stay connected to the internet wherever you go. Remember that data charges may still apply, so do check with your carrier before you begin to use your Raspberry Pi modem regularly.

Consider taking this project one step further by sharing the Raspberry Pi’s usb0 connection through its Ethernet port. This will allow you to really take working from home seriously by using connecting your Raspberry Pi to another device, switch, or router.

Want to secure your internet connection when traveling? Here’s how to build a portable VPN router with a Raspberry Pi and OpenWRT.

When your rival has to bail out your assistant.

You can’t call this offline, Notion.

Don’t let someone else take over your phone number.

The key is not to spook your friends with over-the-top shenanigans.

The fix was buried in one tiny toggle.

Technology Explained

PC & Mobile