The ADuCM3029_demo_cn0398 is a pH and moisture measurements demo project, for the EVAL-ADICUP3029 base board with additional EVAL-CN0398-ARDZ shield, created using CrossCore Embedded Studio and GNU ARM compiler. The demo uses an ESP8266 WiFi module to transmit data to the cloud, by publishing to a MQTT broker.
The ADuCM360_demo_cn0398 project uses the EVAL-CN0398-ARDZ shield which is a single supply, low power, high precision complete solution for soil moisture and pH measurements, including temperature compensation. The circuit is optimized for capacitive soil moisture sensors that are insensitive to water salinity and do not corrode over time. The circuit also measures soil pH so it increases the range of applications where this shield can be used.
The circuit is divided into three independent measurement front ends: pH, soil moisture, and temperature. After signal conditioning, the three channels share an AD7124-8, 24-bit sigma-delta (Σ-Δ) ADC. The AD7124-8, is a low power, low noise, completely integrated analog front end for high precision measurement applications. The board offers the possibility to configure Vin supply voltage (P10 connector) in order to use 5V or 7V-12V. Considering moisture sensor which is used, the P8 connector configure 3.3V or 5V supply. The user has the possibility to select one of the three GPIOs available for ADC CS pin using P5 connector (default configuration for P5 is 1-2 position). For temperature compensation can be used an RTD PT100 sensor, 2-wire (this is used in the demo), 3-wire or 4-wire connection (see P1 connector). For this demo was used for the moisture measurement the VH400 sensor (P2) and for pH measurement Atlas Scientific sensor (J1). The ADuCM360_demo_cn0398 application processes ADC outputs for all 3 channels (RTD, pH and moisture), calculates pH and moisture values using as input RTD temperature value. This data is sent to cloud using the UART module on the base board and the ESP8266 WiFi module. The 24-bits ADC data are received using SPI interface of the EVAL-ADICUP3029 board.
The temperature value is calculated based on the RTD resistance:
CODE - ADC output Rrtd = ((CODE - 2^23)* Rref)/GAIN*2^23 Rref - Reference resistor (5kΩ) GAIN - used gain for RTD channel (16)
1. RTD resistance > 100Ω
2. RTD resistance ≤ 100Ω
The pH value can be calculated in two ways, so user can configure which one did he want for his application: using two-point calibration data or using Nernst equation. The pH value will be calculated using calibration measured value:
y1 - measured voltage at calibration point 1 for known pH y2 - measured voltage at calibration point 2 for known pH pH = [m*(V -y2 + Voffset) + x2] x1 - known pH at calibration point 1 x2 - known pH at calibration point 2 m = [(x2-x1)/(y2-y1)] V - pH channel measured voltage Voffset - Offset voltage
A default calibration package can be loaded (in case is not wanted to perform calibration everytime). For this is needed to update default_calibration_ph array with known values before the board is program. In case the two-point calibration is not wanted, for pH calculation is used Nernst equation:
ph = [PH_ISO -((V - a) / ((2.303 * AVOGADRO * (T + 273.1))] PH_ISO - reference hydrogen ion concentration (7) V - pH channel measured voltage a - zero point tolerance (see //ZERO_POINT_TOLERANCE// parameter) AVOGADRO - Avogadro's number (8.314) T - RTD temperature
The moisture value can be also calculated in two ways. First way is to use piece-wise formulas given by manufacturer (check USE_MANUFACTURER_MOISTURE_EQ parameter. For Vegetronix may use the follow formulas (m - moisture value and Vm - moisture channel measured voltage):
|0V - 1.1V||m = 10 * Vm - 1|
|1.1V - 1.3V||m = 25 * Vm - 17.5|
|1.3V - 1.82V||m = 48.08 * Vm - 47.5|
|1.82V - 2.2V||m = 26.32 * Vm - 7.89|
Otherwise the moisture value can be calculated using transfer function for the sensor:
m =-1.18467 + 21.5371*Vm - 110.996*Vm^2 + 397.025*Vm^3 - 666.986*Vm^4 + 569.236*Vm^5 -246.005*Vm^6 + 49.4867*Vm^7 -3.37077*Vm^8
The following is a list of items needed in order to replicate this demo.
/* SSID of the access point. */ uint8_t aWifiSSID = "****"; /* Password of the access point. */ uint8_t aWifiPassword = "****"; /* IP address of the broker to publish to. */ uint8_t aMQTTBrokerIp = "****";
/* Port of the broker to publish to. */ uint8_t aMQTTBrokerPort = "1883"; /*! MQTT publisher name. */ uint8_t aMQTTPublisherName = "device_publisher"; uint8_t aMQTTTopicName = "cn0398"; uint8_t aMQTTTopic = "comm_channel"; /*! MQTT publish packet quality of service. */ #define ADI_WIFI_MQTT_PUBLISER_QOS (0u)
The program connects to a WiFi network and to a TCP MQTT broker. After receiving the SUBACK confirmation from the server, the program starts by asking the user for calibration details through MQTT publishes on cn0398 topic(default, can be changed). The messages can be answered by a publish to the comm_channel topic(default, can be changed), to which the application is subscribed. After the calibration sequence the program enters an infinite loop in which it waits for 500 ms then outputs instantaneous values of the measured temperature, pH and moisture. This data can also be seen with a subscriber to the cn0398 topic.
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
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 ADuCM_demo_cn0398.h file. Once you run the executable, Mosquitto assumes that you are running on that network.
/* SSID of the access point. */ uint8_t aWifiSSID = "****"; /* Password of the access point. */ uint8_t aWifiPassword = "****"; /* IP address of the broker to publish to. */ uint8_t aMQTTBrokerIp = "****"; /* Port of the broker to publish to. */ uint8_t aMQTTBrokerPort = "1883";
C:\MosquittoMQTT>mosquitto_sub.exe -t cn0398
This command subscribes to the topic and will display the cn0398 data. It should look similar to the image below.
C:\MosquittoMQTT>mosquitto_pub.exe -m y -t comm_channel
There are two basic ways to program the ADICUP3029 with the software for the CN0398.
Using the drag and drop method, the software is going to be a version that Analog Devices creates for testing and evaluation purposes. This is the EASIEST way to get started with the reference design
Importing the project into CrossCore is going to allow you to change parameters and customize the software to fit your needs, but will be a bit more advanced and will require you to download the CrossCore toolchain.
The software for the ADuCM3029_demo_cn0398 can be found here:
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.
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.
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.