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

Kairam Lab 5

Page history last edited by sanjay.kairam@... 10 years, 11 months ago

Part A. Graphical LCD 

a. With the smaller font, what is the longest message you can write across one line of the display? How many lines can you write?

 

Looks like 14 characters per line - 5 lines total.

 

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

 

Yes, it's just a rectangle...but I drew it myself!

 

Part B. microSD Card

 

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

 

I inserted this line after the completion of the while loop which reads all of the data.

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

 

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

 

As a quick fix, I would probably read the data into memory, add the string to the beginning and then write that all back to the SD card.

 

a. Post your code.

 

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

 

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

 

  // Initialize display

  display.begin();

 

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

 

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

  if (dataFile) {

    while (dataFile.available()) {

      display.clearDisplay();

      display.setCursor(0, 0);

      display.print(dataFile.read());

      display.display();

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

{

}

 

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

 

Seemed like a pretty straightforward change - I added code to set the SD card to pin 17 and initialize it. Then, I replaced function calls EEPROM.read() --> dataFile.read() and EEPROM.write() --> dataFile.write();

 

Part D. Create an Etch-a-Sketch!

Use any combination of input sensors and switches with the Graphical LCD  to create your own unique Etch a Sketch*. You are welcome to make as liberal an interpretation of the Etch a Sketch concept as you like, as long as you:

 

- Allow a user to control the creation of a drawing

- Give users real-time feedback of what they're drawing

- Make it possible to clear a drawing

 

Optional: - Make it possible to save a drawing

Optional: - Make it possible to recall a drawing after it has been cleared from the screen

 

Note: Your fellow students have found that you have to init your SD card before your LCD in the setup function.

 

Hint: We've made the cache that the nokia_5110_lcd stores of the screen a 'public' variable, so you can copy it to a file by saving lcd.lcd_buffer:

 

#define LCDCOLMAX    84
#define LCDPIXELROWMAX    48
class Nokia_3310_lcd : public Print
{
  ...
  public:
    unsigned uint8_t pcd8544_buffer[LCDROWMAX*LCDCOLMAX/8];
...
}

 

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

 

 

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

 

Comments (0)

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