Skip to content

Instantly share code, notes, and snippets.

@ladyada
Created March 27, 2021 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ladyada/fd6dbc5a7efdc3e01468416603d38df5 to your computer and use it in GitHub Desktop.
Save ladyada/fd6dbc5a7efdc3e01468416603d38df5 to your computer and use it in GitHub Desktop.
Feather RP2040 + SPI TFT + MCP9808 Demo
#include <SPI.h>
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "Adafruit_MCP9808.h"
#include <Fonts/FreeSans18pt7b.h>
// These are 'flexible' lines that can be changed
#define TFT_CS 9
#define TFT_DC 10
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, -1);
Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();
void setup() {
//while (!Serial) delay(10);
delay(500);
Serial.begin(9600);
Serial.println("ILI + MCP Test!");
Wire1.setSDA(2);
Wire1.setSCL(3);
if (!tempsensor.begin(0x18, &Wire1)) {
Serial.println("Couldn't find MCP9808! Check your connections and verify the address is correct.");
while (1);
}
Serial.println("Found MCP9808!");
tempsensor.setResolution(3);
SPI.setSCK(18);
SPI.setTX(19);
SPI.setRX(20);
tft.begin();
tft.fillScreen(ILI9341_BLACK);
tft.setRotation(1);
tft.setFont(&FreeSans18pt7b);
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(30, 50);
tft.print("MCP9808");
tft.setCursor(30, 90);
tft.print("Temperature:");
}
void loop(void) {
tft.setCursor(30, 130);
tft.fillRect(30, 100, 150, 40, ILI9341_BLACK);
tft.print(tempsensor.readTempC(),2);
tft.print(" *C");
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment