Dear Programmer,
This is in response to the suggestion from my "Starting Over" forum subject. Been trying to send this for answers after learning how to navigate the forum:
Dear Forum,
You may be glad to know that my “AVRdude error” disappeared, once I got it into my thick head that you don’t compile and upload with the Xbee attached and my thanks to Sparkfun’s hammering that warning in its tutorials. To my great satisfaction and your relief, I wrote a movement sensor program that sends the data perfectly from the Xbee shield/Uno to the Xbee/explorer/computer/X-CTU terminal. I use “do” loops to print “1” or “0” every six seconds to mySerial, depending on the PIR state being high or low, respectively. Now, I can risk self-inflicted humiliation with two questions:
First and less important is that I’m not sure how the program works, because the “do” list for “mySerial.print” is followed by “Serial.read()” and “while Serial.available()==0). Alternatively, the “do” list for “Serial.print) is followed by “myserial.read()” and “while myserial.available()==0). Are these opposite commands placed to set up the next “do” loop? I’d have the same question if I just used “while” instead of a “do” loop. But it works.
Second question: My plan is to send the PIR sensor data from a “remote” Xbee to a datalogger SD card on a “base”,instead of the explorer/computer. I’ve configured the Xbees with puTTY on the explorer and I would like a simple arrangement for the “remote” like a lily pad Xbee reading the sensor. I don’t know if the lily pad is possible, since the datalogger would be stacked on the Xbee shield/UNO “base” that contains the program. Also, my working Ladyada datalogger wants “dataFile.print” and the base would look for “mySerial.print”. Is there a problem, or does it need some conversion from mySerial to dataFile?
Once again, thanks for your help.
Here’s my stab at a sketch for “mySerial.print” to “dataFile.print”. See the "//" questions.
/*
* Xbee wireless PIR sensor to datalogger with Arduino 1.0.1
*/
#include <SD.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial = SoftwareSerial(0,1);
const int chipSelect = 10;
unsigned long time;
const int ledPin = 8; // choose the pin for the LED
const int inputPin = 7; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
void setup()
{
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
Serial.begin(9600);
Serial.print("Initializing SD Card...");
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
return;
}
Serial.println("card initialized");
Serial.print("Goodnight Moon");
mySerial.begin(9600);
mySerial.println("Hello World");
}
void loop()
{
delay(6000);
float time = millis();
pirState = digitalRead(inputPin); // read input value
if (pirState == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); //LED on
delay (500);
digitalWrite(ledPin, LOW); //LED OFF
File dataFile = SD.open("datalog.txt", FILE_WRITE);
do {
Serial.print(" "); // this is just to check on the serial monitor
Serial.print(time/60000);
Serial.print(", ");
Serial.println("1");
mySerial.read();
}
while (mySerial.available()==0);
do {
mySerial.print (" ");
mySerial.print(time/60000);
mySerial.print(", ");
mySerial.println("1");
Serial.read();
}
while (Serial.available()==0);
do {
dataFile.print("");
dataFile.print(time/6000);
dataFile.print (", ");
dataFile.println('1');
mySerial.read(); //would this work?
}
while (mySerial.available()==0);
} //Closes "if" statement
else {
do { //omitted Serial.pring list
mySerial.print(" ");
mySerial.print(time/60000);
mySerial.print(" ");
mySerial.println("0");
Serial.read();
}
while (Serial.available()==0);
do {
dataFile.print(" ");
dataFile.print(time/60000);
dataFile.print(" ");
dataFile.println("0");
mySerial.read(); //again, will this work?
}
while mySerial.available()==0); //would this work?
} //Closes "else" statwement
if (pirState == HIGH) {
// We only want to print on the output change, not state
pirState = LOW;
}
//Closes loop
}
I get an error "dataFile not declared in this scope" but this is not my question--see // above
Cheers and thanks,
Oldguy
------------------------end
That's it.