Commit 237b8f00 authored by Patrick's avatar Patrick

revised examples, removed minus error in month/day fos setting time

parent ebcca3e7
......@@ -4,6 +4,7 @@ red_peg RP;
void setup() {
Serial.begin(BAUD);
Serial.println("starting rp_ma4_20");
RP.begin();
}
......@@ -12,13 +13,14 @@ void loop() {
delay(100);
t_SensorData depth = RP.get(MA4_20);
RP.sensorsOff();
if (depth.sensor == MA4_20) {
Serial.print("Value: ");
Serial.print(depth.reading);
Serial.print(", ");
Serial.print(RP.mA(depth));
Serial.print(" mA, ");
Serial.print(RP.level(depth, 7000));
Serial.print(RP.level(depth, 7000L));
Serial.print(" mm");
Serial.println();
} else {
......
/*
SD card read/write with Red-Peg
This example shows how to read and write data to and from an SD card file
The circuit:
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4
modified from sketch by
David A. Mellis & Tom Igoe
*/
#define SD_CS_PIN 5 //5
#include <SPI.h>
//#include <SD.h>
#include <SdFat.h>
SdFat SD;
File myFile;
#include <red_peg.h>
red_peg RP;
File myFile;
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(BAUD); // 115200
Serial.begin(BAUD);
Serial.println("starting rp_sd_logger");
RP.begin();
Serial.print("Initializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
pinMode(10, OUTPUT);
pinMode(SD_CS_PIN, OUTPUT);
pinMode(SD_SS, OUTPUT);
if (!SD.begin(SD_CS_PIN)) {
if (!SD.begin(SD_SS)) {
Serial.println("initialization failed!");
return;
}
......@@ -54,6 +33,8 @@ void loop()
myFile = SD.open("readings.csv", FILE_WRITE);
if (myFile) {
Serial.print("Writing to readings.csv: ");
// write the timestamp to the file
myFile.print(temp.y);
myFile.print("-");
myFile.print(temp.m);
......@@ -67,14 +48,21 @@ void loop()
myFile.print(":");
myFile.print(temp.ss);
myFile.print("Z");
// plus a comma delimeter
myFile.print(", ");
// followed by the temperature
myFile.print(RP.degC(temp));
// and a new line
myFile.println();
// close the file:
myFile.close();
// Then print what we sent to the Serial port
RP.print_data(temp);
Serial.println("done.");
// and wait 5 seconds
delay(5000);
}
}
......
......@@ -5,12 +5,13 @@ RTC_DS1307 rtc;
#define SENSOR_ACTIVE_PIN 6
#define READING_DELAY 10000
#define BAUD 115200
uint32_t last_reading = READING_DELAY;
void setup()
{
Serial.begin(115200);
Serial.begin(BAUD);
Serial.println(F("starting set_the_time"));
// check we have an RTC attached
......@@ -20,7 +21,7 @@ void setup()
}
reportTimeNow();
Serial.println(F("To set the time send \"T YYYY-MM-DD hh:mm:ss\""));
Serial.println(F("To set the time send \"T YYYY MM DD hh mm ss\""));
}
void loop()
......@@ -31,6 +32,7 @@ void loop()
} else if (millis() - last_reading >= READING_DELAY) {
// otherwise read out the time at regular intervals
reportTimeNow();
last_reading = millis();
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment