I just bought the WIO GPS Board v1.4 05/15/2017.
I also have the Multichannel Gas Sensor v1.0, with a software update to the latest version.
When I used the multi channel gas sensor on the Groove board it worked with no issues.
Now I plug it to the Wio board, and it does not work.
It all fails on this command:
</s> gas.begin(0x04);//the default I2C address of the slave is 0x04
gas.powerOn();<e>
It seems that normal Serial is not working with this board, you have to use SerialUSB. But I tried replacing all of the Serial.print with SerialUSB print in the multichannel.cpp but that did not fix it.
Please help me get this sensor working.
This is the entire code:
[code]
#include <Wire.h>
// Read Data from Grove - Multichannel Gas Sensor
#include “MutichannelGasSensor.h”
#include <SoftwareSerial.h>
#include “MC20_Common.h”
#include “MC20_Arduino_Interface.h”
#include “MC20_GNSS.h”
#define GrovePowerPin 12
SoftwareSerial s_serial(2, 3); // TX, RX
#define sensor s_serial
#define GrovePowerPin 12
const float VRefer = 3.3; // voltage of adc reference
const int pinAdc = A0;
const unsigned char cmd_get_sensor[] =
{
0xff, 0x01, 0x86, 0x00, 0x00,
0x00, 0x00, 0x00, 0x79
};
unsigned char dataRevice[9];
int temperature;
int CO2PPM;
void setup(){
SerialUSB.begin(115200);
pinMode(GrovePowerPin, OUTPUT);
// write high to grove power pin to enable all the Grove ports,
// or only Grove D2 port is usable.
digitalWrite(GrovePowerPin, HIGH);
SerialUSB.println(“Power On”);
sensor.begin(9600);
gas.begin(0x04);//the default I2C address of the slave is 0x04
gas.powerOn();
}
void loop(){
float Vout =0;
Vout = readO2Vout();
SerialUSB.print(Vout);
SerialUSB.print(" V, Concentration of O2 is ");
SerialUSB.println(readConcentration());
if(dataRecieve())
{
SerialUSB.print("Temperature: ");
SerialUSB.print(temperature);
SerialUSB.print(" CO2: ");
SerialUSB.print(CO2PPM);
SerialUSB.println("");
}
float c;
c = gas.measure_NH3();
SerialUSB.print("The concentration of NH3 is ");
if(c>=0) SerialUSB.print(c);
else SerialUSB.print("invalid");
SerialUSB.println(" ppm");
c = gas.measure_CO();
SerialUSB.print("The concentration of CO is ");
if(c>=0) SerialUSB.print(c);
else SerialUSB.print("invalid");
SerialUSB.println(" ppm");
c = gas.measure_NO2();
SerialUSB.print("The concentration of NO2 is ");
if(c>=0) SerialUSB.print(c);
else SerialUSB.print("invalid");
SerialUSB.println(" ppm");
c = gas.measure_C3H8();
SerialUSB.print("The concentration of C3H8 is ");
if(c>=0) SerialUSB.print(c);
else SerialUSB.print("invalid");
SerialUSB.println(" ppm");
c = gas.measure_C4H10();
SerialUSB.print("The concentration of C4H10 is ");
if(c>=0) SerialUSB.print(c);
else SerialUSB.print("invalid");
SerialUSB.println(" ppm");
c = gas.measure_CH4();
SerialUSB.print("The concentration of CH4 is ");
if(c>=0) SerialUSB.print(c);
else SerialUSB.print("invalid");
SerialUSB.println(" ppm");
c = gas.measure_H2();
SerialUSB.print("The concentration of H2 is ");
if(c>=0) SerialUSB.print(c);
else SerialUSB.print("invalid");
SerialUSB.println(" ppm");
c = gas.measure_C2H5OH();
SerialUSB.print("The concentration of C2H5OH is ");
if(c>=0) SerialUSB.print(c);
else SerialUSB.print("invalid");
SerialUSB.println(" ppm");
delay(1000);
}
bool dataRecieve(void)
{
byte data[9];
int i = 0;
//transmit command data
for(i=0; i<sizeof(cmd_get_sensor); i++)
{
sensor.write(cmd_get_sensor[i]);
}
delay(10);
//begin reveiceing data
if(sensor.available())
{
while(sensor.available())
{
for(int i=0;i<9; i++)
{
data[i] = sensor.read();
}
}
}
for(int j=0; j<9; j++)
{
SerialUSB.print(data[j]);
SerialUSB.print(" ");
}
SerialUSB.println("");
if((i != 9) || (1 + (0xFF ^ (byte)(data[1] + data[2] + data[3] + data[4] + data[5] + data[6] + data[7]))) != data[8])
{
return false;
}
CO2PPM = (int)data[2] * 256 + (int)data[3];
temperature = (int)data[4] - 40;
return true;
}
float readO2Vout()
{
long sum = 0;
for(int i=0; i<32; i++)
{
sum += analogRead(pinAdc);
}
sum >>= 5;
float MeasuredVout = sum * (VRefer / 1023.0);
return MeasuredVout;
}
float readConcentration()
{
// Vout samples are with reference to 3.3V
float MeasuredVout = readO2Vout();
//float Concentration = FmultiMap(MeasuredVout, VoutArray,O2ConArray, 6);
//when its output voltage is 2.0V,
float Concentration = MeasuredVout * 0.21 / 2.0;
float Concentration_Percentage=Concentration*100;
return Concentration_Percentage;
}
[/code]