I have an ebook which is converted to a .txt file saved on an SD card, which is connected to the Arduino. I'm trying to display the words from the book on a 16x2 LCD display, one word at a time. It works mostly except when it reads a word that has an apostrophe or a pipe symbol: it does not display correctly to the LCD or the serial output.

For example the word "author's" will be displayed as "authorâs" (edit: there is actually two boxes between the "â" and the s that is not displaying on this forum) on both the LCD and serial output.

I've spent an entire day now with this one problem hopefully there is a mistake someone can pick up on :/

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

const int chipSelect = 53;

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

char nextChar;
String wordBuffer = "";

void setup() {
  lcd.begin(16, 2);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  Serial.print("Initializing SD card...");
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    while (1);
  Serial.println("card initialized.");
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile = SD.open("datalog.txt");
  if (dataFile) {
    while (dataFile.available()) {
      nextChar = dataFile.read();
      if (isWhitespace(nextChar)){
        wordBuffer = "";
      } else {
        wordBuffer = wordBuffer + nextChar;
  } else {
    // if the file isn't open, pop up an error:  
    Serial.println("error opening datalog.txt");

void loop() {
  • When you look into the .txt file and look for that word and show the hexadecimal values for that word, can you see if that is normal ascii code or something else? You show the sketch, but I think the problem is the way the ebook is converted to a .txt file.
    – Jot
    Aug 17, 2018 at 22:24
  • I checked the .txt file and it's in utf-8. I used calibre to save it as ascii but now in the text document a lot of letters have been replaced with question marks. Converting to ascii is not really going to work if things like apostrophes become question marks. maybe I can find a different format that will work.
    – Kara
    Aug 17, 2018 at 22:55

1 Answer 1


The text file is not ASCII, it is UTF-8. You will either have to convert it to pure ASCII, or write (or obtain) a conversion routine to approximate the UTF-8 characters using ASCII on the Arduino.

Maybe this can help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.