Introduction: Map Orientation Through Web Server

About: We are a group of makers. We work in IoT, IOS app, android app, embedded design, sensor design, raspberry pi, arduino, beaglebone, particle electron, particle photon, Bluetooth.

Internet of Things, (IoT) is one of the popular topics on the planet right now. And, it is growing swiftly day by day with Internet. The Internet of Things is changing simple homes into smart homes, where everything from your lights to your locks can be controlled from your smartphone or desktop. This is the luxury everyone wants to own.

We always play with the tools we got and keep working on going to the next step of our limits. We try to give our customer a vision of latest technologies and ideas. So, that you can turn your home into smart homes and enjoy the taste of luxury without much efforts.

Today, we think on working on one of the most important topic in IoT - Digital Map Orientation.

We will build a web server through which we can monitor the movements of any device or thing (Its up to you, whom you wana spy ;) ). You can always think about upgrading this project to the next level with some modifications and do not forgot to tell us in the comments below.

Lets start than.. !!

Step 1: Equipment We Need.. !!

1. LSM9DS0 Sensor

The 3-in-1 sensor manufactured by STMicroelectronics, the LSM9DS0 is a system-in-package featuring a 3D digital linear acceleration sensor, a 3D digital angular rate sensor, and a 3D digital magnetic sensor. The LSM9DS0 has a linear acceleration full scale of ±2g/±4g/±6g/±8g/±16g, a magnetic field full-scale of ±2/±4/±8/±12 gauss and an angular rate of ±245/±500/±2000 dps.

2. Adafruit Huzzah ESP8266

The ESP8266 processor from Espressif is an 80 MHz microcontroller with a full WiFi front-end (both as client and access point) and TCP/IP stack with DNS support as well. The ESP8266 is an incredible platform for IoT application development. The ESP8266 provides a mature platform for monitoring and control applications using the Arduino Wire Language and the Arduino IDE.

3. ESP8266 USB Programmer

his ESP8266 host adapter was designed specifically by the Dcube Storefor the Adafruit Huzzah version of the ESP8266, allowing the I²C interface.

4. I2C Connecting Cable

5. Mini USB Cable

The mini USB cable Power supply is an ideal choice for powering the Adafruit Huzzah ESP8266.

Step 2: Hardware Connections

In general, making connections is the easiest part in this project. Follow the instructions and images, and you should have no problems.

First of all take the Adafruit Huzzah ESP8266 and place the USB Programmer (with Inward Facing I²C Port) on it. Press the USB Programmer gently and we are done with this step as easy as pie (See the picture above).

Connection of the Sensor and Adafruit Huzzah ESP8266
Take the sensor and Connect the I²C Cable with it. For proper operation of this cable, please remember I²C Output ALWAYS connects to the I²C Input. The same had to be followed for the Adafruit Huzzah ESP8266 with the USB Programmer mounted over it (See the picture above).

With the help of ESP8266 USB Programmer, it is very easy to program ESP. All you need to do is plug the sensor into USB Programmer and you are good to go. We prefer to use this adapter because it makes a lot easier to connect the hardware. No worrying about soldering the pins of ESP to the sensor or reading the pin diagrams and datasheet. We can use and work on multiple sensors simultaneously, you just need to make a chain. Without these plug and play USB Programmer there is a lot of risk of making wrong connection. A bad wiring can kill your wifi as well as your sensor.


Note:
The brown wire should always follow the Ground (GND) connection between the output of one device and the input of another device.

Powering of the Circuit

Plug in the Mini USB cable into the power jack of Adafruit Huzzah ESP8266. Light it up and voila, we are good to go!

Step 3: Code

The ESP Code for the Adafruit Huzzah ESP8266 and LSM9DS0 Sensor is available on our github repository.

Before going on to the code, make sure you read the instructions given in the Readme file and setup your Adafruit Huzzah ESP8266 according to it. It will take just 5 minutes to set up the ESP.

The code is lengthy but it's in the simplest form that you can imagine of and you will have no difficulty in understanding it.

For your convenience, you can copy the working ESP code for this sensor from here also:

// Distributed with a free-will license.
// Use it any way you want, profit or free, provided it fits in the licenses of its associated works. // LSM9DSO // This code is designed to work with the TCS3414_I2CS I2C Mini Module available from dcubestore.com.

#include <ESP8266WiFi.h>

#include <WiFiClient.h>

#include <ESP8266WebServer.h>

#include <Wire.h>

// LSM9DSO Gyro I2C address is 6A(106) #define Addr_Gyro 0x6A // LSM9DSO Accl I2C address is 1E(30) #define Addr_Accl 0x1E

const char* ssid = "your ssid"; const char* password = "your password"; int xGyro, yGyro, zGyro, xAccl, yAccl, zAccl, xMag, yMag, zMag;

ESP8266WebServer server(80);

void handleroot() { unsigned int data[6];

// Start I2C Transmission Wire.beginTransmission(Addr_Gyro); // Select control register 1 Wire.write(0x20); // Data rate = 95Hz, X, Y, Z-Axis enabled, power on Wire.write(0x0F); // Stop I2C Transmission Wire.endTransmission();

// Start I2C Transmission Wire.beginTransmission(Addr_Gyro); // Select control register 4 Wire.write(0x23); // Full-scale 2000 dps, continuous update Wire.write(0x30); // Stop I2C Transmission Wire.endTransmission();

// Start I2C Transmission Wire.beginTransmission(Addr_Accl); // Select control register 1 Wire.write(0x20); // Acceleration data rate = 100Hz, X, Y, Z-Axis enabled, power on Wire.write(0x67); // Stop I2C Transmission on the device Wire.endTransmission();

// Start I2C Transmission Wire.beginTransmission(Addr_Accl); // Select control register 2 Wire.write(0x21); // Full scale selection +/- 16g Wire.write(0x20); // Stop I2C Transmission Wire.endTransmission();

// Start I2C Transmission Wire.beginTransmission(Addr_Accl); // Select control register 5 Wire.write(0x24); // Magnetic high resolution, output data rate = 50Hz Wire.write(0x70); // Stop I2C Transmission Wire.endTransmission();

// Start I2C Transmission Wire.beginTransmission(Addr_Accl); // Select control register 6 Wire.write(0x25); // Magnetic full-scale +/- 12 gauss Wire.write(0x60); // Stop I2C Transmission Wire.endTransmission();

// Start I2C Transmission Wire.beginTransmission(Addr_Accl); // Select control register 7 Wire.write(0x26); // Normal mode, magnetic continuous conversion mode Wire.write(0x00); // Stop I2C Transmission Wire.endTransmission(); delay(300);

for (int i = 0; i < 6; i++) { // Start I2C Transmission Wire.beginTransmission(Addr_Gyro); // Select data register Wire.write((40 + i)); // Stop I2C Transmission Wire.endTransmission();

// Request 1 byte of data Wire.requestFrom(Addr_Gyro, 1);

// Read 6 bytes of data // xGyro lsb, xGyro msb, yGyro lsb, yGyro msb, zGyro lsb, zGyro msb if (Wire.available() == 1) { data[i] = Wire.read(); } }

// Convert the data int xGyro = ((data[1] * 256) + data[0]); int yGyro = ((data[3] * 256) + data[2]); int zGyro = ((data[5] * 256) + data[4]);

for (int i = 0; i < 6; i++) { // Start I2C Transmission Wire.beginTransmission(Addr_Accl); // Select data register Wire.write((40 + i)); // Stop I2C Transmission Wire.endTransmission();

// Request 1 byte of data Wire.requestFrom(Addr_Accl, 1);

// Read 6 bytes of data // xAccl lsb, xAccl msb, yAccl lsb, yAccl msb // zAccl lsb, zAccl msb if (Wire.available() == 1) { data[i] = Wire.read(); } }

// Convert the data int xAccl = ((data[1] * 256) + data[0]); int yAccl = ((data[3] * 256) + data[2]); int zAccl = ((data[5] * 256) + data[4]);

for (int i = 0; i < 6; i++) { // Start I2C Transmission Wire.beginTransmission(Addr_Accl); // Select data register Wire.write((8 + i)); // Stop I2C Transmission Wire.endTransmission();

// Request 1 byte of data Wire.requestFrom(Addr_Accl, 1);

// Read 6 bytes of data // xMag lsb, xMag msb, yMag lsb, yMag msb // zMag lsb, zMag msb if (Wire.available() == 1) { data[i] = Wire.read(); } }

// Convert the data int xMag = ((data[1] * 256) + data[0]); int yMag = ((data[3] * 256) + data[2]); int zMag = ((data[5] * 256) + data[4]);

// Output data to serial monitor Serial.print("X-Axis of rotation : "); Serial.println(xGyro); Serial.print("Y-Axis of rotation : "); Serial.println(yGyro); Serial.print("Z-Axis of rotation : "); Serial.println(zGyro); Serial.print("Acceleration in X-Axis : "); Serial.println(xAccl); Serial.print("Acceleration in Y-Axis : "); Serial.println(yAccl); Serial.print("Acceleration in Z-Axis : "); Serial.println(zAccl); Serial.print("Magnetic field in X-Axis : "); Serial.println(xMag); Serial.print("Magnetic field in Y-Axis : "); Serial.println(yMag); Serial.print("Magnetic filed in Z-Axis : "); Serial.println(zMag);

// Output data to web server server.sendContent ("

" "

DCUBE STORE

" "

www.dcubestore.com

" " LSM9DS0 Sensor I2C Mini Module

"); server.sendContent ("

X-Axis of rotation = " + String(xGyro)); server.sendContent ("

Y-Axis of rotation = " + String(yGyro)); server.sendContent ("

Z-Axis of rotation = " + String(zGyro)); server.sendContent ("

Acceleration in X-Axis = " + String(xAccl)); server.sendContent ("

Acceleration in Y-Axis = " + String(yAccl)); server.sendContent ("

Acceleration in Z-Axis = " + String(zAccl)); server.sendContent ("

Magnetic filed in X-Axis = " + String(xMag)); server.sendContent ("

Magnetic filed in Y-Axis = " + String(yMag)); server.sendContent ("

Magnetic filed in Z-Axis = " + String(zMag)); delay(1000); }

void setup() { // Initialise I2C communication as MASTER Wire.begin(2, 14); // Initialise serial communication, set baud rate = 115200 Serial.begin(115200);

// Connect to WiFi network WiFi.begin(ssid, password);

// Wait for connection while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.print("Connected to "); Serial.println(ssid);

// Get the IP address of ESP8266 Serial.print("IP address: "); Serial.println(WiFi.localIP());

// Start the server server.on("/", handleroot); server.begin(); Serial.println("HTTP server started"); }

void loop() { server.handleClient(); }

Step 4: Working of Code

Now, download (or git pull) the code and open it in the Arduino IDE.

Compile and upload the code and see the output on Serial Monitor.

Note: Before uploading, make sure you enter your SSID network and password in the code.

Copy the IP address of ESP8266 from the Serial Monitor and paste it in your web browser. You will see a web page with axis of rotation, acceleration and magnetic field reading in the 3-axis.

The output of the sensor on Serial Monitor and Web Server are shown in the picture above.

Step 5: Applications and Features

The LSM9DS0 is a system-in-package featuring a 3D digital linear acceleration sensor, a 3D digital angular rate sensor, and a 3D digital magnetic sensor. By measuring these three properties, you can gain a great deal of knowledge about an object’s movement. Measuring the force and direction of Earth’s magnetic field with a magnetometer, you can approximate your heading. An accelerometer in your phone can measure the direction of the force of gravity, and estimate orientation(portrait, landscape, flat, etc.). Quadcopters with built-in gyroscopes can look out for sudden rolls or pitches. We can use this in Global Positioning System(GPS).

Some more applications include Indoor navigation, Smart user interfaces, Advanced gesture recognition, Gaming and virtual reality input devices, etc.

With the help of ESP8266, we can increase its capacity to a greater length. We can control our appliances and monitor there performance form our desktops and mobile devices. We can store and manage the data online and study them anytime for modifications. More applications include Home Automation, Mesh Network, Industrial Wireless Control, Baby Monitors, Sensor Networks, Wearable Electronics, Wi-Fi Location-aware Devices, Wi-Fi Position System Beacons.

Step 6: Resources for Going Further

For more information about LSM9DS0 and ESP8266, check out the links below: