As requested... my sketch, complete with the test code of my SD Card and LCD...
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <SD.h>
#include <Keypad.h>
File root;
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
byte rowPins[ROWS] = {5, 6, 7, 8}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {2, 3, 4}; //connect to the column pinouts of the keypad
//Create an object of keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
//------------------------------------LCD----------------------------------------
lcd.init(); // initialize the lcd
lcd.backlight(); //Backlight on
// lcd.noBacklight(); // Backlight off
lcd.setCursor(1,0); // Set cursor to 1 character in, on line zero
lcd.print("hello everyone"); // Print a message to the LCD.
lcd.setCursor(1,1); // Set cursor to 1 character in, on 2nd line
lcd.print("konichiwaa"); // Print message
//------------------------------------LCD----------------------------------------
//------------------------------------SD CARD------------------------------------
Serial.print("Initializing SD card...");
if (!SD.begin(10)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
root = SD.open("/");
printDirectory(root, 0);
Serial.println("done!");
//------------------------------------SD CARD------------------------------------
}
void loop() {
//------------------------------------KEYPAD-------------------------------------
char customKey = keypad.getKey();
if (customKey){
Serial.println(customKey);
}
//------------------------------------KEYPAD-------------------------------------
}
//------------------------------------SD CARD------------------------------------
void printDirectory(File dir, int numTabs) {
while (true) {
File entry = dir.openNextFile();
if (! entry) {
// no more files
break;
}
for (uint8_t i = 0; i < numTabs; i++) {
Serial.print('\t');
}
Serial.print(entry.name());
if (entry.isDirectory()) {
Serial.println("/");
printDirectory(entry, numTabs + 1);
} else {
// files have sizes, directories do not
Serial.print("\t\t");
Serial.println(entry.size(), DEC);
}
entry.close();
}
}
//------------------------------------SD CARD------------------------------------
// End sketch
And the wiring diagram that I had sketched up on my phone to match... Sorry the pins aren't labeled, but hopefully can still be deciphered.
EDIT 1: The battery/charge controller/switch are not currently connected to my circuit... not that it matters for this issue.
EDIT 2: Included Serial Output after punching in the keypad numbers left to right, top to bottom...
Initializing SD card...initialization done.
SYSTEM~1/
INDEXE~1 76
WPSETT~1.DAT 12
README~1.TXT 1225
VANQUI~1.XLS 13905
X-TERR~1.XLS 13903
done!
1
2
3
4
5
6
7
8
9
*
*
#