| 
  • 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: Etch-a-Sketch!

Page history last edited by evclark@stanford.edu 8 years, 4 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?

Longest message on one line: 14 characters

Number of lines: 6

 

4. Try the code from Examples->nokia_5110_lcd->GraphicsExample. Modify the code to display a logo for yourself (the screen is 84x48 pixels). You can either use the graphical library's functions (to make circles, rectangles, etc), or you can use whatever program you like to create an 84x48 monochrome bitmap file (.bmp), such as in MS Paint or the GIMP. You can also convert another image into a monochrome .bmp format suitable for our display: 

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

 

Rock climbing dude!

 

Part C. microSD Card 

Some of these line assignments overlap with the Graphical LCD line assignments!  

a. Why is this? What can (or should) you do about it?

The chip select pins determine which slave the teensy is talking to at any given time, so there is no conflict.

 

3. Use this code to read the datalog.txt file from the microSD card to your serial terminal.  

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

 #include <SD.h>

 

// On the Ethernet Shield, CS is pin 4. Note that even if it's not

// used as the CS pin, the hardware CS pin (10 on most Arduino boards,

// 53 on the Mega) must be left as an output or the SD library

// functions will not work.

const int chipSelect = 12;

 

void setup()

{

  Serial.begin(9600);

  Serial.print("Initializing SD card...");

 

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

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

  dataFile.close();

 

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

  // if the file is available, write to the serial port:

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

{

}

 

 

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

Save the current file contents in a buffer, seek to the start of the file ( File.seek(0) ), write in the string you want to insert, then copy the buffer back into the file after that position.

 

4. Merge your code from the Part A above and your code from step 3 above to output data from the text file on the microSD card to your graphical LCD. (If you have trouble, and even if you don't, this is an excellent opportunity to learn to use the Logic Analyzer!) 

a. Post your code.  

#include <SD.h>

#define NO_GRAPHICS

#define NO_BITMAP

#include <nokia_5110_lcd.h>

 

//LCD PINS

#define LCD_PWR   10

#define LCD_SCE   9

#define LCD_RESET 8

#define LCD_DC    4

 

// On the Ethernet Shield, CS is pin 4. Note that even if it's not

// used as the CS pin, the hardware CS pin (10 on most Arduino boards,

// 53 on the Mega) must be left as an output or the SD library

// functions will not work.

const int chipSelect = 12;

 

Nokia_5110_lcd lcd(LCD_PWR, LCD_DC, LCD_SCE, LCD_RESET);

 

void setup()

{

  Serial.begin(9600);

  Serial.print("Initializing SD card...");

 

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

 

  lcd.init(127); //parameter is contrast value, between 0 [low] and 127 [high]

  lcd.clear();

 

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

 

  String text;

 

  // if the file is available, write to the serial port:

  if (dataFile) {

    while (dataFile.available()) {

      //Serial.write(dataFile.read());

      char c = dataFile.read();

      text += c;

    }

    dataFile.close();

  }  

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

  else {

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

  } 

 

  char textArray[text.length()];

  text.toCharArray(textArray, text.length()) ;

  lcd.writeString(0, 0, textArray, MODE_NORMAL);

}

 

void loop()

{

}

 

5. Modify your data logger code from last lab so that you can write to the microSD card. If you took apart your data logger already, make the changes to your old code that you would need to make it write to the SD card.

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

Import the GLCD libraries instead of the LiquidCrystal ones, and write the <, >, ^, or v characters to the GLCD using lcd.writeString() instead.

 

 

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:

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.