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

  • Want to organize your cloud files? Sign up for a free webinar to see how Dokkio (a new product from PBworks) can help you find, organize, and collaborate on your Drive, Gmail, Dropbox, and Slack files: Weds, May 27 at 2PM Eastern / 11AM Pacific
View
 

ee 47 lab report 5

Page history last edited by Jomar 8 years, 11 months ago

Make an Etch-a-Sketch

  Part A. Graphical LCD

There is a box of Graphical Displays on the resistor shelf with Nokia 5110 displays in it. The datasheet for the controller on the display is here

If you have a lot of trouble getting this to work, remove the 7.5k and 15k resistors (but not the 100 Ohm LED resistor) and wire the logic directly in at 5V. Do not connect Vcc to 5V though. This lack of signal voltage conversion is bad technical form, as the device has 3.3V logic levels, but it's also a robust device so it survives on 5V logic if you need to use direct pins from the Arduino.

3. Try the code from Examples->nokia_5110_lcd->Strings. Unlike your LCD (where the LCD controller controls the font rendering), the graphical lcd is controlled pixel by pixel, so that the Arduino handles what the text will look like. (So you can get different fonts!)

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

 

Filling up the display with as many ā€˜iā€™ characters as possible, I found that I could fit a 14 character message on one line. Counting the number of rows, there is 6 possible lines to write.

4. Try the code from Examples->nokia_5110_lcd->Graphics. 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 MS Paint or the GIMP:

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

 

Part B. microSD Card

The microSD card communicates with the Arduino using SPI. We'll be using modified SD card adapters as microSD card readers. There is a stash of 1GB microSD cards and microSD adapters in the class cabinet. Get one of each.

 

 

1. Solder 7 pins of single row header(USE THE RIGHT ANGLE HEADERS INSTEAD OF THE FLAT ONES SHOWN IN THE PHOTO)onto the microSD adapter so that we can use it as a cheap microSD card to protoboard adapter. Find the sheet of label stickers in the lab cabinet so that you can label your pins. Use the photo above to make sure you put the stickers on in the right direction!

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

 Pin 11 the MOSI port and Pin 13 the SCK port share some wires with the Graphical LCD. These digital pins give and receive bit signals from the various devices. They overlap a little, but this is ok and we need not do anything about it.

 

3. Use Examples->SD->DumpFile to read the datalog.txt file from the microSD card to your serial terminal. 

Modify the code to (a) append "Stop saying that!" (or another suitable quote!) to the endof the file's current contents, and (b) print out the updated file to the serial terminal. You'll want to use some of the functions from the example code in the Examples->SD folder. This should only take about 3-5 lines of code. 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 = 4;

 

void setup()

{

Serial.begin(9600);

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

// make sure that the default chip select pin is set to

// output, even if you don't use it:

pinMode(10, 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);

dataFile.println("Stop saying that, sketchbag!");

dataFile.close();

Serial.println("Write to it.");

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

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

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

{

}

Explain what would you do differently (or show us your code!) to insert the same text string, but at the beginningof the file (without over-writing the current contents).

 To insert text at the beginning of the file without overwriting the previous text, open the old file. Read and copy all of the text into a number of char arrays or strings. Then write the first line using a statement like this.

if (dataFile.seek(0)) dataFile.println("Writing to beginning. ");

After this is written to the beginning of the file, print the rest of the original text from the saved arrays or strings. Then close the file.

 

4. Merge your code from the Section 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!)

Post your code.

 

#define NO_GRAPHICS

#define NO_BITMAP

#include <nokia_5110_lcd.h>

 

//LCD PINS

#define LCD_PWR 6

#define LCD_SCE 9

#define LCD_RESET 8

#define LCD_DC 7

 

//SPI PINS

#define PIN_SDIN 11

#define PIN_SCLK 13

 

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

 

 

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

 

void spi_init(){

pinMode(10, INPUT); // SS pin, should be pulled high.

pinMode(12, INPUT); // MISO

pinMode(11, OUTPUT); //MOSI

pinMode(13, OUTPUT); //SCLK

digitalWrite(10, HIGH);

SPCR = _BV(SPE) | _BV(MSTR) | _BV(SPR0);

}

 

void setup()

{

CLKPR = 0x80;

CLKPR = 0x1;

spi_init();

lcd.init();

lcd.clear();

Serial.begin(9600);

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

// make sure that the default chip select pin is set to

// output, even if you don't use it:

pinMode(10, 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 (dataFile)

{

if (dataFile.seek(0)) dataFile.println("Writing to beginning....sketch");

dataFile.close();

}

Serial.println("Write to it.");

**/

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

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

if (dataFile) {

while (dataFile.available()) {

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

lcd.write(dataFile.read());

delay(50);

}

dataFile.close();

}

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

else {

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

}

}

 

void loop()

{

}

 

 

This photo shows some of the poem from the dialog of my SD card on the LCD screen.

 

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.

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

 Instead of writing the values into the EEPROM, I instead have to write them into a big array of integers that I would write to a file on the SD card. After that, I would close the file, then reopen and access the text and simply write this to the graphical LCD.

Part C. 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 save a drawing

- Make it possible to clear a drawing

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

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

#define LCDPIXELROWMAX    48

class Nokia_3310_lcd : public Print

{

  ...

  public:

    unsigned char lcd_buffer[LCDROWMAX][LCDCOLMAX];

...

}

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

Will go back to finish my Etch-a-Sketch if I have enough time!

 

Comments (0)

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