Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 /** 00002 * @file main.cpp 00003 * @brief Main file for the CN0357-example project 00004 * @author Analog Devices Inc. 00005 * 00006 * For support please go to: 00007 * Github: https://github.com/analogdevicesinc/mbed-adi 00008 * Support: https://ez.analog.com/community/linux-device-drivers/microcontroller-no-os-drivers 00009 * Product: www.analog.com/EVAL-CN0357-ARDZ 00010 * More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all 00011 00012 ******************************************************************************** 00013 * Copyright 2016(c) Analog Devices, Inc. 00014 * 00015 * All rights reserved. 00016 * 00017 * Redistribution and use in source and binary forms, with or without 00018 * modification, are permitted provided that the following conditions are met: 00019 * - Redistributions of source code must retain the above copyright 00020 * notice, this list of conditions and the following disclaimer. 00021 * - Redistributions in binary form must reproduce the above copyright 00022 * notice, this list of conditions and the following disclaimer in 00023 * the documentation and/or other materials provided with the 00024 * distribution. 00025 * - Neither the name of Analog Devices, Inc. nor the names of its 00026 * contributors may be used to endorse or promote products derived 00027 * from this software without specific prior written permission. 00028 * - The use of this software may or may not infringe the patent rights 00029 * of one or more patent holders. This license does not release you 00030 * from the requirement that you obtain separate licenses from these 00031 * patent holders to use this software. 00032 * - Use of the software either in source or binary form, must be run 00033 * on or directly connected to an Analog Devices Inc. component. 00034 * 00035 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR 00036 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 00037 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00038 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, 00039 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00040 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR 00041 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00042 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00043 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00044 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00045 * 00046 ********************************************************************************/ 00047 #include "mbed.h" 00048 #include "CN0357.h" 00049 00050 /** @mainpage 00051 * CN0357 single-supply, low noise, portable gas detector circuit using an 00052 * electrochemical sensor. The Alphasense CO-AX carbon monoxide sensor is used 00053 * in this example. Electrochemical sensors offer several advantages for 00054 * instruments that detect or measure the concentration of many toxic gases. 00055 * Most sensors are gas specific and have usable resolutions under one part per 00056 * million (ppm) of gas concentration. 00057 * 00058 * EVAL-CN0357 example program for MBED platforms. To achieve connection between 00059 * the shield and the ST Nucleo, the following connections need to be made: 00060 * 00061 * - ICSP pin 1 -> pin 12 of the Arduino header 00062 * - ICSP pin 3 -> pin 13 of the Arduino header 00063 * - ICSP pin 4 -> pin 11 of the Arduino header 00064 * - if VIN is not supplied, 5V to VIN 00065 * 00066 * @page CN0357 CN0357 Analog Devices wiki page 00067 * @brief link-> 00068 * https://wiki.analog.com/resources/eval/user-guides/eval-adicup360/hardware/cn0357 00069 * @page AD7790 AD7790 datasheet 00070 * @brief link -> 00071 * http://www.analog.com/media/en/technical-documentation/data-sheets/AD7790.pdf 00072 * @page AD5270 AD5270 datasheet 00073 * @brief link -> 00074 * http://www.analog.com/media/en/technical-documentation/data-sheets/AD5270_5271.pdf 00075 * 00076 */ 00077 const float SENSOR_RANGE = 2000; ///< gas sensor range in PPM 00078 const float SENSOR_SENSITIVITY = (65 * pow(10, -9)); ///< gas sensor sensitivity in A/ppm - 65 nA/ppm 00079 00080 Serial pc(USBTX, USBRX); ///< Serial interface to the pc 00081 00082 /** 00083 @brief Displays CN0357 circuit readings and data to the UART 00084 00085 @param ui16Data - ADC data register value to be displayed 00086 @param fData1 - ADC input voltage reading to be displayed 00087 @param fdata2 - Gas Concentration reading to be displayed 00088 00089 **/ 00090 void display_data(uint8_t ui8Status_Reg, uint16_t ui16Data, float fData1, float fdata2) 00091 { 00092 pc.printf("\r\nStatus Register value: 0x%x", ui8Status_Reg); 00093 pc.printf("\r\nADC Data Register Value = %#08x", ui16Data); /** Send valid ADC data register value*/ 00094 pc.printf("\r\nADC Input Voltage input = %f V", fData1); /** Send valid voltage input value */ 00095 pc.printf("\r\nGas Concentration = %f PPM", fdata2); /** Send valid gas concentration value */ 00096 00097 pc.printf("\r\n"); 00098 } 00099 00100 /** 00101 * Project entry-point - initializes the CN0357 shield, reads the data when the ADC is ready and outputs the sensor 00102 * value in PPM 00103 */ 00104 00105 #define SINGLE_CONVERSION 00106 //#define CONTINOUS_CONVERSION 00107 00108 int main() 00109 { 00110 /* Main variables */ 00111 CN0357 cn0357; 00112 uint8_t ui8Status_Reg = 0; 00113 #ifdef SINGLE_CONVERSION 00114 cn0357.init(SENSOR_RANGE, SENSOR_SENSITIVITY); 00115 #elif defined CONTINOUS_CONVERSION 00116 cn0357.init(SENSOR_RANGE, SENSOR_SENSITIVITY, CN0357::INTERNAL_AD7790, 0x00, 0x07); 00117 #else 00118 #error define SINGLE_CONVERSION or CONTINOUS_CONVERSION, but not both 00119 #endif 00120 00121 00122 /* Infinite loop */ 00123 while (1) { 00124 wait_ms(1000); 00125 #ifdef CONTINOUS_CONVERSION 00126 ui8Status_Reg = cn0357.read_adc_status(); // Read ADC Status Register // 00127 00128 if (ui8Status_Reg != 0x08) { // Checks if ADC data is available 00129 pc.printf("\r\nStatus Register value: 0x%x", ui8Status_Reg); 00130 } else 00131 #endif 00132 { 00133 uint16_t ui16Adcdata = cn0357.read_sensor(); 00134 float fAdcVoltage = cn0357.data_to_voltage(ui16Adcdata); // Convert ADC data to voltage 00135 float fConcentration = cn0357.calc_ppm(fAdcVoltage); // Convert voltage to Gas concentration 00136 display_data(ui8Status_Reg, ui16Adcdata, fAdcVoltage, fConcentration); // Display data thru UART 00137 } 00138 } 00139 00140 00141 /* Infinite loop, never returns. */ 00142 } 00143
Generated on Tue Jul 12 2022 17:59:52 by
1.7.2
CN0357 - Toxic gas measurement
CN0216 - Weight Scale