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

COsorio Lab5

Page history last edited by Benjamin Tee 8 years, 2 months ago

Part A. Mod your Teensy

a. How can you check that your board is now running at 3.3V? Check it out!

I measured the voltage between ground and VCC with a multimeter. It read 3.27 V.

Part B. Graphical LCD

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

 

?

 

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

?

 

Part C. microSD Card

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

                Both devices communicate with the microcontroller through SPI. When the microcontroller is “talking” to one device, the chip select pin for the device will indicate that it is the active device and it should be “listening”.

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

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

  if(dataFile){

    Serial.print("Writing to file.");

    dataFile.println(" he who must not be named.");

    dataFile.close();

    Serial.println("Done");

  }

//For some reason, the appended message gets written twice. I didn’t figure out why.

3b. 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 save the old message, then start a new message and simply append the old message to the new one. The Strings library would make this really easy, but I would probably just use malloc and do it manually to avoid using an entire library for 3 lines of code.

4a. Post your code.

/*

Adapted from the SD file card dump example.

This program reads the file datafile.txt from the SD card and displays

it's contents on the LCD screen.

 */

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

#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

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

char* message;

int i=0;

char c=0;

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.

  Serial.println("Open File");

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

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

  if (dataFile) {

    Serial.println("Reading file...");

    Serial.println("Datafile size:");

    Serial.println(dataFile.size());

    message=(char*)malloc(dataFile.size()+1);

    while (dataFile.available()) {

      message[i]=dataFile.read();

      i++;

    }

    message[i]='\0';

    Serial.println(message);

    Serial.println("Done");

    dataFile.close();

  } 

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

  else {

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

  }

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

}

void loop()

{

  lcd.clear();

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

    delay(5000);

}

 

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

/*

Used code for eeprom_write exampl and eeprom_read example

Also used code from SD example

The main changes are just initializing the SD card. We no longer have to advance an address, because the SD library takes care of appending data for us.

 */

 

#include <EEPROM.h>

 

int waddr = 0;

boolean wmode=true;

int raddress=0;

byte value;

int button=3;

const int chipSelect = 12;

 

 

void setup()

{

  pinMode(button,INPUT);

  Serial.begin(9600);

  delay(500);

  Serial.print("Started\n");

  Serial.print("Wmode ");

 

  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;

  }

 

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

 

 

  Serial.println("card initialized.");

 

  Serial.print(wmode);

  Serial.println();

}

 

void writedata(){

  // need to divide by 4 because analog inputs range from

  // 0 to 1023 and each byte of the EEPROM can only hold a

  // value from 0 to 255.

  int val = analogRead(0) / 4;

 

  // write the value to the appropriate byte of the EEPROM.

  // these values will remain there when the board is

  // turned off.

  dataFile.write(val);

 

  delay(100);

}

 

void readdata(){

  // read a byte from the datafile

  value = dataFile.read();

 

  Serial.print(raddress);

  Serial.print("\t");

  Serial.print(value, DEC);

  Serial.println();

 

  delay(100);

 

 

}

 

void loop(){

 

  if(wmode){

    writedata();

  }

  else{

    readdata();

  }

  if(digitalRead(button)){

    dataFile.close();

    if(wmode){ 

      wmode=false;

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

    }

    else{

      wmode=true;

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

    }

  }

}

Etch A Sketch

 

Comments (1)

Benjamin Tee said

at 8:08 pm on Aug 20, 2012

-0.5 for missing answers

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