Finke Andrew Lab 5


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

    I was able to write "AAAAAAAAAAAAAA"

 

 

    How many lines can you write?

    Six lines of text.

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

 

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

  if (dataFile) {

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

    while (dataFile.available()) {

      Serial.write(dataFile.read());

    }

    dataFile.close();

  }

 

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.

     Use a variable (probably a string) to hold the sd card contents and add the new string to the very beginning. Then write this final string to the card.

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?

     It is not possible to work around the limitation as you can't just "create" space from no where. You could use a form of compression, but the Arduino's memory space is always finite.

 

 

a. Post your code.

#include <SPI.h>

#include <SPI.h>

#include <SD.h>

#include <Adafruit_GFX.h>

#include <Adafruit_PCD8544.h>

 

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

 

void setup() {

  display.begin();

  display.setContrast(55);

  display.clearDisplay();

  display.setCursor(0, 0);

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

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

    // don't do anything more:

    return;

  }

  Serial.println("card 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 (dataFile) {

    while (dataFile.available()) {

      char data = dataFile.read();

      display.print(data);

  Serial.write(data);

    }

    dataFile.close();

  }  

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

  else {

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

  } 

  display.display();

}

 

void loop()

{

}

 

 

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

     I had to include the additional libraries needed for the new display and sd card support, as well as change my eprom code to write to the sd card.

 

 

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

     http://youtu.be/qJBRUGZRFlQ

 

 

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

     Done