Arduino - How To Read Sd Card Text File Line By Line

Photo of Ron

Made by Ron / Displays / Robotics / Sensors

About the project

In this tutorial we will learn how to read the SD card text file line by line.

Project info

Difficulty: Easy

Platforms: AdafruitArduinoDFRobotVisuino

Estimated time: 1 hour

License: GNU General Public License, version 3 or later (GPL3+)

Items used in this project

Hardware components

Jumper wires (generic) Jumper wires (generic) x 1
Adafruit MICRO SD CARD Module Adafruit MICRO SD CARD Module x 1
DFRobot LCD i2c 20X4 DFRobot LCD i2c 20X4 x 1
Arduino UNO Arduino UNO x 1

Software apps and online services

Visuino Visuino
Arduino IDE Arduino IDE

Story

In this tutorial 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 Arduino Mega,etc

Also check out this tutorials:

Arduino Nano: Measure Distance With Ultrasonic Ranger and Log It to MicroSD Card With Visuino

Arduino Nano: Log GPS Information to MicorSD Card With Visuino

Step 1: What You Will Need

1 / 5

  • LCD Display I2C 20X4 (if you use diferent LCD then make sure that you specify the right Columns and Rows in the Visuino component)
  • SD card module + SD card
  • Jumper wires
  • Arduino UNO or any other board
  • Visuino software: Download here

Step 2: Start Visuino, and Select the Arduino UNO Board Type

1 / 2

The Visuino: https://www.visuino.eu also needs to be installed. Download 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 on Picture 2

Step 3: 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.

Step 4: 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

Step 5: In Visuino Add Components

1 / 3

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

Step 6: In Visuino Set Components

1 / 4

  • 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.TXTand 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

Step 7: In Visuino Connect Components

1 / 3

  • 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

Step 8: 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.

Step 9: 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 tutorial, you can download it and open it in Visuino: https://www.visuino.eu

Schematics, diagrams and documents

Visuino File

Code

Visuino File

Credits

Photo of Ron

Ron

Arduino Developer

   

Leave your feedback...