Skip to content

Arduino C++ sketches for ESP8266 dev boards and Arduino Nanos

Notifications You must be signed in to change notification settings

kubedzero/arduino-projects

Repository files navigation

ESP8266 Monitoring Code

OTA Update

BME280 Integration

BMP280 Integration

PMS7003 Integration

  • No Adafruit library but there is https://github.com/fu-hsi/pms. According to https://learn.adafruit.com/pm25-air-quality-sensor/arduino-code though there doesn't really need to be a library, it's just softwareserial and whatever's returned from that
  • Used to be set up with the library mentioned above. Pinout from the PMS7003 was
    • PMS -> Arduino (reference direction)
    • nc (red) -> not connected
    • nc (black) -> not connected
    • rat (orange) -> not connected
    • tx (green) -> D6
    • rx (blue) -> D7 BUT not actually needed to function since we're not talking to the PMS7003
    • set (white) -> not connected
    • gnd (red) -> GND
    • vcc (purple) -> 5v or 3.3v works. HOWEVER the datasheet says "DC 5V power supply is needed because the FAN should be driven by 5V. But the high level of data pin is 3.3V. Level conversion unit should be used if the power of host MCU is 5V."
      • 2023 update: The sensor seems to work better when supplied with 5V, so I'm using the USB/5V supply and no level conversion on an Adafruit Huzzah ESP32 Feather and everything seems to work fine.
    • 2023 update: There would be times when it seemed as if no new readings were succeeding, so I changed the call to time out after 2000ms and that seems to have increased update success rate dramatically. Also, I set it so the sensors report the -16384 error value instead of the same value as before if they encounter an error, so Influx isn't filled with questionably reliable repeat readings
  • Refs

VEML6075 UV Sensor Integration

  • Bought a VEML6075 sensor from AliExpress https://www.aliexpress.com/item/32797545230.html?spm=a2g0s.9042311.0.0.5b784c4dAI9lSe for about 4 dollars. It measures UVA and UVB intensity and also calculates the UV index approximation
  • I was able to use the SparkFun VEML6075 library while the sensor's SCL pin was connected to the NodeMCU D1 pin and the SDA pin was connected to the NodeMCU D2 pin, and then two other connections for 3.3v power (5v apparently also works) and ground.
  • I was also able to use the I2C scanner https://playground.arduino.cc/Main/I2cScanner/ to confirm the sensor was recognized and on the right pins before trying the library
  • My next goal is to get this working on an arbitrary pin so that I don't have to displace the DHT22 and BME280 and PMS7003 on the other boards if I want to use this.
  • I was able to use the D1/D2 pins the way I already had for the BMx280. Instead of routing right to the BMx280 I had it go to a breadboard that allowed me to split the SDA/SCL/VCC/GND between the two sensor boards. They were both picked up completely normally, nice!

SGP30 TVOC/eCO2 Air Sensor

  • using the I2C Scanner sketch with no modifications (didn't need to change the Wire pin or anything) I see 3 I2C outputs after daisy chaining VCC/GND/SCL/SDA from the UV + BMP into the SGP. I see I2C addresses 0x10, 0x58, 0x76 and I believe 58 and 76 were there before. Good to know.
  • Going to give the Adafruit SGP30 library a shot since I'm already using Adafruit for BMP280 and BME280. Cool, I get readings with no issues. This is telling me the TVOC is 0ppb (90 when I breathed on it), raw H2 of 12047, raw ethanol of 16560, and eCO2 of around 470ppm. I found a reading website in Hawaii reporting 414ppm so it seems about right.
  • I tried the spark fun library and it reported about the same, 400-410 CO2 ppm and TVOC 0-10ppb, breathing raised it to 430ppm and 49ppb.
  • WHOA dripping some isopropanol nearby made the values go nuts, TVOC of 60000ppb and CO2 of 57000ppm. As expected, pure alcohol vapor isn't going to play nice with the readings
  • Sparkfun allows for mySensor.initAirQuality and then my sensor.measureAirQuality, pretty easy.
  • Adafruit allows for sgp.begin and then sgp.IAQmeasure()
  • I had an issue with gibberish printing out to the logs, even with the original code. Not sure what happened but I updated some libraries and restarted Arduino and then it worked fine
  • 2021Q3 Update: I got a new SGP30 from Adafruit that uses the Stemma QT JST sockets: https://learn.adafruit.com/introducing-adafruit-stemma-qt/technical-specs
    • Black is ground
    • Red is VCC
    • Blue is SDA
    • Yellow is SCL
  • 2022Q1 Update: I wanted the ESP-12 built-in LED to stop blinking every 5 seconds. I didn't have that blinking functionality programmed in, so I assumed it was coming from something else. Sure enough, Pin D4/GPIO2 is where I have the DHT22 connected, and according to https://lowvoltage.github.io/2017/07/09/Onboard-LEDs-NodeMCU-Got-Two that's the same pin used for the LED. I think what was happening was that the DHT was being queried for data, and that activity on pin D4 also triggered the LED. By changing the sketch and wiring to use pin D5 instead, I was able to avoid triggering the LED.
    • On a completely different note, I had an issue with temperature readings shooting up to 150-180 degrees celsius sometimes, and the pressure going nuts as well. Reading through https://forum.arduino.cc/t/bmp280-sensor-wrong-data-readings/513455/15 showed me that the exposed pins on the BMP280 breakout board could switch between I2C and SPI mode. I experimented with a screwdriver touching the pins and sure enough I could cause the weird behavior to occur on demand. Covering the exposed pins seems to have helped drive down the error rate.

SCD40 True CO2 Sensor

  • I bought a true CO2 sensor, so instead of the eCO2 values output by the SGP30, this is truly measuring the CO2 amount in the air. It was about $15 from AliExpress, and the equivalent sensor on Adafruit was $45
  • https://learn.adafruit.com/adafruit-scd-40-and-scd-41/arduino
  • the sample sketch outputs exactly the sort of data I'd want Co2:2030 Temperature:23.54 Humidity:66.57 but also surprised me in that it reads temperature and humidity. Very cool!
  • There also exists an SCD41 that is slightly more accurate (1% accuracy instead of 5% accuracy, for example) but I don't really need that.
  • Adafruit doesn't have their own SCD4x library so I used the manufacturer library that Adafruit references https://github.com/Sensirion/arduino-i2c-scd4x which also requires the Sensirion Core library to be installed.
  • I found that long/bad jumper cables can cause the SCD40 to either not initialize, or return false for the isDataReady function, so well-established wiring is crucial

Using the Arduino Sketch Webpage

  • The webpage output in its current state appears as the following

  • dhtHumidityPercent,dhtTemperatureC,boschHumidityPercent,boschTemperatureC,boschPressurePa,pmsPm10Standard,pmsPm25Standard,pmsPm100Standard,pmsPm10Environmental,pmsPm25Environmental,pmsPm100Environmental,vemlUVA,vemlUVB,vemlUVIndex,sgpTVOC,sgpECO2,scdCO2,scdTemperatureC,scdHumidityPercent
    -16384.00,-16384.00,44.60,27.21,102026.45,17,22,25,17,22,25,-16384.00,-16384.00,-16384.00,25,431,-16384,-16384.00,-16384.00
    

Default I2C Pins

  • I realized that I'm initializing Wire and never defining the pins, which means each board will just choose whatever pins it's configured as defaults for I2C SCL and SDA.
    • For the ESP32 Adafruit Huzzah Feather, SDA is pin 23 and marked SDA on the board, and SCL is pin 22 https://www.adafruit.com/product/3405
    • For the ESP32 from AliExpress (I chose DOIT ESP32 DEVKIT V1 in the Board Manager), there are no SDA/SCL markings on the board, but documentation and experimentation shows pin 22 is SCL and pin 21 is SDA (on either side of the RX/TX SPI pins) https://www.aliexpress.us/item/3256804701258817.html
    • For the various ESP8266 boards (I choose NodeMCU 1.0 ESP 12E in the Board Manager) SCL is D1 and SDA is D2, right next to each other
  • Note that this means a firmware build for the Feather won't work for the DOIT ESP32 because the pinout will be different. Compile and upload separately. This is easy to catch though because I think they use different USB to UART chips (Feather uses the SIL CP2104 and the DOIT uses the CP2102)

USB Drivers

LED_BUILTIN Behavior

  • Pin 13 on the Adafruit Feather is linked to the LED on the board next to the micro USB, at least according to the silkscreen. In operation on my original sketch, it is on all the time.
    • The Feather also has a constantly flashing CHG light indicating it's getting voltage from the USB port
    • The controllable LED is red
    • Looking in the pins_arduino.h with the Feather board loaded, I see LED_BUILTIN = 13 which confirms the suspicion.
  • D2 is marked on the DOIT ESP32 which seems to be GPIO2.
    • Looking in the pins_arduino.h with the DOIT board loaded, I see LED_BUILTIN = 2 which confirms the suspicion.
    • The controllable LED is blue
    • The DOIT also has a red LED that's on all the time to indicate there is power. I sharpie'd over it to dim it a bit
  • I found that with ESP32, setting the LED pin to HIGH turns on the LED, which is the opposite of ESP8266.
  • Initializing the LED pin sets it to LOW by default, so with the ESP32 code I need to add an extra line to set it to HIGH to turn it on while booting.

Compiling

  • I had an issue where I was seeing an error when compiling sketches for my Adafruit Huzzah ESP32 Feather: exec: "python": executable file not found in $PATH; Error compiling for board Adafruit ESP32 Feather. is what Arduino 1.8.19 would print out. I found a suggestion that said to open Arduino from the CLI, meaning open /Applications/Arduino.app and sure enough after that it worked fine!
    • I've never had this issue with Arduino IDE 2.x

About

Arduino C++ sketches for ESP8266 dev boards and Arduino Nanos

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages