I am a newbie, and will really appreciate your help on this. I am trying to build a data logger using the Seeedstudio stalker v2.1 solar kit and GPRS shield to take temperature and humidity measurements.
I would like to record the temperature and humidity to the SD card and after 1 hr transfer the data through the GPRS shield. The following code works fine in logging the temperature and humidity values. But as soon as I insert the GPRS shield, I get the following error message:
Error inside Serial.serialEvent()
java.io.IOException: Bad file descriptor in nativeavailable
at gnu.io.RXTXPort.nativeavailable(Native Method)
at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532)
at processing.app.Serial.serialEvent(Serial.java:215)
at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732)
at gnu.io.RXTXPort.eventLoop(Native Method)
at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)
When I remove the GPRS shield, again, it works fine. Clearly, the GPRS shield is causing problems. (GPRS Shield is configured in the Software UARt mode - which I will need for transferring data.)
Please help.
[code]//Time
#include <Wire.h>
#include “DS3231.h”
//SD
#include <Fat16.h>
#include <Fat16util.h> // use functions to print strings from flash memory
// store error strings in flash to save RAM
#define error(s) error_P(PSTR(s))
//TempHum
#define DHT11_PIN 0 // ADC0
//Hall
volatile byte rpmcount;
unsigned int rpm;
unsigned long timeold;
//Time
DS3231 RTC; //Create the DS3231 object
char weekDay[][4] = {“Sun”, “Mon”, “Tue”, “Wed”, “Thu”, “Fri”, “Sat”,“Sun”};
//SD
SdCard card;
Fat16 file;
// FUNCTIONS START HERE …
//TempHum
byte read_dht11_dat()
{
byte i = 0;
byte result=0;
for(i=0; i< 8; i++){
while(!(PINC & _BV(DHT11_PIN))); // wait for 50us
delayMicroseconds(30);
if(PINC & _BV(DHT11_PIN))
result |=(1<<(7-i));
while((PINC & _BV(DHT11_PIN))); // wait '1' finish
}
return result;
}
//Hall
void rpm_fun()
{
rpmcount++;
//Each rotation, this interrupt function is run twice
}
//SD
void error_P(const char* str) {
PgmPrint("error: ");
SerialPrintln_P(str);
if (card.errorCode) {
PgmPrint("SD error: ");
Serial.println(card.errorCode, HEX);
}
while(1);
}
// SET UP STARTS HERE…
void setup()
{
Serial.begin(19200);
//SD
// initialize the SD card
if (!card.init()) error(“card.init”);
// initialize a FAT16 volume
if (!Fat16::init(&card)) error(“Fat16::init”);
// Time
Wire.begin();
RTC.begin();
//TempHum
DDRC |= _BV(DHT11_PIN);
PORTC |= _BV(DHT11_PIN);
//Hall
attachInterrupt(1, rpm_fun, RISING); // Interrupt triggers on rising edge; when the sensor turns off.
rpmcount = 0;
rpm = 0;
timeold = 0;
Serial.println(“Ready”);
}
// LOOPING STARTS HERE …
void loop()
{
//TempHum
byte dht11_dat[5];
byte dht11_in;
byte i;
int temp;
// start condition
// 1. pull-down i/o pin from 18ms
PORTC &= ~_BV(DHT11_PIN);
delay(18);
PORTC |= _BV(DHT11_PIN);
delayMicroseconds(40);
DDRC &= ~_BV(DHT11_PIN);
delayMicroseconds(40);
dht11_in = PINC & _BV(DHT11_PIN);
if(dht11_in){
Serial.println(“dht11 start condition 1 not met”);
return;
}
delayMicroseconds(80);
dht11_in = PINC & _BV(DHT11_PIN);
if(!dht11_in){
Serial.println(“dht11 start condition 2 not met”);
return;
}
delayMicroseconds(80);
// now ready for data reception
for (i=0; i<5; i++)
dht11_dat[i] = read_dht11_dat();
DDRC |= _BV(DHT11_PIN);
PORTC |= _BV(DHT11_PIN);
byte dht11_check_sum = dht11_dat[0]+dht11_dat[1]+dht11_dat[2]+dht11_dat[3];
// check check_sum
if(dht11_dat[4]!= dht11_check_sum)
{
Serial.println(“DHT11 checksum error”);
}
//Hall
if (rpmcount==1) {
timeold=millis();
}
else if (rpmcount >= 20) {
//Update RPM every 20 counts, increase this for better RPM resolution,
//decrease for faster update
rpm = 60000/(millis() - timeold)*(rpmcount-1);
//timeold = millis();
rpmcount = 0;
// Serial.println(rpm,DEC);
}
//PRINTING DONE HERE…
//Time Check
DateTime now = RTC.now(); //get the current date-time
if( (now.second()%5)==0) //10 refers to the time-interval after which to print data
{
//True, so print to screen…
Serial.print(now.year(),DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.date(), DEC);
Serial.print(',');
Serial.print(weekDay[now.dayOfWeek()]);
Serial.print(',');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.print(',');
//TempHumHall
Serial.print("Curr_humdity,");
Serial.print((dht11_dat[0] << 8 | dht11_dat[1])/10, DEC);
Serial.print(",%,");
Serial.print("Curr_temperature,");
temp = dht11_dat[2] << 8 | dht11_dat[3];
Serial.print((temp/10), DEC);
Serial.print(".");
Serial.print((temp%10), DEC);
Serial.print(",C,");
Serial.print("LastMeas_Curr=");
Serial.println(rpm, DEC);
///Print to screen ends …
//Print to SD starts …
// clear write error
file.writeError = false;
if (!file.open(“DATALOG.CSV”, O_CREAT | O_APPEND | O_WRITE)) error(“open”);
file.print(now.year(),DEC);
file.print('/');
file.print(now.month(), DEC);
file.print('/');
file.print(now.date(), DEC);
file.print(',');
file.print(weekDay[now.dayOfWeek()]);
file.print(',');
file.print(now.hour(), DEC);
file.print(':');
file.print(now.minute(), DEC);
file.print(':');
file.print(now.second(), DEC);
file.print(',');
//TempHumHall
file.print("Curr_humdity,");
file.print((dht11_dat[0] << 8 | dht11_dat[1])/10, DEC);
file.print(",%,");
file.print("Curr_temperature,");
temp = dht11_dat[2] << 8 | dht11_dat[3];
file.print((temp/10), DEC);
file.print(".");
file.print((temp%10), DEC);
file.print(",C,");
file.print("LastMeas_Curr=");
file.println(rpm, DEC);
if (file.writeError) error(“write”);
if (!file.close()) error(“close”);
}
delay(1000);
}[/code]