By All About Circuits
The following tutorial will demonstrate how to Read values from a Text file (.txt,.csv) to blink 1 of 9 LEDs attached to an Arduino. It uses the combination of an Arduino and Processing program to process the file. The Processing program will read the text file in real time, only sending new information to the Arduino.
In this project, you’ll learn how to use an SD card to store and retrieve information with your Arduino system.
Opening a file (to read) opening a new file (to write) since a line can be long (more than arduino's memory), it's best to read it character by character, thus: use a boolean to denote when to start removing a line (set to e.g. Remove = TRUE) For every character you read: If Remove is TRUE, don't write to the output file, otherwise write it. Nov 02, 2009 I've searched google and can't find any examples of Arduino reading a text file. Is it possible to get arduino to read lines from a text file. The text file only contains 3 lines of strings, and each line is only about 9 characters in length e.g. 356:21:45 Thanks, Ribuck.
Courtesy of All About Circuits
Arduino Serial Read Example
It’s worthwhile to learn how to store and retrieve information locally in some Arduino applications. This can be done with an SD (Secure Digital) card, which is a non-volatile memory card commonly used in mobile phones, tablet computers, digital cameras, handheld consoles, and GPS navigation devices. The smallest SD card available is the Micro SD, measuring at just 15x11x11 mm.
SD Card
For this project, we used an Ethernet shield with a micro SD slot on it. Note that other types of shields compatible with the different types of SD cards.
Micro SD cards have 8 pins, which can be seen in the figure above. Each pin has a specific function:
If you attempted to interface this SD card on your own, you would need to make sure all the pins of the SD card connected to the correct pins of your Arduino. Luckily, we used a commercially-available shield, so this was not a concern. We needed to declare the default chip select (CS) pin of the Arduino as OUTPUT, which was pin 53 on our Arduino MEGA. The CS pin is number 4 on the Ethernet shield. We specified this in the code in order to endure the SD card worked properly.
Experiment 1
In this experiment, we learned how to read a file from the SD card.
Hardware Required
- 1 x micro SD card
- 1 x Ethernet shield module
- 1 x Arduino Mega2560
Arduino MEGA with Ethernet shield installed
Code
To read from the SD card, we used the SD.h library. This code assumed that the file 'ourfile.txt' was already written to the SD card.
Experiment 2
In this experiment, we learned how to create a file, write it, and then read it from SD card.
Hardware Required
The same hardware from Experiment 1 is used.
Code
Arduino Serial Read Text File
We used the SD.h library to write a file to the SD card and to read that file.
Key Parts and Components
Arduino
Seeed Technology Co., Ltd