Eerste sketch uploaden

Eerste sketch uploaden

Eindelijk. We zijn nu in staat om code te uploaden naar onze microcontroller.

Copy-Paste onderstaande code volledig naar je Arduino IDE.

/*
  Test of the OLED display for the "LilyGO - TTGO-T-Display" devkit
  The display is a 1.14Inch Oled display, resolution of 240x135 pixels.
  Make sure all to install the "TFT_eSPI" library (Library manager), and have the "User_Setup.h" file modified:
  (Comment out the "#include <User_Setup.h>" and uncomment the "#include <User_Setups/Setup25_TTGO_T_Display.h>" line
  Fonts 1,2,4 ;Font 3, 5, and greater are not defined.
*/

#include <SPI.h>
#include <TFT_eSPI.h> // Hardware-specific library

#define TFT_GREY 0x5AEB // New colour

TFT_eSPI tft = TFT_eSPI();       // Constructor for the TFT library

void setup(void) {
	tft.init();
	tft.setRotation(2);   //setRotation: 2: Screen upside down in landscape
}

void loop() {
	tft.fillScreen(random(0xFFFF));   //Fill screen with random colour


	tft.setCursor(0, 0, 2);   //(cursor at 0,0; font 2, println autosets the cursor on the next line)

	tft.setTextColor(TFT_WHITE, TFT_BLACK); // Textcolor, BackgroundColor; independent of the fillscreen
	tft.setTextSize(1);     //Set text size multiplier to 1

	tft.println("Hello World!");    //Print on cursorpos 0,0

	tft.setTextColor(TFT_WHITE, TFT_BLACK); //Set the font colour to be yellow with no background,
	for (int i = 1; i < 5; i++) {
		tft.setTextFont(i);
		tft.print("Test "); tft.println(i);
	}

	// Set the font colour to be red with black background, set to font 4
	tft.setTextColor(TFT_RED, TFT_WHITE);
	tft.setTextFont(4);
	tft.println((long)3735928559, HEX); //Prints constant in HEX

	tft.setTextColor(TFT_GREEN, TFT_BLACK);
	tft.setTextFont(4);
	tft.print("Large ");
	tft.println("text on screen.");    //Show printing on single line

	tft.setTextFont(1);
	tft.println(F("This will probably be barely readable.")); // Show wrapping and store strings in FLASH "F()"to save RAM


	// Test some print formatting functions
	float fnumber = 123.45;

	tft.setTextColor(TFT_BLUE);    // Set the font colour to be blue with no background, set to font 2
	tft.setTextFont(2);

	tft.print("Float = "); tft.println(fnumber);           // Print floating point number
	tft.print("Binary = "); tft.println((int)fnumber, BIN); // Print as integer value in binary
	tft.print("Hexadecimal = "); tft.println((int)fnumber, HEX); // Print as integer number in Hexadecimal*/
	delay(10000);   //Wait for 10s
}

Als de indentation van je code slordig is door het copy-pasten, klik dan op Tools > Auto Format om deze mooi te maken. Functioneel zal dit uiteraard geen verschil maken: Arduino is ‘C’ met een klein snuifje ‘++’, wat predifined macros en functies. Blokken code worden gegroepeerd met accolades en haakjes, in tegenstelling tot Python bijvoorbeeld.

Hieronder staan de twee knoppen die je het meest zal gebruiken binnen de Arduino IDE:

  • Vinkje = Verify code - Check of de code compileert en geen syntax fouten bevat.
  • Pijltje = Upload code - Upload code naar de microcontroller. Alvorens te uploaden zal de code automatisch geverifieerd en gecompileerd worden. Het is dus niet nodig om op het vinkje te klikken alvorens te uploaden.

Dezelfde code nogmaals uploaden, in de hoop dat deze dan wel correct uitgevoerd wordt zal niets uithalen. Deze code wordt in het flashgeheugen weggeschreven en vervolgens via een hash gevalideerd. Op die manier wordt gecontroleerd dat deze identiek is aan de code die geupload had moeten worden. Gebruik de reset-knop om de microcontroller te herstarten, zodat je kan inschatten welke code uitgevoerd wordt!

  • Upload nu de code naar je microcontroller door op het pijltje te klikken

Het resultaat zou er uit moeten zien zoals in deze afbeelding. Indien dit het geval is werkt alles naar behoren, en zijn we klaar voor het serieuzere werk.

De geuploade code komt terecht in het flashgeheugen op het dev-board. Dit is “permanent” geheugen, wat betekent dus ook dat een reboot of power-down er niet voor zorgt dat de code gewist wordt. Op ieder moment is er maximaal 1 uitvoerbaarbaar beschikbaar in het flashgeheugen!

Indien je een error krijgt, check dan of je
* Het juiste board aangevinkt hebt (LilyGo T-Display, NIET de S3 versie!).
* de juiste COM Poort voor jouw systeem+ESP combi hebt aangeduid.

Linux Vanwege de grote variatie in Linux distro’s is het niet mogelijk om een comprehensive overzicht te geven voor alle specifieke distro’s, maar Pieter Gerets heeft een Getting Started guide voor de T-Display gemaakt, welke je kan gebruiken als startpunt.