Lecture 2.2: Getting Started with LilyGO T-Deck

Introduction

Good morning, everyone! It’s fantastic to see all of you again as we continue our exciting journey into the world of LoRa technology and LilyGO devices. In our last session, we got hands-on with the LilyGO T-Beam, exploring its features and learning how to power it up and program it using the Arduino IDE and ESP-IDF. Today, we’re going to shift our focus to another remarkable device in the LilyGO lineup — the LilyGO T-Deck.

Imagine holding a device in your hand that not only communicates over long distances but also provides real-time feedback through an integrated display and allows for user interaction with built-in buttons. The T-Deck is precisely that devicea powerful tool that bridges the gap between complex IoT systems and user-friendly interfaces.

In this lecture, we’ll delve into the features of the T-Deck, set it up together, and learn how to configure its display and basic LoRa settings. By the end of our session, you’ll be well-equipped to harness the full potential of the T-Deck for your IoT projects.

 

Unboxing and Familiarizing with the T-Deck

Let’s begin by unboxing the T-Deck. If you have your device with you, please take it out so we can explore it together.

What’s Inside the Box:

LilyGO T-Deck Device: A sleek board with an integrated display and input buttons.
LoRa Antenna: An external antenna to enhance LoRa communication.
– USB-C Cable: For powering the device and programming.
– Battery (optional): Some packages include a rechargeable battery.

As you hold the T-Deck, notice its compact design. The integrated display immediately catches the eye, hinting at the interactive possibilities it offers.

 

Key Components of the T-Deck:

1. ESP32 Microcontroller: The heart of the device, providing processing power and connectivity.
2. LoRa Module: Enables long-range communication over LoRa networks.
3. 1.14-inch TFT Display: A color screen for displaying data, menus, and more.
4. Input Buttons: For user interaction, navigating menus, and inputting data.
5. USB-C Port: For power, programming, and serial communication.
6. Battery Connector: For portable operation using a rechargeable battery.
7. GPIO Pins: For connecting additional sensors and peripherals.

Take a moment to familiarize yourself with these components. Understanding the hardware layout is crucial as we proceed to set up and program the device.

 

Powering Up the T-Deck

Before we dive into programming, let’s ensure our T-Deck is properly powered.

Option 1: Using the USB-C Cable

1. Connect the USB-C Cable:

– Plug the USB-C end into the T-Deck.
– Connect the other end to your computer or a USB power adapter.

2. Power Indicators:

– Observe any LEDs or the display to confirm the device is receiving power.
– The screen may light up with a default or splash screen.

Option 2: Using a Battery

1. Insert the Battery:

– If your T-Deck came with a battery, locate the battery connector.
– Connect the battery, ensuring the polarity matches the markings.

2. Safety Precautions:

– Use only compatible batteries recommended by the manufacturer.
– Avoid short circuits and do not expose the battery to extreme conditions.

3. Power On:

– Press the power button if available.
– The display should activate, indicating the device is powered.

Note: The T-Deck can often operate with both the battery and USB power connected. This setup is safe due to built-in power management circuitry, but always refer to the manufacturer’s instructions.

 

Installing Necessary Drivers

To communicate with the T-Deck from your computer, ensure the correct drivers are installed.

1. Identify the USB-to-Serial Chip:

– The T-Deck typically uses the CP210x or CH9102 USB-to-serial converter.

2. Download and Install Drivers:

– CP210x:
– Visit Silicon Labs’ website to download drivers for your OS.
– CH9102:
– Drivers are available from the manufacturer or reliable third-party sources.

3. Verify Installation:

– Connect the T-Deck via USB.
– Open Device Manager (Windows) or System Information (macOS).
– Ensure the device appears under Ports (COM & LPT) or USB devices.

 

Setting Up the Arduino IDE for T-Deck

The Arduino IDE is a user-friendly platform for programming the T-Deck.

1. Install the Arduino IDE:

– Download the latest version from the official Arduino website.
– Follow the installation instructions for your operating system.

2. Add ESP32 Board Support:

– Open the Arduino IDE.
– Navigate to File > Preferences.
– In “Additional Boards Manager URLs,” add:
“`
https://dl.espressif.com/dl/package_esp32_index.json
“`
– Click OK.

3. Install ESP32 Board Definitions:

– Go to Tools > Board > Boards Manager.
– Search for “ESP32”.
– Install the “esp32” by Espressif Systems package.

4. Select the Correct Board and Port:

– Under Tools > Board, select “ESP32 Wrover Module” (suitable for devices with external RAM and displays).
– Under Tools > Port, select the COM port associated with the T-Deck.

Configure Additional Settings:

Partition Scheme: Select “Huge APP (3MB No OTA/1MB SPIFFS)” if you plan to use large applications.
Flash Frequency: 80 MHz.
Upload Speed: 921600 (reduce to 115200 if upload issues occur).
PSRAM: Enable if your T-Deck has external RAM.

 

Exploring the T-Deck’s Features

Now that our development environment is set up, let’s explore what makes the T-Deck unique.

Integrated Display

– A 1.14-inch TFT color screen capable of displaying graphics, text, and user interfaces.
– Useful for real-time data visualization, debugging, and user interaction.

Input Buttons

– Typically includes several buttons for navigating menus or controlling the device.
– May include touch buttons or physical keys, depending on the model.

Connectivity

LoRa Module: For long-range communication.
– Wi-Fi and Bluetooth: Provided by the ESP32 for additional connectivity options.

Expansion Ports

– GPIO Pins: Accessible for connecting sensors, actuators, and other peripherals.
Communication Interfaces: I2C, SPI, UART, and more.

 

Programming the T-Deck Display

Let’s start by programming the display to show a simple message.

1. Install Required Libraries

TFT_eSPI Library:
– Go to Sketch > Include Library > Manage Libraries.
– Search for “TFT_eSPI” by Bodmer.
– Install the library.

2. Configure TFT_eSPI Library

– The TFT_eSPI library requires configuration to match your display.
– Locate the library folder:
– On Windows: `Documents\Arduino\libraries\TFT_eSPI`
– Open `User_Setup_Select.h`.
– Comment out any existing `#include` lines for setups.
– Add or uncomment the line corresponding to your display, e.g.:
“`cpp
#include <User_Setups/Setup25_TTGO_T_Display.h>
“`
– Alternatively, create a custom setup file if needed.

3. Write a Simple Sketch

“`cpp
#include <TFT_eSPI.h>
#include <SPI.h>

TFT_eSPI tft = TFT_eSPI(); // Initialize display

void setup() {
tft.init();
tft.setRotation(0);
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.drawCentreString(“Hello, T-Deck!”, tft.width() / 2, tft.height() / 2, 2);
}

void loop() {
// Empty loop
}
“`

4. Upload the Sketch

– Verify and upload the code to the T-Deck.
– The display should show “Hello, T-Deck!” centered on the screen.

Troubleshooting Display Issues

– Blank Screen: Check your wiring and ensure the correct setup file is included.
Garbled Text: Verify that the correct display driver is specified in the library configuration.

 

Configuring Basic LoRa Settings

Now, let’s configure the T-Deck for basic LoRa communication.

1. Attach the LoRa Antenna

– Ensure the LoRa antenna is securely connected to avoid damage when transmitting.

2. Install the LoRa Library

– In the Arduino IDE, go to **Sketch > Include Library > Manage Libraries**.
– Search for “LoRa” by Sandeep Mistry.
– Install the library.

3. Initialize LoRa in Your Sketch

– Modify the previous display sketch to include LoRa functionality.

“`cpp
#include <LoRa.h>
// … (other includes and initialization)

void setup() {
// … (display initialization)

// Initialize LoRa
Serial.begin(115200);
while (!Serial);
Serial.println(“LoRa Sender”);

LoRa.setPins(18, 14, 26); // NSS, Reset, DIO0 pins (adjust if necessary)

if (!LoRa.begin(915E6)) { // Replace with your regional frequency
Serial.println(“Starting LoRa failed!”);
while (1);
}
}
“`

4. Sending LoRa Messages

– Update the loop to send messages.

“`cpp
void loop() {
tft.fillScreen(TFT_BLACK);
tft.drawCentreString(“Sending packet…”, tft.width() / 2, tft.height() / 2, 2);

Serial.println(“Sending packet…”);
LoRa.beginPacket();
LoRa.print(“Hello from T-Deck!”);
LoRa.endPacket();

delay(5000); // Wait for 5 seconds
}
“`

5. Receiving LoRa Messages (on another device)

– Set up a second T-Deck or T-Beam as a receiver.
– Use the LoRaReceiver example sketch and adjust pin configurations as necessary.

 

Combining Display and LoRa Reception

Let’s create a sketch where the T-Deck receives LoRa messages and displays them on the screen.

1. Receiver Sketch

“`cpp
#include <TFT_eSPI.h>
#include <SPI.h>
#include <LoRa.h>

TFT_eSPI tft = TFT_eSPI();

void setup() {
tft.init();
tft.setRotation(0);
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_WHITE, TFT_BLACK);

Serial.begin(115200);
while (!Serial);
Serial.println(“LoRa Receiver”);

LoRa.setPins(18, 14, 26); // Adjust pins if necessary

if (!LoRa.begin(915E6)) { // Replace with your regional frequency
Serial.println(“Starting LoRa failed!”);
while (1);
}
}

void loop() {
int packetSize = LoRa.parsePacket();
if (packetSize) {
String incoming = “”;

while (LoRa.available()) {
incoming += (char)LoRa.read();
}

Serial.println(“Received: ” + incoming);

tft.fillScreen(TFT_BLACK);
tft.drawCentreString(“Received:”, tft.width() / 2, tft.height() / 2 – 10, 2);
tft.drawCentreString(incoming, tft.width() / 2, tft.height() / 2 + 10, 2);
}
}
“`

2. Testing the Communication

– Upload the sender sketch to one device and the receiver sketch to the T-Deck.
– Observe messages appearing on the T-Deck’s display as they are received.

 

Utilizing the T-Deck’s Input Buttons

The T-Deck’s buttons allow for user interaction, which we can leverage in our projects.

1. Identifying Button Pins

– Refer to the T-Deck’s schematic or documentation to identify which GPIO pins correspond to the buttons.

2. Reading Button Input

“`cpp
const int buttonPin = 0; // Replace with the actual pin number

void setup() {
// … (other initializations)
pinMode(buttonPin, INPUT_PULLUP); // Configure button pin
}

void loop() {
int buttonState = digitalRead(buttonPin);
if (buttonState == LOW) { // Assuming active low
tft.fillScreen(TFT_BLACK);
tft.drawCentreString(“Button Pressed!”, tft.width() / 2, tft.height() / 2, 2);
// Add actions to perform when button is pressed
}
// … (rest of the loop)
}
“`

3. Debouncing Buttons

– Implement debouncing logic to prevent multiple triggers from a single press.
– This can be done using software delays or more sophisticated timing methods.

 

Developing a Menu Interface

Let’s create a simple menu system using the display and buttons.

1. Define Menu Items

“`cpp
String menuItems[] = {“Option 1”, “Option 2”, “Option 3”};
int currentSelection = 0;
“`

2. Display the Menu

“`cpp
void displayMenu() {
tft.fillScreen(TFT_BLACK);
for (int i = 0; i < 3; i++) {
if (i == currentSelection) {
tft.setTextColor(TFT_GREEN, TFT_BLACK);
} else {
tft.setTextColor(TFT_WHITE, TFT_BLACK);
}
tft.drawString(menuItems[i], 10, 10 + i * 20, 2);
}
}
“`

3. Navigating the Menu

– Use buttons to move up and down the menu.

“`cpp
const int upButton = 0; // Adjust pin numbers
const int downButton = 35;
const int selectButton = 34;

void setup() {
// … (other initializations)
pinMode(upButton, INPUT_PULLUP);
pinMode(downButton, INPUT_PULLUP);
pinMode(selectButton, INPUT_PULLUP);
}

void loop() {
if (digitalRead(upButton) == LOW) {
currentSelection = (currentSelection + 2) % 3; // Wrap around
displayMenu();
delay(200); // Debounce delay
}
if (digitalRead(downButton) == LOW) {
currentSelection = (currentSelection + 1) % 3;
displayMenu();
delay(200);
}
if (digitalRead(selectButton) == LOW) {
executeOption(currentSelection);
delay(200);
}
}
“`

4. Executing Menu Options

“`cpp
void executeOption(int selection) {
tft.fillScreen(TFT_BLACK);
tft.drawCentreString(“Executing ” + menuItems[selection], tft.width() / 2, tft.height() / 2, 2);
// Add functionality for each option
}
“`

 

Advanced Configuration: Adjusting LoRa Settings

For more control over your LoRa communication, you can adjust settings like frequency, bandwidth, and spreading factor.

1. Set Frequency

– Ensure you’re using a frequency permitted in your region (e.g., 868E6 for Europe, 915E6 for North America).

“`cpp
LoRa.begin(915E6); // Replace with your frequency
“`

2. Adjust Bandwidth

“`cpp
LoRa.setSignalBandwidth(125E3); // Options: 7.8E3 to 500E3
“`

3. Set Spreading Factor

“`cpp
LoRa.setSpreadingFactor(7); // Options: 6 to 12
“`

4. Set Coding Rate

“`cpp
LoRa.setCodingRate4(5); // Options: 5 to 8
“`

5. Set Transmission Power

“`cpp
LoRa.setTxPower(14); // Options: 2 to 20 dBm
“`

Note: Adjusting these parameters affects range, data rate, and reliability. Higher spreading factors increase range but reduce data rate.

 

Troubleshooting Common Issues

Display Not Working

Incorrect Configuration: Verify the TFT_eSPI library setup matches your display.
– Wiring Issues: Ensure all connections are secure if using external displays.

 

Buttons Not Responding

– Pin Numbers: Double-check that you’re using the correct GPIO pins.
Pull-up Resistors: Ensure input pins are properly configured with internal or external pull-up resistors.

 

LoRa Communication Failing

Frequency Mismatch: Both sender and receiver must use the same frequency.
– Antenna Connection: Confirm antennas are attached and functioning.
– Interference: Try changing the frequency or bandwidth settings to mitigate interference.

 

Conclusion

Today, we’ve embarked on an exciting exploration of the LilyGO T-Deck, unlocking its potential through hands-on setup and programming. We’ve learned how to power up the device, configure the integrated display, utilize input buttons for user interaction, and set up basic LoRa communication.

The T-Deck’s combination of a powerful microcontroller, integrated display, and input capabilities makes it a versatile tool for a wide range of applications—from portable communication devices to interactive IoT controllers.

As you continue to experiment with your T-Deck, consider how you might integrate additional sensors, implement more complex user interfaces, or develop innovative applications that leverage both the display and LoRa capabilities.

 

Questions and Discussion

Let’s open the floor for any questions or insights you’d like to share.

Question: Can I use the T-Deck to connect to Wi-Fi networks and access the internet?*

Answer: Absolutely! The ESP32 microcontroller includes Wi-Fi capabilities. You can program the T-Deck to connect to Wi-Fi networks, send data to cloud services, or even host a web server. This opens up a plethora of possibilities for IoT applications.

Question: How can I display graphics or images on the T-Deck’s screen?*

Answer: The TFT_eSPI library supports drawing shapes, lines, and even displaying bitmap images. You’ll need to format your images appropriately and may need to use an SD card or SPIFFS to store larger files. The library documentation provides examples on how to implement this.

Question: Is it possible to run the T-Deck on battery power for extended periods?*

Answer: Yes, but battery life depends on power management in your code. Implementing deep sleep modes when the device is idle, reducing screen brightness, and optimizing code can significantly extend battery life. However, the display and LoRa transmissions consume power, so careful planning is necessary for long-term battery operation.

 

Additional Resources

– LilyGO GitHub Repositories: Access code examples, schematics, and documentation specific to the T-Deck.
– ESP32 Official Documentation: In-depth information on programming and features.
– TFT_eSPI Library Documentation: Guides and examples for advanced display usage.
– Community Forums: Platforms like the Arduino Forum, ESP32 Forum, and Stack Overflow are valuable for troubleshooting and learning from others.

 

Closing Remarks

As we conclude today’s lecture, I encourage you to continue exploring the capabilities of the T-Deck. The combination of visual feedback and user interaction transforms how we can engage with our IoT projects, making them more intuitive and user-friendly.

Remember, the key to mastery is experimentation. Don’t hesitate to push the boundaries of what we’ve covered today—try new libraries, integrate different sensors, or develop complex interfaces. Your creativity is the only limit.

In our next session, we’ll bring together what we’ve learned by setting up point-to-point communication between LilyGO devices, testing and validating data transmission in real-world scenarios.

Thank you for your enthusiasm and participation. I’m excited to see the innovative projects you’ll develop.

“See you in the next lecture!”

 

 

‘Fix the broken countries of the west through increased transparency, design and professional skills. Support Skills Gap Trainer.’


To see our Donate Page, click https://skillsgaptrainer.com/donate

To see our Twitter / X Channel, click https://x.com/SkillsGapTrain

To see our Instagram Channel, click https://www.instagram.com/skillsgaptrainer/

To see some of our Udemy Courses, click SGT Udemy Page

To see our YouTube Channel, click https://www.youtube.com/@skillsgaptrainer

Scroll to Top