Get Started with the Raspberry Pi
Last updated
Last updated
This tutorial will help you use a KORE Programmable Wireless SIM to build and run your first IoT application. The device you'll build uses a Waveshare SIM7600G-H 4G Hat, a development board which equips a low-cost Raspberry Pi computer with a Simcom 7600G-H cellular modem.
In addition to your configured Programmable Wireless SIM, you will need the following hardware to proceed with this guide:
A Waveshare SIM7600G-H 4G HAT . This is the global version; there are variants that target specific territories.
A Raspberry Pi. This guide was written using the Pi 4 Model B, but there are other versions of the Pi available — it should work with any of them, but we've only tested the 4. The SIM7600G-H 4G Hat works with all but the very first Pi. To use the Pi, you will also need:
A Micro SD card of 8GB or above.
A monitor and an HDMI-to-micro-HDMI cable.
A keyboard and a mouse
A 5V, 2A (10W) USB-C AC adaptor.
An MCP9808 temperature sensor on a breakout board.
You'll need to solder the supplied header pins to the breakout board.
Four female-to-female jumper wires.
The Raspberry Pi has its own setup procedure which involves downloading and installing its Linux operating system, called Raspberry Pi OS, onto the Micro SD card. The Raspberry Pi Foundation has a very good walkthrough of its own that covers this process — you should use this to get your Pi ready before proceeding to the next stage of this guide.
During setup you should connect your Pi 4 to your WiFi network as you will need to download extra software later. We'll disable WiFi in due course to demonstrate data access over cellular.
The SIM7600G-H 4G Hat ships with all you need to fit it onto the Pi. Just follow these steps to set everything up:
Fit your KORE SIM into the SIM7600G-H 4G Hat's SIM retainer. This takes a full-size SIM, so take care removing your SIM from its mount, or use an adapter if you have already removed the SIM as a Micro or Nano SIM:
Lock the SIM retainer in place to keep the KORE SIM secure:
If it's powered up, turn off the Pi.
If you're at the command line, enter sudo shutdown -h
now.
If you're at the desktop, select Shutdown… from the Raspberry menu and then click Shutdown
Remove the power cable when the Pi's activity LED has flashed ten times.
Slot the SIM7600G-H 4G Hat onto the Pi's GPIO header:
Connect the supplied USB cable to the micro USB port marked just USB on the SIM7600G-H 4G Hat and a USB port on the Pi:
Assemble the bundled cellular antenna and connect it to the SIM7600G-H 4G Hat. Fit it to the LTE connector marked MAIN on the board:
Here's a close-up:
Finally, power up the Pi by re-inserting the power cable.
We now need to run through a few steps to get the Pi ready to talk to the SIM7600G-H 4G Hat. Some of these will require you to restart the Pi.
If you're at the Raspberry Pi desktop, select Accessories > Terminal from the Raspberry menu.
Run sudo raspi-config
.
Use the cursor keys to highlight Interfacing Options, then hit Enter:
Now highlight Serial Port and hit Enter:
When you are asked Would you like a login shell to be accessible over serial? select No and hit Enter:
When you are asked Would you like the serial port hardware to be enabled? select Yes and hit Enter:
Select Finish .
The raspi-config
utility will offer to restart the Pi — accept its suggestion.
When the Pi is back up, you should see that the SIM7600G-H 4G Hat's PWR LED is lit. Now press the PWRKEY button on the board — after a brief moment, the NET LED should light up.
At the command line or in a desktop Terminal run:
You should see a list of items all beginning with ttyUSB
and including ttyUSB2
, which is the device you'll use in subsequent steps. If you don't see a list of TTYs, first check that the SIM7600G-H 4G Hat's PWR and NET LEDs are lit. Make sure your USB cable is not connected to USB TO UART on the Hat.
Now you can connect to the Internet. You need to install the PPP (Point-to-Point Protocol) software the Pi will use to establish the connection, and to configure it. First run the following commands at the command line:
The last of these commands opens the primary configuration file in a text editor so you can make the required changes. Make sure the file contains the following lines. Some may be missing, others may be present depending on the version of ppp
you've installed:
In the same file, look for lines very like these and update them so they match what's shown here:
The last line comes from the value you determined earlier.
To initiate an Internet connection, at the command line or in a desktop terminal run:
You'll see a stack of lines displayed at the command line.
Open a fresh terminal and enter:
When the prompt is back, you're ready to try out the Internet connection:
If you're at the desktop, select Turn off Wireless LAN from the network menu at the top right.
If you're at the command line, run sudo ifconfig wlan0 down
.
At the command line or in a desktop terminal, enter ifconfig
and look for the ppp0
entry — it should have a valid IP address listed under inet
:
Open up a browser and navigate to korewireless.com:
Well done! You now have a Raspberry Pi computer that's connected to the Internet via Programmable Wireless. You can now start experimenting with cellular Internet connectivity, or begin developing your own IoT application proof-of-concept.
With the hardware working, you're ready to build your first IoT application. You'll be using a technology called MQTT to transmit sensor data generated by the Raspberry Pi. Picture it as an IoT device in the field relaying data back to base. That data might be the location of a shipping container, the state of a piece of machinery, or any other useful item of information that you need to track.
To build your IoT app, you'll need an 'MQTT broker', which is the server-side system that routes messages from sources ('publishers') to receivers ('subscribers'). We're going to use HiveMQ's free MQTT broker, but there are other public MQTT brokers that you may prefer to use instead — there is a list of them here.
HiveMQ's broker is completely open. Anyone can subscribe or publish to your topic. In production, always use encrypted communications only, and either set up your own MQTT broker or use a private broker service.
Use HiveMQ's web UI to set up the broker. You can do this on your computer, or on the Pi: just fire up a browser from the desktop.
Visit HiveMQ's MQTT web client page .
Click the Connect button:
In the Subscriptions section, click Add New Topic Subscription .
Think up a topic name, make a note of it, and enter it in the Topic field. Make sure you keep the /#
to the end:
Click Subscribe .
On the Raspberry Pi, run the following command in a Terminal window or at the command line:
Open the Pi's text editor — it's in the Pi > Accessories menu — and copy the following code into a new document. You can click the copy icon at the top right of the code panel:
Look for the section marked # EDIT THESE
and change some of the items as follows:
MQTT_CLIENT_ID
— Set this to the topic name you created above, replacing SOME_RANDOM_STRING
.
MQTT_PUBLISH_TOPIC
— Use the topic name, replacing SOME_RANDOM_STRING, followed by /info
.
Save the program in your home folder as mqtt_publish.py
.
Before you run the program you need a source for the data you'll send. This is where the MCP9808 temperature sensor comes in. You should already have soldered header pins to the small sensor board, so you can now connect the board to the Pi according to the diagram below. The Waveshare modem has pins that extend the Pi's own IO pins, so you can just wire the sensor direct to the modem board. The outer row of pins have even numbers, the inner pins odd numbers, both starting at the end closest to the Waveshare LEDs.
MCP9808 Pin | Pi Pin |
---|---|
VDD | Pin 1: 3V3 |
GND | Any GND |
SCL | Pin 5: I2C SCL |
SDA | Pin 3: I2C SDA |
On the Raspberry Pi, switch to the terminal window and run the program with python mqtt_publish.py
.
Switch back to the browser window or tab showing the HiveMQ MQTT broker interface. You should see messages being logged every 60 seconds — the messages currently being sent by your Pi over the cellular network!
If you're getting errors on the Pi side, check you have correctly connected up the sensor. You should also check you have your topic names and subscription set correctly in the mqtt_publish.py
file and on HiveMQ
Your Raspberry Pi and Waveshare SIM7600G-H 4G Hat are now able to access the cellular network, and you've built a basic IoT application using MQTT messaging on top of them. Now it's over to you: what are you going to build? We can't wait to find out.
Here are some suggestions for things to try:
Explore sending MQTT messages back to the Pi. The Pi can subscribe to messages published by the broker — the opposite of the process outlined above — and incorporate logic that reacts to message contents: perhaps switch the reported temperature from Celsius to Fahrenheit.
You can find an updated version of the code you worked with above in our GitHub repo .
In the HiveMQ MQTT broker interface, under Publish , you'll need to set the topic name with /state
at the end and add a message, {"units":"fahrenheit"}
, to send when you click the Publish button. Make sure mqtt_subscribe.py
is running on your Pi when you do.