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

  • Get control of your email attachments. Connect all your Gmail accounts and in less than 2 minutes, Dokkio will automatically organize your file attachments. You can also connect Dokkio to Drive, Dropbox, and Slack. Sign up for free.

View
 

Easwaran_Vinay_Lab 5

Page history last edited by zahraa@... 4 years, 10 months 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?

The longest message with the standard font that can be written across one line is a 14 letter message (including the spaces)

The max you can write is 6 lines

 

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


 

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

 File Voldemort;

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

  if(Voldemort) {

    Voldemort.write("He who must not be named"); //appends the quote at the end of the current text in the file

    Voldemort.close();

   }

Correct but the better answer is :  (-0.1)

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

 

if (dataFile) {

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

 

  dataFile.seek(0);

  while (dataFile.available()) {

    Serial.write(dataFile.read());

  }

  dataFile.close();

}

 

 

 

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.

To do this I have to use a function that places the new string to be entered at the very beginning of the file rather than just append it at the end. 

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?

It would not since the Arduino would not be able to handle files larger than it work with and hence some of the text read back from the file may not be shown on the respective output

 

 

a. Post your code.

#include <SPI.h>

#include <SD.h>

#include <SPI.h>

#include <Adafruit_GFX.h>

#include <Adafruit_PCD8544.h>

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

 

 

 

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

const int chipSelect = 17;

 

void setup()

{

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

  

  if (!SD.begin(chipSelect)) { 

    // don't do anything more:

    return;

  } 

 

  display.begin();

  display.setContrast(50);

  

  File Voldemort;

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

  if(Voldemort) {

    Voldemort.write("He who must not be named");

    Voldemort.close();

   }

 

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

 

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

  if (dataFile) {

    while (dataFile.available()) { 

      display.print(char(dataFile.read())); //the char is used to make sure the lcd doesnt display digits instead of the text

      display.display();

    }

    dataFile.close();

  }  

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

  else {

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

  } 

}

 

void loop()

{

}

 

 

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

After compiling both sets of code from last labs data logger and writing to the SD card from this lab, I had to change:

1. The accelerometer writing to SD card from EEPROM

2. The value being written to the SD card (that of the accelerometer and not our own string)

3. Current Value displayed on screen (that of SD card and not EEPROM)

4. The file structure - delete the original file and create a new file with the same name and write the new values to that

5. The button interface used with the last data logger to remove the use of the button entirely

 

 

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

 

 

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

Done. :)

 

 

 

 

 

 

 

 

Comments (1)

xyyue@... said

at 2:03 pm on Aug 11, 2015

Well done.

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