Stanford EE Lab 5


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?

               • Using the standard font size you can write a maximum of 14 characters on a line. There is a maximum of 6 lines.

 

     5.

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

 

               • 

Fliqz has shut down their service. To access this video, email support with this video id: 0ddbc003d8eb4bde966de230262cca24

B.

     3.

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

               • /*

  SD card read/write

 

 This example shows how to read and write data to and from an SD card file

 The circuit:

 * SD card attached to SPI bus as follows:

 ** MOSI - pin 11

 ** MISO - pin 12

 ** CLK - pin 13

 ** CS - pin 4

 

 created   Nov 2010

 by David A. Mellis

 modified 9 Apr 2012

 by Tom Igoe

 

 This example code is in the public domain.

 

 */

 

#include <SPI.h>

#include <SD.h>

 

File myFile;

 

void setup()

{

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

  Serial.begin(9600);

  while (!Serial) {

    ; // wait for serial port to connect. Needed for Leonardo only

  }

 

 

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

 

  if (!SD.begin(4)) {

    Serial.println("initialization failed!");

    return;

  }

  Serial.println("initialization done.");

 

  // open the file. note that only one file can be open at a time,

  // so you have to close this one before opening another.

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

 

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

  if (myFile) {

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

    myFile.println("I don't like you either! You just watch yourself. We're wanted men. I have the death sentence on twelve systems!");

    // close the file:

    myFile.close();

    Serial.println("done.");

  } else {

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

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

  }

 

  // re-open the file for reading:

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

  if (myFile) {

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

 

    // read from the file until there's nothing else in it:

    while (myFile.available()) {

      Serial.write(myFile.read());

    }

    // close the file:

    myFile.close();

  } else {

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

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

  }

}

 

void loop()

{

  // nothing happens after setup

}

 

          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.

               • The easiest way to insert the same text string but at the beginning of the file would be to copy the contents of the file into a string, and concatenate it to the end of the text string.

 

          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 2.5kB memory limitation, you could create the Strings as PROGMEM to make use of the 32kB of program memory, or process the file contents by char and copy each character over the length of the text string to make room for it to be inserted at the front of the file.

 

 

 

     4.

          a. Post your code.

               • #include <SPI.h>

#include <Adafruit_GFX.h>

#include <Adafruit_PCD8544.h>

#include <SD.h>

 

// Software SPI (slower updates, more flexible pin options):

// pin 7 - Serial clock out (SCLK)

// pin 6 - Serial data out (DIN)

// pin 5 - Data/Command select (D/C)

// pin 4 - LCD chip select (CS)

// pin 3 - LCD reset (RST)

//Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);

 

// Hardware SPI (faster, but must use certain hardware pins):

// SCK is LCD serial clock (SCLK) - this is pin 13 on Arduino Uno

// MOSI is LCD DIN - this is pin 11 on an Arduino Uno

// pin 5 - Data/Command select (D/C)

// pin 4 - LCD chip select (CS)

// pin 3 - LCD reset (RST)

Adafruit_PCD8544 display = Adafruit_PCD8544(5, 4, 3);

// Note with hardware SPI MISO and SS pins aren't used but will still be read

// and written to during SPI transfer.  Be careful sharing these pins!

 

#define NUMFLAKES 10

#define XPOS 0

#define YPOS 1

#define DELTAY 2

 

 

#define LOGO16_GLCD_HEIGHT 16

#define LOGO16_GLCD_WIDTH  16

 

static const unsigned char PROGMEM walltech[] =

{

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B10001111, B01111000, B11111000, B11111110, B01111100, B11111000, B00000110, B00000001, B10000000, B01001111, B10010000, // *   **** ****   *****   *******  *****  *****        **        **        *  *****  *

  B10001110, B00111000, B11111000, B11111110, B01111100, B11111000, B00000110, B00000001, B00000000, B01001111, B10010000, // *   ***   ***   *****   *******  *****  *****        **        *         *  *****  *

  B11001110, B00111001, B11110010, B01111110, B01111100, B11111111, B00111111, B11111111, B00111111, B11001111, B10010000, // **  ***   ***  *****  *  ******  *****  ********  **************  ********  *****  *

  B11000100, B10011001, B11100010, B00111110, B01111100, B11111111, B00111110, B00000001, B00111111, B11000000, B00010000, // **   *  *  **  ****   *   *****  *****  ********  *****        *  ********         *

  B11100100, B10010011, B11100111, B00011110, B01111100, B11111111, B00111110, B00000001, B00111111, B11000000, B00010000, // ***  *  *  *  *****  ***   ****  *****  ********  *****        *  ********         *

  B11100000, B10000011, B11001111, B10011110, B01111100, B11111111, B00111111, B11111111, B00111111, B11001111, B10010000, // ***     *     ****  *****  ****  *****  ********  **************  ********  *****  *

  B11100001, B11000011, B10001111, B10001110, B01111100, B11111111, B00111111, B11111111, B00111111, B11001111, B10010000, // ***    ***    ***   *****   ***  *****  ********  **************  ********  *****  *

  B11110001, B11000111, B00011111, B11000110, B00000100, B00001111, B00111110, B00000001, B00000000, B01001111, B10010000, // ****   ***   ***   *******   **      *      ****  *****        *         *  *****  *

  B11110011, B11100111, B00011111, B11000110, B00000100, B00001111, B00111110, B00000001, B10000000, B01001111, B10010000, // ****  *****  ***   *******   **      *      ****  *****        **        *  *****  *

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

  B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11110000, // ************************************************************************************

};

 

File myFile;

 

void setup()   {

  Serial.begin(9600);

 

  while (!Serial) {

    ; // wait for serial port to connect. Needed for Leonardo only

  }

 

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

 

  if (!SD.begin(4)) {

    Serial.println("initialization failed!");

    return;

  }

  Serial.println("initialization done.");

 

  display.begin();

  display.clearDisplay();

  display.display();

  // init done

  // you can change the contrast around to adapt the display

  // for the best viewing!

  display.setContrast(50);

 

  for(int offset = -38; offset < -6; offset++)

  { 

  display.clearDisplay(); 

  display.fillRect(0, 64 + offset, display.width(), display.height(), BLACK);

  display.drawBitmap(0, offset, walltech, 84, 64, BLACK);

  display.display();

  delay(5);

  }

 

  delay(1500);

 

  for(int offset = -6; offset < 28; offset++)

  { 

  display.clearDisplay(); 

  display.fillRect(0, 0, display.width(), offset, BLACK);

  display.drawBitmap(0, offset, walltech, 84, 64, BLACK);

  display.display();

  delay(5);

  }

 

  display.clearDisplay(); 

  display.display();

 

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

  if (myFile) {

    display.println("test.txt:");

 

    // read from the file until there's nothing else in it:

    while (myFile.available()) {

      display.write(myFile.read());

    }

    // close the file:

    myFile.close();

  } else {

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

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

  }

}

 

void loop() {

 

}

 

 

     5.

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

               • To change the datalogger from recording to EEPROM, remove 

 

“EEPROM.write(addr, val);

addr = addr + 1;

  if(addr == EEPROM.length())

    addr = 0;”

 

and after including the SD library and declaring variables, add the segment 

 

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

 

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

  if (myFile) {

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

    myFile.println(val);

    // close the file:

myFile.close();”

 

 

 

D.

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

          •