I have code that interfaces to a JSN-SR04T ultrasonic sensor and reports the height and number of gallons of water in a large storage tank that runs perfectly on a Photon and on an Electron, but won’t even flash to a Boron. The code - below - includes the New_Ping.h library file written by Tim Eckel. The errors that I get when I try to flash to a Boron are attached as a screenshot. When I queried Tim about the issue, he replied “The problem is the Boron (and all Gen 3 devices) not supporting the SparkIntervalTimer library (as the errors are noting). It seems even the latest version doesn’t support the Gen 3 devices.”
Can anyone suggest an alternative to the New_Ping.h library for this app?
Code:
// This #include statement was automatically added by the Particle IDE.
#include <New_Ping.h>
#include <Wire.h>
// Define variables:
int gallons;
int distance;
int height;
//int arraydistance;
int gap = 0; // Distance between sensor and maximum water level
#define trigPin 2
#define echoPin 3
#define MAX_DISTANCE 400
NewPing sonar = NewPing(trigPin, echoPin, MAX_DISTANCE);
void setup() {
Serial.begin(9600); // Set the speed of the I2C port on the Photon and start it.
Wire.begin();
Particle.function("Gallons", getGallons);
Particle.function("Inches", getInches);
}
// For MTWA:
// int depth [29] = {1480,1438,1396,1356,1316,1271,1226,1186,1146,1096,1046,1003,961,919,876,831,786,741,696,656,616,571,526,482,438,396,354,309,264};
// For Steve Swanberg:
int depth [67] = {919,905,891,877,863,849,836,822,808,794,780,766,752,738,724,710,696,682,668,654,641,627,613,599,585,571,557,543,529,515,501,487,473,460,446,432,418,404,390,376,362,348,334,320,306,292,279,265,251,237,223,209,195,181,167,153,139,125,111,97,84,70,56,42,28,14,0};
// Function to retrieve gallons
int getGallons(String command) {
distance = sonar.ping_in(); // In inches
distance = distance - gap;
height = 67 - distance;
gallons = depth [distance];
return gallons;
} // End getGallons Function
// Function to retrieve height
int getInches(String command) {
distance = sonar.ping_in(); // In inches
distance = distance - gap;
height = 67 - distance;
gallons = depth [distance];
return height;
} // End getInches Function
void loop() {
distance = sonar.ping_in();// In inches
distance = distance - gap;
height = 67 - distance; // Maximum height of water in tank
gallons = depth [distance];
if (distance <10) {
Particle.publish ("Gallons","Error",60, PRIVATE);
Particle.publish ("Inches","Error",60, PRIVATE);
}
else {
Particle.publish ("Gallons",String(gallons),60, PRIVATE);
Particle.publish ("Inches",String(height),60, PRIVATE);
}
delay(300000); // Take a measurement every 5 minutes
}