Connect Your Raspberry Pi to a Cell Network

2022-10-09 09:29:40 By : Ms. Fanny Fu

The ability to connect your Raspberry Pi to a mobile cellular network means you can take it online wherever you are. Here’s how to do it.

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.

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

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).

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.

Assuming that you know how to install Raspberry Pi OS on 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:

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:

You'll notice that 4: usb0 has 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 an eth0 connection 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 near wlan0.

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 the sudo prefix 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, press Ctrl + A then E to turn the echo on.

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

If you received something with usbnet=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:

Type AT once 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 pressing Ctrl + A then X. Ensure you've selected "Yes" and press Enter.

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 the cdc_ether driver. This confirms that your modem is working as expected.

As well, you can repeat the ping command 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 the ECM modem setup for a Quectel modem.

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.

Elijah loves tinkering with electronics, testing new Linux Distributions, and creating DIY servers. Elijah also enjoys the challenge of delivering tech projects throughout his 15 years within the Corporate Finance industry.

Join our newsletter for tech tips, reviews, free ebooks, and exclusive deals!