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

  • Stop wasting time looking for files and revisions. Connect your Gmail, DriveDropbox, and Slack accounts and in less than 2 minutes, Dokkio will automatically organize all your file attachments. Learn more and claim your free account.


Finke Andrew Lab 5

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

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






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.setCursor(0, 0);

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


  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:



  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();






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

  else {

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





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!




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



Comments (1)

xyyue@... said

at 2:04 pm on Aug 11, 2015

Well done.

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