Could The Latest IDE update be causing this issue?

Hey Guys, I have a sketch I have been using over the last week just fine with the web IDE. This sketch would compile and flash just fine.

I added 2 lines of code that caused the LED to Blink 3 times instead of 2 times. I only made this because I heard that you had to change your Sketch before the Spark Core would be updated with the new Firmware updates that were released lastnight.

Now the sketch that used to work just fine is throwing up abunch of errors from the .cpp code. I figure that this has something to do with the updates that have went into effect recently.

Look at the code and let me know if its a easy fix please… :smile:

SHT1x.cpp: In member function 'int SHT1x::shiftIn(int, int, int)':
SHT1x.cpp:134:30: error: 'HIGH' was not declared in this scope
SHT1x.cpp:134:34: error: 'digitalWrite' was not declared in this scope
SHT1x.cpp:135:14: error: 'delay' was not declared in this scope
SHT1x.cpp:136:40: error: 'digitalRead' was not declared in this scope
SHT1x.cpp:137:30: error: 'LOW' was not declared in this scope
SHT1x.cpp: In member function 'void SHT1x::sendCommandSHT(int, int, int)':
SHT1x.cpp:150:21: error: 'OUTPUT' was not declared in this scope
SHT1x.cpp:150:27: error: 'pinMode' was not declared in this scope
SHT1x.cpp:152:26: error: 'HIGH' was not declared in this scope
SHT1x.cpp:152:30: error: 'digitalWrite' was not declared in this scope
SHT1x.cpp:154:26: error: 'LOW' was not declared in this scope
SHT1x.cpp:161:33: error: 'MSBFIRST' was not declared in this scope
SHT1x.cpp:161:51: error: 'shiftOut' was not declared in this scope
SHT1x.cpp:165:21: error: 'INPUT' was not declared in this scope
SHT1x.cpp:166:29: error: 'digitalRead' was not declared in this scope
SHT1x.cpp: In member function 'void SHT1x::waitForResultSHT(int)':
SHT1x.cpp:184:21: error: 'INPUT' was not declared in this scope
SHT1x.cpp:184:26: error: 'pinMode' was not declared in this scope
SHT1x.cpp:188:13: error: 'delay' was not declared in this scope
SHT1x.cpp:189:31: error: 'digitalRead' was not declared in this scope
SHT1x.cpp:191:16: error: 'LOW' was not declared in this scope
SHT1x.cpp:196:14: error: 'HIGH' was not declared in this scope
SHT1x.cpp: In member function 'int SHT1x::getData16SHT(int, int)':
SHT1x.cpp:208:21: error: 'INPUT' was not declared in this scope
SHT1x.cpp:208:26: error: 'pinMode' was not declared in this scope
SHT1x.cpp:209:22: error: 'OUTPUT' was not declared in this scope
SHT1x.cpp:215:26: error: 'HIGH' was not declared in this scope
SHT1x.cpp:215:30: error: 'digitalWrite' was not declared in this scope
SHT1x.cpp:216:26: error: 'LOW' was not declared in this scope
SHT1x.cpp: In member function 'void SHT1x::skipCrcSHT(int, int)':
SHT1x.cpp:232:21: error: 'OUTPUT' was not declared in this scope
SHT1x.cpp:232:27: error: 'pinMode' was not declared in this scope
SHT1x.cpp:235:26: error: 'HIGH' was not declared in this scope
SHT1x.cpp:235:30: error: 'digitalWrite' was not declared in this scope
SHT1x.cpp:237:27: error: 'LOW' was not declared in this scope
make: *** [SHT1x.o] Error 1

Error: Could not compile. Please review your code. 

Check out this topic:

Perhaps it needs to be pinned for a bit longer.

1 Like

I added #include “application.h” to the top of the main sketch cpp code but it does not change the error codes.

I then added “application.h” to the .cpp & .h files but it gave me different errors.

Then finally I tried adding it to the .h file only and it compiled just fine.

Took this beginner awhile to figure that one out.

Thank you BDub for pointing me where I needed to go.

Hi,

i also tried to use the SHT1x lib with CORE in which the #include “application.h” statement is already written.

( i used the on line compiler )

but i got the exact error massage as above . (RWB)

?

Could you share the code you’re using?

@ambroisedutilleul Here is the code that’s working for me and the SHT1 sensor.

I’m sending data to Ubidots.com with this code.

    // This #include statement was automatically added by the Spark IDE.
#include "SHT1x.h"

// This #include statement was automatically added by the Spark IDE.
#include "HttpClient/HttpClient.h"

/**
 * ReadSHT1xValues
 *
 * Read temperature and humidity values from an SHT1x-series (SHT10,
 * SHT11, SHT15) sensor.
 *
 * Copyright 2009 Jonathan Oxer <jon@oxer.com.au>
 * www.practicalarduino.com
 */
 


// Specify data and clock connections and instantiate SHT1x object
#define dataPin  D0
#define clockPin D1
SHT1x sht1x(dataPin, clockPin);


/**
* Declaring the variables.
*/
HttpClient http;
#define VARIABLE_ID "53f8c7d576254210781ba266"
#define VARIABLE_ID2 "542310217625425104c40af4"
#define TOKEN "vTZWSU269MDP2FlcTXcIqqHEKf1CHuvSkIYWKxin0FnfmqJGMKUKOeq9gvvc"


// Headers currently need to be set at init, useful for API keys etc.
http_header_t headers[] = {
      { "Content-Type", "application/json" },
      { "X-Auth-Token" , TOKEN },
    { NULL, NULL } // NOTE: Always terminate headers will NULL
};

http_request_t request;
http_response_t response;

void setup() {
   
    request.hostname = "things.ubidots.com";
    request.port = 80;
    //Serial.begin(9600);
}

void loop() {


float temp_f = 0;
float humidity = 0;

 
    // Read values from the sensor
    temp_f = sht1x.readTemperatureF();
    humidity = sht1x.readHumidity();
    
    delay(10001);

    // Send to Ubidots

    request.path = "/api/v1.6/variables/"VARIABLE_ID"/values";
    request.body = "{\"value\":" + String(temp_f) + "}";
    
    http.post(request, response, headers);
    
    request.path = "/api/v1.6/variables/"VARIABLE_ID2"/values";
    request.body = "{\"value\":" + String(humidity) + "}";

    http.post(request, response, headers);
    //Serial.println(response.status);

    //Serial.println(response.body);

   
}

.cpp

    /**
 * SHT1x Library
 *
 * Copyright 2009 Jonathan Oxer <jon@oxer.com.au> / <www.practicalarduino.com>
 * Based on previous work by:
 *    Maurice Ribble: <www.glacialwanderer.com/hobbyrobotics/?p=5>
 *    Wayne ?: <ragingreality.blogspot.com/2008/01/ardunio-and-sht15.html>
 *
 * Manages communication with SHT1x series (SHT10, SHT11, SHT15)
 * temperature / humidity sensors from Sensirion (www.sensirion.com).
 */

#include "SHT1x.h"

SHT1x::SHT1x(int dataPin, int clockPin)
{
  _dataPin = dataPin;
  _clockPin = clockPin;
}


/* ================  Public methods ================ */

/**
 * Reads the current temperature in degrees Celsius
*/
float SHT1x::readTemperatureC()
{
  int _val;                // Raw value returned from sensor
  float _temperature;      // Temperature derived from raw value

  // Conversion coefficients from SHT15 datasheet
  const float CC1 = -40.0;  // for 14 Bit @ 5V
  const float CC2 =   0.01; // for 14 Bit DEGC

  // Fetch raw value
  _val = readTemperatureRaw();

  // Convert raw value to degrees Celsius
  _temperature = (_val * CC2) + CC1;

  return (_temperature);
}

/**
 * Reads the current temperature in degrees Fahrenheit
 */
float SHT1x::readTemperatureF()
{
  int _val;                 // Raw value returned from sensor
  float _temperature;       // Temperature derived from raw value

  // Conversion coefficients from SHT15 datasheet
  const float CC1 = -40.0;   // for 14 Bit @ 5V
  const float CC2 =   0.018; // for 14 Bit DEGF

  // Fetch raw value
  _val = readTemperatureRaw();

  // Convert raw value to degrees Fahrenheit
  _temperature = (_val * CC2) + CC1;

  return (_temperature);
}

/**
 * Reads current temperature-corrected relative humidity
 */
float SHT1x::readHumidity()
{
  int _val;                    // Raw humidity value returned from sensor
  float _linearHumidity;       // Humidity with linear correction applied
  float _correctedHumidity;    // Temperature-corrected humidity
  float _temperature;          // Raw temperature value

  // Conversion coefficients from SHT15 datasheet
  const float CC1 = -4.0;       // for 12 Bit
  const float CC2 =  0.0405;    // for 12 Bit
  const float CC3 = -0.0000028; // for 12 Bit
  const float CT1 =  0.01;      // for 14 Bit @ 5V
  const float CT2 =  0.00008;   // for 14 Bit @ 5V

  // Command to send to the SHT1x to request humidity
  int _gHumidCmd = 0b00000101;

  // Fetch the value from the sensor
  sendCommandSHT(_gHumidCmd, _dataPin, _clockPin);
  waitForResultSHT(_dataPin);
  _val = getData16SHT(_dataPin, _clockPin);
  skipCrcSHT(_dataPin, _clockPin);

  // Apply linear conversion to raw value
  _linearHumidity = CC1 + CC2 * _val + CC3 * _val * _val;

  // Get current temperature for humidity correction
  _temperature = readTemperatureC();

  // Correct humidity value for current temperature
  _correctedHumidity = (_temperature - 25.0 ) * (CT1 + CT2 * _val) + _linearHumidity;

  return (_correctedHumidity);
}


/* ================  Private methods ================ */

/**
 * Reads the current raw temperature value
 */
float SHT1x::readTemperatureRaw()
{
  int _val;

  // Command to send to the SHT1x to request Temperature
  int _gTempCmd  = 0b00000011;

  sendCommandSHT(_gTempCmd, _dataPin, _clockPin);
  waitForResultSHT(_dataPin);
  _val = getData16SHT(_dataPin, _clockPin);
  skipCrcSHT(_dataPin, _clockPin);

  return (_val);
}

/**
 */
int SHT1x::shiftIn(int _dataPin, int _clockPin, int _numBits)
{
  int ret = 0;
  int i;

  for (i=0; i<_numBits; ++i)
  {
     digitalWrite(_clockPin, HIGH);
     delay(10);  // I don't know why I need this, but without it I don't get my 8 lsb of temp
     ret = ret*2 + digitalRead(_dataPin);
     digitalWrite(_clockPin, LOW);
  }

  return(ret);
}

/**
 */
void SHT1x::sendCommandSHT(int _command, int _dataPin, int _clockPin)
{
  int ack;

  // Transmission Start
  pinMode(_dataPin, OUTPUT);
  pinMode(_clockPin, OUTPUT);
  digitalWrite(_dataPin, HIGH);
  digitalWrite(_clockPin, HIGH);
  digitalWrite(_dataPin, LOW);
  digitalWrite(_clockPin, LOW);
  digitalWrite(_clockPin, HIGH);
  digitalWrite(_dataPin, HIGH);
  digitalWrite(_clockPin, LOW);

  // The command (3 msb are address and must be 000, and last 5 bits are command)
  shiftOut(_dataPin, _clockPin, MSBFIRST, _command);

  // Verify we get the correct ack
  digitalWrite(_clockPin, HIGH);
  pinMode(_dataPin, INPUT);
  ack = digitalRead(_dataPin);
  if (ack != LOW) {
    //Serial.println("Ack Error 0");
  }
  digitalWrite(_clockPin, LOW);
  ack = digitalRead(_dataPin);
  if (ack != HIGH) {
    //Serial.println("Ack Error 1");
  }
}

/**
 */
void SHT1x::waitForResultSHT(int _dataPin)
{
  int i;
  int ack;

  pinMode(_dataPin, INPUT);

  for(i= 0; i < 100; ++i)
  {
    delay(10);
    ack = digitalRead(_dataPin);

    if (ack == LOW) {
      break;
    }
  }

  if (ack == HIGH) {
    //Serial.println("Ack Error 2"); // Can't do serial stuff here, need another way of reporting errors
  }
}

/**
 */
int SHT1x::getData16SHT(int _dataPin, int _clockPin)
{
  int val;

  // Get the most significant bits
  pinMode(_dataPin, INPUT);
  pinMode(_clockPin, OUTPUT);
  val = shiftIn(_dataPin, _clockPin, 8);
  val *= 256;

  // Send the required ack
  pinMode(_dataPin, OUTPUT);
  digitalWrite(_dataPin, HIGH);
  digitalWrite(_dataPin, LOW);
  digitalWrite(_clockPin, HIGH);
  digitalWrite(_clockPin, LOW);

  // Get the least significant bits
  pinMode(_dataPin, INPUT);
  val |= shiftIn(_dataPin, _clockPin, 8);

  return val;
}

/**
 */
void SHT1x::skipCrcSHT(int _dataPin, int _clockPin)
{
  // Skip acknowledge to end trans (no CRC)
  pinMode(_dataPin, OUTPUT);
  pinMode(_clockPin, OUTPUT);

  digitalWrite(_dataPin, HIGH);
  digitalWrite(_clockPin, HIGH);
  digitalWrite(_clockPin, LOW);
}

.h

    #include "application.h"
#ifndef SHT1x_h
#define SHT1x_h


class SHT1x
{
  public:
    SHT1x(int dataPin, int clockPin);
    float readHumidity();
    float readTemperatureC();
    float readTemperatureF();
  private:
    int _dataPin;
    int _clockPin;
    int _numBits;
    float readTemperatureRaw();
    int shiftIn(int _dataPin, int _clockPin, int _numBits);
    void sendCommandSHT(int _command, int _dataPin, int _clockPin);
    void waitForResultSHT(int _dataPin);
    int getData16SHT(int _dataPin, int _clockPin);
    void skipCrcSHT(int _dataPin, int _clockPin);
};

#endif