| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Kim_Minji_Lab5

Page history last edited by zahraa@... 8 years, 8 months ago

Part A. Graphical LCD

3.

a. With the standard font, what is the longest message you can write across one line of the display? How many lines can you write?

Using the standard font, one can write a message that is up to 14 characters long across one line of the display. One can write up to 6 lines.

5.

a. Upload a photo of your personal logo, shown on your LCD screen, to your Lab 5 page.

Part B. microSD Card

3.

a. Include the code that you had to insert to do this in your lab writeup. 

File dataFile = SD.open("datalog.txt", FILE_WRITE);

  if(dataFile){

    dataFile.println("He who must not be named.");

    dataFile.close();

  }

  else{

    Serial.println("error opening datalog.txt");

  }

  dataFile = SD.open("datalog.txt");

 

  if (dataFile) {

    while (dataFile.available()) {

      Serial.write(dataFile.read());

    }

    dataFile.close();

  }   

  else {

    Serial.println("error opening datalog.txt");

  }  

}

The highlighted portions are the inserted lines of code that allowed "He who must not be named" to be appended to the file's contents. The remainder of the code is the original code that allows for the updated file to be printed out. 

b. 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.

In order to write to the beginning of the file, one must go through a more complicated process. First one must save the original string that they want into a new String variable using File.read(); Then using file.seek(0); they may move to the beginning of the file in which they can use file.print() to insert the text string of their desire. Then, one can simply add on their old string back to the end of the new string using file.print(); once again.

c. 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?

If the file is larger than the Arduino's memory, the limitation must be worked around  by transporting sections at a time from the SD card to the Arduino device. One could break the file into 2.5KB sections and continuously move the sections of the file from the SD card to the Arduino device (as the section is processed or has finished its function the next file can move in according to a signal in the code) until the entire file has eventually been transported.

 

 

4.

a. Post your code.

#include <SPI.h>

#include <SD.h>

#include <Adafruit_GFX.h>

#include <Adafruit_PCD8544.h>

 

#define CONTRAST 55

 

Adafruit_PCD8544 display = Adafruit_PCD8544(7,6,5,-1,-1);

const int chipSelect = 17;

String fileText = "";

int startingIndex = 0;

int endingIndex = 14;

 

void setup()

{

 // Open serial communications and wait for port to open:

  Serial.begin(9600);

 

  delay(1000); //this 1 second delay isn't strictly speaking necessary, but it seems to smooth over the USB serial monitor a bit. 

   while (!Serial) {

    ; // wait for serial port to connect. Needed for Leonardo only

  }

 

  Serial.print("Initializing SD card...");

  pinMode(17, OUTPUT); //set SS pin as output. 

 

  // see if the card is present and can be initialized:

  if (!SD.begin(chipSelect)) {

    Serial.println("Card failed, or not present");

    // don't do anything more:

    return;

  }

  Serial.println("card initialized.");

 

  display.begin();

  display.setContrast(CONTRAST);

 

  File dataFile = SD.open("datalog.txt", FILE_WRITE);

  if(dataFile){

    dataFile.print("He who must not be named.");

    dataFile.close();

  }

  else{

    Serial.println("error opening datalog.txt");

  }

 

  dataFile = SD.open("datalog.txt");

  display.clearDisplay();

  display.setCursor(0,0);

 

  if (dataFile) {

    while (dataFile.available()) {

      display.write(dataFile.read());

    }

    dataFile.close();

    display.display();

  }  

  // if the file isn't open, pop up an error:

  else {

    Serial.println("error opening datalog.txt");

  }  

}

void loop()

{

}

 

 

5.

a. Tell us what you had to change to make this work.

In order to make this work, i had to first off import the SD card libraries so that the Arduino would recognize the calls to functions from the SD card. Then, I had to change all of the instances where I stored memory into EEPROM to storing the data into the SD card device. 

 

 

Part D. Create an Etch-a-Sketch!

a. Upload video of your Etch-a-Sketch in action!

 

 

 

b. Post a link to the Lab 5 Etch-a-Sketch Hall of Fame.

 

 

 

 

 

Comments (1)

xyyue@... said

at 2:09 pm on Aug 11, 2015

Well done.

You don't have permission to comment on this page.