PitCJMCU8118 - sensore ambientale CJMCU8118

L'utilizzo del sensore ambientale CJMCU8118 eCO2 eTVOC Temperatura e umidità.

 

Cosa serve:

  • Sensore CJMCU8118
  • cavetti

Il Sensore CJMCU8118 - è una breakboard che al suo interno comprende due sensori il CSS811 per la rilevazione di CO2 (equivalent CO2 - eCO2) e composti volatili (equivalent total VOC eTVOC) e il sensore HDC1080 per la rilevazione di temperatura e umidità.

Codice sorgente per l'uso del sensore HDC1080:


 
/**************************************************************************************

This is example for ClosedCube HDC1080 Humidity and Temperature Sensor breakout booard

Initial Date: 13-May-2016

Hardware connections for Arduino Uno:
VDD to 3.3V DC
SCL to A5
SDA to A4
GND to common ground

Written by AA for ClosedCube

MIT License

**************************************************************************************/

#include "Wire.h"
#include "ClosedCube_HDC1080.h"

ClosedCube_HDC1080 hdc1080;

void setup()
{
	Serial.begin(9600);
	Serial.println("ClosedCube HDC1080 Arduino Test");

	// Default settings: 
	//  - Heater off
	//  - 14 bit Temperature and Humidity Measurement Resolutions
	hdc1080.begin(0x40);

	Serial.print("Manufacturer ID=0x");
	Serial.println(hdc1080.readManufacturerId(), HEX); // 0x5449 ID of Texas Instruments
	Serial.print("Device ID=0x");
	Serial.println(hdc1080.readDeviceId(), HEX); // 0x1050 ID of the device
	
	printSerialNumber();

}

void loop()
{
	Serial.print("T=");
	Serial.print(hdc1080.readTemperature());
	Serial.print("C, RH=");
	Serial.print(hdc1080.readHumidity());
	Serial.println("%");
	delay(3000);
}

void printSerialNumber() {
	Serial.print("Device Serial Number=");
	HDC1080_SerialNumber sernum = hdc1080.readSerialNumber();
	char format[12];
	sprintf(format, "%02X-%04X-%04X", sernum.serialFirst, sernum.serialMid, sernum.serialLast);
	Serial.println(format);
}

Codice sorgente per l'uso del sensore CCS811:


 /******************************************************************************
  Read basic CO2 and TVOCs

  Marshall Taylor @ SparkFun Electronics
  Nathan Seidle @ SparkFun Electronics

  April 4, 2017

  https://github.com/sparkfun/CCS811_Air_Quality_Breakout
  https://github.com/sparkfun/SparkFun_CCS811_Arduino_Library

  Read the TVOC and CO2 values from the SparkFun CSS811 breakout board

  This is the simplest example.  It throws away most error information and
  runs at the default 1 sample per second.

  A new sensor requires at 48-burn in. Once burned in a sensor requires
  20 minutes of run in before readings are considered good.

  Hardware Connections (Breakoutboard to Arduino):
  3.3V to 3.3V pin
  GND to GND pin
  SDA to A4
  SCL to A5

  Resources:
  Uses Wire.h for i2c operation

  Development environment specifics:
  Arduino IDE 1.8.1

  This code is released under the [MIT License](http://opensource.org/licenses/MIT).

  Please review the LICENSE.md file included with this example. If you have any questions
  or concerns with licensing, please contact Questo indirizzo email è protetto dagli spambots. È necessario abilitare JavaScript per vederlo..

  Distributed as-is; no warranty is given.
******************************************************************************/
#include "Wire.h"

#include "SparkFunCCS811.h" //Click here to get the library: http://librarymanager/All#SparkFun_CCS811

//#define CCS811_ADDR 0x5B //Default I2C Address
#define CCS811_ADDR 0x5A //Alternate I2C Address

CCS811 mySensor(CCS811_ADDR);

void setup()
{
  Serial.begin(9600);
  Serial.println("CCS811 Basic Example");

  Wire.begin(); //Inialize I2C Harware

  //It is recommended to check return status on .begin(), but it is not
  //required.
  CCS811Core::status returnCode = mySensor.begin();
  if (returnCode != CCS811Core::SENSOR_SUCCESS)
  {
    Serial.println(".begin() returned with an error.");
    while (1); //Hang if there was a problem.
  }
}

void loop()
{
  //Check to see if data is ready with .dataAvailable()
  if (mySensor.dataAvailable())
  {
    //If so, have the sensor read and calculate the results.
    //Get them later
    mySensor.readAlgorithmResults();

    Serial.print("CO2[");
    //Returns calculated CO2 reading
    Serial.print(mySensor.getCO2());
    Serial.print("] tVOC[");
    //Returns calculated TVOC reading
    Serial.print(mySensor.getTVOC());
    Serial.print("] millis[");
    //Simply the time since program start
    Serial.print(millis());
    Serial.print("]");
    Serial.println();
  }

  delay(10); //Don't spam the I2C bus
}


Codice sorgente per l'uso dei due sensori CJMCU8118:


/*
	Questo sketch è la combinazione dei due esempi relativi ai singoli sensori per l'utilizzo
    della breakboard comprendente entrambi
    20190330 by Zappoco
*/

/******************************************************************************
  Originale --> Example7_SensitivityDemo.ino (SparkFun_CCS811_Arduino_Library-master.zip)
  Sensitivity Demo

  Marshall Taylor @ SparkFun Electronics

  April 4, 2017

  https://github.com/sparkfun/CCS811_Air_Quality_Breakout
  https://github.com/sparkfun/SparkFun_CCS811_Arduino_Library

  Hardware Connections (Breakoutboard to Arduino):
  3.3V to 3.3V pin
  GND to GND pin
  SDA to A4
  SCL to A5

  Generates random temperature and humidity data, and uses it to compensate the CCS811.
  This just demonstrates how the algorithm responds to various compensation points.
  Use NTCCompensated or BME280Compensated for real-world examples.

  Resources:
  Uses Wire.h for i2c operation

  Development environment specifics:
  Arduino IDE 1.8.1

  This code is released under the [MIT License](http://opensource.org/licenses/MIT).

  Please review the LICENSE.md file included with this example. If you have any questions
  or concerns with licensing, please contact [email protected].

  Distributed as-is; no warranty is given.
******************************************************************************/

/**************************************************************************************

Originale --> hdc1080demo.ino (ClosedCube_HDC1080_Arduino-master.zip)

This is example for ClosedCube HDC1080 Humidity and Temperature Sensor breakout booard

Initial Date: 13-May-2016

Hardware connections for Arduino Uno:
VDD to 3.3V DC
SCL to A5
SDA to A4
GND to common ground

Written by AA for ClosedCube

MIT License

**************************************************************************************/

float temperatureVariable = 25.0; //in degrees C
float humidityVariable = 65.0; //in % relative

#include "Wire.h"
#include "ClosedCube_HDC1080.h"
#include "SparkFunCCS811.h" //Click here to get the library: http://librarymanager/All#SparkFun_CCS811

ClosedCube_HDC1080 hdc1080;

//#define CCS811_ADDR 0x5B //Default I2C Address
#define CCS811_ADDR 0x5A //Alternate I2C Address

CCS811 myCCS811(CCS811_ADDR);

void setup()
{
  Serial.begin(9600);
  Serial.println("CCS811 EnvironmentalReadings Example");
  Serial.println("ClosedCube HDC1080 Arduino Test");
  
  Wire.begin();

  //This begins the CCS811 sensor and prints error status of .begin()
  CCS811Core::status returnCode = myCCS811.begin();
  Serial.print("begin exited with: ");
  printDriverError( returnCode );
  Serial.println();

  // Default settings: 
  //  - Heater off
  //  - 14 bit Temperature and Humidity Measurement Resolutions
  hdc1080.begin(0x40);


  Serial.print("Manufacturer ID=0x");
  Serial.println(hdc1080.readManufacturerId(), HEX); // 0x5449 ID of Texas Instruments
  Serial.print("Device ID=0x");
  Serial.println(hdc1080.readDeviceId(), HEX); // 0x1050 ID of the device
  
  printSerialNumber();
  

}

void loop()
{
  Serial.println();
  //Randomize the Temperature and Humidity
  //humidityVariable = (float)random(0, 10000) / 100; //0 to 100%
  //temperatureVariable = (float)random(500, 7000) / 100; // 5C to 70C

  //humidityVariable = (float)random(4200, 4400) / 100; //0 to 100%
  //temperatureVariable = (float)random(2100, 2300) / 100; // 5C to 70C

  humidityVariable = (float)hdc1080.readHumidity();
  temperatureVariable = (float)hdc1080.readTemperature();


  Serial.println("New humidity and temperature:");
  Serial.print("  Humidity: ");
  Serial.print(humidityVariable, 2);
  Serial.println("% relative");
  Serial.print("  Temperature: ");
  Serial.print(temperatureVariable, 2);
  Serial.println(" degrees C");
  myCCS811.setEnvironmentalData(humidityVariable, temperatureVariable);

  Serial.println("Environmental data applied!");
  myCCS811.readAlgorithmResults(); //Dump a reading and wait
  delay(1000);
  //Print data points
  for ( int i = 0; i < 10; i++)
  {
    if (myCCS811.dataAvailable())
    {
      //Calling readAlgorithmResults() function updates the global tVOC and CO2 variables
      myCCS811.readAlgorithmResults();

      Serial.print("CO2[");
      Serial.print(myCCS811.getCO2());
      Serial.print("] tVOC[");
      Serial.print(myCCS811.getTVOC());
      Serial.print("] millis[");
      Serial.print(millis());
      Serial.print("]");
      Serial.println();
    }
    else if (myCCS811.checkForStatusError())
    {
      //If the CCS811 found an internal error, print it.
      printSensorError();
    }
    delay(1000); //Wait for next reading
  }
}


//printDriverError decodes the CCS811Core::status type and prints the
//type of error to the serial terminal.
//
//Save the return value of any function of type CCS811Core::status, then pass
//to this function to see what the output was.
//printDriverError decodes the CCS811Core::status type and prints the
//type of error to the serial terminal.
//
//Save the return value of any function of type CCS811Core::status, then pass
//to this function to see what the output was.
void printDriverError( CCS811Core::status errorCode )
{
  switch ( errorCode )
  {
    case CCS811Core::SENSOR_SUCCESS:
      Serial.print("SUCCESS");
      break;
    case CCS811Core::SENSOR_ID_ERROR:
      Serial.print("ID_ERROR");
      break;
    case CCS811Core::SENSOR_I2C_ERROR:
      Serial.print("I2C_ERROR");
      break;
    case CCS811Core::SENSOR_INTERNAL_ERROR:
      Serial.print("INTERNAL_ERROR");
      break;
    case CCS811Core::SENSOR_GENERIC_ERROR:
      Serial.print("GENERIC_ERROR");
      break;
    default:
      Serial.print("Unspecified error.");
  }
}

//printSensorError gets, clears, then prints the errors
//saved within the error register.
void printSensorError()
{
  uint8_t error = myCCS811.getErrorRegister();

  if ( error == 0xFF ) //comm error
  {
    Serial.println("Failed to get ERROR_ID register.");
  }
  else
  {
    Serial.print("Error: ");
    if (error & 1 << 5) Serial.print("HeaterSupply");
    if (error & 1 << 4) Serial.print("HeaterFault");
    if (error & 1 << 3) Serial.print("MaxResistance");
    if (error & 1 << 2) Serial.print("MeasModeInvalid");
    if (error & 1 << 1) Serial.print("ReadRegInvalid");
    if (error & 1 << 0) Serial.print("MsgInvalid");
    Serial.println();
  }
}

void printSerialNumber() {
  Serial.print("Device Serial Number=");
  HDC1080_SerialNumber sernum = hdc1080.readSerialNumber();
  char format[12];
  sprintf(format, "%02X-%04X-%04X", sernum.serialFirst, sernum.serialMid, sernum.serialLast);
  Serial.println(format);
}


 

Scarica tutto quello che serve: