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

Gilliand Lab 5

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

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?

14 characters across one line of display, up to 6 lines

 

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

see "Lab 5 5.a." in my lab folder

 

Part B

3. 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 the file is available, write to it:

  if (dataFile) {

    dataFile.println("Yesterday you said Tomorrow!");

    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.

make a new file with the original text string and write the original file's content in it at the beginning

 

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?

yes because it's in a file that doesn't have the limited memory like the Arduino

4. a. Post your code.

#include <SPI.h>

#include <SD.h>

#include <Adafruit_GFX.h>

#include <Adafruit_PCD8544.h>

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

 

const int chipSelect = 17;

 

 void setup() 

{

     display.begin();

     display.setContrast(CONTRAST);

 

     Serial.begin(9600);

     delay(5000); //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 Leondardo only 

     }

     display.clearDisplay();

       display.setCursor(0, 0);

 

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

     pinMode(17, OUTPUT); //set SS pin as output.

 

     if (!SD.begin(chipSelect)) {

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

        return;

     }

     Serial.printIn("card initialized.");

 

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

 

     if (dataFile)

     {

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

       dataFile.printIn("Lord Voldemort"};

       dataFile.close();

 

       Serial.printIn("done.");

     } else {

 

     }

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

 

     if (dataFile) {

       while (dataFile.available()) {

         val+=dataFile.read();

           display.print(val);

             display.display();

           val=0

      }

     dataFile.close();

    }

 

     else {

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

      }

    }

 

    void loop()

  {

  }    

 

 

#define CONTRAST 50

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

I needed read and write functions so I changed to "dataFile.read()" and "dataFile.printIn" from EEPROM.read and .write. I created "dataFile = SD.open("datalog.txt", FILE_WRITE);" and the same again but with "READ". 

Part D

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

Code for my Etch a Sketch:

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#define CONTRAST 50
Adafruit_PCD8544 display = Adafruit_PCD8544(7,6,5,-1,3);
#define LCDWIDTH 84
#define LCDHEIGHT 48

int buttonState = 0;
int sensorPin = 6;
int sensorValue = 0;
int directionPin = A1;
int directionValue = 0;

void setup() {
  Serial.begin(9600);
  display.begin();
  display.setContrast(50);
  pinMode(11, INPUT);
  pinMode(12, INPUT);
  display.clearDisplay();
  display.setCursor(0,0);
  display.print("Starting Etch a Sketch");
  display.display();
  delay(5000);
  display.clearDisplay();

  
}

static int x = 1;
static int y = 1;
static int width = 5;
static int height = 7;

void loop() {
  
  display.drawRect(x, y, width, height, BLACK);
  display.display();
  x += 1;
  y += 1;
  width += 1;
  height += 1;

  if(digitalRead(11))
  {
    display.clearDisplay();
  }

}


 

 

Comments (1)

xyyue@... said

at 2:06 pm on Aug 11, 2015

Well done.

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