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

  • Get control of your email attachments. Connect all your Gmail accounts and in less than 2 minutes, Dokkio will automatically organize your file attachments. You can also connect Dokkio to Drive, Dropbox, and Slack. Sign up for free.

View
 

Lab 5 WriteUp

Page history last edited by Robert Jackson 7 years, 2 months ago

A. Graphical LCD

 

3)

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?

     14 characters, 4 lines down

 

4)

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

 

#include <Adafruit_GFX.h>

#include <Adafruit_PCD8544.h>

#include "Stanford.h";

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

 

void setup() {

  display.begin();

  display.setContrast(50);

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

  //display.drawBitmap(0, 0, stanford_bmp, 64, 48, 1); //look familiar on the screen?

  display.drawCircle(30, 11, 10, 1);

  display.drawCircle(50, 11, 10, 1);

  display.drawCircle(30, 11, 9, 1);

  display.drawCircle(50, 11, 9, 1);

  display.drawFastHLine(27, 11, 7, 1);

  display.drawFastHLine(47, 11, 7, 1);

  display.drawFastVLine(50, 8, 7, 1);

  display.fillRoundRect(34, 35, 26, 10, 4, 1);

  display.setCursor(20, 25);

  display.print("ARDUINO");

  display.drawLine(38, 41, 41, 38, 0);

  display.drawLine(42, 41, 45, 38, 0);

  display.drawLine(46, 41, 49, 38, 0);

  display.drawLine(50, 41, 53, 38, 0);

  display.display();

}

  

void loop() {

  delay(1);

}

 

 

B. MicroSD Card

 

3)

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

 

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

 

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

  if (dataFile) {

    int fileSize = dataFile.size();

    dataFile.seek(fileSize);

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

  }  

 

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

  if(dataFile) {

    while (dataFile.available()) {

      Serial.write(dataFile.read());

    }

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

 

I would read in the current contents first, store them in a string, and then concatenate that string onto the end of the line of text I want to insert at the beginning of the file. Then, I would overwrite the data with the new concatenated string.

 

4)

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

   }

  display.begin();

  display.setContrast(50);

 

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

 

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

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

  if (dataFile) {

    dataFile.write("EE47 Yay");

    dataFile.close();

  }  

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

  else {

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

  } 

 

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

  if (dataFile) {

      display.clearDisplay();

      display.setCursor(0,0);

      display.print(dataFile.read());

      display.display();

 

      while (dataFile.available()) {

      Serial.write(dataFile.read());

    }

  }  

  else {

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

  }  

}

 

void loop()

{

}

 

 

 

5)

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

 

When we are reading and writing to the EEPROM, there is a slightly different track for each mode. When writing to the EEPROM, instead I would append the values as text into the datafile so that they would get stored in the SD card. When reading, I would read the values in 1 by 1, understanding what format they had been written in so I would know how much to read in. 

 

D. Etch-A-Sketch

 

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

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

 

#include <SPI.h>

#include <SD.h>

 

#include <Adafruit_GFX.h>

#include <Adafruit_PCD8544.h>

 

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

 

// these constants describe the pins. They won't change:

const int xpin = A0;                  // x-axis of the accelerometer

const int ypin = A1;                  // y-axis

const int zpin = A2;                  // z-axis (only on 3-axis models)

const int lrpin = A5;

const int udpin = A4;

int x = 0;

int y = 0;

int z = 0;

int upDown = 0;

int leftRight = 0;

int xpos = 0;

int ypos = 0;

 

// initialize the library with the numbers of the interface pins

 

void setup()

{

  // initialize the serial communications:

  Serial.begin(9600);

  display.begin();

  display.setContrast(50);

  display.clearDisplay();

  xpos = 40;

  ypos = 24;

  display.drawPixel(xpos, ypos, 1);

  display.display();

  delay(2000);

}

 

void loop()

{

 

  // get the accelerometer values, standard (no movement are (322, 359, 325)

  x = analogRead(xpin);

  y = analogRead(ypin);

  z = analogRead(zpin);

  if(x>475 || x<220 || y>490 || y<220 || z>450 || z<200) {

     display.clearDisplay();

     display.display();

     delay(2000); 

  }

 

  int tempLR = leftRight;

  int tempUD = upDown;

  leftRight = analogRead(lrpin); //0 -> 682

  upDown = analogRead(udpin); //0 -> 682

 

  if(leftRight-3 >  tempLR) {

    xpos++;

    display.drawPixel(xpos, ypos, 1);

  }

  else if(leftRight+3 < tempLR) {

    xpos--;

    display.drawPixel(xpos, ypos, 1);

  }

 

  if(upDown-3 > tempUD) {

    ypos--;

    display.drawPixel(xpos, ypos, 1);

  }

  else if(upDown+3 < tempUD) {

    ypos++;

    display.drawPixel(xpos, ypos, 1);

  }

 

  display.display();

}

 

 

 

Comments (0)

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