Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LEDS on TTGO ESP32 T8 1.7.1 #14

Open
paolovr70 opened this issue Mar 26, 2020 · 8 comments
Open

LEDS on TTGO ESP32 T8 1.7.1 #14

paolovr70 opened this issue Mar 26, 2020 · 8 comments

Comments

@paolovr70
Copy link

Dear All,
where can I find a pinout of the board? (on the site producer there is no schematic).
There are 3 leds on board. One is for battery, but the other two?
Are there problems if I need to use I2C and one of the leds is connected to 21/22 pins (which are the hardware I2C pins)?
Thanks.
paolo

@tionebrr
Copy link

tionebrr commented Jul 22, 2020

Hi Paolo.

  • According to the schematic, blue is for battery charge, red is the 3v3 power, and green is wired to IO21.
  • Schematic is in this repository, but the version changes are not pushed here. The pinout is the same as other official ESP32 modules.
  • You can use any pin as I²C with the ESP32. GPIOs are actually very flexible. Refer to the ESP32 datasheet.

There is not a lot of help or information about this specific module (the T8) because there is nothing special about it really. It is wired like most other ESP32 modules and thus can be used like any other module. Only difference is the SDCard slot which is actually wired in SPI mode like shown on the schematic and not like advertised.

@hasaranga
Copy link

Hi Paolo.

* According to the schematic, blue is for battery charge, red is the 3v3 power, and green is wired to IO21.

* Schematic is in this repository, but the version changes are not pushed here. The pinout is the same as other official ESP32 modules.

* You can use any pin as I²C with the ESP32. GPIOs are actually very flexible. Refer to the ESP32 datasheet.

There is not a lot of help or information about this specific module (the T8) because there is nothing special about it really. It is wired like most other ESP32 modules and thus can be used like any other module. Only difference is the SDCard slot which is actually wired in SPI mode like shown on the schematic and not like advertised.

Can it run in 1bit mode? Because I have the same board but the first call to SD_MMC.begin("/sdcard", true) always fail. Second call works. Tried with a different SD card and reduced the cpu freq but the same results.

TTGO issue

@tionebrr
Copy link

tionebrr commented Jan 22, 2021

I'm using the ESP-IDF and thus don't know anything about the specifics of the arduino implementation.
Remember, the SDCard is wired as an SPI device, so it is one bit. There might be a way to tell SD_MMC to initialize as an SPI SD.
The T8 board is missing two data line to work in 4-bits mode. So it might work with the SDMMC Driver with 1-bit width. However, I remember having had issues with the SDMMC driver and switched to the ESP-IDF SD SPI Host Driver.

@dizcza
Copy link

dizcza commented Sep 3, 2021

@tionebrr could you please clarify this

Remember, the SDCard is wired as an SPI device, so it is one bit

aren't you trying to say that an SD card will work only in 1-bit width mode for this board while using the SD-MMC driver?

@tionebrr
Copy link

tionebrr commented Sep 3, 2021

@dizcza You're right, sorry for the confusion. I re-checked the docs and it should work in SDMMC 1-bit mode. I edited my previous comment.

@dizcza
Copy link

dizcza commented Sep 3, 2021

@tionebrr thank you for the clarification. It did help because I thought I was doing something wrong by not being able to mount an SD card with the 4-bit operation mode.

BTW, shouldn't this issue be closed? It has been answered fairly in the first comment. The author perhaps was wondering whether the LED will be blinking if IO21 pin is used as SDA with some I2C-connected device. In either case, you can't use it as LED with active I2C communication going through this pin.

Let me also answer another question posted here to quantify it's fully resolved.
@hasaranga you had the following problem:

... I have the same board but the first call to SD_MMC.begin("/sdcard", true) always fail. Second call works.

It's because a pull-up resistor is missing on D0 line (as in many other variants of an ESP32 board). You can do either a hardware fix (pulling up a 10 kOhm resistor to pin "2") or a software fix. The software fix is to call pinMode(2, INPUT_PULLUP); prior to initializing the SD card. Below is a working example of using SDMMC driver with TTGO T8 in Arduino IDE with the latest esp32 library installed (v1.0.6; I've not checked v2.0.0 yet).

An example of using SDMMC driver with TTGO T8 in Arduino IDE
/*
 * Connect the SD card to the following pins:
 *
 * SD Card | ESP32
 *    D2       12
 *    D3       13
 *    CMD      15
 *    VSS      GND
 *    VDD      3.3V
 *    CLK      14
 *    VSS      GND
 *    D0       2  (add 1K pull up after flashing)
 *    D1       4
 */

#include "FS.h"
#include "SD_MMC.h"

void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
    Serial.printf("Listing directory: %s\n", dirname);

    File root = fs.open(dirname);
    if(!root){
        Serial.println("Failed to open directory");
        return;
    }
    if(!root.isDirectory()){
        Serial.println("Not a directory");
        return;
    }

    File file = root.openNextFile();
    while(file){
        if(file.isDirectory()){
            Serial.print("  DIR : ");
            Serial.println(file.name());
            if(levels){
                listDir(fs, file.name(), levels -1);
            }
        } else {
            Serial.print("  FILE: ");
            Serial.print(file.name());
            Serial.print("  SIZE: ");
            Serial.println(file.size());
        }
        file = root.openNextFile();
    }
}

void createDir(fs::FS &fs, const char * path){
    Serial.printf("Creating Dir: %s\n", path);
    if(fs.mkdir(path)){
        Serial.println("Dir created");
    } else {
        Serial.println("mkdir failed");
    }
}

void removeDir(fs::FS &fs, const char * path){
    Serial.printf("Removing Dir: %s\n", path);
    if(fs.rmdir(path)){
        Serial.println("Dir removed");
    } else {
        Serial.println("rmdir failed");
    }
}

void readFile(fs::FS &fs, const char * path){
    Serial.printf("Reading file: %s\n", path);

    File file = fs.open(path);
    if(!file){
        Serial.println("Failed to open file for reading");
        return;
    }

    Serial.print("Read from file: ");
    while(file.available()){
        Serial.write(file.read());
    }
}

void writeFile(fs::FS &fs, const char * path, const char * message){
    Serial.printf("Writing file: %s\n", path);

    File file = fs.open(path, FILE_WRITE);
    if(!file){
        Serial.println("Failed to open file for writing");
        return;
    }
    if(file.print(message)){
        Serial.println("File written");
    } else {
        Serial.println("Write failed");
    }
}

void appendFile(fs::FS &fs, const char * path, const char * message){
    Serial.printf("Appending to file: %s\n", path);

    File file = fs.open(path, FILE_APPEND);
    if(!file){
        Serial.println("Failed to open file for appending");
        return;
    }
    if(file.print(message)){
        Serial.println("Message appended");
    } else {
        Serial.println("Append failed");
    }
}

void renameFile(fs::FS &fs, const char * path1, const char * path2){
    Serial.printf("Renaming file %s to %s\n", path1, path2);
    if (fs.rename(path1, path2)) {
        Serial.println("File renamed");
    } else {
        Serial.println("Rename failed");
    }
}

void deleteFile(fs::FS &fs, const char * path){
    Serial.printf("Deleting file: %s\n", path);
    if(fs.remove(path)){
        Serial.println("File deleted");
    } else {
        Serial.println("Delete failed");
    }
}

void testFileIO(fs::FS &fs, const char * path){
    File file = fs.open(path);
    static uint8_t buf[512];
    size_t len = 0;
    uint32_t start = millis();
    uint32_t end = start;
    if(file){
        len = file.size();
        size_t flen = len;
        start = millis();
        while(len){
            size_t toRead = len;
            if(toRead > 512){
                toRead = 512;
            }
            file.read(buf, toRead);
            len -= toRead;
        }
        end = millis() - start;
        Serial.printf("%u bytes read for %u ms\n", flen, end);
        file.close();
    } else {
        Serial.println("Failed to open file for reading");
    }


    file = fs.open(path, FILE_WRITE);
    if(!file){
        Serial.println("Failed to open file for writing");
        return;
    }

    size_t i;
    start = millis();
    for(i=0; i<2048; i++){
        file.write(buf, 512);
    }
    end = millis() - start;
    Serial.printf("%u bytes written for %u ms\n", 2048 * 512, end);
    file.close();
}

void setup(){
    Serial.begin(115200);
    delay(1000);
    pinMode(2, INPUT_PULLUP);
    if(!SD_MMC.begin("/sdcard", true, false)){
        Serial.println("Card Mount Failed");
        return;
    }
    uint8_t cardType = SD_MMC.cardType();

    if(cardType == CARD_NONE){
        Serial.println("No SD_MMC card attached");
        return;
    }

    Serial.print("SD_MMC Card Type: ");
    if(cardType == CARD_MMC){
        Serial.println("MMC");
    } else if(cardType == CARD_SD){
        Serial.println("SDSC");
    } else if(cardType == CARD_SDHC){
        Serial.println("SDHC");
    } else {
        Serial.println("UNKNOWN");
    }

    uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024);
    Serial.printf("SD_MMC Card Size: %lluMB\n", cardSize);

    listDir(SD_MMC, "/", 0);
    createDir(SD_MMC, "/mydir");
    listDir(SD_MMC, "/", 0);
    removeDir(SD_MMC, "/mydir");
    listDir(SD_MMC, "/", 2);
    writeFile(SD_MMC, "/hello.txt", "Hello ");
    appendFile(SD_MMC, "/hello.txt", "World!\n");
    readFile(SD_MMC, "/hello.txt");
    deleteFile(SD_MMC, "/foo.txt");
    renameFile(SD_MMC, "/hello.txt", "/foo.txt");
    readFile(SD_MMC, "/foo.txt");
    testFileIO(SD_MMC, "/test.txt");
    Serial.printf("Total space: %lluMB\n", SD_MMC.totalBytes() / (1024 * 1024));
    Serial.printf("Used space: %lluMB\n", SD_MMC.usedBytes() / (1024 * 1024));
}

void loop(){

}

@dizcza
Copy link

dizcza commented Sep 4, 2021

@tionebrr
could you also clarify

You can use any pin as I²C with the ESP32

Clearly, we cannot use any GPIO pin as I2C, can we? There are only two I2C according to the seller information. One is at 21 & 22 pins. Where is the other? (I'd like to keep pin 21 for LED.)
Thank you.

@tionebrr
Copy link

tionebrr commented Sep 4, 2021

@dizcza Not really any indeed. You can't use an "input only" pin for SDA for example.
There are two I2C peripherals in the ESP32 but they are behind a GPIO Mux. You can route most ESP32 internal peripherals to any GPIO. The GPIO Muxing however introduces a timing constraint (because it's clocked by the APB at 80MHz), so some peripherals (SPI, Ethernet, SDMMC etc...) are better locked to a specific set of pins.

I²C is obviously tolerant enough and can be routed anywhere.

You can check the list in the datasheet page 37.

Also I agree that this issue should be closed. The LilyGo folks does not seem to be monitoring this repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants