|
| 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 <Adafruit_NeoPixel.h> |
| 8 | +#include "Adafruit_TestBed.h" |
| 9 | +#include <Adafruit_BME280.h> |
| 10 | +#include <Adafruit_ST7789.h> |
| 11 | +#include <Fonts/FreeSans12pt7b.h> |
| 12 | + |
| 13 | +Adafruit_BME280 bme; // I2C |
| 14 | +bool bmefound = false; |
| 15 | +extern Adafruit_TestBed TB; |
| 16 | + |
| 17 | +Adafruit_MAX17048 lipo; |
| 18 | +Adafruit_ST7789 display = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST); |
| 19 | + |
| 20 | +GFXcanvas16 canvas(240, 135); |
| 21 | + |
| 22 | +void setup() { |
| 23 | + Serial.begin(115200); |
| 24 | + //while (! Serial) delay(10); |
| 25 | + |
| 26 | + delay(100); |
| 27 | + |
| 28 | + TB.neopixelPin = PIN_NEOPIXEL; |
| 29 | + TB.neopixelNum = 1; |
| 30 | + TB.begin(); |
| 31 | + TB.setColor(WHITE); |
| 32 | + |
| 33 | + display.init(135, 240); // Init ST7789 240x135 |
| 34 | + display.setRotation(3); |
| 35 | + canvas.setFont(&FreeSans12pt7b); |
| 36 | + canvas.setTextColor(ST77XX_WHITE); |
| 37 | + |
| 38 | + if (!lipo.begin()) { |
| 39 | + Serial.println(F("Couldnt find Adafruit MAX17048?\nMake sure a battery is plugged in!")); |
| 40 | + while (1) delay(10); |
| 41 | + } |
| 42 | + |
| 43 | + Serial.print(F("Found MAX17048")); |
| 44 | + Serial.print(F(" with Chip ID: 0x")); |
| 45 | + Serial.println(lipo.getChipID(), HEX); |
| 46 | + |
| 47 | + if (TB.scanI2CBus(0x77)) { |
| 48 | + Serial.println("BME280 address"); |
| 49 | + |
| 50 | + unsigned status = bme.begin(); |
| 51 | + if (!status) { |
| 52 | + Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!"); |
| 53 | + Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16); |
| 54 | + Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n"); |
| 55 | + Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n"); |
| 56 | + Serial.print(" ID of 0x60 represents a BME 280.\n"); |
| 57 | + Serial.print(" ID of 0x61 represents a BME 680.\n"); |
| 58 | + return; |
| 59 | + } |
| 60 | + Serial.println("BME280 found OK"); |
| 61 | + bmefound = true; |
| 62 | + } |
| 63 | + |
| 64 | + pinMode(0, INPUT_PULLUP); |
| 65 | + pinMode(1, INPUT_PULLDOWN); |
| 66 | + pinMode(2, INPUT_PULLDOWN); |
| 67 | +} |
| 68 | + |
| 69 | +uint8_t j = 0; |
| 70 | + |
| 71 | +void loop() { |
| 72 | + Serial.println("**********************"); |
| 73 | + |
| 74 | + TB.printI2CBusScan(); |
| 75 | + |
| 76 | + if (j % 2 == 0) { |
| 77 | + canvas.fillScreen(ST77XX_BLACK); |
| 78 | + canvas.setCursor(0, 17); |
| 79 | + canvas.setTextColor(ST77XX_RED); |
| 80 | + canvas.println("Adafruit Feather"); |
| 81 | + canvas.setTextColor(ST77XX_YELLOW); |
| 82 | + canvas.println("ESP32-S2 TFT Demo"); |
| 83 | + canvas.setTextColor(ST77XX_GREEN); |
| 84 | + canvas.print("Battery: "); |
| 85 | + canvas.setTextColor(ST77XX_WHITE); |
| 86 | + canvas.print(lipo.cellVoltage(), 1); |
| 87 | + canvas.print(" V / "); |
| 88 | + canvas.print(lipo.cellPercent(), 0); |
| 89 | + canvas.println("%"); |
| 90 | + canvas.setTextColor(ST77XX_BLUE); |
| 91 | + canvas.print("I2C: "); |
| 92 | + canvas.setTextColor(ST77XX_WHITE); |
| 93 | + for (uint8_t a=0x01; a<=0x7F; a++) { |
| 94 | + if (TB.scanI2CBus(a, 0)) { |
| 95 | + canvas.print("0x"); |
| 96 | + canvas.print(a, HEX); |
| 97 | + canvas.print(", "); |
| 98 | + } |
| 99 | + } |
| 100 | + canvas.println(""); |
| 101 | + canvas.print("Buttons: "); |
| 102 | + Serial.println(digitalRead(0)); |
| 103 | + Serial.println(digitalRead(1)); |
| 104 | + Serial.println(digitalRead(2)); |
| 105 | + if (!digitalRead(0)) { |
| 106 | + canvas.print("D0, "); |
| 107 | + } |
| 108 | + if (digitalRead(1)) { |
| 109 | + canvas.print("D1, "); |
| 110 | + } |
| 111 | + if (digitalRead(2)) { |
| 112 | + canvas.print("D2, "); |
| 113 | + } |
| 114 | + display.drawRGBBitmap(0, 0, canvas.getBuffer(), 240, 135); |
| 115 | + pinMode(TFT_BACKLITE, OUTPUT); |
| 116 | + digitalWrite(TFT_BACKLITE, HIGH); |
| 117 | + } |
| 118 | + |
| 119 | + TB.setColor(TB.Wheel(j++)); |
| 120 | + delay(10); |
| 121 | + return; |
| 122 | +} |
0 commit comments