Print to Display

I have some thing so simple, and I cannot figure it out. I've always struggled with setting LCD's up properly. I have been able to get text and data to show on my screen, but not what I want, I simply want it to show the external temp reading, the PWM% and the Fan RPMs.

Here is what I'm using for hardware: Overview | Adafruit ESP32-S2 TFT Feather | Adafruit Learning System
And fan controller with an external sensor: Overview | EMC2101 Fan Controller and Temperature sensor | Adafruit Learning System

If someone can point me in the direction of a good tutorial for text on LCD's I would be extremely grateful. I like to try myself first, before I ask for literal help.

Thank you!

Please post your sketch, using code tags when you do

It sounds like you need help with string formatting maybe and not necessarily specific to an LCD. If you can get text to the screen then that's all you need there. Now you just need to build the text you want to see.

Or maybe I misunderstood you. An example of what you mean might help.

Here is a video, if you scrub to 11:30 you’ll see the display in action. I want close to the same thing, except to include PWM% as well.

As a starting point I tried this:


void loop() {
    // when characters arrive over the serial port...
    if (Serial.available()) {
      // wait a bit for the entire message to arrive
      delay(100);
      // clear the screen
      lcd.clear();
      // read all the available characters
      while (Serial.available() > 0) {
        // display each character to the LCD
        lcd.write(Serial.read());
      }
    }
  }

The issue is the Adafruit library doesn’t support lcd.clear(); so that’s one issue. I took that out and the code compiles fine but nothing shows up.

Here is my existing code, in the loop section, if I take any of the Serial.print lines and change them to tft.print those lines will show up on the screen.


// Basic demo for readings from Adafruit EMC2101
#include <Adafruit_EMC2101.h>
#include <Wire.h>
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h>

// Use dedicated hardware SPI pins
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
Adafruit_EMC2101  emc2101;

void setup(void) {
  Serial.begin(115200);
  while (!Serial) delay(10);     // will pause Zero, Leonardo, etc until serial console opens

  Serial.print(F("Adafruit EMC2101 test!"));
  pinMode(TFT_BACKLITE, OUTPUT);
  digitalWrite(TFT_BACKLITE, HIGH);
  pinMode(TFT_I2C_POWER, OUTPUT);
  digitalWrite(TFT_I2C_POWER, HIGH);
  delay(10);

  // initialize TFT
  tft.init(135, 240); // Init ST7789 240x135
  tft.setRotation(3);
  tft.setTextColor(ST77XX_WHITE);
  tft.setTextSize(2);

  Serial.println(F("Initialized"));

  uint16_t time = millis();
  tft.fillScreen(ST77XX_BLACK);
  time = millis() - time;

  uint16_t getFanMinRPM();

  Serial.println(time, DEC);
  delay(500);

  // Try to initialize!
  if (!emc2101.begin()) {
    Serial.println("Failed to find EMC2101 chip");
    while (1) { delay(10); }
  }
  Serial.println("EMC2101 Found!");
  emc2101.setDutyCycle(5);
  emc2101.setLUT(0, 20, 1);
  emc2101.setLUT(1, 30, 10);
  emc2101.setLUT(2, 40, 40);
  emc2101.setLUT(3, 60, 60);
  emc2101.setLUT(4, 80, 80);
  emc2101.setLUT(5, 100, 100);
  emc2101.LUTEnabled(true);
  emc2101.setLUTHysteresis(5); // 5 degree C fudge factor
  Serial.print("LUT Hysteresis: "); Serial.println(emc2101.getLUTHysteresis());
  Serial.print("LUT enabled: "); Serial.println(emc2101.LUTEnabled());
  Serial.print("enable force success: "); Serial.println(emc2101.enableForcedTemperature(false));

  //  emc2101.setDataRate(EMC2101_RATE_1_16_HZ);
  Serial.print("Data rate set to: ");
  switch (emc2101.getDataRate()) {
    case EMC2101_RATE_1_16_HZ: Serial.println("1/16_HZ"); break;
    case EMC2101_RATE_1_8_HZ: Serial.println("1/8_HZ"); break;
    case EMC2101_RATE_1_4_HZ: Serial.println("1/4_HZ"); break;
    case EMC2101_RATE_1_2_HZ: Serial.println("1/2_HZ"); break;
    case EMC2101_RATE_1_HZ: Serial.println("1 HZ"); break;
    case EMC2101_RATE_2_HZ: Serial.println("2 HZ"); break;
    case EMC2101_RATE_4_HZ: Serial.println("4 HZ"); break;
    case EMC2101_RATE_8_HZ: Serial.println("8 HZ"); break;
    case EMC2101_RATE_16_HZ: Serial.println("16 HZ"); break;
    case EMC2101_RATE_32_HZ: Serial.println("32 HZ"); break;
  }

  emc2101.enableTachInput(true);
  emc2101.setPWMDivisor(0);
  
}



void loop() {
  Serial.print("PWM: ");
  Serial.print(emc2101.getDutyCycle());
  Serial.println("%");
  Serial.print("Fan RPM:: ");
  Serial.print(emc2101.getFanRPM());
  Serial.println(" RPM");
  Serial.print("External Temperature: ");
  Serial.print(emc2101.getExternalTemperature());
  Serial.println(" degrees C");
  delay(3000);

}

That is how to clear the screen. Or do the screen fill to the backgroud color of your choice.

Use the setCursor() function to place text and print() to print.

With print() do I need to do tft.print() or just straight print()?

Sorry, I should have used complete statements.

Yes, you must use tft.print(); or tft.setCursor();.

From the Adafruit ST7789 library graphicstest_st7789.ino example

void testdrawtext(char *text, uint16_t color) 
{
  tft.setCursor(0, 0);
  tft.setTextColor(color);
  tft.setTextWrap(true);
  tft.print(text);
}

One of those codes is for an LCD screen and one is for a TFT. Which do you have?

I have a TFT screen.

So why is half of your thread about an LCD? The original post only says an LCD. It never mentions a TFT.

Why are you trying examples for an LCD? You shouldn't expect LCD code to work on a TFT. Get an example for a TFT.

Which one?
Please post a link to specs/data/place of purchase please.

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

Here is the board - Overview | Adafruit ESP32-S2 TFT Feather | Adafruit Learning System
I'm also using this fan control board - Overview | EMC2101 Fan Controller and Temperature sensor | Adafruit Learning System ;along with an external NPN temp sensor as per documentation.

I was not aware the programming was that much different between a TFT and an LCD. I appreciate the help, and I did mention I'm new to this so any help is appreciated.

What I really want is just a sample piece of code that I can try and work with. All the examples I've found deal with graphics, bmp's, etc...I don't need any of that, I just want text!

I think you are discovering that ALL TFT programming is graphical.

Well I worked it out, on to the next task for this project, I’m sure I’ll be back with more questions.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.