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

LoganMurphy_Lab05

Page history last edited by Vivien Tsao 7 years, 1 month 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?

 

There are 14 characters per line, and 6 lines available.

 

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

 

http://pressplay.pbworks.com/w/file/68153813/P-40small.jpg

 

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

 

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

 

  // if the file opened okay, write to it:

  if (myFile) {

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

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

    // close the file:

    myFile.close();

    Serial.println("done.");

  } else {

    // if the file didn't open, print an error:

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

  }

 

 

D. Explain what would you do differently (or show us your code!) to insert the same text string, but at the beginning of the file (without over-writing the current contents).

 

I would add a "myFile.seek( 0 )" command, Like so:

 

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

 

  // if the file opened okay, write to it:

  if (myFile) {

    myFile.seek(0);

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

    myFile.println("testing 1, 2, 3.");

    // close the file:

    myFile.close();

    Serial.println("done.");

  } else {

    // if the file didn't open, print an error:

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

  }

 

E. Post your code.

 

 

/*

  SD card file dump

 

 This example shows how to read a file from the SD card using the

 SD library and send it over the serial port.

 

 The circuit:

 * SD card attached to SPI bus as follows:

 ** MOSI - pin 11

 ** MISO - pin 12

 ** CLK - pin 13

 ** CS - pin 17 (listed on Micro as SS)

 

 

 created  22 December 2010

 by Limor Fried

 modified 9 Apr 2012

 by Tom Igoe

 modified 1 May 2013

 by Harry Johnson

 This example code is in the public domain.

 

 */

 

#include <SPI.h>

#include <SD.h>

#include <Adafruit_GFX.h>

#include <Adafruit_PCD8544.h>

//On the Arduino Micro, the SS pin is defined in software as pin 17. 

const int chipSelect = 17;

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

String storage;

 

void setup()

{

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

  Serial.begin(9600);

  display.begin();

  display.setContrast(70);

  //counter = 0;

  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

  }

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

 

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

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

    // don't do anything more:

    return;

  }

  Serial.println("card initialized.");

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

 

  // if the file opened okay, write to it:

  if (myFile) {

    myFile.seek(0);

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

    myFile.println("testing 1, 2, 3.");

    // close the file:

    myFile.close();

    Serial.println("done.");

  } else {

    // if the file didn't open, print an error:

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

  }

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

      storage += (char)dataFile.read();

    //  display.print(dataFile.read());

    }

    dataFile.close();

  }  

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

  else {

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

  } 

  display.clearDisplay();

  display.setCursor(0, 0); //set top-left corner at text at positon 0,0 (upper left most section of screen). 

  display.print(storage);

  //display.print("storage");

  display.display();

  Serial.println(storage);

  delay(100);

}

 

void loop()

{

} 

 

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

 

Instead of printing directly to the serial monitor, the data needed to be converted into ASCII characters and appended to a string. That string could then be printed directly to the graphical LCD.

 

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

 

insert here

 

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

 

http://pressplay.pbworks.com/w/page/26098855/Lab%205%20Etch-a-Sketches%20Hall%20of%20Fame

 

 

 

 

Comments (1)

Vivien Tsao said

at 2:51 pm on Aug 14, 2013

Good job! 10/10

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