Arduino - How to Read SD Card Text File Line by Line
License: GNU Lesser General Public License Microcontrollers Wifi Arduino ESP32
We will learn how to read the SD card text file line by line.
Watch the Video!
Note: You can use other displays such as OLED, but make sure that you use a board with enough memory, like an Arduino Mega, etc.
Learn more about Visuino: What is Visuino
What You Will Need
LCD Display I2C 20X4 (if you use a different LCD, then specify the right columns and rows in the Visuino component)
Arduino Uno or any other Arduino board
Visuino software: Download here





Start Visuino, and Select the Arduino UNO Board Type
The Visuino: https://www.visuino.eu also needs to be installed. Download the free version or register for a free trial.
Start Visuino as shown in the first picture. Click on the "Tools" button on the Arduino component (Picture 1) in Visuino. When the dialog appears, select "Arduino UNO" as shown in Picture 2


Prepare the SD Card
Open a Notepad or any other writing software on your computer and write it like this:TEXT LINE1
TEXT LINE2
TEXT LINE3
TEXT LINE4
Then save it as a "TEST.TXT" to the SD card. Remove the SD card from your computer and put it in the Arduino SD card module.

Circuit
Connect SD card Module pin GND to Arduino pin GND
Connect SD card Module pin VCC to Arduino pin 5V
Connect SD card Module pin SCK to Arduino digital pin 13
Connect SD card Module pin MISO to Arduino digital pin 12
Connect SD card Module pin MOSI to Arduino digital pin 11
Connect SD card Module pin CS to Arduino digital pin 10
Connect LCD Display pin VCC to Arduino pin 5V
Connect LCD Display Module pin GND to Arduino pin GND
Connect LCD Display pin SCL to Arduino pin SCL
Connect LCD Display pin SDA to Arduino pin SDA

In Visuino Add Components
Add "Micro SD Card Module" component
Add "Liquid Crystal Display (LCD) - I2C" component
Add "Start" component



In Visuino Set Components
Double-click on the "SDCard1" component, and in the Elements window, drag "File" to the left side
Now on the Left side of the Elements window select "File1" and in the properties window set "New Line" to False, "Path Name" to TEST.TXT
and select "Elements" and click on the 3 dots button, a New Elements window will open, here drag 4X "Read Text Line" to the left side.Close both "Elements" windows
Select "LiquidCrystalDisplay1" and in the properties window set the properties of your LCD in our case the LCD is 20X4, so set "Columns" to 20 and "Rows" to 4




In Visuino Connect Components
Connect "SDCard1" pin SPI to Arduino pin SPI In
Connect "SDCard1" pin Chip Select to Arduino digital pin 10
Connect "Start1" pin Out to "SDCard1" pin > "Read Text Line1" pin Clock
Connect "Start1" pin Out to "SDCard1" pin > "Read Text Line2" pin Clock
Connect "Start1" pin Out to "SDCard1" pin > "Read Text Line3" pin Clock
Connect "Start1" pin Out to "SDCard1" pin > "Read Text Line4" pin Clock
Connect "SDCard1" pin > "Read Text Line1" pin Out to "LiquidCrystalDisplay1" pin In
Connect "SDCard1" pin > "Read Text Line2" pin Out to "LiquidCrystalDisplay1" pin In
Connect "SDCard1" pin > "Read Text Line3" pin Out to "LiquidCrystalDisplay1" pin In
Connect "SDCard1" pin > "Read Text Line4" pin Out to "LiquidCrystalDisplay1" pin In
Connect "LiquidCrystalDisplay1" pin I2C Out to Arduino pin I2C In



Generate, Compile, and Upload the Arduino Code
In Visuino, at the bottom click on the "Build" Tab, make sure the correct port is selected, then click on the "Compile/Build and Upload" button.

Play
If you power the Arduino UNO, the Display will show the text lines that are in the text file on the SD card.
Congratulations! You have completed your project with Visuino. Also attached is the Visuino project that I created for this; you can download it and open it in Visuino: https://www.visuino.eu

