Page 1 of 1

stuck on hspi for ttgo t-beam

Posted: Thu Oct 08, 2020 7:36 pm
by faceless105
I hate to say it, but this is out of my normal realm and I'm struggling. I have a ttgo t-beam v1 board and I love the features. However, I want to handle some data logging via a micro sd card. I did some research and the sample code looked really straight forward. But things don't seem to be working. I'm of the mindset that it's my code and not the wiring, and I've confirmed that my SD card can read and write when I use it with my computer directly. The wiring looks complete but I haven't run a multimeter over anything. I'm hoping someone can give me a bit of direction or tell if there's anything I need to watch out for when re-assigning pins for spi?

The code checks to see if it can detect the microSD, then checks if the file is there. If it is, then it reports, otherwise it'll try to create the file and report again if it's there.

My output hasn't been successful output:

Code: Select all

Card failed, or not present
data.csv doesn't exist.
Creating data.csv...
data.csv doesn't exist.
I'm currently at a bit of a loss. Any recommendations?

Code: Select all

#include <SPI.h>
#include <SD.h>

// HSPI
#define HSPI_SCLK 14
#define HSPI_MISO 4
#define HSPI_MOSI 13
#define HSPI_CS 2

SPIClass * hspi = NULL;

String dataString =""; // holds the data to be written to the SD card
File sensorData;

void setup() {

  hspi = new SPIClass(HSPI);
  hspi->begin(HSPI_SCLK, HSPI_MISO, HSPI_MOSI, HSPI_CS); //SCLK, MISO, MOSI, SS
  pinMode(HSPI_CS, OUTPUT); //HSPI SS

  Serial.begin(115200);

  // see if the card is present and can be initialized:
  if (!SD.begin(HSPI_CS)) {
    Serial.println("Card failed, or not present");
  }

  if (SD.exists("data.csv")) {
    Serial.println("data.csv exists.");
  }
  else {
    Serial.println("data.csv doesn't exist.");
  }

  // open a new file and immediately close it:
  Serial.println("Creating data.csv...");
  sensorData = SD.open("data.csv", FILE_WRITE);
  sensorData.close();

  // Check to see if the file exists:
  if (SD.exists("data.csv")) {
    Serial.println("data.csv exists.");
  }
  else {
    Serial.println("data.csv doesn't exist.");
  }
  while(1);
}

void loop() {

}

Re: stuck on hspi for ttgo t-beam

Posted: Mon Oct 12, 2020 12:34 pm
by faceless105
I found the issue to be a 2-part deal.

The first issue was, this has to run on 5v.

The second issue was the addressing of the file. It required the slash in front of it.

This worked:

Code: Select all

SD.exists("/data.csv")