Commit 9b578595 authored by Patrick's avatar Patrick

change to SDI_12

parent 8590a8c8
This diff is collapsed.
/* ======================== Arduino SDI-12 =================================
Arduino library for SDI-12 communications to a wide variety of environmental
sensors. This library provides a general software solution, without requiring
any additional hardware.
======================== Attribution & License =============================
Copyright (C) 2013 Stroud Water Research Center
Available at https://github.com/StroudCenter/Arduino-SDI-12
Authored initially in August 2013 by:
Kevin M. Smith (http://ethosengineering.org)
Inquiries: SDI12@ethosengineering.org
based on the SoftwareSerial library (formerly NewSoftSerial), authored by:
ladyada (http://ladyada.net)
Mikal Hart (http://www.arduiniana.org)
Paul Stoffregen (http://www.pjrc.com)
Garrett Mace (http://www.macetech.com)
Brett Hagman (http://www.roguerobotics.com/)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef SDI12_h
#define SDI12_h
// Import Required Libraries
#include <avr/interrupt.h> // interrupt handling
#include <avr/parity.h> // optimized parity bit handling
#include <inttypes.h> // integer types library
#include <Arduino.h> // Arduino core library
class SDI12
{
private:
static SDI12 *_activeObject; // static pointer to active SDI12 instance
void setState(uint8_t state); // sets the state of the SDI12 objects
void wakeSensors(); // used to wake up the SDI12 bus
void writeChar(uint8_t out); // used to send a char out on the data line
void receiveChar(); // used by the ISR to grab a char from data line
public:
SDI12(uint8_t dataPin); // constructor
~SDI12(); // destructor
void begin(); // enable SDI-12 object
void end(); // disable SDI-12 object
void forceHold(); // sets line state to HOLDING
void sendCommand(String cmd); // sends the String cmd out on the data line
int available(); // returns the number of bytes available in buffer
int peek(); // reveals next byte in buffer without consuming
int read(); // returns next byte in the buffer (consumes)
void flush(); // clears the buffer
bool setActive(); // set this instance as the active SDI-12 instance
bool isActive(); // check if this instance is active
static inline void handleInterrupt(); // intermediary used by the ISR
};
#endif
......@@ -121,8 +121,8 @@ char* red_peg::sensor_message(sensor_e request)
return "ADC2";
} else if (request == ADC3) {
return "ADC3";
} else if (request == SDI12) {
return "SDI12";
} else if (request == SDI_12) {
return "SDI_12";
} else {
return "UNKNOWN";
}
......@@ -141,7 +141,7 @@ void red_peg::sensorsOff()
// turn it off
digitalWrite(SENSOR_ACTIVE_PIN, LOW);
// switch to low impedance
pinMode(SENSOR_ACTIVE_PIN, INPUT);
//pinMode(SENSOR_ACTIVE_PIN, INPUT);
}
float red_peg::degC(t_SensorData data_record)
......
......@@ -29,7 +29,7 @@
#define PROCESSING_DELAY 100 // no. ms to allow for the slave to process the request
// possible inputs for the_command or the_sensor
enum sensor_e {EMPTY, AVAILABLE, OK, RTC, ADC1, ADC2, ADC3, SDI12};
enum sensor_e {EMPTY, AVAILABLE, OK, RTC, ADC1, ADC2, ADC3, SDI_12, SET_RTC};
// and some aliases relavent for the red-peg shield
#define MA4_20 ADC1
#define ANA ADC2
......@@ -48,10 +48,11 @@ typedef struct{
uint8_t m, d, hh, mm, ss; //the timestamp in DateTime-ready format
union {
// some aliases for the data reading
int16_t the_reading;
int16_t reading;
int16_t value;
int16_t integer;
int32_t the_reading;
int32_t reading;
int32_t value;
int32_t integer;
float float_level;
};
//float the_data; // replaced with functions
uint8_t end_byte = END_BYTE;
......
......@@ -214,8 +214,8 @@ char* red_peg_slave::sensor_message(sensor_e request)
return "ADC2";
} else if (request == ADC3) {
return "ADC3";
} else if (request == SDI12) {
return "SDI12";
} else if (request == SDI_12) {
return "SDI_12";
} else {
return "UNKNOWN";
}
......
......@@ -15,6 +15,7 @@
#define SS_SLAVE_PIN 10
#define SD_SLAVE_PIN 5
#define SLAVE_SENSOR_ACTIVE_PIN 2
#define SDI_12_PIN 9
class red_peg_slave
{
......
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