Pages: [1]   Go Down
Author Topic: Data Logger Shield Gone Haywire (Arduino Brain Library)  (Read 831 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

(also posted to LadyAda forums)

So I've got the awesome Data Logger Shield. When I upload the demo sketch (lighttemplogger - http://github.com/adafruit/Light-and-Temp-logger http://github.com/kitschpatrol/Arduino-Brain-Library/zipball/master ), it works great! Time to make it do something useful. I want to log data from an EEG toy using the Arduino Brain Library (http://frontiernerds.com/brain-hack).Turns out the Brain library already outputs data in CSV, sweet.

I don't know much about coding, so I just took the relevant bits of the Brain library's BrainSerialOut program:
Code:
#include <Brain.h>

// Set up the brain parser, pass it the hardware serial object you want to listen on.
Brain brain(Serial);

void loop() {
if (brain.update()) {
  Serial.println(brain.readErrors());
Serial.println(brain.readCSV());
}
}

and grafted them onto lighttemplogger:

Code:
#include <SD.h>
#include <Wire.h>
#include "RTClib.h"
#include <Brain.h>
[...]
Code:
// for the data logging shield, we use digital pin 10 for the SD cs line
const int chipSelect = 10;

// the logging file
File logfile;

Brain brain(Serial);
[...]

Code:
void loop(void)
{
  DateTime now;
// Expect packets about once per second.
// The .readCSV() function returns a string (well, char*) listing the most recent brain data, in the following format:
// "signal strength, attention, meditation, delta, theta, low alpha, high alpha, low beta, high beta, low gamma, high gamma"
if (brain.update()) {
  Serial.println(brain.readErrors());
Serial.println(brain.readCSV());
}

  // delay for the amount of time we want between readings
  delay((LOG_INTERVAL -1) - (millis() % LOG_INTERVAL));
 
[...]

Right, then.

When I run lighttemplogger, I get the following happy output over serial monitor:
Code:
Initializing SD card...card initialized.
Logging to: LOGGER47.CSV
millis,stamp,datetime,light,temp,vcc
999, 1337967332, "2012/5/25 17:35:32", 1023, 535.42, 1.10
1999, 1337967333, "2012/5/25 17:35:33", 1023, 535.42, 1.10
2999, 1337967334, "2012/5/25 17:35:34", 1023, 535.42, 1.10

When I run my version of the code (with the Brain library Frankensteined in), I get something a little more monstrous:
Code:
Initializin
ÿÿÿÿÿ¸ÕßÜÿ ŸÕßÜÿ ŸÕßÜÿ À¸ÕßÜÿ ŸÕßÜÿ ŸÕßÜÿ ŸÕßÜÿ ŸÕßÜÿ ŸÕßÜÿ ŸÕßÜÿ ¸ÕßÜÿ À¸ÕßÜÿ ŸÕßÜÿ ŸÕßÜÿ ŸÕßÜÿ Š¸ÕßÜÿ ŸÕßÜÿ ŸÕßÜÿ ŸÕßÜÿ ðÄã¸ÕßÜÿ ŸÕßÜÿ ŸÕßÜÿ ŸÕßÜÿ Š¸ÕßÜÿ ŸÕßÜÿ ŸÕßÜÿ ŸÕßÜÿ ŸÕßÜÿ ñ¸ÕßÜÿ ŸÕßÜÿ ŸÕßÜÿ ŸÕßÜÿ ¸ÕßÜÿ ŸÕßÜÿ à¸ÕßÜÿ Š¸ÕßÜÿ

Any ideas what could be going wrong here?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And yes, just so we're clear, I'm aware that my modifications to the lighttemplogger sketch wouldn't actually log brain data to the card. I'm just trying to take it slow and get the Brain library to work with a logging sketch before I actually get logging.
Logged

Germany
Offline Offline
Faraday Member
**
Karma: 59
Posts: 3071
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Any ideas what could be going wrong here?
Yes, and you're hiding the most interesting part of your code: Where are you writing to the SD card ?
There's your error ... smiley-wink

BTW1: I'm too lazy to search for that Brain library: What's the data type returned by Brain::readCSV() ?
BTW2: It's a bit unclear to me why there is no output visible from 
   Serial.println(brain.readErrors());
I had expected at least an empty line in the Serial Monitor...
Logged

Pages: [1]   Go Up
Jump to: