ADataDate / pxt-airQuality

Makecode Package for the CCS811 Air Quality Sensor
MIT License
5 stars 6 forks source link

Library only works if I -first- upload an Arduino program, and -then- transfer my MakeCode program #3

Open kristianpedersen opened 5 years ago

kristianpedersen commented 5 years ago

At first when using your library, I only got one static reading showing unrealistically high eCO2 values. Often at around 65000.

I then discovered the sensor works great with Arduino IDE and Sparkfun's CCS811 library. The eCO2 values stay at around 400, and increase significantly when I breathe on the sensor.

Finally, I discovered that your library does work! If I first transfer an Arduino sketch and then transfer my code with your MakeCode library, I get expected readings. If I pull the USB plug and put it back in, the readings go back to being static again.

Here are the respective error and status codes MakeCode gives me: Successful readings: Error 0, status alternates between 144 and 152. Unsuccessful readings: Error 3, status 16

Here's an example of a log, where you can see where the USB was pulled out and put back in. As you can see, the bottom line has been repeated 741 times:

Error: 0, status: 144, ppm: 415
Error: 0, status: 152, ppm: 415
4Error: 0, status: 144, ppm: 415
Error: 0, status: 152, ppm: 410
3Error: 0, status: 144, ppm: 410
Error: 0, status: 152, ppm: 410
2Error: 0, status: 144, ppm: 410
741Error: 3, status: 16, ppm: 4349

My Arduino program:

#include <Wire.h>
#include "SparkFunCCS811.h"
CCS811 mySensor(0x5B);

void setup()
{
  Serial.begin(9600);
  Wire.begin();
  CCS811Core::status returnCode = mySensor.begin();
}

void loop()
{
  if (mySensor.dataAvailable())
  {
    mySensor.readAlgorithmResults();
    Serial.println(mySensor.getCO2());
  }
  delay(10);
}

My MakeCode program:

airQuality.setAddress(CCS811_I2C_ADDRESS.ADDR_0x5B)

basic.forever(function () {
    serial.writeLine(`Error: ${airQuality.readError()}, status: ${airQuality.readStatus()}, ppm: ${airQuality.readCo2()}`)
})

The sensor has been connected using 3.3V, GND, SDA and SCL.

kristianpedersen commented 5 years ago

Here's how I set up my micro:bit with the Arduino IDE for those who are interested: https://learn.adafruit.com/use-micro-bit-with-arduino?view=all

compie67 commented 3 years ago

great and for my students step forward. Do you have some images of how you set this up with the wirers

The sensor we got is this https://nl.aliexpress.com/item/32820864503.html?aff_platform=product&sk=b0kN9BLE&aff_trace_key=dbfc44fbef034f3e9914720a3f8477ea-1600332411778-03544-b0kN9BLE&terminal_id=572a9b244f20404bb6b192346a9d9ad7

thanks @kristianpedersen

kristianpedersen commented 3 years ago

I don't have the sensor available anymore, but here's the wiring I used:

https://learn.sparkfun.com/tutorials/ccs811-air-quality-breakout-hookup-guide?_ga=2.247983623.1628361269.1600844274-1632825319.1582815869#example-basic-reading

And here are the corresponding pins on the micro:bit

https://microbit-micropython.readthedocs.io/en/v1.0.1/pin.html