Skip to content

Shield Demo

Timothy Woo edited this page Dec 16, 2024 · 30 revisions

Go back to File -> Examples -> Adafruit FONA Library and choose the appropriate demo sketch:

  • If you are using Arduino Uno, Mega, or other AVR microcontroller choose the LTE_Demo sketch.
  • If you're using an ESP8266 you should also select the LTE_Demo sketch above but follow the comments to make some very minor changes for the software serial initialization!
  • If you're using a SAMD microcontroller (like Arduino Zero, Adafruit M0, or other ATSAMD21 microcontroller) then use the SAMD_LTE_Demo sketch and physically wire up the TX/RX of the shield to hardware serial port on the SAMD microcontroller board.
  • If you're concerned about the sketch taking up too much memory on your microcontroller (like on the ATmega32u4 boards like Arduino Leonardo), you can use the SIM7XXX_LTE_Demo sketch instead, but note that this sketch only supports the LTE modems (SIM7000/SIM7500).
  • If you're using the ESP32 please use the ESP32_LTE_Demo sketch instead.

Again, make sure the pin definitions are correct and correspond with the hardware you're using. Upload this sketch and open the serial monitor! It should communicate with the LTE module, print out the IMEI number and print a big list of options for you to test. By default the serial monitor baud rate should be set to 9600 and you will need to choose "Both NL and CR" (newline and carriage return) in order to send the commands properly. At the top of the serial monitor simply enter the letter of the function you want to test and press enter (or click "Send" at the top right of the serial monitor).

Set the APN

At the end of the setup() function you will see a line like "fona.setNetworkSettings(F("hologram"));" which sets the Access Point Name (APN). You will need this line to access the web! However, keep in mind that you must first run the command "G" (see two sections ahead) in order for the APN to actually get set. The APN is specific to your SIM card and carrier and you should check its documentation. Usually you don't need a username and password, but again, that depends on your carrier and SIM card.

Note on Baud Rate

By default the SIM7000 runs at 115200 baud but this is too fast for software serial to reliably operate on and characters might randomly appear as square boxes or other odd symbols (for example, an "A" could show as "@"). In order to fix this I've added baud rate setup in the setup() function of the example sketches that starts at 115200 (default baud) then configures the module to 9600 baud. Unfortunately older firmware versions of the SIM7000A seem to not remember the new baud rate setting if it's powered off then back on, but that's OK since it always resets to 115200 and we can easily start from there then set it back to a lower rate. When the sketch first starts it should look like this:

and that's it! You should see the IMEI number of the module along with some setup commands to make the module connect (hopefully on its own) and then following that will be a giant list of command options to try out! Note that this Arduino library supports several different modules, so depending on which module you have, certain commands may or may not be applicable.

Since the module initialization code starts at 115200 baud rate and switches the module to 9600, please make sure the module is set to either baud rate before the sketch runs. If you had set it to, say, 4800, set the baud rate back using the command AT+IPR=115200 or AT+IPR=9600 directly via USB using a serial terminal like PuTTy (see this page) before loading the LTE_Demo sketch. Note that if you are using hardware serial (like if you are externally wiring the SIM7000 board to another board) you can fix the baud rate to 115200 and not worry about switching to a lower rate.

Trying out Commands!

  • Type "n" and press enter to check the network registration. You should see "Registered (home)" or "Registered (roaming)" on the Hologram SIM. If not, check if your antenna is attached as well as your LiPo battery! You may also need to run the "G" command (described below) first in order to set the APN.

IMPORTANT: If you are having troubles connecting to the network automatically, please visit this wiki page first, then come back here. Without being connected you're not going to have much fun!

  • Check the network signal strength by entering "i". You should get an RSSI value; the higher this value the better! Mine was 31, which indicates the best signal strength bracket! If you are not connected to a network you will get 99.

  • Now that you're connected, let's see some more details about the connection by using the "1" command. (If you're not connected, try the "G" command first, then return to this). The following example shows that we are currently connected to LTE CAT-M1 on band 13. Check the command "AT+CPSI" in the AT command manual for more info on the other values listed there. The second command ("AT+COPS?") gives you the current mode and carrier name. Since I'm using a Hologram SIM card in the United States it shows "Verizon Wireless Hologram".

  • If you have a LiPo battery connected you can also check the voltage and fill percentage of the battery with the command "b". Note that if there is no battery it will always read around 4200mV and say the battery is at 100%:

  • To enable GPRS or 4G, enter "G" to enable data. This sets the APN and is crucial for getting your device connected to the web! If you see "ERROR" try turning data off by using "g" then try again. If this command was successful you should see the NET LED start to blink more rapidly.

  • Note that if you're only using 4G LTE you can open Adafruit_FONA.cpp (located in the Adafruit FONA library folder) and go to the "enableGPRS" function and uncomment the if statements that automatically determines if you're using an LTE module and will eliminate unnecessary AT commands. Save the file and re-upload the sketch.

  • To test if you can actually do something with your module, enter "w". It will prompt you to enter the URL of the webpage you want to read, and copy/paste the example URL "dweet.io/get/latest/dweet/for/sim7000test123" and press enter. Shortly thereafter it should give you the message "{"this":"failed","with":404,"because":"we couldn't find this"}"

  • Now let's test sending dummy data to dweet.io, a free cloud API by entering "2" in the serial monitor. You should see it run through some AT commands and get a "200" status code while the AT commands run smoothly. If you get a 601 code please check if you actually initialized the 4G connection with the command "G", and if you get 404 make sure your URL is correct! If you want to use SSL, open the "Adafruit_FONA.h" library file and set "SSL_FONA" to 1, then change the URL in the Arduino sketch to "https://"

  • To test if the data really got through, try "w" again and this time enter "http://dweet.io/get/latest/dweet/for/{deviceID}" without the brackets, where the device ID is the IMEI number of your device which should be printed at the very top of the serial monitor from the module initialization. You should see "succeeded" and a JSON response containing the data that you had just sent! (Note that the battery level is just a dummy number that is set in the code and may not be your actual battery level)

  • Now it's time to test the GPS! Enable power to the GPS using "O"

  • Enter "L" to query the location data. Note that you might have to wait a little bit before it will get a fix on the location and you may get a empty values (nothing) separate by commas like in the image below. You can keep entering "L" until it shows you some data!

  • Once it gives you data, copy and paste it into Microsoft Word or a text editor so that it's easier to read. You will see that the third number (the numbers are separated by commas) is the date and time, and the next three numbers are the latitude, longitude, and elevation (in meters) of your location! To check if it was accurate, go to this online tool and search your current location. It should give you the lat/long and altitude and compare these values with the one your GPS gave!

  • If you don't need GPS you can turn it off with "o" (lower case!). This saves about 30mA so for low-power applications this is something you should definitely do!

Pretty cool huh?

IoT Example: GPS Tracking!

Now that you have verified that your module is working as expected, let's have some more fun with a practical example of how we can use the LTE shield to send data to the cloud! First open the "IoT_Example" sketch. This example sends GPS location and bearing data as well as temperature and supply voltage to a free cloud API called dweet.io or alternatively, to a free IoT dashboard service called ThingsBoard.io. Upload the sketch and watch the serial monitor in amazement as the LTE shield works its magic!

Check out the following Instructables I made on how to turn your shield into a GPS tracker!