Reading text from sd card is returning weird characters? 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 on 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 display 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 display 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&nbsp;&lt;LiquidCrystal.h&gt;
#include&nbsp;&lt;SPI.h&gt;
#include&nbsp;&lt;SD.h&gt;

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() {

&nbsp;&nbsp;lcd.begin(16, 2);

&nbsp;&nbsp;Serial.begin(9600);
&nbsp;&nbsp;while (!Serial) {
&nbsp;&nbsp;&nbsp;&nbsp;;&nbsp;// wait for serial port to connect. Needed for native USB port only
&nbsp;&nbsp;}

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

&nbsp;&nbsp;// see if the card is present and can be initialized:
&nbsp;&nbsp;if (!SD.begin(chipSelect)) {
&nbsp;&nbsp;&nbsp;&nbsp;Serial.println("Card failed, or not present");
&nbsp;&nbsp;&nbsp;&nbsp;// don't do anything more:
&nbsp;&nbsp;&nbsp;&nbsp;while (1);
&nbsp;&nbsp;}
&nbsp;&nbsp;Serial.println("card initialized.");

&nbsp;&nbsp;// open the file. note that only one file can be open at a time,
&nbsp;&nbsp;// so you have to close this one before opening another.
&nbsp;&nbsp;File dataFile = SD.open("datalog.txt");


&nbsp;&nbsp;if (dataFile) {
&nbsp;&nbsp;&nbsp;&nbsp;while (dataFile.available()) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nextChar&nbsp;=&nbsp;dataFile.read();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (isWhitespace(nextChar)){

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lcd.print(wordBuffer);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Serial.println(wordBuffer);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lcd.display();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delay(500);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wordBuffer&nbsp;=&nbsp;"";
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lcd.clear();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else{

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wordBuffer&nbsp;=&nbsp;wordBuffer&nbsp;+&nbsp;nextChar;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wordBuffer.trim();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;dataFile.close();
&nbsp;&nbsp;}

&nbsp;&nbsp;// if the file isn't open, pop up an error:
&nbsp;&nbsp;else {
&nbsp;&nbsp;&nbsp;&nbsp;Serial.println("error opening datalog.txt");
&nbsp;&nbsp;}
}

void loop() {
}
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.