Data logging Arduino Micro + SD Breakout

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Data logging Arduino Micro + SD Breakout

Post by adafruit_support_bill »

You need a capital 'K' in getKey().

Christian123123
 
Posts: 47
Joined: Sat Jun 29, 2013 7:42 pm

Re: Data logging Arduino Micro + SD Breakout

Post by Christian123123 »

Ok i put a capital K, but now i type in numbers nothing shows up in the serial monitor and nothing is saved on the datalog.txt file either.

Code: Select all

void loop()
{
  
while (kpd.getKey() == NO_KEY) { }
  
char key = kpd.getKey();

if (key != NO_KEY)

{

  
if(key) // Check for a valid key.
{
switch (key)
{
case '*':
digitalWrite(ledpin, LOW);
break;
case '#':
digitalWrite(ledpin, HIGH);
break;
default:
Serial.println(key);
}
}


// 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 the file is available, write to it:
if (dataFile) {
dataFile.println(key); // print your keypad here
dataFile.close();
// print to the serial port too:
Serial.println(key);
} 
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
} 
}
}

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Data logging Arduino Micro + SD Breakout

Post by adafruit_support_bill »

Actually, if you are using the latest keypad library, it should work without that line. The multiple key-presses you were seeing before were probably due to contact bounce. You can try adding a "delay(100);" instead of that "while" statement.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”