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

EE47: Lab 5

Page history last edited by zahraa@... 5 years, 2 months ago

Lab 5

 

Part A. Graphical LCD

 

3.3 V = (r2)/(r1+r2) * 5 V

.66 = (r2)/(r1 + r2)

.66r1 + .66r2 = r2

.66r1 = .34r2

 

r1=10

r2=20

 

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; 6

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

Part B. microSD Card

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("The Doctor");

    dataFile.close();

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

 

    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.

Read first 2.5 kb. Create new temporary file. Paste contents. Read next 2.5 kb. So on. After complete copy, File.seek(0) of original. Write insertion. Copy contents back into original from temporary. Delete temporary.

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 works.

 

 

Part C. microSD Card + LCD + other

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_PCD8544.h>

#include <Adafruit_GFX.h>

 

#include <SPI.h>

 

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

 

  display.begin();

  display.setContrast(60);

 

  // 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("The Doctor");

    dataFile.close();

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

 

    while (dataFile.available()) {

      display.print(dataFile.read());

    }

    dataFile.close();

  }  

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

  else {

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

  } 

}

 

void loop()

{

}

 

 

 

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

I had to initialize the SD card for read/write. Then seek to start of file (or create a new one). Then as values were read, write them into the sd card in some logical way that they could be decoded, a protocol if you will.

 

 

Part D. Create an Etch-a-Sketch!

 

 

Comments (1)

xyyue@... said

at 2:18 pm on Aug 11, 2015

Well done.

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