Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Compile error for SDI-12

  1. #1
    Junior Member
    Join Date
    Nov 2018
    Posts
    3

    Compile error for SDI-12

    I am using an SDI-12 library which you can find at Github here here. It works great on the UNO or any other board but gets errors when I try to compile with Teensy. The error and codes are posted below. Any thoughts on why Teensy would give an error that variables are not declared but if I compile for UNO all of the variables are declared?


    Code:
    In file included from C:\Users\Fred\Documents\Arduino\d_simple_logger\d_simple_logger.ino:62:0:
    
    C:\Users\Fred\Documents\Arduino\libraries\SDI-12-master\src/SDI12.h:63:21: error: 'LookaheadMode' has not been declared
    
       int peekNextDigit(LookaheadMode lookahead, bool detectDecimal);
    
                         ^
    
    C:\Users\Fred\Documents\Arduino\libraries\SDI-12-master\src/SDI12.h:128:17: error: 'LookaheadMode' has not been declared
    
       long parseInt(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
    
                     ^
    
    C:\Users\Fred\Documents\Arduino\libraries\SDI-12-master\src/SDI12.h:129:20: error: 'LookaheadMode' has not been declared
    
       float parseFloat(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
    
                        ^
    
    C:\Users\Fred\Documents\Arduino\libraries\SDI-12-master\src/SDI12.h:128:43: error: 'SKIP_ALL' was not declared in this scope
    
       long parseInt(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
    
                                               ^
    
    C:\Users\Fred\Documents\Arduino\libraries\SDI-12-master\src/SDI12.h:129:46: error: 'SKIP_ALL' was not declared in this scope
    
       float parseFloat(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
    
                                                  ^
    
    d_simple_logger: In function 'void takeMeasurement(char)':
    d_simple_logger:183: warning: logical not is only applied to the left hand side of comparison 
       while(!mySDI12.available()>1); // wait for acknowlegement
    
                                 ^
    
    Using library SDI-12-master at version 1.3.4 in folder: C:\Users\Fred\Documents\Arduino\libraries\SDI-12-master 
    Error compiling for board Teensy 3.2 / 3.1.

    Here is the code I am using which works perfectly on an UNO.

    Code:
    #include <SDI12.h>
    
    #define SERIAL_BAUD 115200  // The baud rate for the output serial port
    #define DATA_PIN 7         // The pin of the SDI-12 data bus
    #define POWER_PIN -1       // The sensor power pin (or -1 if not switching power)
    
    // Define the SDI-12 bus
    SDI12 mySDI12(DATA_PIN);
    
    // keeps track of active addresses
    // each bit represents an address:
    // 1 is active (taken), 0 is inactive (available)
    // setTaken('A') will set the proper bit for sensor 'A'
    byte addressRegister[8] = {
      0B00000000,
      0B00000000,
      0B00000000,
      0B00000000,
      0B00000000,
      0B00000000,
      0B00000000,
      0B00000000
    };
    
    uint8_t numSensors = 0;
    
    
    // converts allowable address characters '0'-'9', 'a'-'z', 'A'-'Z',
    // to a decimal number between 0 and 61 (inclusive) to cover the 62 possible addresses
    byte charToDec(char i){
      if((i >= '0') && (i <= '9')) return i - '0';
      if((i >= 'a') && (i <= 'z')) return i - 'a' + 10;
      if((i >= 'A') && (i <= 'Z')) return i - 'A' + 37;
      else return i;
    }
    
    // THIS METHOD IS UNUSED IN THIS EXAMPLE, BUT IT MAY BE HELPFUL.
    // maps a decimal number between 0 and 61 (inclusive) to
    // allowable address characters '0'-'9', 'a'-'z', 'A'-'Z',
    char decToChar(byte i){
      if((i >= 0) && (i <= 9)) return i + '0';
      if((i >= 10) && (i <= 36)) return i + 'a' - 10;
      if((i >= 37) && (i <= 62)) return i + 'A' - 37;
      else return i;
    }
    
    void printBufferToScreen(){
      String buffer = "";
      mySDI12.read(); // consume address
      while(mySDI12.available()){
        char c = mySDI12.read();
        if(c == '+'){
          buffer += ',';
        }
        else if ((c != '\n') && (c != '\r')) {
          buffer += c;
        }
        delay(50);
      }
     Serial.print(buffer);
    }
    
    // gets identification information from a sensor, and prints it to the serial port
    // expects a character between '0'-'9', 'a'-'z', or 'A'-'Z'.
    void printInfo(char i){
      String command = "";
      command += (char) i;
      command += "I!";
      mySDI12.sendCommand(command);
      // Serial.print(">>>");
      // Serial.println(command);
      delay(30);
    
      printBufferToScreen();
    }
    
    void takeMeasurement(char i){
      String command = "";
      command += i;
      command += "M!"; // SDI-12 measurement command format  [address]['M'][!]
      mySDI12.sendCommand(command);
      delay(30);
    
      // wait for acknowlegement with format [address][ttt (3 char, seconds)][number of measurments available, 0-9]
      String sdiResponse = "";
      delay(30);
      while (mySDI12.available())  // build response string
      {
        char c = mySDI12.read();
        if ((c != '\n') && (c != '\r'))
        {
          sdiResponse += c;
          delay(5);
        }
      }
      mySDI12.clearBuffer();
    
      // find out how long we have to wait (in seconds).
      uint8_t wait = 0;
      wait = sdiResponse.substring(1,4).toInt();
    
      // Set up the number of results to expect
      // int numMeasurements =  sdiResponse.substring(4,5).toInt();
    
      unsigned long timerStart = millis();
      while((millis() - timerStart) < (1000 * wait)){
        if(mySDI12.available())  // sensor can interrupt us to let us know it is done early
        {
          mySDI12.clearBuffer();
          break;
        }
      }
      // Wait for anything else and clear it out
      delay(30);
      mySDI12.clearBuffer();
    
      // in this example we will only take the 'DO' measurement
      command = "";
      command += i;
      command += "D0!"; // SDI-12 command to get data [address][D][dataOption][!]
      mySDI12.sendCommand(command);
      while(!mySDI12.available()>1); // wait for acknowlegement
      delay(300); // let the data transfer
      printBufferToScreen();
      mySDI12.clearBuffer();
    }
    
    // this checks for activity at a particular address
    // expects a char, '0'-'9', 'a'-'z', or 'A'-'Z'
    boolean checkActive(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
        mySDI12.sendCommand(myCommand);
        delay(30);
        if(mySDI12.available()) {  // If we here anything, assume we have an active sensor
          printBufferToScreen();
          mySDI12.clearBuffer();
          return true;
        }
      }
      mySDI12.clearBuffer();
      return false;
    }
    
    // this quickly checks if the address has already been taken by an active sensor
    boolean isTaken(byte i){
      i = charToDec(i); // e.g. convert '0' to 0, 'a' to 10, 'Z' to 61.
      byte j = i / 8;   // byte #
      byte k = i % 8;   // bit #
      return addressRegister[j] & (1<<k); // return bit status
    }
    
    // this sets the bit in the proper location within the addressRegister
    // to record that the sensor is active and the address is taken.
    boolean setTaken(byte i){
      boolean initStatus = isTaken(i);
      i = charToDec(i); // e.g. convert '0' to 0, 'a' to 10, 'Z' to 61.
      byte j = i / 8;   // byte #
      byte k = i % 8;   // bit #
      addressRegister[j] |= (1 << k);
      return !initStatus; // return false if already taken
    }
    
    // THIS METHOD IS UNUSED IN THIS EXAMPLE, BUT IT MAY BE HELPFUL.
    // this unsets the bit in the proper location within the addressRegister
    // to record that the sensor is active and the address is taken.
    boolean setVacant(byte i){
      boolean initStatus = isTaken(i);
      i = charToDec(i); // e.g. convert '0' to 0, 'a' to 10, 'Z' to 61.
      byte j = i / 8;   // byte #
      byte k = i % 8;   // bit #
      addressRegister[j] &= ~(1 << k);
      return initStatus; // return false if already vacant
    }
    
    
    void setup(){
      Serial.begin(SERIAL_BAUD);
      while(!Serial);
    
      Serial.println("Opening SDI-12 bus...");
      mySDI12.begin();
      delay(500); // allow things to settle
    
      // Power the sensors;
      if(POWER_PIN > 0){
        Serial.println("Powering up sensors...");
        pinMode(POWER_PIN, OUTPUT);
        digitalWrite(POWER_PIN, HIGH);
        delay(200);
      }
    
      Serial.println("Scanning all addresses, please wait...");
      /*
          Quickly Scan the Address Space
       */
    
      for(byte i = '0'; i <= '9'; i++) if(checkActive(i)) {numSensors++; setTaken(i);}   // scan address space 0-9
    
      for(byte i = 'a'; i <= 'z'; i++) if(checkActive(i)) {numSensors++; setTaken(i);}   // scan address space a-z
    
      for(byte i = 'A'; i <= 'Z'; i++) if(checkActive(i)) {numSensors++; setTaken(i);}   // scan address space A-Z
    
      /*
          See if there are any active sensors.
       */
      boolean found = false;
    
      for(byte i = 0; i < 62; i++){
        if(isTaken(i)){
          found = true;
          Serial.print("First address found:  ");
          Serial.println(decToChar(i));
          Serial.print("Total number of sensors found:  ");
          Serial.println(numSensors);
          break;
        }
      }
    
      if(!found) {
        Serial.println("No sensors found, please check connections and restart the Arduino.");
        while(true);
      } // stop here
    
      Serial.println();
      Serial.println("Time Elapsed (s), Sensor Address and ID, Measurement 1, Measurement 2, ... etc.");
      Serial.println("-------------------------------------------------------------------------------");
    }
    
    void loop(){
    
      // scan address space 0-9
      //for(char i = '0'; i <= '9'; i++) if(isTaken(i)){
      char i = '0';
        Serial.print(millis()/1000);
        Serial.print(",\t");
        printInfo(i);
        Serial.print(",\t");
        takeMeasurement(i);
        Serial.println();
     // }
    //
    //  // scan address space a-z
    //  for(char i = 'a'; i <= 'z'; i++) if(isTaken(i)){
    //    Serial.print(millis()/1000);
    //    Serial.print(",\t");
    //    printInfo(i);
    //    Serial.print(",\t");
    //    takeMeasurement(i);
    //    Serial.println();
    //  }
    //
    //  // scan address space A-Z
    //  for(char i = 'A'; i <= 'Z'; i++) if(isTaken(i)){
    //    Serial.print(millis()/1000);
    //    Serial.print(",\t");
    //    printInfo(i);
    //    Serial.print(",\t");
    //    takeMeasurement(i);
    //    Serial.println();
    //  };
    
      delay(10000); // wait ten seconds between measurement attempts.
    
    }

  2. #2
    went to github,
    https://github.com/EnviroDIY/Arduino-SDI-12
    read this,
    The Arduino Due, Arduino 101, Teensy, and ESP8266/ESP32 boards are not supported at this time. If you are interested in adding support for those boards, please send pull requests.

    thought i would mention it.

  3. #3
    Junior Member
    Join Date
    Nov 2018
    Posts
    3
    Thanks, I saw that. I am starting to attempt to integrate it with the Teensy and will see how that goes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •