Hi.
My project is explained here:
http://forums.adafruit.com/viewtopic.php?f=31&t=70471
I am trying to use the sketch bellow (written by fat16lib) to log high speed samples for my project. If someone could help me in the following:
1- I am using 3208 ADC, the adafruit datalogger shield and a 2560 mega board. Both ADC and shield communicate by SPI with mega. Is it advisable to comunicate by SPI from both devices to mega or is there other solution?
2- When I try to compile the sketch I get an error like this:
binaryLogger.ino:58:1: error: 'include' does not name a type
binaryLogger.ino: In function 'void __vector_13()':
binaryLogger.ino:99:42: error: 'readMCP3201' was not declared in this scope
binaryLogger.ino: In function 'void logData()':
binaryLogger.ino:256:23: error: 'BUFFER_BLOCK_COUNT' was not declared in this scope
binaryLogger.ino:261:28: error: 'initMcpSar' was not declared in this scope
binaryLogger.ino:270:33: error: 'class SdFat' has no member named 'cwd'
binaryLogger.ino:303:29: error: 'block' was not declared in this scope
binaryLogger.ino:313:28: error: too few arguments to function 'unsigned char TimerTwo::init(unsigned int, void (*)(), bool)'
In file included from binaryLogger.ino:27:0:
C:\Program Files (x86)\Arduino\libraries\TimerTwo/TimerTwo.h:13:16: note: declared here
unsigned char init(unsigned usec, void (*f)(), bool reset = false);
Thanks.
For now i am just struggling with the sketch writen by fat16lib. Trying to use it for my goals. The sketch you talk from March or part of it is yet to be added.
For now i just want to read values from a simple pot in series with a resistor, convert analog to digital using the 3208 and send data to the sd card the fastet possible way.
I am using version 1.6.0.
Atached is my librarie folder content and the sketch.
Thanks.
binaryLogger.ino (11.2 KB)
In the 12th post of this thread: SPI problem with adafruit SD shield & Mega - Storage - Arduino Forum
fat16lib wrote:
ou will never log data very fast if you share the SPI bus between an ADC and a SD card so software SPI should be used for either the ADC or SD card.
To log data fast you need to read the ADC in an interrupt routine and buffer data to be sent to the SD card.
Thats why i asked in my first post if using spi for both is advisable.
I have now instaled IDE version 1.6.5.
It keeps happening an error that i don t understant:
In file included from binaryLogger.ino:25:0:
C:\Program Files (x86)\Arduino\libraries\SdFat/SdFat.h:26:33: fatal error: SdSpiCard/SdSpiCard.h: No such file or directory
#include "SdSpiCard/SdSpiCard.h"
^
compilation terminated.
Multiple libraries were found for "SdFatUtil.h"
Used: C:\Program Files (x86)\Arduino\libraries\SdFatUtil
Not used: C:\Program Files (x86)\Arduino\libraries\SdFat
Erro ao compilar.
I go to the directory it says in the error message and i allready have SdSpiCard.h file included there, why that error message keeps coming always?
Please help.
Thanks.
binaryLogger.ino (12.5 KB)
Hi.
I was now able to write a sketch for this project. My sketch is mainly based on your light temperature sketch, with some changes to meet my requirements.
I allready tested it with a voltage divider and it does what is suposed to, but didnt tested with the pressure sensor yet in the car.
I would like you to help me in some issues like:
-
i am recording 2 variables to the SD card, psg and copy, respectively pressure value and pulse number from the toothed wheel. For a faster ploting point of view it would be fine for the 2 values to apear in diferent columns in excel. Can it be done, and if yes how could it be done?
-
Is it faster to record data to a BIN file than to a CSV file? If yes does it worth the change?
Thanks.
#include <SD.h>
#include <Wire.h>
//#include "RTClib.h"int
#include <SPI.h>
/////////////////////////////////////////////////variables///////////////////////////////////////////
#define psg 15
int count_pulses=0;
int psg_reading;
int copy=0;
// the digital pins that connect to the LEDs
#define redLEDpin 2
#define greenLEDpin 3
// how many milliseconds between grabbing data and logging it. 1000 ms is once a second
//#define LOG_INTERVAL 1 // mills between entries (reduce to take more/faster data) ////milisegundos entre leituras consecutivas////
// how many milliseconds before writing the logged data permanently to disk
// set it to the LOG_INTERVAL to write each time (safest)
// set it to 10*LOG_INTERVAL to write all data every 10 datareads, you could lose up to
// the last 10 reads if power is lost but it uses less power and is much faster!
#define SYNC_INTERVAL 1000 // mills between calls to flush() - to write data to the card
/////duvida: o que é flush??/////
uint32_t syncTime = 0; // time of last sync()
/////duvida: que intervalo é este??/////////
#define ECHO_TO_SERIAL 0 // echo data to serial port //////////não quero que apareçam o s resultados no serial port, porque pode atrasar o processo, por isso fica a 0 ///////////////
#define WAIT_TO_START 1 // Wait for serial input in setup()
//RTC_DS1307 RTC; // define the Real Time Clock object
// for the data logging shield, we use digital pin 10 for the SD cs line
const int chipSelect = 10;
// the logging file
File logfile;
////////////////////////////////////////////////////////////////////////////////
void error(char *str)
{
Serial.print("error: ");
Serial.println(str);
// red LED indicates error
digitalWrite(redLEDpin, HIGH);
while(1);
}
////////////////////////////////////////////////////////////////////////////////////////
void setup(void) {
// put your setup code here, to run once:
Serial.begin(9600);
//while(!Serial){;};
Serial.println();
// use debugging LEDs
pinMode(redLEDpin, OUTPUT);
pinMode(greenLEDpin, OUTPUT);
#if WAIT_TO_START
Serial.println("Type any character to start");
while (!Serial.available());
#endif //WAIT_TO_START
// initialize the SD card
Serial.print("Initializing SD card...");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(10, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(10, 11, 12, 13)) {
error("Card failed, or not present");
}
Serial.println("card initialized.");
// create a new file
char filename[] = "LOGGER00.CSV"; /////No sketch do light temperature é CSV!///////////
for (uint8_t i = 0; i < 100; i++) {
filename[6] = i/10 + '0';
filename[7] = i%10 + '0';
if (! SD.exists(filename)) {
// only open a new file if it doesn't exist
logfile = SD.open(filename, FILE_WRITE);
break; // leave the loop!
}
}
if (! logfile) {
error("couldnt create file");
}
///////////É aqui que ele guarda o nome de um ficheiro//////////////////
Serial.print("Logging to: ");
Serial.println(filename);
/////////////////////////////////////////////////////////////////////
// connect to RTC
/* Wire.begin();
if (!RTC.begin()) {
logfile.println("RTC failed");
#if ECHO_TO_SERIAL
Serial.println("RTC failed");
#endif //ECHO_TO_SERIAL
}*/
//////////////////escreve o cabeçalho dos resultados/////////////////
logfile.println("psg_reading,count_pulses");
#if ECHO_TO_SERIAL
Serial.println("psg_reading,count_pulses");
#endif //ECHO_TO_SERIAL
/////código relacionado com o interruptor////////
pinMode(3,INPUT);
digitalWrite(3,HIGH);
attachInterrupt(1,react,CHANGE);
////////////////////////////////////////////////
}
void loop() {
// put your main code here, to run repeatedly:
//DateTime now;
// delay for the amount of time we want between readings
// delay((LOG_INTERVAL -1) - (millis() % LOG_INTERVAL));
digitalWrite(greenLEDpin, HIGH);
int psgReading = analogRead(psg);
detachInterrupt(1); //Deactivate interrupt and does the copies from the variables called in the interrupt//
copy = count_pulses;
attachInterrupt(1,react,CHANGE);
if (copy>=1)
{
// logfile.print(", ");
logfile.println(psgReading);
// logfile.print(", ");
logfile.println(copy);
#if ECHO_TO_SERIAL
// Serial.print(", ");
Serial.print(psgReading);
Serial.print(", ");
Serial.print(copy);
#endif //ECHO_TO_SERIAL
logfile.println();
#if ECHO_TO_SERIAL
Serial.println();
#endif // ECHO_TO_SERIAL
digitalWrite(greenLEDpin, LOW);
// Now we write data to disk! Don't sync too often - requires 2048 bytes of I/O to SD card
// which uses a bunch of power and takes time
if ((millis() - syncTime) < SYNC_INTERVAL) return;
syncTime = millis();
// blink LED to show we are syncing data to the card & updating FAT!
digitalWrite(redLEDpin, HIGH);
logfile.flush();
digitalWrite(redLEDpin, LOW);
}
if (copy>=4000)
{
count_pulses=0;
}
}
void react() //Interrupt routine//
{
count_pulses++;
}