Wrong characters writing in file on SD card

Hi pylon,

I tried your solution but what I had was just a file starting with the characters "ï» ¿". I saw that this in some versions of Excel can work or not. It didn't work for me. But your suggestion opened my mind to move on to another solution.

Searching for these characters here, I realized that I could simply convert the characters I need to byte. Then I found this site https://www.branah.com/unicode-converter that converts the characters I need to the corresponding byte. Then I just have to write it down.

jimLee,

I didn't quite understand your suggestion. In case I would just convert the character I need, is that it? That "something" in the case would be the byte to return?

Thank you Guys!

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

const int chipSelect = 10;
File dataFile;

void setup() {

  Serial.begin(9600);

  while (!Serial);

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

  if (!SD.begin(chipSelect)) {

    Serial.println("initialization failed. Things to check:");

    Serial.println("1. is a card inserted?");

    Serial.println("2. is your wiring correct?");

    Serial.println("3. did you change the chipSelect pin to match your shield or module?");

    Serial.println("Note: press reset or reopen this serial monitor after fixing your issue!");

    while (true);

  }

  Serial.println("initialization done.");
}

void loop() {

  String dataString = "variável;cartão;número";

  unsigned char bom1[] = { 0x56, 0x61, 0x72, 0x69, 0xE1, 0x76, 0x65, 0x6C, 0x3b, 0x43, 0x61, 0x72, 0x74, 0xe3, 0x6f, 0x3b, 0x4e, 0xfa, 0x6d, 0x65, 0x72, 0x6f};

  dataFile = SD.open("datalog.csv", FILE_WRITE);

  if (dataFile) {

    dataFile.print((char*)bom1);
    dataFile.println("");

    dataFile.close();

    Serial.println(dataString);

  }

  else {

    Serial.println("error opening datalog.txt");
  }
  delay(3000);
}