Xinyuan-LilyGO / LilyGo-EPD47

GNU General Public License v3.0
416 stars 122 forks source link

I2C doesn't work? #122

Closed MrMutlu closed 2 weeks ago

MrMutlu commented 4 months ago

Hi, i am using Screen-4.7-S3 V2.3 2021-6-10 version of epaper. I am trying to i2c work but its seeing RTC address ( im assuming address: 0x51 ). However touch example and demo example for searching touch address didn't work. I haven't connected any cables that arrived with package ( i bought with soldered version so terminal line and power cables came). I also want to state that sometimes it doesn't see other I2C sensors too. Here is my snippet of code:

#ifndef BOARD_HAS_PSRAM
#error "Please enable PSRAM, Arduino IDE -> tools -> PSRAM -> OPI !!!"
#endif

#include <Arduino.h>
#include "epd_driver.h"
#include "utilities.h"
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_HTS221.h>
#include <Adafruit_LPS2X.h>
#include <Adafruit_LSM9DS1.h>
#include "MSTrans.h"
#include "opensans10.h"
#include <TouchDrvGT911.hpp>

TouchDrvGT911 touch;
Adafruit_HTS221 hts;
Adafruit_LSM9DS1 lsm;
Adafruit_LPS25 lps;

uint8_t *framebuffer = NULL;

void setup()
{
  Serial.begin(115200);
  vTaskDelay(5000 / portTICK_PERIOD_MS);

  framebuffer = (uint8_t *)ps_calloc(sizeof(uint8_t), EPD_WIDTH * EPD_HEIGHT / 2);
  if (!framebuffer) {
    Serial.println("alloc memory failed !!!");
    while (1);
  }
  memset(framebuffer, 0xFF, EPD_WIDTH * EPD_HEIGHT / 2);

  epd_init();
  epd_poweron();
  epd_clear();

  //* Sleep wakeup must wait one second, otherwise the touch device cannot be addressed
  if (esp_sleep_get_wakeup_cause() != ESP_SLEEP_WAKEUP_UNDEFINED) {
    vTaskDelay(1000 / portTICK_PERIOD_MS);
  }

  // Assuming that the previous touch was in sleep state, wake it up
  pinMode(TOUCH_INT, OUTPUT);
  digitalWrite(TOUCH_INT, HIGH);

  Wire.begin(BOARD_SDA, BOARD_SCL);

  byte busStatus;

  for (int i2cAddress = 0x00; i2cAddress < 0x80; i2cAddress++)
  {
    Wire.beginTransmission(i2cAddress);
    busStatus = Wire.endTransmission();
    if (busStatus == 0x00)
    {
      Serial.print("I2C Device found at address: 0x");
      Serial.println(i2cAddress, HEX);
    }

    else
    {
      Serial.print("I2C Device not found at address: 0x");
      Serial.println(i2cAddress, HEX);
    }
  }

  Serial.println("EPAPER");

  // Initialize sensors and check for success
  if (!hts.begin_I2C(0x5F)) {
    Serial.println("HTS221 initialization failed!");

  } else {
    Serial.println("HTS221 initialized successfully");
  }

  if (!lsm.begin()) {
    Serial.println("LSM9DS1 initialization failed!");

  } else {
    Serial.println("LSM9DS1 initialized successfully");
  }

  if (!lps.begin_I2C(0x5C)) {
    Serial.println("LPS25 initialization failed!");

  } else {
    Serial.println("LPS25 initialized successfully");
  }

  uint8_t touchAddress = 0x14;

  Wire.beginTransmission(0x14);
  if (Wire.endTransmission() == 0) {
    touchAddress = 0x14;
  }
  Wire.beginTransmission(0x5D);
  if (Wire.endTransmission() == 0) {
    touchAddress = 0x5D;
  }

  touch.setPins(-1, TOUCH_INT);
  if (!touch.begin(Wire, touchAddress , BOARD_SDA, BOARD_SCL)) {
    Serial.println("Failed to find GT911 - check your wiring!");
  }

  Serial.println("Started Touchscreen poll...");

  lps.setDataRate(LPS25_RATE_12_5_HZ);
  lsm.setupAccel(lsm.LSM9DS1_ACCELRANGE_8G);
  lsm.setupMag(lsm.LSM9DS1_MAGGAIN_12GAUSS);
  lsm.setupGyro(lsm.LSM9DS1_GYROSCALE_500DPS);

  vTaskDelay(1000 / portTICK_PERIOD_MS);
  epd_poweroff();

  firstBoot();
  vTaskDelay(5000 / portTICK_PERIOD_MS);
  Rect_t area = {
    .x = 0,
    .y = 0,
    .width = MSTrans_width,
    .height = MSTrans_height
  };
  epd_poweron();
  epd_clear();
  epd_draw_grayscale_image(area, (uint8_t *)MSTrans_data);
  // Update the display
  epd_draw_grayscale_image(epd_full_screen(), framebuffer);
  epd_poweroff();
  // Create the sensor tasks
  xTaskCreatePinnedToCore(accelGyroMagTask, "AccelGyroMagTask", 4096, NULL, 1, NULL, 0);
  xTaskCreatePinnedToCore(tempHumPressureTask, "TempHumPressureTask", 4096, NULL, 1, NULL, 0);
  xTaskCreatePinnedToCore(debugTerminalTask, "DebugTerminalTask", 4096, NULL, 1, NULL, 0);
}
MrMutlu commented 4 months ago

Ok my bad i didn't realize i bought basic version instead of touch version. Then i want to ask how can i use touch pins at back of the board? Any suggestions for extra component?

github-actions[bot] commented 4 weeks ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 2 weeks ago

This issue was closed because it has been inactive for 14 days since being marked as stale.