Skip to content

Commit 2a748e0

Browse files
committed
SD card and RTC projects
1 parent 05a4f12 commit 2a748e0

File tree

4 files changed

+119
-0
lines changed

4 files changed

+119
-0
lines changed

DS1307 RTC with Arduino/README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# [Interfacing 16x2 LCD with Arduino](https://circuitdigest.com/microcontroller-projects/interfacing-16x2-lcd-with-arduino)
2+
3+
<img src="https://github.com/Circuit-Digest/Basic-Arduino-Tutorials-for-Beginners-/blob/d72d720d083c663016516b760d49e7d76e152fe6/Interfacing%2016x2%20LCD%20with%20Arduino/Image/16x2-LCD_Title-image.jpg" width="" alt="alt_text" title="image_tooltip">
4+
<br>
5+
6+
<br>
7+
<a href="https://circuitdigest.com/tags/arduino"><img src="https://img.shields.io/static/v1?label=&labelColor=505050&message=Arduino Basic Tutorials Circuit Digest&color=%230076D6&style=social&logo=google-chrome&logoColor=%230076D6" alt="circuitdigest"/></a>
8+
<br>
9+
10+
[<h1>Click here](https://circuitdigest.com/tags/arduino) for the complete tutorials on Arduino basics.</h1>
11+
12+
13+
<br>
14+
<br>
15+
<br>
16+
In this digital age, we come across LCDs all around us from simple calculators to smartphones, computers and television sets etc. The LCDs use liquid crystals to produce images or texts. The LCDs are categorized into different categories based on different criteria like type of manufacturing, monochrome or colour, and weather Graphical or character LCD. In this tutorial, we will be talking about the 16X2 character LCD Modules.
17+
<br>
18+
The 16x2 LCDs are very popular among the DIY community. Not only that you can also find them in many laboratory and industrial equipment. It can display up to 32 characters at a time. Each character segment is made up of 40 pixels that are arranged in a 5x8 matrix. We can create alphanumeric characters and customs characters by activating the corresponding pixels. Here is a vector representation of a 16x2 LCD, in which you can see those individual pixels.
19+
<br>
20+
[Note: As this projects are very simple we are only providing the code, schemaitic, and a few essential images if you want to get the images or code explanations do check out the Circuit Digest website.
21+
<br>
22+
<br>
23+
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#include <SD.h>
2+
const int chipSelect = 10;
3+
File myFile;
4+
5+
void setup() {
6+
7+
// Open serial communications and wait for port to open:
8+
Serial.begin(9600);
9+
10+
// wait for Serial Monitor to connect. Needed for native USB port boards only:
11+
while (!Serial);
12+
13+
14+
check_and_create_file();
15+
write_text();
16+
}
17+
18+
void loop() {
19+
20+
// nothing happens after setup finishes.
21+
}
22+
23+
24+
void check_and_create_file()
25+
{
26+
Serial.print("Initializing SD card...");
27+
28+
/*Check if the SD card exist or not*/
29+
if (!SD.begin(chipSelect)) {
30+
Serial.println("initialization failed!");
31+
while (1);
32+
}
33+
34+
Serial.println("initialization done.");
35+
36+
if (SD.exists("data_log.txt"))
37+
Serial.println("data_log.txt exists.");
38+
39+
else
40+
{
41+
Serial.println("data_log.txt doesn't exist.");
42+
43+
44+
/* open a new file and immediately close it:
45+
this will create a new file */
46+
47+
Serial.println("Creating data_log.txt...");
48+
49+
myFile = SD.open("data_log.txt", FILE_WRITE);
50+
51+
myFile.close();
52+
53+
/* Now Chec agin if the file exists in
54+
the SD card or not */
55+
56+
if (SD.exists("data_log.txt"))
57+
Serial.println("data_log.txt exists.");
58+
59+
else
60+
Serial.println("data_log.txt doesn't exist.");
61+
}
62+
}
63+
64+
65+
void write_text()
66+
{
67+
myFile = SD.open("data_log.txt", FILE_WRITE);
68+
69+
// if the file opened okay, write to it:
70+
if (myFile) {
71+
Serial.print("Writing to data_log.txt...");
72+
myFile.println("testing 1, 2, 3.");
73+
// close the file:
74+
myFile.close();
75+
Serial.println("done.");
76+
} else {
77+
// if the file didn't open, print an error:
78+
Serial.println("error opening data_log.txt");
79+
}
80+
81+
// re-open the file for reading:
82+
myFile = SD.open("data_log.txt");
83+
if (myFile) {
84+
Serial.println("data_log.txt:");
85+
86+
// read from the file until there's nothing else in it:
87+
while (myFile.available()) {
88+
Serial.write(myFile.read());
89+
}
90+
// close the file:
91+
myFile.close();
92+
} else {
93+
// if the file didn't open, print an error:
94+
Serial.println("error opening data_log.txt");
95+
}
96+
}

0 commit comments

Comments
 (0)