Iwo terminal + MiCS6814 problem

Hi ! I tried to connect with my iwo terminal and MiCS6814 gas sensors.
I’m very new in this field so I apologize in advance if it’s too basic question.

When I upload the example code, I can see the right results in the serial monitor.
But after I transferred this code to show the result in the iwo terminal monitor, the value is different.

The code below is the code of my work (The first two values (CO, NO2) were not correct, so I didn’t finish the code for the rest of them.)

=====================Arduino code===========================

#include <TFT_eSPI.h>
#include “SparkFunBME280.h”

#include <Wire.h>
#include <MiCS6814-I2C.h>

BME280 mySensor;

MiCS6814 sensor;
bool sensorConnected;

TFT_eSPI tft;
TFT_eSprite spr = TFT_eSprite(&tft); //sprite

void setup() {

Serial.begin(115200);
  tft.begin();

tft.setRotation(3);
delay(3000);
Wire.begin();

if (mySensor.beginI2C() == false) //Begin communication over I2C
{
Serial.println(“The sensor did not respond. Please check wiring.”);
while(1); //Freeze

// Connect to sensor using default I2C address (0x04)
// Alternatively the address can be passed to begin(addr)
sensorConnected = sensor.begin();

Serial.begin(115200);
if (sensorConnected == true) {
// Print status message
Serial.println(“Connected to MiCS-6814 sensor”);

// Turn heater element on
sensor.powerOn();

// Print header for live values
Serial.println("Current concentrations:");
Serial.println("CO\tNO2\tNH3\tC3H8\tC4H10\tCH4\tH2\tC2H5OH");

} else {
// Print error message on failed connection
Serial.println(“Couldn’t connect to MiCS-6814 sensor”);
}

}

tft.fillScreen(TFT_BLACK);
tft.setFreeFont(&FreeSansBoldOblique18pt7b);
tft.setTextColor(TFT_WHITE);
tft.drawString(“Air Quality”, 70, 10 , 1);
//Line
for (int8_t line_index = 0; line_index < 5 ; line_index++)
{
tft.drawLine(0, 50 + line_index, tft.width(), 50 + line_index, TFT_GREEN);
}
//Humid%
tft.drawRoundRect(5, 60, ((tft.width() / 2) - 20)/2 , (tft.height() - 65) / 2 , 10, TFT_WHITE); // L1
//Pressure hPa
tft.drawRoundRect(((tft.width() / 2) - 20)/2 +10 , 60, ((tft.width() / 2) - 20)/2 , (tft.height() - 65) / 2 , 10, TFT_WHITE); // L1
//Alt m
tft.drawRoundRect(5 , (tft.height() / 2) + 30, ((tft.width() / 2) - 20)/2 , (tft.height() - 65) / 2 , 10, TFT_WHITE); // s1
//Temp C
tft.drawRoundRect(((tft.width() / 2) - 20)/2 +10 , (tft.height() / 2) + 30, ((tft.width() / 2) - 20)/2 , (tft.height() - 65) / 2 , 10, TFT_WHITE); // s1

//Multichannel gas
tft.drawRoundRect((tft.width() / 2) -5 , 60, (tft.width() / 2) , (tft.height() - 65) , 10, TFT_WHITE); // s4

//Humid%
tft.setFreeFont(&FreeSansBoldOblique9pt7b);
tft.setTextColor(TFT_RED);
tft.drawString(“Humid”, 7 , 65 , 1);
tft.setTextColor(TFT_GREEN);
tft.drawString("%", 55, 118, 1);

//Press hPa
tft.setFreeFont(&FreeSansBoldOblique9pt7b);
tft.setTextColor(TFT_RED);
tft.drawString(“Press”, ((tft.width() / 2) - 20)/2 +10 , 65 , 1);
tft.setTextColor(TFT_GREEN);
tft.drawString(“hPa”, 110, 118, 1);

//Alt ft
tft.setFreeFont(&FreeSansBoldOblique9pt7b);
tft.setTextColor(TFT_RED) ;
tft.drawString(“Alt”, 7 , 155 , 1);
tft.setTextColor(TFT_GREEN);
tft.drawString(“ft”, 55, 210, 1);
//Temp F
tft.setFreeFont(&FreeSansBoldOblique9pt7b);
tft.setTextColor(TFT_RED) ;
tft.drawString(“Temp”, ((tft.width() / 2) - 20)/2 +10 , 155 , 1);
tft.setTextColor(TFT_GREEN);
tft.drawString(“F”, 130, 210, 1);

//CO
tft.setFreeFont(&FreeSansBoldOblique9pt7b);
tft.setTextColor(TFT_RED) ;
tft.drawString(“CO”, (tft.width() / 2) , 65 , 1);
//NO2
tft.setFreeFont(&FreeSansBoldOblique9pt7b);
tft.setTextColor(TFT_RED) ;
tft.drawString(“NO2”, (tft.width() / 2)+50 , 65 , 1);
//NH3
tft.setFreeFont(&FreeSansBoldOblique9pt7b);
tft.setTextColor(TFT_RED) ;
tft.drawString(“NH3”, (tft.width() / 2)+100 , 65 , 1);
//C4H10
tft.setFreeFont(&FreeSansBoldOblique9pt7b);
tft.setTextColor(TFT_RED) ;
tft.drawString(“C4H10”, (tft.width() / 2) , 65+50 , 1);
//H2
tft.setFreeFont(&FreeSansBoldOblique9pt7b);
tft.setTextColor(TFT_RED) ;
tft.drawString(“H2”, (tft.width() / 2)+75 , 65+50 , 1);
//CH4
tft.setFreeFont(&FreeSansBoldOblique9pt7b);
tft.setTextColor(TFT_RED) ;
tft.drawString(“CH4”, (tft.width() / 2)+110 , 65+50 , 1);
//C3H8
tft.setFreeFont(&FreeSansBoldOblique9pt7b);
tft.setTextColor(TFT_RED) ;
tft.drawString(“C3H8”, (tft.width() / 2) , 65+100 , 1);
//C2H5OH
tft.setFreeFont(&FreeSansBoldOblique9pt7b);
tft.setTextColor(TFT_RED) ;
tft.drawString(“C2H5OH”, (tft.width() / 2)+70 , 65+100 , 1);

}
void loop() {

int h = mySensor.readFloatHumidity();

Serial.print("Humidity: ");
Serial.print(mySensor.readFloatHumidity(), 0);

spr.createSprite(40, 30);
spr.fillSprite(TFT_BLACK);
spr.setFreeFont(&FreeSansBoldOblique9pt7b);
spr.setTextColor(TFT_WHITE);
spr.drawNumber(h, 0, 0, 1);
spr.pushSprite(15, 90);
spr.deleteSprite();

int p = mySensor.readFloatPressure();
Serial.print(" Pressure: ");
Serial.print(mySensor.readFloatPressure(), 0);

spr.createSprite(40, 30);

spr.setFreeFont(&FreeSansBoldOblique9pt7b);
spr.setTextColor(TFT_WHITE);
spr.drawNumber(p, 0, 0, 1);
spr.setTextColor(TFT_GREEN);
spr.pushSprite(90, 90);
spr.deleteSprite();

int a = mySensor.readFloatAltitudeFeet();
Serial.print(" Alt: ");
//Serial.print(mySensor.readFloatAltitudeMeters(), 1);
Serial.print(mySensor.readFloatAltitudeFeet(), 1);

spr.createSprite(40, 30);

spr.setFreeFont(&FreeSansBoldOblique9pt7b);
spr.setTextColor(TFT_WHITE);
spr.drawNumber(a, 0, 0, 1);
spr.setTextColor(TFT_GREEN);
spr.pushSprite(15 , 185);
spr.deleteSprite();

int t = mySensor.readTempF();
Serial.print(" Temp: ");
//Serial.print(mySensor.readTempC(), 2);
Serial.print(mySensor.readTempF(), 2);

spr.createSprite(40, 30);

spr.setFreeFont(&FreeSansBoldOblique9pt7b);
spr.setTextColor(TFT_WHITE);
spr.drawNumber(t, 0, 0, 1);
spr.setTextColor(TFT_GREEN);
spr.pushSprite(90 , 185);
spr.deleteSprite();

int co = sensor.measureCO();

Serial.print(sensor.measureCO());

spr.createSprite(40, 30);
spr.fillSprite(TFT_BLACK);
spr.setFreeFont(&FreeSansBoldOblique9pt7b);
spr.setTextColor(TFT_WHITE);
spr.drawNumber(co, 0, 0, 1);
spr.pushSprite((tft.width() / 2), 85);
spr.deleteSprite();

int no2 = sensor.measureNO2();

Serial.print(sensor.measureCO());

spr.createSprite(40, 30);
spr.fillSprite(TFT_BLACK);
spr.setFreeFont(&FreeSansBoldOblique9pt7b);
spr.setTextColor(TFT_WHITE);
spr.drawNumber(no2, 0, 0, 1);
spr.pushSprite((tft.width() / 2)+50, 85);
spr.deleteSprite();

Serial.print(sensor.measureNO2());
Serial.print("\t");
Serial.print(sensor.measureNH3());
Serial.print("\t");
Serial.print(sensor.measureC3H8());
Serial.print("\t");
Serial.print(sensor.measureC4H10());
Serial.print("\t");
Serial.print(sensor.measureCH4());
Serial.print("\t");
Serial.print(sensor.measureH2());
Serial.print("\t");
Serial.println(sensor.measureC2H5OH());

}

========================================================

display shows like this.

And the example code of MiCS sensor

/**

  • ReadGases
  • Continuously reads the gas measurements in ppm from
  • the attached MiCS-6814 sensor through I2C.
  • MIT License
  • Copyright © 2018 Nis Wechselberg
  • Permission is hereby granted, free of charge, to any person obtaining a copy
  • of this software and associated documentation files (the “Software”), to deal
  • in the Software without restriction, including without limitation the rights
  • to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  • copies of the Software, and to permit persons to whom the Software is
  • furnished to do so, subject to the following conditions:
  • The above copyright notice and this permission notice shall be included in all
  • copies or substantial portions of the Software.
  • THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  • IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  • FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  • AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  • LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  • OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  • SOFTWARE.
    */

#include <MiCS6814-I2C.h>

MiCS6814 sensor;
bool sensorConnected;

void setup() {
// Initialize serial connection
Serial.begin(115200);

// Connect to sensor using default I2C address (0x04)
// Alternatively the address can be passed to begin(addr)
sensorConnected = sensor.begin();

if (sensorConnected == true) {
// Print status message
Serial.println(“Connected to MiCS-6814 sensor”);

// Turn heater element on
sensor.powerOn();

// Print header for live values
Serial.println("Current concentrations:");
Serial.println("CO\tNO2\tNH3\tC3H8\tC4H10\tCH4\tH2\tC2H5OH");

} else {
// Print error message on failed connection
Serial.println(“Couldn’t connect to MiCS-6814 sensor”);
}
}

void loop() {
if (sensorConnected) {
// Print live values
Serial.print(sensor.measureCO());
Serial.print("\t");
Serial.print(sensor.measureNO2());
Serial.print("\t");
Serial.print(sensor.measureNH3());
Serial.print("\t");
Serial.print(sensor.measureC3H8());
Serial.print("\t");
Serial.print(sensor.measureC4H10());
Serial.print("\t");
Serial.print(sensor.measureCH4());
Serial.print("\t");
Serial.print(sensor.measureH2());
Serial.print("\t");
Serial.println(sensor.measureC2H5OH());
}

// Wait a small amount of time
delay(1000);
}

And the serial monitor when I run the code above (I put it in text because I’m not allowed to attach more than one image…)

23:31:32.002 -> 4.51 0.12 0.85 798.04 529.65 699.74 0.76 1.68
23:31:32.997 -> 4.51 0.12 0.85 798.04 529.65 699.74 0.76 1.68
23:31:34.039 -> 4.51 0.12 0.85 798.04 529.65 699.74 0.76 1.68

In conclusion, Why the results between iwo terminal monitor and serial monitor are different?
How can I fix it?

Many many thanks in advance.

Hi, I think the problem is that the function ‘sensor.measureCO()’ returns a value of type float but you assign it to the variable co of type int.
You can convert the returned value of type float to a String and write this string to the desired position.
float co = sensor.measureCO();
String coString = String(co,2); // two decimal places