brookedot

Untitled

Jun 5th, 2025
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. // SPDX-FileCopyrightText: 2022 Limor Fried for Adafruit Industries
  2. //
  3. // SPDX-License-Identifier: MIT
  4.  
  5. #include <Arduino.h>
  6. #include "Adafruit_MAX1704X.h"
  7. #include <SensirionI2cSen66.h>
  8. #include <Wire.h>
  9. #include <Fonts/FreeSans12pt7b.h>
  10.  
  11. #include <Adafruit_GFX.h> // Core graphics library
  12. #include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
  13. #include <SPI.h>
  14.  
  15. Adafruit_ST7789 display = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
  16. SensirionI2cSen66 sensor;
  17.  
  18. GFXcanvas16 canvas(240, 135);
  19. Adafruit_MAX17048 lipo;
  20.  
  21. bool maxfound = false;
  22. bool lcfound = false;
  23.  
  24. // macro definitions
  25. // make sure that we use the proper definition of NO_ERROR
  26. #ifdef NO_ERROR
  27. #undef NO_ERROR
  28. #endif
  29. #define NO_ERROR 0
  30.  
  31.  
  32. static char errorMessage[64];
  33. static int16_t error;
  34.  
  35. void setup() {
  36. Serial.begin(115200);
  37. // while (! Serial) delay(10);
  38.  
  39. delay(100);
  40.  
  41. // turn on the TFT / I2C power supply
  42. pinMode(TFT_I2C_POWER, OUTPUT);
  43. digitalWrite(TFT_I2C_POWER, HIGH);
  44. delay(10);
  45.  
  46. display.init(135, 240); // Init ST7789 240x135
  47. display.setRotation(3);
  48. canvas.setFont(&FreeSans12pt7b);
  49. canvas.setTextColor(ST77XX_WHITE);
  50.  
  51.  
  52. if (!lipo.begin()) {
  53. Serial.println(F("Couldnt find Adafruit MAX1704X?\nMake sure a battery is plugged in!"));
  54. while (1) delay(10);
  55. }
  56. Serial.print(F("Found MAX17048"));
  57. Serial.print(F(" with Chip ID: 0x"));
  58. Serial.println(lipo.getChipID(), HEX);
  59. maxfound = true;
  60.  
  61. }
  62.  
  63. uint8_t j = 0;
  64.  
  65. void loop() {
  66.  
  67. float massConcentrationPm1p0 = 0.0;
  68. float massConcentrationPm2p5 = 0.0;
  69. float massConcentrationPm4p0 = 0.0;
  70. float massConcentrationPm10p0 = 0.0;
  71. float humidity = 0.0;
  72. float temperature = 0.0;
  73. float vocIndex = 0.0;
  74. float noxIndex = 0.0;
  75. uint16_t co2 = 0;
  76.  
  77. error = sensor.readMeasuredValues(
  78. massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
  79. massConcentrationPm10p0, humidity, temperature, vocIndex, noxIndex,
  80. co2);
  81. if (error != NO_ERROR) {
  82. Serial.print("Error trying to execute readMeasuredValues(): ");
  83. errorToString(error, errorMessage, sizeof errorMessage);
  84. Serial.println(errorMessage);
  85. return;
  86. }
  87.  
  88. if (j % 2 == 0) {
  89. canvas.fillScreen(ST77XX_BLACK);
  90. canvas.setCursor(0, 17);
  91. canvas.setTextColor(ST77XX_RED);
  92. canvas.println("Adafruit Feather");
  93. canvas.setTextColor(ST77XX_YELLOW);
  94. canvas.println("ESP32-S3 TFT Demo");
  95. canvas.setTextColor(ST77XX_GREEN);
  96. canvas.print("Battery: ");
  97. canvas.setTextColor(ST77XX_WHITE);
  98. canvas.print(lipo.cellVoltage(), 1);
  99. canvas.print(" V / ");
  100. canvas.print(lipo.cellPercent(), 0);
  101. canvas.println("%");
  102. canvas.setTextColor(ST77XX_BLUE);
  103. canvas.print("I2C: ");
  104. canvas.setTextColor(ST77XX_WHITE);
  105. for (uint8_t a=0x01; a<=0x7F; a++) {
  106. if (valid_i2c[a]) {
  107. canvas.print("0x");
  108. canvas.print(a, HEX);
  109. canvas.print(", ");
  110. }
  111. }
  112. canvas.println("");
  113. canvas.print("Buttons: ");
  114. Serial.println(digitalRead(0));
  115. Serial.println(digitalRead(1));
  116. Serial.println(digitalRead(2));
  117. if (!digitalRead(0)) {
  118. canvas.print("D0, ");
  119. }
  120. if (digitalRead(1)) {
  121. canvas.print("D1, ");
  122. }
  123. if (digitalRead(2)) {
  124. canvas.print("D2, ");
  125. }
  126. display.drawRGBBitmap(0, 0, canvas.getBuffer(), 240, 135);
  127. pinMode(TFT_BACKLITE, OUTPUT);
  128. digitalWrite(TFT_BACKLITE, HIGH);
  129. }
  130. j++;
  131. return;
  132. }
  133.  
Advertisement
Add Comment
Please, Sign In to add comment