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

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Lab 5 (2)

Page history last edited by joseph15@... 10 years, 8 months ago

Part A. Graphical LCD

 

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?

 

Six lines of fourteen characters each can be written on the display.

 

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

 

A photo has been included in my folder. Also, the logo was drawn using only code. A copy of the algorithm used has been added below.

 

int x=42;

int y=24;

int toAdd=1;

for(int count=1;count<8;count++)

{

for(int a=1;a<count+1+toAdd;a++)

{

display.drawPixel(x+a,y,150);

}

toAdd++;

x+=(toAdd);

for(int a=1;a<count+2+toAdd;a++)

{

display.drawPixel(x,y+a,150);

}

toAdd++;

y+=(toAdd);

for(int a=1;a<count+3+toAdd;a++)

{

display.drawPixel(x-a,y,150);

}

toAdd++;

x-=(toAdd);

for(int a=1;a<count+4+toAdd;a++)

{

display.drawPixel(x,y-a,150);

}

toAdd++;

y-=(toAdd);

}

 

Part B. microSD Card

 

3.

 

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

 

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

dataFile.println("Lord Voldemort. Remember Cedric Diggory.");

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

 

Note: this method will work only provided that enough SRAM is available.

 

/*

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;

String txt = "Remember, if the time should come when you have to make a choice between what is right and what is easy, remember what happened to a boy who was good, and kind, and brave, because he strayed across the path of...";

String contents="";

char charData;

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

SD.remove("datalog.txt");

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

dataFile.print(txt);

dataFile.close();

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

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

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

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

if (dataFile) {

while (dataFile.available()) {

char temp=(char)dataFile.read();

contents+=temp;

}

dataFile.close();

}

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

dataFile.seek(0);

dataFile.print("Lord Voldemort. Remember Cedric Diggory.");

for(int i=0;i<contents.length();i++)

{

dataFile.write(contents[i]);

}

Serial.print("\r\n");

dataFile.close();

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

if (dataFile) {

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()

{

}

 

 

4.

 

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

#include <Adafruit_PCD8544.h>

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

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

const int chipSelect = 17;

String txt = "Remember, if the time should come when you have to make a choice between what is right and what is easy, remember what happened to a boy who was good, and kind, and brave, because he strayed across the path of...";

String contents="";

char charData;

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.

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

SD.remove("datalog.txt");

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

dataFile.print(txt);

dataFile.close();

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

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

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

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

if (dataFile) {

while (dataFile.available()) {

char temp=(char)dataFile.read();

contents+=temp;

}

dataFile.close();

}

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

dataFile.seek(0);

dataFile.print("Lord Voldemort. Remember Cedric Diggory.");

for(int i=0;i<contents.length();i++)

{

dataFile.write(contents[i]);

}

dataFile.close();

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

if (dataFile) {

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

}

display.begin();

display.setContrast(50);

display.clearDisplay(); //clear all the screen

delay(500);

for(int i=0;i<contents.length();i++)

{

charData=contents[i];

display.write(charData);

}

display.display();

}

void loop()

{

}

 

5.

 

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

 

My data logger code only used EEPROM to store an array. It contained a randomly generated set of ints varying from 6 to 9, inclusive. Hence, EEPROM storage could easily be replaced with SD card storage. After initializing the SD card and opening a new file, dataFile.print(int) could be used to write in the array. Then, these values could be traversed using a line of code such as char c = dataFile.read(index);. After finishing one iteration of reading, the cursor can be reset to the beginning of the file by calling dataFile.seek(0);

 

Part D. Create an Etch-a-Sketch!

 

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

 

Video is live at http://youtu.be/jyDlyXAmHns

 

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

Link posted to http://pressplay.pbworks.com/w/page/26098855/Lab%205%20Etch-a-Sketches%20Hall%20of%20Fame

 

 

Comments (0)

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