multifuncional logger problem

Hello,

According to this project
http://arduinoprojects101.com/arduino-rpm-counter-tachometer/
i'm trying to make a RPM, temperature and current logger, but my code that i made from RPM tachometer and some Logger code shows nonsense's, if i running only the RPM tachometer everything is OK.
There's my code

#include <SD.h> 

float tempC; 

//Temp sensors
int tempPin0 = 0; 
int tempPin1 = 1; 
int tempPin2 = 2; 
int tempPin3 = 3; 

//Current sensors
int currentPin4 = 4; 
int currentPin5 = 5; 

//SD logger
int CS_pin = 10; 

//RPM stuff
int ledPin13 = 6;
int ledPin12 = 5; 

volatile byte rpmcount; 
unsigned int rpm; 
unsigned long timeold; 


void rpm_fun() 
{ 
rpmcount++; 
} 

void setup() 
{ 
Serial.begin(9600); 
Serial.println("Kortele ruosiama"); 

pinMode(CS_pin, OUTPUT); 
if(!SD.begin(CS_pin)) 
{ 
Serial.println("Korteles klaida"); 
return; 
} 
Serial.println("Kortele pagatava"); 

//RPM stuff
attachInterrupt(0, rpm_fun, FALLING); 
pinMode(ledPin13, OUTPUT); 
digitalWrite(ledPin13, HIGH); 

rpmcount = 0; 
rpm = 0; 
timeold = 0; 
} 

void loop() 
{ 
//Analog read
long sensor0 = analogRead(tempPin0); 
long sensor1 = analogRead(tempPin1); 
long sensor2 = analogRead(tempPin2); 
long sensor3 = analogRead(tempPin3); 
long sensor4 = analogRead(currentPin4); 
long sensor5 = analogRead(currentPin5); 


sensor0 = (5.0 * sensor0 * 100.0)/1024.0; 
sensor1 = (5.0 * sensor1 * 100.0)/1024.0; 
sensor2 = (5.0 * sensor2 * 100.0)/1024.0; 
sensor3 = (5.0 * sensor3 * 100.0)/1024.0; 
sensor4 = (5.0 * sensor4 * 100.0)/1024.0; 
sensor5 = (5.0 * sensor5 * 100.0)/1024.0; 

//Tacho stuff'as 
detachInterrupt(0); 
rpm = 30*1000/(millis() - timeold)*rpmcount; 
timeold = millis(); 
rpmcount = 0; 


//Results 
String sn0 = ":"; 
String sn1 = "Temp.kb.reg:"; 
String sn2 = "Temp.db.mot:"; 
String sn3 = "Temp.db.reg:"; 
String sn4 = "Srove.kb:"; 
String sn5 = "Srove.db:"; 
String sn6 = "RPM.kb:"; 
String sn7 = "RPM.db:"; 

String string0 = sensor0; 
String string1 = sensor1; 
String string2 = sensor2; 
String string3 = sensor3; 
String string4 = sensor4; 
String string5 = sensor5; 
String stringRPMkb = rpm; 



String stringTOP = sn0 + string0 + sn0 + string1 + sn0 + string2 + sn0 + string3 + sn0 + string4 + sn0 + string5 + sn0 + stringRPMkb; 


File dataFile = SD.open("log.txt", FILE_WRITE); 
if(dataFile) 
{ 
dataFile.println(stringTOP); 
dataFile.close(); 
Serial.println(stringTOP); 
} 
else 
{ 
Serial.println("Failas nepasiekiamas"); 
} 
attachInterrupt(0, rpm_fun, FALLING); 
delay(1000); 
}

I thing that for you guys the code may be look weird, but the temperature and current logging stuff for me is understandable, only with RPM i get wrong numbers. So what i'm doing wrong?

Thank you.

Depending on your Arduino model, interrupt 0 may be associated to different digital pins, usually to pin 2 (see http://arduino.cc/en/Reference/AttachInterrupt). My impression is that you are try to use pin 5 for the IR receiver, and that's not going to generate an interrupt on any Arduino. Or, if digital pin 2 remains unconnected (floating), you may get interrupts generated at random. It may not be the only problem, but I would start from fixing this part which is surely making things less predictable.

All those Strings are useless. The File::print() method KNOWS how to convert ints and floats to text. There is no reason to convert the ints and floats to Strings that the print() method then needs to unwrap to get the data.

Detaching and reattaching the interrupt is unnecessary. The only time that you don't want an interrupt to fire is when copying rpm count. That can be done using cli() before and see() after making the copy.

see() ?

Bob

see() ?

Stupid Mac and autocorrect.

sei()