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

Lab 5 - IK

Page history last edited by Ian 7 years, 1 month ago

lab 5 ee47

 

John “ian” kelly

 

 

out sick for a while - catching up 

so this may be a bit late

david said this was okay. 

 

 

 

 

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?

 I can get 14 characters on one line of display. 

and 6 lines total on the screen. 

 

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

 

 

 

 

 

Part B - micro SD card

 

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

 

code I added/modified: 

 

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

 

  // if the file is available, write to it:

  if (dataFile) {

    Serial.print("writing new quote to file");

    dataFile.println(" \n Really, Hagrid, if you are holding out for universal \n popularity, I'm afraid you will be in \n this cabin for a very long time.");

    dataFile.close();

    Serial.println("done.");

  } 

 

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

  if(dataFile){

    Serial.println("about to read: ");

 

    while (dataFile.available()) { 

      Serial.write(dataFile.read());

    }

    dataFile.close();

  }  

 

 

 

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

 

open the file. create a new byte variable fileCopy and set the current contents of the file to this new variable. close the file. open file, write to it with O_WRITE and O_Truncate with you new quote then write fileCopy to the file as well. 

 

 

 

 

  1.   a. Post your code. (for reading from SD card and printing to GLCD)

 

/*

prints data from sd card to graphical lcd 

by storing sd card data into a byte (int) array

concatenating this array into a string 

then printing the string to the glcd.

*/

 

#include <SPI.h>

#include <SD.h>

#include <Adafruit_GFX.h>

#include <Adafruit_PCD8544.h>

 

 

const int chipSelect = 17;

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

int toGLCDprint[200];

int index = 0;

int i = 0;

String toPrint = " ";

 

void setup() {

  Serial.begin(9600);

  delay(1000);

  //while (!Serial) {

  //  ;

 // }

 

  //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.");

 

 

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

  if(dataFile){

    //Serial.println("about to read: ");

 

 

    while (dataFile.available()) { 

 

      toGLCDprint[index] = dataFile.read();

      index++;

 

    }

 

    for ( int i = 0; i < index; i++){

 

    toPrint += char(toGLCDprint[i]);

 

    }

    dataFile.close();

 

  }  

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

  else {

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

  } 

 

 display.begin();

 

}

 

 

 

void loop() {

 

  display.setContrast(60);

 

  display.clearDisplay();

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

 

 

 

   display.print(toPrint);

   //display.print(char(toGLCDprint[i]));

 

   //display.println(char(64));

   Serial.print(" ");

   // display.print(char(toGLCDprint[3]));

   // display.setCursor(i,0);

   delay(1);

 

  display.display();

  delay(500); 

}

  1. modify your data logger. 

 

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

 

Had to change almost all of my code to make this work. The old code stored values in eeprom and wrote to an lcd - non of which are being used in the new code. 

 

SD reading and writing is still giving me some problems - mostly the serial port is being annoying and I have to upload/unplug a lot. 

 

What i did is in void set up is 

initialize sd card and write a value that i read from my A0 input pin. 

then i closed the file and then opened it again and read the values written in the file to the serial monitor. 

 

If you want to continuously log values over time and display them to serial monitor you can wrap my code in a while(true) with a delay. 

 

 

 

Part D. Create an Etch-a-Sketch!

Here is my ultra awesome  Etch-a-sketch:

 

http://www.youtube.com/watch?v=DG1wlo18Nv8

 

 

Comments (1)

Vivien Tsao said

at 3:00 pm on Aug 14, 2013

Good. 10/10

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