Wiki

This version is outdated by a newer approved version.DiffThis version (21 Aug 2017 15:45) was approved by Brandon Bushey.The Previously approved version (18 Aug 2017 22:34) is available.Diff

This is an old revision of the document!


Accelerometer Demo using Wi-Fi (with EVAL-ADXL362-ARDZ)

The ADuCM3029_demo_esp8266 is a Wi-Fi demo project for the EVAL-ADICUP3029 base board with additional EVAL-ADXL362-ARDZ shield, created using the Analog Devices Cross Core Embedded Studio.

General Description/Overview

The ADuCM3029_demo_esp8266 project uses the EVAL-ADXL362-ARDZ shield which has an ADXL362 3-axis MEMS accelerometer and a incorporated NHD-C12832A1Z-NSW-BBW display (128×32). However, for this example the display is not used.

The EVAL-ADICUP3029 is designed for IOT (Internet of Things) applications in mind, and therefore comes with on board Wi-Fi ESP8266 module.

Also, in order to fully make use of the IOT capability, MQTT messaging protocol is used as it is extremely simple and lightweight.

Demo Requirements

The following is a list of items needed in order to replicate this demo.

  • Hardware
    • EVAL-ADICUP3029
    • EVAL-ADXL362-ARDZ
    • Mirco USB to USB cable
    • PC or Laptop with a USB port
  • Software
    • ADICUP3029_ADXL362 software
    • CrossCore Embedded Studio (2.6.0 or higher)
    • ADuCM302x DFP (2.0.0 or higher)
    • ADICUP3029 BSP (1.1.0 or higher)
    • Mosquitto Broker

Setting up the Hardware

  1. Move the S2 switch to the WiFi position on the EVAL-ADICUP3029.
  2. The ESP8266 Enable Pin needs to be tied directly to 3.3V or pulled high to the GPIO via a 10K ohm resistor. Because this is not currently on the Rev B or Rev C version of the ADICUP3029, you will need to solder a small fly wire from the 3.3V pin to the enable pin.










  3. Plug the ESP8266 in the P1 connector on the EVAL-ADICUP3029.
  4. Plug the EVAL-ADXL362-ARDZ shield in the EVAL-ADICUP3029 base board.
  5. Plug the USB cable

Using an MQTT Broker

The program connects to a WiFi network and to a TCP MQTT broker. After receiving the SUBACK confirmation from the server, the program enters an infinite loop where it waits for an ADXL-362 interrupt which is triggered when the acceleration on any axes is greater than 50 mG. Afterwards, the program publishes the x, y, z readings on adxl topic. A subscriber to this topic can view this information.

Installing the Mosquitto Broker

This example uses the Eclipse Mosquitto which is an open source (EPL/EDL licensed) message broker that implements the MQTT protocol versions 3.1 and 3.1.1. However, the user is free to use his favorite MQTT broker with minimal changes. MQTT provides a lightweight method of carrying out messaging using a publish/subscribe model. This makes it suitable for “Internet of Things” messaging such as with low power sensors or mobile devices such as phones, embedded computers or microcontrollers.

Alternatively, there is an additional step-by-step procedure written which can be used in combination with the steps outlined below. The combination of both procedures should be enough to get most PC/laptops working. Installing and Configuring Mosquitto

  1. Double click the downloaded .exe file, and install the Mosquitto program
  2. During the install, Mosquitto will ask you to make sure you have 2 other programs installed.
  3. Click the links within the Windows install wizard BEFORE completing the Mosquitto install.
    1. Refer to pictures outlined in the additional step by step instructions.
  4. Make sure these additional programs are installed before you continue
  5. Click next and finish the installation.
    1. You may run into an issue that says “VCRUNTIME140.dll is missing. In order to proceed you must first have this installed.
    2. After looking around, I found a great website to download the DLL files from, as well as a great video that shows you have to fix the issue, and it did work for me. Please note, that this solution is NOT affiliated with Analog Devices, and Analog Devices assumes no responsibility for any problems or damages occurred during this process.
    3. Re-Run the Mosquitto.exe file, inorder to complete the installation process.

Setting up Mosquitto to Receive MQTT Data

  1. With Mosquitto and other software properly installed, you should be able to run mosquitto. Open a Command Prompt and navigate to the folder where mosquitto is installed. The default location is C:\Program Files (x86)\mosquitto
  2. Type mosquitto.exe -v to start the broker in verbose mode. Copy this code block into your command line editor to navigate to the folder and execute the program:
     cd C:\Program Files (x86)\mosquitto\mosquitto.exe -v 

    It should look like the following picture

    Make sure that your computer or laptop is connected to the same network you are going to configure in the ESP8266.h file. Once you run the executable, Mosquitto assumes that you are running on that network.

  3. The mosquitto broker is now running locally and has the same IP as your machine and by default runs on port 1883. Open a new Command Prompt and type ipconfig to get your local IP address
  4. In the ESP8266.h header file you need to configure the following parameters:
    SSID = ""         //Service set identifier, name of the WiFi network to connect the ESP8266//
    PASS = ""         //WiFi network password//
    MQTT_SERVER = ""  //IP of the mosquitto broker from the previous step//
    PORT = "1883"     //by default is 1883//
  5. Open a third Command Prompt and navigate to the folder where mosquitto is installed and type this command and hit the <ENTER> key:
     cd C:\Program Files (x86)\mosquitto\mosquitto_sub -t adxl 

    This command subscribes to the topic and will display the accelerometer data. It should look similar to the image below.

Outputting Data

  1. You are now ready to flash the program on the ADICUP3029 and run it. Before downloading the code, please press the WIFI_RESET button (S4) on the ADICUP3029.
  2. If everything works fine, in the CrossCore Embedded Studio console you should see:
  3. The program has connected to the local WiFi network, to the TCP mosquitto broker, subscribed to subtopic an received SUBACK as a confirmation from the broker.
  4. The program will publish x, y, z data on the adxl topic. In order to view this information, we can use mosquitto_sub and subscribe to the adxl topic.
  5. At each ADXL362 movement, an interrupt is triggered and as a result, the x, y, z information is published. In the console publishing sensor reading message is displayed, while in the mosquitto_sub cmd window you should see the values of x, y, z axis:

Obtaining the Source Code

We recommend not opening the project directly, but rather import it into CrossCore Embedded Studios and make a local copy in your workspace.

The source code and include files of the AduCM3029_demo_esp8266 can be found here:

How to use the Tools

The official tool we promote for use with the EVAL-ADICUP3029 is CrossCore Embedded Studio. For more information on downloading the tools and a quick start guide on how to use the tool basics, please check out the Tools Overview page.

Importing

For more detailed instructions on importing this application/demo example into the CrossCore Embedded Studios tools, please view our How to import existing projects into your workspace section.

Debugging

For more detailed instructions on importing this application/demo example into the CrossCore Embedded Studios tools, please view our How to configure the debug session section.

Project Structure

The ADuCM3029_demo_esp8266 project use basic ARM Cortex-M C/C++ Project structure. This project contains: system initialization part - disabling watchdog, setting system clock, enabling clock for peripheral; port configuration for SPI, accelerometer sensor; ESP8266 initialization - UART and GPIO.

In the src folder you will find the source and header files related to adxl362 application, ESP8266 library and MQTT library. The Communication.c/h files contain SPI and UART specific data, meanwhile the ADXL362.c/h files contain the accelerometer data.

  1. MQTT folder contains the library which implements the MQTT protocol. We recommend to use it as is, without modifying anything.
  2. ADXL362.c/h are the files for ADXL362 accelerometer control. Here you can modify:
    • Accelerometer scan interval - how often to update sensor information. Set the SCAN_SENSOR_TIME parameter - msec (ADXL362.h):
       #define SCAN_SENSOR_TIME   500 
    • Sensor activity and inactivity thresholds - ACT_VALUE and INACT_VALUE paramaters used to determine at which acceleration values the sensor can react at sleep/wake-up commands ( ADXL362.h ):
       #define ACT_VALUE          50 
       #define INACT_VALUE        50 
    • Sensor activity and inactivity time - ACT_TIMER and INACT_TIMER paramaters used to determine sleep/wake-up intervals( ADXL362.h ):
       #define ACT_TIMER          100
       #define INACT_TIMER        10 
  3. ESP8266.c/h is the ESP8288 Library which uses AT commands and UART to communicate with the WiFi module. Here you can and should modify:
    • SSID, PASS and MQTT_SERVER - replace with your specific data:
       #define SSID           "****" 
       #define PASS	        "****" 
       #define MQTT_SERVER 	"****" 

End of Document

resources/eval/user-guides/eval-adicup3029/reference_designs/demo_adxl362.1503323126.txt.gz · Last modified: 21 Aug 2017 15:45 by Brandon Bushey