T-Display-S3 and JST Pin 43
-
Apologies if this has been resolved in the past. I assume it has but could not find a post to address it. No search in this forum?.
I am new to using the T-Display-S3 and programing it via VSCode. In the past I have used it and programmed it via Home Assistant and ESPHome successfully.
I am trying to use a DS18B20 Dallas Temperature sensor connected to pin 43 of the JST connector. I am flashing the board successfully but are getting a -127.00 message on the console.
Have been patching code from a few places to try to get it to work. Obviously I don't know what I am doing. This is what I got so far:
#include <OneWire.h> #include <DallasTemperature.h> #include <TFT_eSPI.h> // Graphics and font library for ST7735 driver chip #include <SPI.h> #include <WiFi.h> #include <pin_config.h> #include <Wire.h> // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) OneWire oneWire(ONE_WIRE_BUS); // Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire); TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h TFT_eSprite sprite = TFT_eSprite(&tft); float val = 1.23; //my default value for sanity check float scaling = 0.0017; // to read voltage on USB as 5.00 void setup(void) { Wire.begin(43, 44); //SDA, SCL pinMode(PIN_POWER_ON, OUTPUT); // to boot with battery... digitalWrite(PIN_POWER_ON, HIGH); // and/or power from 5v rail instead of USB tft.init(); tft.setRotation(3); Serial.begin(9600); sensors.begin(); } void loop(void) { val = analogRead(PIN_BAT_VOLT); // read the input pin for battery voltage Serial.print(" Requesting temperatures..."); sensors.requestTemperatures(); // Send the command to get temperature readings Serial.println("DONE"); Serial.println(sensors.getTempCByIndex(0)); tft.fillScreen(TFT_BLACK); tft.setCursor(0, 10, 1); tft.setTextColor(TFT_WHITE); tft.setTextSize(2); tft.println("Developer Temp is: "); tft.setCursor(0, 30, 2); tft.setTextColor(TFT_WHITE); tft.setTextSize(2); tft.println(sensors.getTempCByIndex(0)); tft.setCursor(0, 80, 2); tft.setTextColor(TFT_BLUE); tft.setTextSize(2); tft.println("D-76"); tft.setCursor(0, 120, 2); tft.setTextColor(TFT_RED); tft.setTextSize(2); tft.println(val*scaling); tft.setCursor(70, 120, 2); tft.setTextColor(TFT_RED); tft.setTextSize(2); tft.println("vDC"); delay(2000); }
and the pin_config.h file is this:
#pragma once #define WIFI_SSID "xxxxxxxx" #define WIFI_PASSWORD "xxxxxxxx" #define WIFI_CONNECT_WAIT_MAX (30 * 1000) #define NTP_SERVER1 "pool.ntp.org" #define NTP_SERVER2 "time.nist.gov" #define GMT_OFFSET_SEC (3600 * 8) #define DAY_LIGHT_OFFSET_SEC 0 /* LCD CONFIG */ #define EXAMPLE_LCD_PIXEL_CLOCK_HZ (6528000) //(10 * 1000 * 1000) // The pixel number in horizontal and vertical #define EXAMPLE_LCD_H_RES 320 #define EXAMPLE_LCD_V_RES 170 #define LVGL_LCD_BUF_SIZE (EXAMPLE_LCD_H_RES * EXAMPLE_LCD_V_RES) #define EXAMPLE_PSRAM_DATA_ALIGNMENT 64 /*ESP32S3*/ #define PIN_LCD_BL 38 #define PIN_LCD_D0 39 #define PIN_LCD_D1 40 #define PIN_LCD_D2 41 #define PIN_LCD_D3 42 #define PIN_LCD_D4 45 #define PIN_LCD_D5 46 #define PIN_LCD_D6 47 #define PIN_LCD_D7 48 #define PIN_POWER_ON 15 #define PIN_LCD_RES 5 #define PIN_LCD_CS 6 #define PIN_LCD_DC 7 #define PIN_LCD_WR 8 #define PIN_LCD_RD 9 #define PIN_BUTTON_1 0 #define PIN_BUTTON_2 14 #define PIN_BAT_VOLT 4 #define PIN_IIC_SCL 17 #define PIN_IIC_SDA 18 #define PIN_TOUCH_INT 16 #define PIN_TOUCH_RES 21 /* External expansion */ #define PIN_SD_CMD 13 #define PIN_SD_CLK 11 #define PIN_SD_D0 12 /*Personal Setup*/ #define ONE_WIRE_BUS 43
I have tried the temp sensor code from the following link but cannot get it to work either:
Any help would be greatly appreciated!!!
-
The HotHead Temp Sensor sketch is an example of reading a SHTx series temp/humidity sensor using i2c, but not onewire!
Having said that, I just discovered that I too cannot read the onewire sensor on pin 43 either!
It appears that 43 and 44 are set by the I/O mux in the ESP32 to be I2C, they recommend that you use another GPIO pin!
I am investigating right now, will get back to you later!
(Check this post, I may just edit my answer!)
-Terry -
From @teastain2 an example of DS18B20 Dallas Temperature sensor connected to pin 17 on my LilyGO T-Display S3 and tested good!
#include <OneWire.h> #include <DallasTemperature.h> const int oneWireBus = 17; //WORKS with pin17 but neither 43 or 44. OneWire oneWire(oneWireBus); DallasTemperature sensors(&oneWire); void setup() { Serial.begin(115200); sensors.begin(); } void loop() { sensors.requestTemperatures(); float temperatureC = sensors.getTempCByIndex(0); Serial.print(temperatureC); Serial.println("ºC"); Serial.println(" "); delay(2000); }
-
@teastain2 Thank you so much for your time and answers. I know that, somehow, the T-Display-S3 and the Dallas sensor works with PIN43 as I can make it work flashing it with ESPHome. Don't know why. I want to learn how to develop with the Arduino IDE and is why I am trying to get this to work now. I know also of other projects by the YouTuber Volos Projects where he uses devices connected through the JST connectors:
Code in GitHub for his project
I see that he uses libraries specific to these small sensors so I am assuming that the pins get assigned there.
Unfortunately my project needs to use the JST connector as I have it in a case for a particular use. If need be, I will go back to flashing it with ESPHome but would love to figure out how to use the JST connector as it looks like the best quick solution to connecting many sensors in a clean, universal way.
-
@patofoto well this is good news. If ESPHome can use a onewire sensor on pin 43 then we need to look at how it assigns the pin.
As you may know, the DS18B20 is a onewire device not i2c. Onewire is somewhat outdated now replaced largely by i2c. The JST is intended for I2c which is a bus topology that will support many sensors and I/O devices at one time due to their internal addressing. SPI is popular for displays and SD cards.
The Volos example uses solely i2c sensors! This is a good example of multiple i2c sensors on an i2c bus.
If you were to use the JST for onewire sensors there would be no way to connect i2c sensors.
Arduino IDE is the way to go. It gives low level control and is the most flexible to customization.
Yes, the libraries take care of the on-chip address.
I made my own GitHub repository for the LilyGO T-Display S3:
https://github.com/teastainGit/LilyGO-T-display-S3-setup-and-examples
Take a look for more info!
-Terry -
@teastain2 I see. Thank you so much for your explanation. I now understand that onewire is a protocol like i2c. So the onewire library in Arduino is too old to be used in the T-Display-S3 and enable
Where can I start looking to see how ESPHome implements this?. This is the ESPHome page for the Dallas sensor:
This is the YAML code that ESPHome uses to flash my T-Display_S3:
esphome: name: developer-temp friendly_name: Developer Temp external_components: - source: github://landonr/lilygo-tdisplays3-esphome components: [tdisplays3] esp32: board: esp32-s3-devkitc-1 framework: type: arduino # Enable logging logger: # Enable Home Assistant API api: encryption: key: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ota: password: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" wifi: ssid: !secret wifi_ssid password: !secret wifi_password # Enable fallback hotspot (captive portal) in case wifi connection fails ap: ssid: "Developer-Temp Fallback Hotspot" password: "xxxxxxxxxxxxxxxxx" captive_portal: # bluetooth_proxy: # active: true time: - platform: homeassistant id: ha_time switch: - platform: gpio pin: GPIO38 name: "Backlight" id: backlight internal: true restore_mode: RESTORE_DEFAULT_ON - platform: gpio pin: GPIO15 name: "Battery" id: battery internal: true restore_mode: RESTORE_DEFAULT_ON dallas: - pin: GPIO43 update_interval: 5s sensor: - platform: dallas address: 0xd901211238e13128 name: "Developer Temperature" resolution: 12 id: devTemp - platform: adc pin: 4 raw: True filters: - multiply: 0.00095238 # 3.9/4095, for attenuation 11db attenuation: 11db name: VBatt id: vcc update_interval: 5s font: - file: type: gfonts family: Roboto weight: 300 id: font1 size: 14 - file: 'Tahoma.ttf' id: font2 size: 14 - file: 'Tahoma-Bold.ttf' id: font3 size: 14 #Web Server web_server: port: 80 mqtt: broker: !secret mqtt_ip port: !secret mqtt_port username: !secret mqtt_user password: !secret mqtt_pass #Display Resolution 320x170 display: - platform: tdisplays3 id: disp update_interval: 1s rotation: 270 lambda: |- auto headerBckgrd = Color(210, 0, 0); auto entityNames = Color(0, 255, 0); auto dataBckgrnd = Color(101, 101, 101); auto entityBckgrnd = Color(50, 50, 50); auto data = Color(255, 255, 255); auto orange = Color(255, 165, 0); auto black = Color(0, 0, 0); auto col1 = 60; auto col2 = 70; auto col3 = 225; auto col4 = 235; auto fontSize = 14; auto spacing = 2; auto line1 = 0; it.filled_rectangle(0, 0, 320, 170, dataBckgrnd); it.filled_rectangle(0, 18, 65, 170, entityBckgrnd); it.filled_rectangle(160, 18, 70, 170, entityBckgrnd); it.filled_rectangle(0, 0, 320, 19, headerBckgrd); it.line(160, 19, 160, 170, headerBckgrd); it.printf(160, line1, id(font3), data, TextAlign::TOP_CENTER, "Developer Temperature"); it.print((col1), 21, id(font2), entityNames, TextAlign::TOP_RIGHT, "Date"); it.printf(col2, 21, id(font2), data, TextAlign::TOP_LEFT, id(ha_time).now().strftime("%m-%d-%Y").c_str()); it.print(col1, 37, id(font2), entityNames, TextAlign::TOP_RIGHT, "Time"); it.printf(col2, 37, id(font2), data, TextAlign::TOP_LEFT, id(ha_time).now().strftime("%I:%M:%S %p").c_str()); it.print(col1, 101, id(font2), entityNames, TextAlign::TOP_RIGHT, "DEV"); it.printf(col2, 101, id(font2), data, TextAlign::TOP_LEFT, "%.1f° C", id(devTemp).state); it.print(col1, 117, id(font2), entityNames, TextAlign::TOP_RIGHT, "Battery"); it.printf(col2, 117, id(font2), data, TextAlign::TOP_LEFT, "%.1f (%.2f %%)", id(vcc).state);
I super appreciate all you time spent on this. Please let me know when you don't have any more interest/time.
-
@patofoto No worries, I'm a retired engineer with spare time, looking for a challenge.
Well, you did get a value from the Dallas while it was under ESPHome.
I could not see anything in the YAML that configures the I2C port signal SDA to be a bi-directional serial comm link like onewire!
There must be another config file when you select LilyGO T-Display S3 .
I'm still poking around on it, intriguing.
-Terry -
@teastain2 Hey there. Hoping I don't sound like I am pushing you. Just curious if you had made any progress with pin assignments and the JST connector. I reverted to using ESPHome for programing my board so I am good for using it now but would love to move to using VSCode and getting to learn Arduino better.
-
@patofoto well indeed, I did not make progress even after finding some info on page 455 of 1500 in the Espressif S3 guide.
I can’t justify learning Esphome to search for the configuration file that sets 43 as GPIO. I have to ask you to put on your engineer hat and search around in the configuration files.
My net search was frustrated with 100% help on using any pin as I2C, but not the other way around.
So.
I am going to raise an Issue on the LilyGO T-Display S3 GitHub repository to see if they are setting it deep inside the bootloader.
I am a huge supporter of Arduino IDE and I want to get to the bottom of this!
I will renew my efforts!
-Terry -
@patofoto 4:50PM EDT Thursday June 15
I submitted this issue with LilyGO:
https://github.com/Xinyuan-LilyGO/T-Display-S3/issues/161
Please check it and confirm!
-Terry -
@teastain2 Thank you!. Just checked your post and saw an answer. Unsure what they mean. Will follow the link they provide and see what I can discover. This is already way over my head to know what to look for but have the patience for trial and error. Will report back if I have any success with something.
-
@teastain2 Just ordered a new T-Display-S3 for testing. Only have one at the moment and is in use. Will start testing soon.
-
@patofoto Not to be proud, but I have worked on this non-stop for a week!
I too want to know why, for example, pin44 does not work and the pin next to it, on the side of the board, pin 18 does!!!
Here is a somehow relevant, but confusing observation:
When uploading my test sketch on pin 43, I see the sensor led flicker as if displaying the serial data on pin43. -
@patofoto Well, it took months and months but finally some guys over on the GitHub for ESP-Arduino finally found it!
https://github.com/espressif/arduino-esp32/issues/8324#issuecomment-1725784617
The helper util file in the onewire lib had an outdated notion that there could not possibly be pins greater that 33.
I edited mine and now it works!
Wow, what a ride!
-Terry