Skip to content

Instantly share code, notes, and snippets.

@liamcottle
Last active December 30, 2024 12:36
Show Gist options
  • Save liamcottle/68eff49fe6d7b10e06d6b8208f76dbf5 to your computer and use it in GitHub Desktop.
Save liamcottle/68eff49fe6d7b10e06d6b8208f76dbf5 to your computer and use it in GitHub Desktop.
Heltec T114 Display in Arduino (Slow Bitmap Drawing)
/**
* Simple demo for using Heltec T114 Display, but drawing bitmaps is slow :(
* Author: Liam Cottle <[email protected]>
*
* Install Heltec_nRF52 Board from GitHub
* - https://github.com/HelTecAutomation/Heltec_nRF52
*
* Once board is installed, you may need to "chmod +x" the following files:
* - ~/Documents/Arduino/hardware/heltec/Heltec_nRF52/tools/uf2conv/uf2conv.py
* - ~/Documents/Arduino/hardware/heltec/Heltec_nRF52/tools/adafruit-nrfutil/macos/adafruit-nrfutil
*
* I also had to modify a few of the platform*.txt files, to remove the "python" prefix on macOS, otherwise I got "file not found"
* - tools.uf2conv.cmd.macosx
*
* Sources:
* - https://github.com/meshtastic/firmware/blob/58d80b8557a849b7d3331fb3318d521a0c6cbcab/variants/heltec_mesh_node_t114/variant.h
* - http://community.heltec.cn/t/heltec-meshnode-t114-display/17164
* - https://github.com/lyusupov/SoftRF/blob/80d8eb42d7df0500614b7c7f1f7217f672b5bfbf/software/firmware/source/SoftRF/src/platform/nRF52.cpp#L1057
*/
#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>
#include <Arduino.h>
/* ADC */
#define SOC_GPIO_PIN_T114_ADC_EN 6 // P0.06
/* Ext. sensors */
#define SOC_GPIO_PIN_T114_VEXT_EN 21 // P0.21
/* TFT */
#define TFT_WIDTH 135
#define TFT_HEIGHT 240
#define SOC_GPIO_PIN_T114_TFT_MOSI 9 // P1.09
#define SOC_GPIO_PIN_T114_TFT_MISO 11 // P1.11 NC
#define SOC_GPIO_PIN_T114_TFT_SCK 8 // P1.08
#define SOC_GPIO_PIN_T114_TFT_SS 11 // P0.11
#define SOC_GPIO_PIN_T114_TFT_DC 12 // P0.12
#define SOC_GPIO_PIN_T114_TFT_RST 2 // P0.02
#define SOC_GPIO_PIN_T114_TFT_EN 3 // P0.03
#define SOC_GPIO_PIN_T114_TFT_BLGT 15 // P0.15
Adafruit_ST7789 tft(&SPI1, SOC_GPIO_PIN_T114_TFT_SS, SOC_GPIO_PIN_T114_TFT_DC, SOC_GPIO_PIN_T114_TFT_RST);
static unsigned char bm_def[] PROGMEM = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xb4, 0x61, 0x10, 0x8c, 0x23, 0xc4, 0x3f, 0xff,
0xb5, 0xa7, 0xb7, 0xb5, 0xed, 0xed, 0xbf, 0xff, 0xb5, 0xb9, 0xb4, 0xb4, 0x6d, 0xed, 0xbf, 0xff,
0x85, 0xa1, 0x10, 0xb4, 0x21, 0x44, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xe7, 0x1c, 0xfe, 0x7f, 0x8f, 0xf0, 0x00,
0x1f, 0xf7, 0x9d, 0xff, 0x7f, 0x9f, 0xf0, 0x00, 0x1c, 0x77, 0xfd, 0xc7, 0x73, 0xdc, 0x00, 0x00,
0x1f, 0xe7, 0xfd, 0xc7, 0x71, 0xdf, 0x00, 0x00, 0x1f, 0xe7, 0x7d, 0xc7, 0x71, 0xdf, 0x00, 0x00,
0x1c, 0x77, 0x3d, 0xc7, 0x73, 0xdc, 0x00, 0x00, 0x1c, 0x77, 0x1d, 0xff, 0x7f, 0x9f, 0xf0, 0x00,
0x1c, 0x77, 0x1c, 0xfe, 0x7f, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x54,
0x2a, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x62, 0x24, 0x49, 0x22, 0x4e, 0x44,
0x00, 0x24, 0x93, 0x66, 0xc9, 0x32, 0x44, 0x28, 0x00, 0x20, 0x92, 0xa5, 0x49, 0x2a, 0x44, 0x10,
0x00, 0x24, 0x92, 0x24, 0x49, 0x26, 0x44, 0x10, 0x00, 0x18, 0x62, 0x24, 0x46, 0x22, 0x44, 0x10,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x1c, 0x9c, 0x44, 0x88, 0xc7, 0x1c, 0x00, 0x00, 0x10, 0x92, 0x6c, 0xa9, 0x24, 0x90,
0x00, 0x00, 0x1c, 0x9c, 0x54, 0xa9, 0xe7, 0x1c, 0x00, 0x00, 0x10, 0x94, 0x44, 0xa9, 0x25, 0x10,
0x00, 0x00, 0x10, 0x92, 0x44, 0x51, 0x24, 0x9c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
void setup(void) {
// enable vext (not required for screen to work, but probably for antenna boost?)
digitalWrite(SOC_GPIO_PIN_T114_VEXT_EN, HIGH);
pinMode(SOC_GPIO_PIN_T114_VEXT_EN, OUTPUT);
// enable power to display
digitalWrite(SOC_GPIO_PIN_T114_TFT_EN, LOW);
pinMode(SOC_GPIO_PIN_T114_TFT_EN, OUTPUT);
// enable backlight led (display is off without this)
digitalWrite(SOC_GPIO_PIN_T114_TFT_BLGT, LOW);
pinMode(SOC_GPIO_PIN_T114_TFT_BLGT, OUTPUT);
// enable adc (not required for screen to work, but probably for measuring battery level)
digitalWrite(SOC_GPIO_PIN_T114_ADC_EN, HIGH);
pinMode(SOC_GPIO_PIN_T114_ADC_EN, OUTPUT);
// init tft
tft.init(TFT_WIDTH, TFT_HEIGHT);
tft.setRotation(3);
tft.setSPISpeed(40000000);
// show something on the display
tft.fillScreen(ST77XX_BLACK); // clear the screen
tft.setTextColor(ST77XX_WHITE); // set text color to white
tft.setTextSize(2); // set text size
tft.setCursor(0, 0); // set cursor position
// tft.print("Testing...");
}
void loop() {
// this is slow!
tft.fillScreen(ST77XX_BLACK);
tft.drawBitmap(0, 0, bm_def, 64, 37, ST77XX_WHITE, ST77XX_BLACK);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment