Raspberry pie 57/100 - Pico connected to Internet of things NB IOT

Recently, a project wanted to monitor the abnormal situation of an object on the construction site. This kind of thing should be able to stand by for 20 ~ 30 days with a 3.7V battery. Under normal circumstances, it is almost in a static state, and there will be a little vibration due to nearby interference. When there is a large movement, it should be able to give an alarm and send location information, so that managers can quickly grasp the latest situation.

Initially, I wanted to use 2G SMS to solve the problem, but several major operators are shutting down 2G networks, which may not be reliable.

I want to use 3G/4G technology for daily use, but this connection mode consumes too much power. It's good to be on standby for a few days. Finally, I think of Nb IOT, narrow-band Internet of things. The technology is very new, with low power consumption and low communication frequency and speed, which can meet the needs of some sensors in the Internet of things to transmit a small number of important parameters regularly.

I recently studied the raspberry pie Pico, looked for the board related to Pico, and finally found it SIM7020C module with light snow.

Official overview:

This product is a raspberry Pico expansion board with Nb IOT (narrowband Internet of things) function, domestic NB IOT all network communication, serial port AT command control, and supports protocol communication such as HTTP/MQTT/LWM2M/COAP. It has the advantages of low delay, low power consumption, wide coverage and low cost. It is very suitable for Internet of things applications such as intelligent instruments, asset tracking and remote monitoring.

Several features:

  • Onboard Raspberry Pi Pico interface, applicable to Raspberry Pi Pico series motherboard
  • UART interface communication, serial port AT command control, supporting multiple communication protocols and multiple cloud platforms
  • The onboard 3.7V lithium battery interface and charging circuit can be connected with external rechargeable lithium battery to realize external power supply, and support charging and discharging at the same time
  • There are 2 LED indicators on board to facilitate viewing the operation status of the module
  • Onboard nano SIM card slot, domestic NB IOT special card supporting telecom / China Unicom / China Mobile
  • Provide complete supporting materials and manuals (micro Python sample program and user manual, etc.)

141 yuan was bought on an East platform (excluding Pico) and photographed in kind.

I marked the base welding when I bought it, so that I can insert Pico and then plug it into the panel package. In the future, I will connect gyroscopes and other components. I forgot to connect the antenna in the following figure.

With the device carrying a telecom NB IOT card (Nano card), it seems that it can only be used for the Internet of things, not for the Internet traffic of mobile phones.

The main references come from this website:
https://www.waveshare.net/wiki/Pico-SIM7020C-NB-IoT Then I started my tossing trip.

The connection is very simple, because its 40 pins can directly correspond to Pico one by one. As long as it is connected according to the mark of USB port, this module mainly uses 4 pins (excluding power supply and grounding).

GP0/GP1 RXD/TXD for serial port.
GP14 is the switch of the whole module.
GP17 is a DTR used to wake up the module.

This module can be powered by Pico's VBUS. I used it when debugging on the computer. Computer USB 5V - > Pico VBUS - > sim7020c VBUS.

In the future, the power can be supplied by lithium battery ON the construction site. Just turn a switch near the VSYS ON the board to the ON position, lithium battery 3.7V - > sim7020c VSYS - > Pico VSYS.

There are 180 lines of micro Python code provided on the official website. It doesn't take care of the feelings of newcomers at all. Let me slowly get familiar with it.

Let me test the AT command first:

import machine
import utime
import binascii

uart = machine.UART(0, 115200, tx=machine.Pin(0), rx=machine.Pin(1))

# pico's GP14 controls the start and stop of SIM7020C
pwr_enable = machine.Pin(PWR_ENABLE_PIN, machine.Pin.OUT)

def wait_response(timeout = 2000):
    prvMills = utime.ticks_ms()
    resp = b''
    while (utime.ticks_ms() - prvMills) < timeout:
        if uart.any():
            resp = b''.join([resp, uart.read(1)])
    if resp != b'':

def send_cmd_and_wait(cmd, timeout=2000):
    print("[[command]:" + cmd)
    uart.write((cmd + '\r\n').encode())

def at_command_test():
    send_cmd_and_wait("AT+CPIN?")       #whether some password is required or not
    send_cmd_and_wait("AT+CSQ")         #received signal strength
    send_cmd_and_wait("AT+CGREG?")      #the registration of the ME.
    send_cmd_and_wait("AT+CGATT?")      #GPRS Service's status
    send_cmd_and_wait("AT+CGACT?")      #PDN active status
    send_cmd_and_wait("AT+COPS?")       #Query Network information
    send_cmd_and_wait("AT+CGCONTRDP")   #Attached PS domain and got IP address automatically

# Clear the buffer of the serial port


After running the program, the following output is obtained:

UART(0, baudrate=115200, bits=8, parity=None, stop=1, tx=0, rx=1, txbuf=256, rxbuf=256, timeout=0, timeout_char=1, invert=None)
[[command]: AT

[[command]: ATE1

[[command]: AT+CGMM


[[command]: AT+CPIN?


[[command]: AT+CSQ
+CSQ: 11,0


[[command]: AT+CGREG?
+CGREG: 0,1


[[command]: AT+CGATT?


[[command]: AT+CGACT?
+CGACT: 1,1


[[command]: AT+COPS?
+COPS: 0,2,"46000",9


[[command]: AT+CGCONTRDP
+CGCONTRDP: 1,5,"cmnbiot",""


Find the AT instruction manual of SIM7020 on the Internet. There are more than 200 pages. You can't read it. Learn the most basic first.

ATE refers to setting Echo mode. 1 means that the input command is output intact, which can be used to debug errors. The output is too verbose, or use ATE0 to turn it off.

AT+CGMM can obtain the model of the module. Here is SIM7020C.

AT+CPIN? Used to query whether there is PIN password protection. Return READY to indicate that it is directly available.

AT+CSQ query information strength. Returns 2 integers. The first integer is between 0 and 31, representing information strength, and the second integer represents channel bit error rate. 99 means unkown. I didn't connect the antenna at first, and the signal strength was 0. After connecting the antenna, it was stable at 11 or 12.

AT+CGREG? Used to query the registration status of the network.
0,0 – not registered, MT is not currently searching a new operator to register to
0,1 – Registered, home network
0,2 – Searching
0,3 – Registration denied
0,5 – Registered, non-home network

AT+CGATT? Get the connection status of GPRS/Packet Domain, and return 0 to indicate that it is not connected and 1 is connected.

AT+CGACT? Used to activate PDP context. PDP refers to Packet Data Protocol. I don't know its specific content yet. Cgact returns 2 integers. The first is (like a serial number in PDP), and 1 is activated.


I'm tired of writing today. I'll sort out these two commands tomorrow.

Tags: Python Embedded system IoT Raspberry Pi nb-iot

Posted on Fri, 03 Dec 2021 21:24:00 -0500 by craige