Lab 5 Questions
Part A:
3A. With the standard font, what is the longest message you can write across one line of the display? How many lines can you write?
With the standard font, the longest message you can write is a 14 unit message (14 letters can fit in one line), and you can write 5 lines in the display.
Using the standard font, the display shows 6 lines of 14 characters each. -0.25
5A. Upload a photo of your personal logo, shown on your LCD screen, to your Lab 5 page.
✔
Part B:
3A. Include the code that you had to insert to do this in your lab writeup.
#include <SPI.h>
#include <SD.h>
const int chipSelect = 17;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
delay(1000);
while (!Serial) {};
Serial.print("Initializing SD card...");
pinMode(17, OUTPUT); //set SS pin as output.
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
return;
}
Serial.println("card initialized.");
File dataFile = SD.open("datalog.txt",FILE_WRITE);
if(dataFile) {
dataFile.print("He who must not be named!");
dataFile.close();
}
dataFile=SD.open("datalog.txt");
if (dataFile) {
while (dataFile.available()) {
Serial.write(dataFile.read());
}
dataFile.close();
} else {
Serial.println("error opening datalog.txt");
}
}
void loop() {
}
✔
3B. Explain what would you do differently to insert the same text string, but at the beginning of the file (without over-writing the current contents). You don't have to code this: just explain the process. If you're interested and have time make it work, show us your program.
I would put the contents inside the file to a separate file on the SD card, clear the current file and write my own text, and then copy back the info from the second file. Then, I would delete that temporary file with all the evidence of the transfer.
✔
3C. Now tell us if your approach would work if the file were larger than your Arduino's memory (which is 2.5KB). If not, how could you work around that limitation?
My method would still work if the file was larger than the Arduino’s memory because it is only limited by the memory of the SD card which has more than the Arduino. To copy the file into a temporary file and back again would require me to do in pieces because of the small Arduino’s memory.
✔
4A. Post your code.
#include <SPI.h>
#include <SD.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#define CONTRAST 50
Adafruit_PCD8544 display = Adafruit_PCD8544(7,6,5,-1,-1);
const int chipSelect = 17;
void setup() {
display.begin();
display.setContrast(CONTRAST);
display.clearDisplay();
display.setCursor(0, 0);
Serial.begin(9600);
delay(1000);
while (!Serial) {
;
}
Serial.print("Initializing SD card...");
pinMode(17, OUTPUT); //set SS pin as output.
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
return;
}
Serial.println("card initialized.");
File dataFile = SD.open("datalog.txt",FILE_WRITE);
if(dataFile) {
dataFile.print("He who must not be named!");
dataFile.close();
}
dataFile=SD.open("datalog.txt");
if (dataFile) {
while (dataFile.available()) {
display.write(dataFile.read());
display.display();
delay(500);
}
dataFile.close();
} else {
Serial.println("error opening datalog.txt");
}
}
void loop() {
}
✔
5A. Tell us what you had to change to make this work.
The changes that I had to make this work was to first import the SD card libraries. Then, I changed the EEPROM reading and writing lines to reading and writing from the SD card file instead of the Arduino EEPROM. Then, I would open and close the current file.
✔
Part D:
1A. Upload video of your Etch-a-Sketch in action!
1B. Post a link to the Lab 5 Etch-a-Sketch Hall of Fame.