Displaying Text from Datalogger shield on OLED SSD1315 (arduino-seeds)?

I read the code you have posted.

The code inside loop is executed again and again infinitely.
That is what loop is made for:

looping infinitely.
For your testcode it will be better if the code is executed only once.

that is what function setup() is made for
so here is a code-version that has the code that you had inside loop()

inside a new function which I gave the name
myTestSD_OLED_Function()

the lines of code starting with

void myTestSD_OLED_Function() {

are the definition of the function

the line with

myTestSD_OLED_Function(); 

is calling this function

as myTestSD_OLED_Function(); is inside setup()
it gets executed only once

#include "Arduino_SensorKit.h"
#include <SPI.h>
#include <Wire.h>
#include <SD.h>

String text;
const int chipSelect = 10;

File myFile;
void setup() {
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.print("Initializing SD card...");

  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("BPM.txt", FILE_WRITE);

  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    Serial.print("testing 1, 2, 3.");
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

  // re-open the file for reading:
  myFile = SD.open("BPM.txt", FILE_READ);
  if (myFile) {
    Serial.println("BPM.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      text = myFile.readString();
      delay(100);
      //Serial.println(text);

    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

  Serial.println(text);
  // Oled.setFont(u8x8_font_chroma48medium8_r);
  //Oled.setCursor(0, 3);

  Oled.begin();
  Oled.setFlipMode(true);

  Oled.setFont(u8x8_font_chroma48medium8_r);

  myTestSD_OLED_Function(); 

}

void myTestSD_OLED_Function() {
  Oled.setCursor(0, 3);
  Oled.refreshDisplay();
  delay(1000);
  
  // re-open the file for reading:
  myFile = SD.open("BPM.txt", FILE_READ);

  if (myFile) {
    Oled.println("BPM.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      text = myFile.readString();
      delay(1000);
      Serial.println(text);
      Oled.println(text);

    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
  
}


void loop(){

}

For narrowing down the problem you should print all things that you are "printing to the OLED also print to the serial monitor.
I added this line

      Serial.println(text);
      Oled.println(text);

If this code-version does not work you should go back to the most simple possible code that does test the OLED-Display by printing a constant string

    Serial.println("ABC");
    Oled.println("ABC");

and test if this works

if this works next step is assigning characters to a variable and printing it

    char myTestCharArray [] = "ABC";
    Serial.println(myTestCharArray);
    Oled.println(myTestCharArray);

and test if this works

next with variable-type String

    String myTestStr = "ABC";
    Serial.println(myTestStr);
    Oled.println(myTestStr);

next with variable-type String

If you don't know yet what variables are how setup() and loop() work
I recommend
Take a look into this tutorial:

Arduino Programming Course

It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going. So give it a try and report your opinion about this tutorial.

best regards Stefan

1 Like