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

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Curtis Ryan Lab 5

Page history last edited by zahraa@... 8 years, 7 months ago

Ryan Curtis

EE 47

Summer 2015

Lab Report #5

 

Part A

3. 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?

You can write 14 characters to a line and up to 6 lines of text.

 

Part B

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

/*

  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>

 

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

const int chipSelect = 17;

 

void setup()

{

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

    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", FILE_WRITE);

 

  if (dataFile) {

    dataFile.seek(dataFile.size());

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

    dataFile.seek(0);

 

    while (dataFile.available()) {

      Serial.write(dataFile.read());

    }

    dataFile.close();

  }  

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

  else {

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

  } 

}

 

void loop()

{

}

 

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.

I would create a temporary file and write the text string in the beginning. I would then copy over all of the text from the original file to follow the beginning string. I can then set the original file equal to the contents of the temporary file.

 

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?

My approach would not work with files larger than can be stored on the Arduino. A simple work around for this problem is to utilize the SD card and create the temporary file on the SD card.

 

 

4. a. 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>

 

#define CONTRAST 50

 

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

const int chipSelect = 17;

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

 

void setup()

{

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

    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", FILE_WRITE);

 

  display.begin();

  display.setContrast(CONTRAST);

  display.clearDisplay();

  display.setCursor(0, 0);

  if (dataFile) {

    dataFile.seek(dataFile.size());

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

    dataFile.seek(0);

 

    while (dataFile.available()) {

      display.write(dataFile.read());

    }

    display.display();

    dataFile.close();

  }  

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

  else {

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

  } 

}

 

void loop()

{

}

 

 

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

I had to change the include statements to be:

#include <SPI.h>

#include <SD.h>

I also needed to create a file on the SD card that I would use by saying SD.open("myFile.txt"); and then save it as a File object. Once I did this, I could replace every instance of EEPROM with my file variable. Lastly, I had to make a few slight changes to parameters of read and write functions and replace length with size.

 

 

Part D

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:02 pm on Aug 11, 2015

Well done.

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