-
Notifications
You must be signed in to change notification settings - Fork 215
Shield Demo
Go back to File -> Examples -> Adafruit FONA Library but choose the "LTE_Demo" example sketch. Again, make sure the pin definitions are correct. 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 115200 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).
At the end of the setup() function you will see a line like "fona.setGPRSNetworkSettings(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.
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 4800 baud. Unfortunately the module seems not to 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 set it back to a lower rate. If you didn't power cycle the device you can bypass waiting for the initialization at 115200 baud to scroll through the serial monitor simply by pressing the reset button on the Arduino. When the sketch first starts it should look like this:
Notice how there will most likely be some weird characters that should be something else, but don't fret! This is because software serial can't handle 115200 baud rate. The next thing the Arduino will do is set the baud rate to 4800:
and that's it! You should see the IMEI number and then following that will be a giant list of command options to try out!
Note that if you are using hardware serial (like if you are externally wiring the SIM7000 board to another board) you most likely won't have to deal with the baud rate reset issue since you can simply use the default 115200. However, it's good just to be aware of this!
- 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.
- 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 next 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" and the number 8 after it also indicates that it's LTE CAT-M1.
- 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 GPRS. This sets the APN and is crucial for getting your device connected to the web! If you see "ERROR" try turning GPRS 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 at line 1168 (approx) 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. You should get a "200" status code and the AT commands should 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!
- 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 87% battery 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?
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!