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


Brody Cameron Lab 5

Page history last edited by xyyue@... 4 years, 10 months ago

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?

The display holds 14 characters, with up to 6 lines


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

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

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



Correct but the better answer is :  (-0.1)

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


if (dataFile) {

  dataFile.println("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.

To do this, save what's currently on the SD card as a variable, then concatenate what you want to add on to the beginning of the original.

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?

To work around the memory limitation, you have to cut up the file into chunks first in order to add them one by one.


a. Post your code.


#include <SPI.h>

#include <Adafruit_GFX.h>

#include <Adafruit_PCD8544.h>

#include <SD.h>


#define CONTRAST 50

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

int counter;

const int chipSelect = 17;


void setup() {




  counter = 0;


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

  pinMode(17, OUTPUT);


  if (!SD.begin(chipSelect)) {

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

    // don't do anything more:



  display.println("card initialized.");



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

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


  if (dataFile) {

    while (dataFile.available()) {




  }  =

  else {

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






void loop() {


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

Instead of writing to the EEPROM, I write to the SD card.



Comments (0)

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