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

View
 

Beomjun Aaron Bae Lab 5

Page history last edited by xinyi xie 6 years, 1 month ago

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

- 14 characters on each line and 5 lines

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

 

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

#include <SD.h>

 

File myFile;

 

void setup()

{

  Serial.begin(9600);

   while (!Serial) {

    ; 

  }

 

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

   pinMode(10, OUTPUT);

 

  if (!SD.begin(4)) {

    Serial.println("initialization failed!");

    return;

  }

  Serial.println("initialization done.");

 

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

 

  if (myFile) {

    Serial.print("Writing to test.txt...");

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

    myFile.close();

    Serial.println("done.");

  } else {

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

  }

 

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

  if (myFile) {

    Serial.println("datalog.txt:");

 

    while (myFile.available()) {

    Serial.write(myFile.read());

    }

    myFile.close();

  } else {

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

  }

}

 

void loop()

{

}

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

     - Read all the content of the file, clear the text file, and rewrite the text with the new phrase to start the file off.

 

B3c. 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 would not work if the file was bigger than the arduino's memory. I could create another file that would have the desired content, delete the original file and rename the file we created already to the original file's name.

 

B4a. Post your code.

#include <SPI.h>

#include <Adafruit_GFX.h>

#include <Adafruit_PCD8544.h>

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

 

#include <SD.h>

 

const int chipSelect = 17;

const int CONTRAST = 55;

void setup()

{

  initializeLCD();

  initializeSerial();  

  initializeSD();

 

  String fileName = "Test.text";

  deleteFileSD(fileName);

  writeSD(fileName, "Ozymandias");  

  readNDisplay(fileName);  

}

void initializeLCD(){

  display.begin();

  display.setContrast(CONTRAST);

  display.clearDisplay();

}

void initializeSerial(){

  Serial.begin(9600);

  delay(1000); 

}

void initializeSD(){

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

  pinMode(17, OUTPUT);

 

  if (!SD.begin(chipSelect)) {

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

    return;

  }

  Serial.println("card initialized.");

 

}

void readNDisplay(String fileName){  

  char charBuffer[fileName.length()];

  fileName.toCharArray(charBuffer, fileName.length());

 

  File dataFile = SD.open(charBuffer);

 

  if (dataFile) {

    while (dataFile.available()) {

      display.write(dataFile.read());

    }

    dataFile.close();

  }  

  else {

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

  } 

}

void writeSD(String fileName, String content){

  char charBuffer[fileName.length()];

  fileName.toCharArray(charBuffer, fileName.length());

 

  File myFile = SD.open(charBuffer, FILE_WRITE);

 

  if (myFile) {

    Serial.print("Writing to test.txt...");

    myFile.println(content);

    myFile.close();

    Serial.println("done.");

  } else {

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

  }

}

void deleteFileSD(String fileName){

  char charBuffer[fileName.length()];

  fileName.toCharArray(charBuffer, fileName.length());

 

  if(SD.exists(charBuffer)){

    SD.remove(charBuffer);  

  } 

  Serial.println("done");

}

/*

void lcdDisplay(char* context){

  display.clearDisplay();

  display.setCursor(0,0);

  display.write(context);

  display.display();

}*/

void loop()

{

}

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

     - instead of saving the value of the rotary encoder, I would need to save the value into a text file and the file would be saved in the micro SD Card. 

 

 

Da. 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)

xinyi xie said

at 9:09 pm on Aug 6, 2014

Great job!

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