Arduino - MKRNBToolsTestModem
NB Test Modem
This sketch tests the modem on the MKR NB 1500 to see if it is working correctly. You do not need a SIM card for this example.
Hardware Required
- Arduino MKR NB 1500
- antenna
Circuit
Code
First, import the MKRNB library
#include <MKRNB.h>
Create an instance of the NBModem class:
NBModem modem;
Create a variable to hold the IMEI number of the modem
String IMEI = "";
In setup
, open a serial connection to the computer. After opening the connection, send a message indicating the sketch has started.
void setup(){
Serial.begin(9600);
Serial.print("Starting modem test...");
Call modem.begin()
to start the modem. Send a status message depending on the outcome, and end setup()
.
if(modem.begin())
Serial.println("modem.begin() succeeded");
else
Serial.println("ERROR, no modem answer.");
}
Inside loop
, use modem.getIMEI()
to return the IMEI number of the modem. This number is unique to your NB module.
void loop()
{
// get modem IMEI
Serial.print("Checking IMEI...");
IMEI = modem.getIMEI();
If there is a valid response from getIMEI()
, print it to the serial monitor and reset the modem with modem.begin()
.
if(IMEI != NULL)
{
// show IMEI in serial monitor
Serial.println("Modem's IMEI: " + IMEI);
// reset modem to check booting:
Serial.print("Reseting modem...");
modem.begin();
Once reset, check the IMEI again. If it is a valid return again, the modem is functioning as expected.
if(modem.getIMEI() != NULL)
{
Serial.println("Modem is functoning properly");
}
If, after resetting the modem, there is not a valid return from getIMEI()
, report an error
else
{
Serial.println("Error: getIMEI() failed after modem.begin()");
}
If you never received an IMEI after starting the sketch, report it, and end the program.
}
else
{
Serial.println("Error: Could not get IMEI");
}
// do nothing:
while(true);
}
Once your code is uploaded, open the serial monitor to see the various messages generated by the test procedure..
The complete sketch is below.
/*
This example tests to see if the modem of the
MKR NB 1500 board is working correctly. You do not need
a SIM card for this example.
Circuit:
* MKR NB 1500 board
* Antenna
Created 12 Jun 2012
by David del Peral
modified 21 Nov 2012
by Tom Igoe
*/
// libraries
#include <MKRNB.h>
// modem verification object
NBModem modem;
// IMEI variable
String IMEI = "";
void setup() {
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start modem test (reset and check response)
Serial.print("Starting modem test...");
if (modem.begin()) {
Serial.println("modem.begin() succeeded");
} else {
Serial.println("ERROR, no modem answer.");
}
}
void loop() {
// get modem IMEI
Serial.print("Checking IMEI...");
IMEI = modem.getIMEI();
// check IMEI response
if (IMEI != NULL) {
// show IMEI in serial monitor
Serial.println("Modem's IMEI: " + IMEI);
// reset modem to check booting:
Serial.print("Resetting modem...");
modem.begin();
// get and check IMEI one more time
if (modem.getIMEI() != NULL) {
Serial.println("Modem is functoning properly");
} else {
Serial.println("Error: getIMEI() failed after modem.begin()");
}
} else {
Serial.println("Error: Could not get IMEI");
}
// do nothing:
while (true);
}
See Also
Arduino MKR NB 1500 - Complete product description.
Getting started with the MKR NB 1500 - Get everything set up in minutes.
MKRNB library - Your reference for the NB Library.
GSMModem Constructor
begin()
getIMEI()
MKRNBScanNetworks - Scans the available networks and prints informations about IMEI and number of the SIM card.
MKRNBToolsTestGPRS - Tries to access the internet over GPRS.
MKRNBToolsPinManagement - How to to change or remove the PIN number.
Last revision 2019/04/22 by SM