CH376msc Library - Unable to read CSV

I'm trying to use the CH376msc library by György Kovács ( to read data from a CSV file on a USB stick. However, when I attempt to read the file, all I get is gibberish. I have checked, and put the CSV file in Unicode (UTF-8) format.

I do not believe this is a hardware issue, as the example code from the library runs without issues on the same setup.

Below is the sample sketch I'm trying to use to read the data:

#include <SoftwareSerial.h>
#include <Ch376msc.h>

SoftwareSerial stickSerial(6, 5); //6 is RX, 5 is TX on Arduino - so 5 to RX on CH376 and 6 to TX on CH376
Ch376msc stickReader(stickSerial);
int numTries = 0;

void setup() {
  Serial.begin(9600); //Initialise serial to talk to serial monitor
  stickSerial.begin(9600); //Initialise serial to talk to USB stick

void loop() {
  // put your main code here, to run repeatedly:
  if (stickReader.checkIntMessage()) {
    if (stickReader.getDeviceStatus()) {
      Serial.println("Flash drive ready.");
    } else {
      Serial.println("No flash drive detected.");

void loadCalibration() {
  //This will load the calibration data from a CSV file and display it on serial. If no USB drive is detected,
  // it will just end.  It will load one line of the CSV file at a time.
  char trackBuf[6]; //Buffer to hold the track identifier (loco ID)
  char magClaiBuf[6]; //Buffer to hold the calibration value for magnet end
  char noMagCaliBuf[6]; //Buffer to hold calibration value for non-magnet end

  //If we get to this point, we've got a functional USB drive
  Serial.println("loadCalibration called");
  Serial.print("file opened: ");
  while (true) { //Set to 'true' for testing purposes
    //Continue as long as there is data in the file
    stickReader.readFileUntil(',', trackBuf, sizeof(trackBuf)); //Read first field
    stickReader.readFileUntil(',', magClaiBuf, sizeof(magClaiBuf)); //Read second field
    stickReader.readFileUntil('\n', noMagCaliBuf, sizeof(noMagCaliBuf)); //Read third field - ends with newline
    //Data is read in and being held - now just need to process it
    Serial.print("Loco ID: ");
    Serial.print("Magnet end: ");
    Serial.print("Non-magent end: ");

The CSV file was made in OpenOffice, and is as follows:


I have taken the following steps to troubleshoot so far:

  • Ensured the CSV file is in UTF-8 encoding
  • Formatted the flash drive
  • Put the filename in all caps (as per a discussion on the Github post)
  • Tried with a .TXT extension as well as .CSV

None of these options have worked, they just produce output like this:

6:24:51.464 -> loadCalibration called
16:24:51.510 -> file opened: 0
16:24:51.510 -> Loco ID: ⸮⸮ۻ⸮⸮⸮⸮^{⸮Mݶ⸮
16:24:51.557 -> Magnet end: ⸮
16:24:51.557 -> Non-magent end: 
16:24:51.604 -> ****
16:24:51.604 -> Loco ID: ⸮⸮ۻ⸮⸮⸮⸮^{⸮Mݶ⸮
16:24:51.651 -> Magnet end: ⸮
16:24:51.651 -> Non-magent end: 
16:24:51.651 -> ****
16:24:51.698 -> Loco ID: ⸮⸮ۻ⸮⸮⸮⸮^{⸮Mݶ⸮
16:24:51.698 -> Magnet end: ⸮

What am I missing?

I've found what I'm missing. The call to loadCalibration() in the Setup() function shouldn't be there - it should only be called in the main body of the loop.

Now I've just got to figure out why 'readFileUntil' seems to be ignoring the delimiter.

That library does not read/write UTF-8 data, it just reads/writes raw bytes. If you just have numbers in your file, it doesn't matter.

I managed to get it working by using the 'readLong' function in place of the 'readFileUntil' fuction - it's just a CSV of numbers. Used the same delimiters as the example code, then cast the longs to ints to be put into the existing code.