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!
a. With the standard font, what is the longest message you can write across one line of the display? How many lines can you write?
The longest message I can write is 14 characters long. I wrote abcdefghijklmn. When I reach "o," the message moves down to the next line. I can write up to five liens on the LCD.
Using the standard font, the display shows 6 lines of 14 characters each. -0.25
Part B:
Question 3:
a. Include the code that you had to insert to do this in your lab writeup.
Here is the code. The part I added is in bold.
/*
SD card file dump
This example shows how to read a file from the SD card using the
SD library and send it over the serial port.
The circuit:
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 17 (listed on Micro as SS)
created 22 December 2010
by Limor Fried
modified 9 Apr 2012
by Tom Igoe
modified 1 May 2013
by Harry Johnson
This example code is in the public domain.
*/
#include <SPI.h>
#include <SD.h>
//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:
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
// Note that I do not I have to re-initialize the "dataFile" file.
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()
{
}
✔
b. Explain what would you do differently to insert the same text string, but at the beginning of the file (without over-writing the current contents). You don't have to code this: just explain the process. If you're interested and have time make it work, show us your program.
I could copy the original file's contents into a temporary string file. Then, I could use the seek() function to move the pointer to the beginning of the original file and write the new text. The pointer is now at the end of the new text, so I can simply add the contents of the temporary string file to the new text.
✔good answer
c. Now tell us if your approach would work if the file were larger than your Arduino's memory (which is 2.5KB). If not, how could you work around that limitation?
My current approach wouldn't work. All I need to do is write all of the new file's contents into a new file on the SD card. The SD card has significantly more storage space than the arduino, so I can simply use it to store, and read, the contents.
✔
Question 4:
a. Post your code.
Here is the code:
#include <SPI.h>
#include <SD.h>
//On the Arduino Micro, the SS pin is defined in software as pin 17.
const int chipSelect = 17;
char inc = 'a';
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#define CONTRAST 50
// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// RST and CS are not connected to Arduino, and as such are listed as pin -1.
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
dataFile = SD.open("datalog.txt");
display.begin();
display.setContrast(CONTRAST);
display.setCursor(0, 0);
display.clearDisplay();
Serial.println("thing");
String retVal = "";
// if the file is available, write to it:
if (dataFile) {
while (dataFile.available()) {
inc = dataFile.read();
retVal += (char) inc;
}
Serial.println(retVal);
display.print(retVal);
display.display();
dataFile.close();
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}
}
void loop() {
}
✔
Question 5:
a. Tell us what you had to change to make this work.
I sent the data to the SD card instead of the EEPROM. Then, I changed the code for the graphical LCD to replace the previous LCD. I wrote the data to the SD card and immediately sent it to the LCD. I continuously changed the values to save space on the SD card.
Here is the code:
#include <SPI.h>
#include <SD.h>
#include <LiquidCrystal.h>
#include <EEPROM.h>
//On the Arduino Micro, the SS pin is defined in software as pin 17.
const int chipSelect = 17;
char inc = 'a';
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#define CONTRAST 50
// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// RST and CS are not connected to Arduino, and as such are listed as pin -1.
Comments (1)
xyyue@... said
at 2:30 pm on Aug 11, 2015
Well done.
You don't have permission to comment on this page.