Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for BoronLTE board from Particle.io #122

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ The known compatibile pins for common variants are shown below:
**ESP32:**
- Any GPIO

**Particle (Boron LTE):**
- Any digital GPIO

Note that not all of these pins are available with our [Variants and Branches](https://github.com/EnviroDIY/Arduino-SDI-12#variants-and-branches), below.


Expand Down
6 changes: 6 additions & 0 deletions examples/l_particle_boron/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[//]: # ( @page example_k_page Example K: Concurrent Measurements )
# Example K: Concurrent Measurements

This is very similar to example C - finding all attached sensors and display info.
Unlike example C, however, which scan all the ports, this only scan the sensors attached to D2

69 changes: 69 additions & 0 deletions examples/l_particle_boron/example.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include "SDI12_boards.h"

// This #include statement was automatically added by the Particle IDE.
#include "SDI12.h"


void printInfo(SDI12 sdi, char i) {
String command = "";
command += (char)i;
command += "I!";
sdi.sendCommand(command);
sdi.clearBuffer();
delay(30);

if(sdi.available()){
String msg=String(i);
msg+=": ";
while (sdi.available()) {
msg+=(char)sdi.read();
delay(10); // 1 character ~ 7.5ms
}
Particle.publish("address", String(i));
Particle.publish("msg", msg);
}
}

// this checks for activity at a particular address
// expects a char, '0'-'9', 'a'-'z', or 'A'-'Z'
boolean checkActive(SDI12 sdi, char i) {
String myCommand = "";
myCommand = "";
myCommand += (char)i; // sends basic 'acknowledge' command [address][!]
myCommand += "!";

for (int j = 0; j < 3; j++) { // goes through three rapid contact attempts
sdi.sendCommand(myCommand);
sdi.clearBuffer();
delay(30);
if (sdi.available()) { // If we here anything, assume we have an active sensor
return true;
}
}
sdi.clearBuffer();
return false;
}

void scanAddressSpace(SDI12 sdi) {
// scan address space 0-9
for (char i = '0'; i <= '9'; i++)
if (checkActive(sdi, i)) { printInfo(sdi, i); }
// scan address space a-z
for (char i = 'a'; i <= 'z'; i++)
if (checkActive(sdi, i)) { printInfo(sdi, i); }
// scan address space A-Z
for (char i = 'A'; i <= 'Z'; i++)
if (checkActive(sdi, i)) { printInfo(sdi, i); };
}

void setup(){
Particle.publish("ticks", String(System.ticksPerMicrosecond()));

}
void loop(){
SDI12 mySDI12(D2);
mySDI12.begin();
scanAddressSpace(mySDI12);
mySDI12.end();
delay(100000);
}
10 changes: 8 additions & 2 deletions src/SDI12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,12 @@ void SDI12::setPinInterrupts(bool enable) {
// Merely need to detach the interrupt function from the pin
else
detachInterrupt(digitalPinToInterrupt(_dataPin));
#elif defined(PARTICLE)
// Merely need to attach the interrupt function to the pin
if (enable) attachInterrupt(_dataPin, handleInterrupt, CHANGE);
// Merely need to detach the interrupt function from the pin
else
detachInterrupt(_dataPin);

#elif defined(__AVR__) && not defined(SDI12_EXTERNAL_PCINT)
if (enable) {
Expand Down Expand Up @@ -547,7 +553,7 @@ void SDI12::sendResponse(FlashString resp) {

// Passes off responsibility for the interrupt to the active object.
// On espressif boards (ESP8266 and ESP32), the ISR must be stored in IRAM
#if defined(ESP32) || defined(ESP8266)
#if defined(ESP32) || defined(ESP8266)
void ICACHE_RAM_ATTR SDI12::handleInterrupt() {
if (_activeObject) _activeObject->receiveISR();
}
Expand Down Expand Up @@ -728,4 +734,4 @@ ISR(PCINT3_vect) {

#endif // SDI12_EXTERNAL_PCINT

#endif // __AVR__
#endif // __AVR__
4 changes: 2 additions & 2 deletions src/SDI12.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ typedef const __FlashStringHelper* FlashString;
#define SDI12_BUFFER_SIZE 81
#endif

#if defined(ESP32) || defined(ESP8266)
#if defined(ESP32) || defined(ESP8266) || defined(PARTICLE)
/**
* @brief This enumeration provides the lookahead options for parseInt(), parseFloat().
*
Expand Down Expand Up @@ -979,4 +979,4 @@ class SDI12 : public Stream {
/**@}*/
};

#endif // SRC_SDI12_H_
#endif // SRC_SDI12_H_
4 changes: 2 additions & 2 deletions src/SDI12_boards.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ void SDI12Timer::resetSDI12TimerPrescale(void) {

// Espressif ESP32/ESP8266 boards
//
#elif defined(ESP32) || defined(ESP8266)
#elif defined(ESP32) || defined(ESP8266) || defined(PARTICLE)

void SDI12Timer::configSDI12TimerPrescale(void) {}
void SDI12Timer::resetSDI12TimerPrescale(void) {}
Expand All @@ -276,4 +276,4 @@ sdi12timer_t SDI12Timer::SDI12TimerRead(void) {
// Unknown board
#else
#error "Please define your board timer and pins"
#endif
#endif
6 changes: 3 additions & 3 deletions src/SDI12_boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ sensors. This library provides a general software solution, without requiring

#include <Arduino.h>

#if defined(ESP32) || defined(ESP8266)
#if defined(ESP32) || defined(ESP8266) || defined(PARTICLE)
/** The interger type (size) of the timer return value */
typedef uint32_t sdi12timer_t;
#else
Expand Down Expand Up @@ -466,7 +466,7 @@ class SDI12Timer {

// Espressif ESP32/ESP8266 boards
//
#elif defined(ESP32) || defined(ESP8266)
#elif defined(ESP32) || defined(ESP8266) || defined(PARTICLE)
/**
* @brief Read the processor micros and right shift 6 bits (ie, divide by 64) to get a
* 64µs tick.
Expand Down Expand Up @@ -515,4 +515,4 @@ class SDI12Timer {
#endif
};

#endif // SRC_SDI12_BOARDS_H_
#endif // SRC_SDI12_BOARDS_H_