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

  • Get control of your email attachments. Connect all your Gmail accounts and in less than 2 minutes, Dokkio will automatically organize your file attachments. You can also connect Dokkio to Drive, Dropbox, and Slack. Sign up for free.

View
 

Lab 5 Galyardt Jackson

Page history last edited by Jackson Galyardt 5 years, 11 months ago

Part A

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?

You can write "12345678901234" on one line (14 characters), and the display can fit 5 lines.

5.

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

Here is my strange, modified Stanford logo:

http://i.imgur.com/w3b0RFo.jpg

 

Part B

3.

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

#include <SPI.h>

#include <SD.h>

void setup()

{

  Serial.begin(9600);

  delay(1000);

  while (!Serial) {

    ;

  }

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

  pinMode(17, 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) {

    Serial.println("Writing to file...");

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

    dataFile.close();

  }

 

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

 

  if (dataFile) {

    while (dataFile.available()) {

      Serial.write(dataFile.read());

    }

    dataFile.close();

  }  

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

  else {

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

  } 

}

 

void loop()

{

}

 

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.

Copy the current contents of the file into memory, use the function seek(0) to get to the beginning of the file, add "He who must not be named!", and then print the rest of the file.

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?

Nope, but this could be solved by creating a buffer and writing parts of the document incrementally.

4.

a. Post your code.

 

#include <SPI.h>

#include <SD.h>

#include <Adafruit_GFX.h>

#include <Adafruit_PCD8544.h>

 

const int chipSelect = 17;

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

 

 

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."); 

  display.begin();

  display.clearDisplay();

  display.setContrast(50);

  Serial.println("LCD initialized"); 

  // open the file. note that only one file can be open at a time,

  // so you have to close this one before opening another.

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

  // if the file is available, write to it:

  if (dataFile) {

    while (dataFile.available()) {

     //Serial.write(dataFile.read());

     Serial.println("First part of loop");

     display.write(dataFile.read());

     display.display();

     Serial.println("Second part of loop");

    }

    dataFile.close();

 

  }  

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

  else {

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

  }  

}

void loop()

{

  Serial.println("Looping...");

  delay(1000);

}

5.

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

Add all the SD card initialization code, and then take the data stored in memory and add it onto the SD card using the various print functions. Using the SD library you can choose to overrite the existing file or add on.

Part D

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

https://www.youtube.com/watch?v=L6KszBKQ-_c&feature=youtu.be

 

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

 

Comments (1)

xinyi xie said

at 1:42 pm on Aug 10, 2014

Great job!

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