Last change
on this file since 175 was 175, checked in by ertl-honda, 8 years ago |
ライブラリを Arduino IDE 1.7.9 にupdate
|
File size:
1.6 KB
|
Line | |
---|
1 | /*
|
---|
2 |
|
---|
3 | This example tests to see if the modem of the
|
---|
4 | GSM shield is working correctly. You do not need
|
---|
5 | a SIM card for this example.
|
---|
6 |
|
---|
7 | Circuit:
|
---|
8 | * GSM shield attached
|
---|
9 |
|
---|
10 | ATTENTION: to work correctly with M0/M0 pro you have to connect pin 2 to pin 4 of the shield
|
---|
11 |
|
---|
12 | Created 12 Jun 2012
|
---|
13 | by David del Peral
|
---|
14 | modified 21 Nov 2012
|
---|
15 | by Tom Igoe
|
---|
16 |
|
---|
17 | http://arduino.cc/en/Tutorial/GSMToolsTestModem
|
---|
18 |
|
---|
19 | This sample code is part of the public domain
|
---|
20 |
|
---|
21 | */
|
---|
22 |
|
---|
23 | // libraries
|
---|
24 | #include <GSM.h>
|
---|
25 |
|
---|
26 | // modem verification object
|
---|
27 | GSMModem modem;
|
---|
28 |
|
---|
29 | // IMEI variable
|
---|
30 | String IMEI = "";
|
---|
31 |
|
---|
32 | void setup()
|
---|
33 | {
|
---|
34 | // initialize serial communications and wait for port to open:
|
---|
35 | SerialUSB.begin(9600);
|
---|
36 | while (!SerialUSB) {
|
---|
37 | ; // wait for serial port to connect. Needed for Leonardo only
|
---|
38 | }
|
---|
39 |
|
---|
40 | // start modem test (reset and check response)
|
---|
41 | SerialUSB.print("Starting modem test...");
|
---|
42 | if (modem.begin())
|
---|
43 | SerialUSB.println("modem.begin() succeeded");
|
---|
44 | else
|
---|
45 | SerialUSB.println("ERROR, no modem answer.");
|
---|
46 | }
|
---|
47 |
|
---|
48 | void loop()
|
---|
49 | {
|
---|
50 | // get modem IMEI
|
---|
51 | SerialUSB.print("Checking IMEI...");
|
---|
52 | IMEI = modem.getIMEI();
|
---|
53 |
|
---|
54 | // check IMEI response
|
---|
55 | if (IMEI != NULL)
|
---|
56 | {
|
---|
57 | // show IMEI in serial monitor
|
---|
58 | SerialUSB.println("Modem's IMEI: " + IMEI);
|
---|
59 | // reset modem to check booting:
|
---|
60 | SerialUSB.print("Resetting modem...");
|
---|
61 | modem.begin();
|
---|
62 | // get and check IMEI one more time
|
---|
63 | if (modem.getIMEI() != NULL)
|
---|
64 | {
|
---|
65 | SerialUSB.println("Modem is functoning properly");
|
---|
66 | }
|
---|
67 | else
|
---|
68 | {
|
---|
69 | SerialUSB.println("Error: getIMEI() failed after modem.begin()");
|
---|
70 | }
|
---|
71 | }
|
---|
72 | else
|
---|
73 | {
|
---|
74 | SerialUSB.println("Error: Could not get IMEI");
|
---|
75 | }
|
---|
76 | // do nothing:
|
---|
77 | while (true);
|
---|
78 | }
|
---|
79 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.