NB-IoT Tutorials
Examples will be made for the following boards:
SODAQ ExpLoRer | https://shop.sodaq.com/en/explorer.html |
Arduino Zero / M0 | https://www.arduino.cc/en/Guide/ArduinoZero |
Arduino Leonardo | https://www.arduino.cc/en/Guide/ArduinoLeonardoMicro |
If you have an other board with the Arduino pinout, your board might also work. Ask your question on forum.sodaq.com.
Add Sodaq download url
Go to the library page to add the json to the Arduino IDE
Download the required libraries
Sketch -> Include Library -> Manage Libraries…
Install the SODAQ NB-IoT library
Install the SODAQ WDT ( WatchDog Timer ) library
Accelerometer NB-IoT shield
The first batch of the Sodaq NB-IoT shield was shipped with the LSM303C.
All other batches are shipped with the LSM303AGR.
LSM303C
Download the latest version of the Adafruit LSM303 library.
Update the I2C addresses inside the library to:
/*========================================================================= I2C ADDRESS/BITS -----------------------------------------------------------------------*/ #define LSM303_ADDRESS_ACCEL (0x1D) // 0011001x #define LSM303_ADDRESS_MAG (0x1E) // 0011110x /*=========================================================================*/
All libraries can be found in Documents > Arduino > libraries
Go to folder Adafruit_LSM303DLHC
Open Adafruit_LSM303_U.h with a text editor and change the lines.
LSM303AGR
Download the Sodaq_LSM303AGR from the Arduino Library Manager or from our github.
/* Example for using the accelerometer with the Sodaq_LSM303AGR library */ /* The example is tested on an Arduino M0 and a Sodaq Explorer with a Sodaq NB-IoT shield */ /* This code prints accelerometer readings every second and registers whether the board is flipped by interrupt */ #include <Arduino.h> #include <Sodaq_LSM303AGR.h> Sodaq_LSM303AGR AccMeter; // Print the debug information on the SerialUSB #define USB SerialUSB // The interrupt pin for the Accelerometer is attached to D4 #define ACC_INT_PIN 4 // Threshold for interrupt trigger double threshold = -0.8; int now = millis(); void setup() { USB.begin(9600); while ((!USB) && (millis() < 10000)) { // Wait 10 seconds for the Serial Monitor } // Start the I2C bug Wire.begin(); AccMeter.rebootAccelerometer(); delay(1000); // Enable the Accelerometer AccMeter.enableAccelerometer(); // Attach interrupt event fot the Accelerometer pinMode(ACC_INT_PIN, INPUT); attachInterrupt(ACC_INT_PIN, interrupt_event, RISING); // Enable interrupts on the SAMD GCLK->CLKCTRL.reg = GCLK_CLKCTRL_ID(GCM_EIC) | GCLK_CLKCTRL_GEN_GCLK1 | GCLK_CLKCTRL_CLKEN; // If Z goes below threshold the interrupt is triggered AccMeter.enableInterrupt1(AccMeter.ZLow, threshold, 0, AccMeter.PositionRecognition); } void loop() { // Print sensor readings every second if ((now + 1000) < millis()) { now = millis(); read_AccMeter(); } } void read_AccMeter() { USB.print("x = "); USB.print(AccMeter.getX()); USB.print("\ty = "); USB.print(AccMeter.getY()); USB.print("\tz = "); USB.println(AccMeter.getZ()); } void interrupt_event() { // Do not print in an interrupt event when sleep is enabled. USB.println("Board flipped"); }
More tutorials:
Passthrough sketch, send AT commands
Send temperature and humidity to All Things Talk
Add pressure and GPS to All Things Talk
With MQTT you can get your last message from All Things Talk and use it on your own server.
Download the How-To word document to get started.