Add libraries, picocalc notes.

This commit is contained in:
2025-04-01 18:28:52 -07:00
parent 1c3052c977
commit e77a69ce91
598 changed files with 475037 additions and 0 deletions

View File

@@ -0,0 +1,135 @@
// Diagnostic test for the displayed colour order
//
// Written by Bodmer 17/2/19 for the TFT_eSPI library:
// https://github.com/Bodmer/TFT_eSPI
/*
Different hardware manufacturers use different colour order
configurations at the hardware level. This may result in
incorrect colours being displayed.
Incorrectly displayed colours could also be the result of
using the wrong display driver in the library setup file.
Typically displays have a control register (MADCTL) that can
be used to set the Red Green Blue (RGB) colour order to RGB
or BRG so that red and blue are swapped on the display.
This control register is also used to manage the display
rotation and coordinate mirroring. The control register
typically has 8 bits, for the ILI9341 these are:
Bit Function
7 Mirror Y coordinate (row address order)
6 Mirror X coordinate (column address order)
5 Row/column exchange (for rotation)
4 Refresh direction (top to bottom or bottom to top in portrait orientation)
3 RGB order (swaps red and blue)
2 Refresh direction (top to bottom or bottom to top in landscape orientation)
1 Not used
0 Not used
The control register bits can be written with this example command sequence:
tft.writecommand(TFT_MADCTL);
tft.writedata(0x48); // Bits 6 and 3 set
0x48 is the default value for ILI9341 (0xA8 for ESP32 M5STACK)
in rotation 0 orientation.
Another control register can be used to "invert" colours,
this swaps black and white as well as other colours (e.g.
green to magenta, red to cyan, blue to yellow).
To invert colours insert this line after tft.init() or tft.begin():
tft.invertDisplay( invert ); // Where invert is true or false
*/
#include <SPI.h>
#include <TFT_eSPI.h> // Hardware-specific library
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
void setup(void) {
tft.init();
tft.fillScreen(TFT_BLACK);
tft.drawRect(0, 0, tft.width(), tft.height(), TFT_GREEN);
// Set "cursor" at top left corner of display (0,0) and select font 4
tft.setCursor(0, 4, 4);
// Set the font colour to be white with a black background
tft.setTextColor(TFT_WHITE);
// We can now plot text on screen using the "print" class
tft.println(" Initialised default\n");
tft.println(" White text");
tft.setTextColor(TFT_RED);
tft.println(" Red text");
tft.setTextColor(TFT_GREEN);
tft.println(" Green text");
tft.setTextColor(TFT_BLUE);
tft.println(" Blue text");
delay(5000);
}
void loop() {
tft.invertDisplay( false ); // Where i is true or false
tft.fillScreen(TFT_BLACK);
tft.drawRect(0, 0, tft.width(), tft.height(), TFT_GREEN);
tft.setCursor(0, 4, 4);
tft.setTextColor(TFT_WHITE);
tft.println(" Invert OFF\n");
tft.println(" White text");
tft.setTextColor(TFT_RED);
tft.println(" Red text");
tft.setTextColor(TFT_GREEN);
tft.println(" Green text");
tft.setTextColor(TFT_BLUE);
tft.println(" Blue text");
delay(5000);
// Binary inversion of colours
tft.invertDisplay( true ); // Where i is true or false
tft.fillScreen(TFT_BLACK);
tft.drawRect(0, 0, tft.width(), tft.height(), TFT_GREEN);
tft.setCursor(0, 4, 4);
tft.setTextColor(TFT_WHITE);
tft.println(" Invert ON\n");
tft.println(" White text");
tft.setTextColor(TFT_RED);
tft.println(" Red text");
tft.setTextColor(TFT_GREEN);
tft.println(" Green text");
tft.setTextColor(TFT_BLUE);
tft.println(" Blue text");
delay(5000);
}

View File

@@ -0,0 +1,188 @@
/*
This sketch reads the user setup information from the processor via the Serial Port
It is a support and diagnostic sketch for the TFT_eSPI library:
https://github.com/Bodmer/TFT_eSPI
The output is essentially a copy of the User_Setep configuration so can be used to
verify the correct settings are being picked up by the compiler.
If support is needed the output can be cut and pasted into an Arduino Forum post and
already includes the formatting [code]...[/code] markups.
Written by Bodmer 9/4/18
*/
//>>>>> Note: STM32 pin references above D15 may not reflect board markings <<<<<
#include <SPI.h>
#include <TFT_eSPI.h> // Graphics library
TFT_eSPI tft = TFT_eSPI(); // Invoke library
#ifdef ARDUINO_ARCH_ESP8266
ADC_MODE(ADC_VCC); // Read the supply voltage
#endif
setup_t user; // The library defines the type "setup_t" as a struct
// Calling tft.getSetup(user) populates it with the settings
//------------------------------------------------------------------------------------------
void setup() {
// Use serial port
Serial.begin(115200);
// Initialise the TFT screen
tft.init();
}
//------------------------------------------------------------------------------------------
void loop(void) {
tft.getSetup(user); //
Serial.print("\n[code]\n");
Serial.print ("TFT_eSPI ver = "); Serial.println(user.version);
printProcessorName();
#if defined (ESP32) || defined (ARDUINO_ARCH_ESP8266)
if (user.esp < 0x32F000 || user.esp > 0x32FFFF) { Serial.print("Frequency = "); Serial.print(ESP.getCpuFreqMHz());Serial.println("MHz"); }
#endif
#ifdef ARDUINO_ARCH_ESP8266
Serial.print("Voltage = "); Serial.print(ESP.getVcc() / 918.0); Serial.println("V"); // 918 empirically determined
#endif
Serial.print("Transactions = "); Serial.println((user.trans == 1) ? "Yes" : "No");
Serial.print("Interface = "); Serial.println((user.serial == 1) ? "SPI" : "Parallel");
#ifdef ARDUINO_ARCH_ESP8266
if (user.serial == 1){ Serial.print("SPI overlap = "); Serial.println((user.overlap == 1) ? "Yes\n" : "No\n"); }
#endif
if (user.tft_driver != 0xE9D) // For ePaper displays the size is defined in the sketch
{
Serial.print("Display driver = "); Serial.println(user.tft_driver, HEX); // Hexadecimal code
Serial.print("Display width = "); Serial.println(user.tft_width); // Rotation 0 width and height
Serial.print("Display height = "); Serial.println(user.tft_height);
Serial.println();
}
else if (user.tft_driver == 0xE9D) Serial.println("Display driver = ePaper\n");
if (user.r0_x_offset != 0) { Serial.print("R0 x offset = "); Serial.println(user.r0_x_offset); } // Offsets, not all used yet
if (user.r0_y_offset != 0) { Serial.print("R0 y offset = "); Serial.println(user.r0_y_offset); }
if (user.r1_x_offset != 0) { Serial.print("R1 x offset = "); Serial.println(user.r1_x_offset); }
if (user.r1_y_offset != 0) { Serial.print("R1 y offset = "); Serial.println(user.r1_y_offset); }
if (user.r2_x_offset != 0) { Serial.print("R2 x offset = "); Serial.println(user.r2_x_offset); }
if (user.r2_y_offset != 0) { Serial.print("R2 y offset = "); Serial.println(user.r2_y_offset); }
if (user.r3_x_offset != 0) { Serial.print("R3 x offset = "); Serial.println(user.r3_x_offset); }
if (user.r3_y_offset != 0) { Serial.print("R3 y offset = "); Serial.println(user.r3_y_offset); }
if (user.pin_tft_mosi != -1) { Serial.print("MOSI = "); Serial.print("GPIO "); Serial.println(getPinName(user.pin_tft_mosi)); }
if (user.pin_tft_miso != -1) { Serial.print("MISO = "); Serial.print("GPIO "); Serial.println(getPinName(user.pin_tft_miso)); }
if (user.pin_tft_clk != -1) { Serial.print("SCK = "); Serial.print("GPIO "); Serial.println(getPinName(user.pin_tft_clk)); }
#ifdef ARDUINO_ARCH_ESP8266
if (user.overlap == true)
{
Serial.println("Overlap selected, following pins MUST be used:");
Serial.println("MOSI = SD1 (GPIO 8)");
Serial.println("MISO = SD0 (GPIO 7)");
Serial.println("SCK = CLK (GPIO 6)");
Serial.println("TFT_CS = D3 (GPIO 0)\n");
Serial.println("TFT_DC and TFT_RST pins can be user defined");
}
#endif
String pinNameRef = "GPIO ";
#ifdef ARDUINO_ARCH_ESP8266
pinNameRef = "PIN_D";
#endif
if (user.esp == 0x32F) {
Serial.println("\n>>>>> Note: STM32 pin references above D15 may not reflect board markings <<<<<");
pinNameRef = "D";
}
if (user.pin_tft_cs != -1) { Serial.print("TFT_CS = " + pinNameRef); Serial.println(getPinName(user.pin_tft_cs)); }
if (user.pin_tft_dc != -1) { Serial.print("TFT_DC = " + pinNameRef); Serial.println(getPinName(user.pin_tft_dc)); }
if (user.pin_tft_rst!= -1) { Serial.print("TFT_RST = " + pinNameRef); Serial.println(getPinName(user.pin_tft_rst)); }
if (user.pin_tch_cs != -1) { Serial.print("TOUCH_CS = " + pinNameRef); Serial.println(getPinName(user.pin_tch_cs)); }
if (user.pin_tft_wr != -1) { Serial.print("TFT_WR = " + pinNameRef); Serial.println(getPinName(user.pin_tft_wr)); }
if (user.pin_tft_rd != -1) { Serial.print("TFT_RD = " + pinNameRef); Serial.println(getPinName(user.pin_tft_rd)); }
if (user.pin_tft_d0 != -1) { Serial.print("\nTFT_D0 = " + pinNameRef); Serial.println(getPinName(user.pin_tft_d0)); }
if (user.pin_tft_d1 != -1) { Serial.print("TFT_D1 = " + pinNameRef); Serial.println(getPinName(user.pin_tft_d1)); }
if (user.pin_tft_d2 != -1) { Serial.print("TFT_D2 = " + pinNameRef); Serial.println(getPinName(user.pin_tft_d2)); }
if (user.pin_tft_d3 != -1) { Serial.print("TFT_D3 = " + pinNameRef); Serial.println(getPinName(user.pin_tft_d3)); }
if (user.pin_tft_d4 != -1) { Serial.print("TFT_D4 = " + pinNameRef); Serial.println(getPinName(user.pin_tft_d4)); }
if (user.pin_tft_d5 != -1) { Serial.print("TFT_D5 = " + pinNameRef); Serial.println(getPinName(user.pin_tft_d5)); }
if (user.pin_tft_d6 != -1) { Serial.print("TFT_D6 = " + pinNameRef); Serial.println(getPinName(user.pin_tft_d6)); }
if (user.pin_tft_d7 != -1) { Serial.print("TFT_D7 = " + pinNameRef); Serial.println(getPinName(user.pin_tft_d7)); }
#if defined (TFT_BL)
Serial.print("\nTFT_BL = " + pinNameRef); Serial.println(getPinName(user.pin_tft_led));
#if defined (TFT_BACKLIGHT_ON)
Serial.print("TFT_BACKLIGHT_ON = "); Serial.println(user.pin_tft_led_on == HIGH ? "HIGH" : "LOW");
#endif
#endif
Serial.println();
uint16_t fonts = tft.fontsLoaded();
if (fonts & (1 << 1)) Serial.print("Font GLCD loaded\n");
if (fonts & (1 << 2)) Serial.print("Font 2 loaded\n");
if (fonts & (1 << 4)) Serial.print("Font 4 loaded\n");
if (fonts & (1 << 6)) Serial.print("Font 6 loaded\n");
if (fonts & (1 << 7)) Serial.print("Font 7 loaded\n");
if (fonts & (1 << 9)) Serial.print("Font 8N loaded\n");
else
if (fonts & (1 << 8)) Serial.print("Font 8 loaded\n");
if (fonts & (1 << 15)) Serial.print("Smooth font enabled\n");
Serial.print("\n");
if (user.serial==1) { Serial.print("Display SPI frequency = "); Serial.println(user.tft_spi_freq/10.0); }
if (user.pin_tch_cs != -1) { Serial.print("Touch SPI frequency = "); Serial.println(user.tch_spi_freq/10.0); }
Serial.println("[/code]");
delay(3000);
}
void printProcessorName(void)
{
Serial.print("Processor = ");
if ( user.esp == 0x8266) Serial.println("ESP8266");
if ( user.esp == 0x32) Serial.println("ESP32");
if ( user.esp == 0x32F) Serial.println("STM32");
if ( user.esp == 0x2040) Serial.println("RP2040");
if ( user.esp == 0x0000) Serial.println("Generic");
}
// Get pin name
int8_t getPinName(int8_t pin)
{
// For ESP32 and RP2040 pin labels on boards use the GPIO number
if (user.esp == 0x32 || user.esp == 0x2040) return pin;
if (user.esp == 0x8266) {
// For ESP8266 the pin labels are not the same as the GPIO number
// These are for the NodeMCU pin definitions:
// GPIO Dxx
if (pin == 16) return 0;
if (pin == 5) return 1;
if (pin == 4) return 2;
if (pin == 0) return 3;
if (pin == 2) return 4;
if (pin == 14) return 5;
if (pin == 12) return 6;
if (pin == 13) return 7;
if (pin == 15) return 8;
if (pin == 3) return 9;
if (pin == 1) return 10;
if (pin == 9) return 11;
if (pin == 10) return 12;
}
if (user.esp == 0x32F) return pin;
return pin; // Invalid pin
}

View File

@@ -0,0 +1,37 @@
// Walking 1 write and read pixel test
#include <TFT_eSPI.h>
#include <SPI.h>
#define TDELAY 500
TFT_eSPI tft = TFT_eSPI();
void setup() {
Serial.begin(115200);
tft.init();
tft.fillScreen(0xF81F);
}
void loop() {
static uint32_t wr = 1;
static uint32_t rd = 0xFFFFFFFF;
delay(TDELAY);
tft.drawPixel(30,30,wr);
Serial.print(" Pixel value written = ");Serial.println(wr,HEX);
rd = tft.readPixel(30,30);
Serial.print(" Pixel value read = ");Serial.println(rd,HEX);
if (rd!=wr) {
Serial.println(" ERROR ^^^^");
//while(1) yield();
}
else Serial.println(" PASS ");
// Walking 1 test
wr = wr<<1;
if (wr >= 0x10000) wr = 1;
}

View File

@@ -0,0 +1,49 @@
// This sketch is to test the touch controller, nothing is displayed
// on the TFT. The TFT_eSPI library must be configured to suit your
// pins used. Make sure both the touch chip select and the TFT chip
// select are correctly defined to avoid SPI bus contention.
// Make sure you have defined a pin for the touch controller chip
// select line in the user setup file or you will see "no member"
// compile errors for the touch functions!
// It is a support and diagnostic sketch for the TFT_eSPI library:
// https://github.com/Bodmer/TFT_eSPI
// The "raw" (unprocessed) touch sensor outputs are sent to the
// serial port. Touching the screen should show changes to the x, y
// and z values. x and y are raw ADC readings, not pixel coordinates.
#include <SPI.h>
#include <TFT_eSPI.h>
TFT_eSPI tft = TFT_eSPI();
//====================================================================
void setup(void) {
Serial.begin(115200);
Serial.println("\n\nStarting...");
tft.init();
}
//====================================================================
void loop() {
uint16_t x, y;
tft.getTouchRaw(&x, &y);
Serial.printf("x: %i ", x);
Serial.printf("y: %i ", y);
Serial.printf("z: %i \n", tft.getTouchRawZ());
delay(250);
}
//====================================================================