WString.h ERROR, Arduino 1.0 Uno --SOLVED

Hello, Newbie here, getting this error wondering if anyone can lead me in the right direction, spent few days now going through forums to find an answer, clearly something todo with WString.h, I think. I found similar problems in the forum that were easily fixed by replacing thisnthat.h with Arduino.h but that has not worked for me as of yet, tried in many places as well but no luck. Also found the following in the 1.0 release notes that may be telling me "yep might not work"...

  • The String class has been reimplemented as well, by Paul Stoffregen. This new version is more memory-efficient and robust. Some functions which previously returned new string instances (e.g. trim() and toUpperCase()) have been changed to instead modify strings in place.

Anyway any help much appreciated, I'd hate to go back to Arduino 0022 but will if I must.

In file included from C:\Temp\arduino-1.0\hardware\arduino\cores\arduino/Arduino.h:191,
                 from C:\Users\PRANCER\Documents\Arduino\libraries\DHT22\DHT22.cpp:47:
C:\Temp\arduino-1.0\hardware\arduino\cores\arduino/WString.h:116: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, const char*)' conflicts with
C:\Temp\arduino-1.0\hardware\arduino\cores\arduino/WString.h:115: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, const String&)' here
C:\Temp\arduino-1.0\hardware\arduino\cores\arduino/WString.h:117: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, char)' conflicts with
C:\Temp\arduino-1.0\hardware\arduino\cores\arduino/WString.h:116: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, const char*)' here
C:\Temp\arduino-1.0\hardware\arduino\cores\arduino/WString.h:118: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, unsigned char)' conflicts with
C:\Temp\arduino-1.0\hardware\arduino\cores\arduino/WString.h:117: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, char)' here
C:\Temp\arduino-1.0\hardware\arduino\cores\arduino/WString.h:119: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, int)' conflicts with
C:\Temp\arduino-1.0\hardware\arduino\cores\arduino/WString.h:118: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, unsigned char)' here
C:\Temp\arduino-1.0\hardware\arduino\cores\arduino/WString.h:120: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, unsigned int)' conflicts with
C:\Temp\arduino-1.0\hardware\arduino\cores\arduino/WString.h:119: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, int)' here
C:\Temp\arduino-1.0\hardware\arduino\cores\arduino/WString.h:121: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, long int)' conflicts with
C:\Temp\arduino-1.0\hardware\arduino\cores\arduino/WString.h:120: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, unsigned int)' here
C:\Temp\arduino-1.0\hardware\arduino\cores\arduino/WString.h:122: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, long unsigned int)' conflicts with
C:\Temp\arduino-1.0\hardware\arduino\cores\arduino/WString.h:121: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, long int)' here
In file included from C:\Users\PRANCER\Documents\Arduino\libraries\DHT22\DHT22.cpp:47:
C:\Temp\arduino-1.0\hardware\arduino\cores\arduino/Arduino.h:195: error: declaration of C function 'uint16_t makeWord(byte, byte)' conflicts with
C:\Temp\arduino-1.0\hardware\arduino\cores\arduino/Arduino.h:194: error: previous declaration 'uint16_t makeWord(uint16_t)' here
C:\Temp\arduino-1.0\hardware\arduino\cores\arduino/Arduino.h:205: error: declaration of C function 'long int random(long int)' conflicts with
c:/temp/arduino-1.0/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:504: error: previous declaration 'long int random()' here
C:\Temp\arduino-1.0\hardware\arduino\cores\arduino/Arduino.h:206: error: declaration of C function 'long int random(long int, long int)' conflicts with
C:\Temp\arduino-1.0\hardware\arduino\cores\arduino/Arduino.h:205: error: previous declaration 'long int random(long int)' here

Here's the problem section of WString.h, my untrained eye know not what todo with this...

    friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs);
    friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr);
    friend StringSumHelper & operator + (const StringSumHelper &lhs, char c);
    friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num);
    friend StringSumHelper & operator + (const StringSumHelper &lhs, int num);
    friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num);
    friend StringSumHelper & operator + (const StringSumHelper &lhs, long num);
    friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num);

We've seen the errors, now let's see the code ...

Acab: Anyway any help much appreciated, I'd hate to go back to Arduino 0022 but will if I must.

Why, anyway? It works perfectly.

Maybe DHT22.cpp needs to be updated for Arduino 1.0 ? (If you can, you should post that file and the corresponding .h too).

DHT22.cpp

/*
  DHT22.cpp - DHT22 sensor library
  Developed by Ben Adams - 2011

  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 St, Fifth Floor, Boston, MA  02110-1301  USA


Humidity and Temperature Sensor DHT22 info found at
http://www.sparkfun.com/products/10167

Version 0.4: 24-Jan-2011 by Ben Adams
Added return code constants to keywords.txt
Returns DHT_ERROR_CHECKSUM on check sum mismatch 

Version 0.3: 17-Jan-2011 by Ben Adams
This version reads data
Needs check sum code added at the end of readData

Version 0.2: 16-Jan-2011 by Ben Adams
Changed coding style to match other Arduino libraries.
This version will not read data either!

Version 0.1: 10-Jan-2011 by Ben Adams nethoncho AT gmail.com
First Version is a skeleton. This version will not read data!
Code adapted from the following sources:
The Arduino OneWire lib
http://sheepdogguides.com/arduino/ar3ne1humDHT11.htm

*/

#include "DHT22.h"
#include "pins_arduino.h"

extern "C" {
#include "Arduino.h"  // replaced "WConstants.h"
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
}

#define DIRECT_READ(base, mask)		(((*(base)) & (mask)) ? 1 : 0)
#define DIRECT_MODE_INPUT(base, mask)	((*(base+1)) &= ~(mask))
#define DIRECT_MODE_OUTPUT(base, mask)	((*(base+1)) |= (mask))
#define DIRECT_WRITE_LOW(base, mask)	((*(base+2)) &= ~(mask))
//#define DIRECT_WRITE_HIGH(base, mask)	((*(base+2)) |= (mask))

// This should be 40, but the sensor is adding an extra bit at the start
#define DHT22_DATA_BIT_COUNT 41

DHT22::DHT22(uint8_t pin)
{
    _bitmask =  digitalPinToBitMask(pin);
    _baseReg = portInputRegister(digitalPinToPort(pin));
    _lastReadTime = millis();
    _lastHumidity = DHT22_ERROR_VALUE;
    _lastTemperature = DHT22_ERROR_VALUE;
}

//
// Read the 40 bit data stream from the DHT 22
// Store the results in private member data to be read by public member functions
//
DHT22_ERROR_t DHT22::readData()
{
  uint8_t bitmask = _bitmask;
  volatile uint8_t *reg asm("r30") = _baseReg;
  uint8_t retryCount;
  uint8_t bitTimes[DHT22_DATA_BIT_COUNT];
  int currentHumidity;
  int currentTemperature;
  uint8_t checkSum, csPart1, csPart2, csPart3, csPart4;
  unsigned long currentTime;
  int i;

  currentHumidity = 0;
  currentTemperature = 0;
  checkSum = 0;
  currentTime = millis();
  for(i = 0; i < DHT22_DATA_BIT_COUNT; i++)
  {
    bitTimes[i] = 0;
  }

  if(currentTime - _lastReadTime < 2000)
  {
    // Caller needs to wait 2 seconds between each call to readData
    return DHT_ERROR_TOOQUICK;
  }
  _lastReadTime = currentTime;

  // Pin needs to start HIGH, wait until it is HIGH with a timeout
  cli();
  DIRECT_MODE_INPUT(reg, bitmask);
  sei();
  retryCount = 0;
  do
  {
    if (retryCount > 125)
    {
      return DHT_BUS_HUNG;
    }
    retryCount++;
    delayMicroseconds(2);
  } while(!DIRECT_READ(reg, bitmask));
  // Send the activate pulse
  cli();
  DIRECT_WRITE_LOW(reg, bitmask);
  DIRECT_MODE_OUTPUT(reg, bitmask); // Output Low
  sei();
  delayMicroseconds(1100); // 1.1 ms
  cli();
  DIRECT_MODE_INPUT(reg, bitmask);	// Switch back to input so pin can float
  sei();
  // Find the start of the ACK Pulse
  retryCount = 0;
  do
  {
    if (retryCount > 25) //(Spec is 20 to 40 us, 25*2 == 50 us)
    {
      return DHT_ERROR_NOT_PRESENT;
    }
    retryCount++;
    delayMicroseconds(2);
  } while(!DIRECT_READ(reg, bitmask));
  // Find the end of the ACK Pulse
  retryCount = 0;
  do
  {
    if (retryCount > 50) //(Spec is 80 us, 50*2 == 100 us)
    {
      return DHT_ERROR_ACK_TOO_LONG;
    }
    retryCount++;
    delayMicroseconds(2);
  } while(DIRECT_READ(reg, bitmask));
  // Read the 40 bit data stream
  for(i = 0; i < DHT22_DATA_BIT_COUNT; i++)
  {
    // Find the start of the sync pulse
    retryCount = 0;
    do
    {
      if (retryCount > 35) //(Spec is 50 us, 35*2 == 70 us)
      {
        return DHT_ERROR_SYNC_TIMEOUT;
      }
      retryCount++;
      delayMicroseconds(2);
    } while(!DIRECT_READ(reg, bitmask));
    // Measure the width of the data pulse
    retryCount = 0;
    do
    {
      if (retryCount > 50) //(Spec is 80 us, 50*2 == 100 us)
      {
        return DHT_ERROR_DATA_TIMEOUT;
      }
      retryCount++;
      delayMicroseconds(2);
    } while(DIRECT_READ(reg, bitmask));
    bitTimes[i] = retryCount;
  }
  // Now bitTimes have the number of retries (us *2)
  // that were needed to find the end of each data bit
  // Spec: 0 is 26 to 28 us
  // Spec: 1 is 70 us
  // bitTimes[x] <= 11 is a 0
  // bitTimes[x] >  11 is a 1
  // Note: the bits are offset by one from the data sheet, not sure why
  for(i = 0; i < 16; i++)
  {
    if(bitTimes[i + 1] > 11)
    {
      currentHumidity |= (1 << (15 - i));
    }
  }
  for(i = 0; i < 16; i++)
  {
    if(bitTimes[i + 17] > 11)
    {
      currentTemperature |= (1 << (15 - i));
    }
  }
  for(i = 0; i < 8; i++)
  {
    if(bitTimes[i + 33] > 11)
    {
      checkSum |= (1 << (7 - i));
    }
  }

  _lastHumidity = (float(currentHumidity & 0x7FFF) / 10.0);
  if(currentTemperature & 0x8000)
  {
   // Below zero, non standard way of encoding negative numbers!
    currentTemperature &= 0x7FFF;
    _lastTemperature = (float(currentTemperature) / 10.0) * -1.0;
  }
  else
  {
    _lastTemperature = float(currentTemperature) / 10.0;
  }

  csPart1 = currentHumidity >> 8;
  csPart2 = currentHumidity & 0xFF;
  csPart3 = currentTemperature >> 8;
  csPart4 = currentTemperature & 0xFF;
  if(checkSum == ((csPart1 + csPart2 + csPart3 + csPart4) & 0xFF))
  {
    return DHT_ERROR_NONE;
  }
  return DHT_ERROR_CHECKSUM;
}

float DHT22::getHumidity()
{
  return _lastHumidity;
}

float DHT22::getTemperatureC()
{
  return _lastTemperature;
}

//
// This is used when the millis clock rolls over to zero
//
void DHT22::clockReset()
{
  _lastReadTime = millis();
}

Example Sketch that comes with DHT22.h

#include <DHT22.h>

// Data wire is plugged into port 7 on the Arduino
// Connect a 4.7K resistor between VCC and the data pin (strong pullup)
#define DHT22_PIN 7

// Setup a DHT22 instance
DHT22 myDHT22(DHT22_PIN);

void setup(void)
{
  // start serial port
  Serial.begin(9600);
  Serial.println("DHT22 Library Demo");
}

void loop(void)
{ 
  DHT22_ERROR_t errorCode;

  delay(2000);
  Serial.print("Requesting data...");
  errorCode = myDHT22.readData();
  switch(errorCode)
  {
    case DHT_ERROR_NONE:
      Serial.print("Got Data ");
      Serial.print(myDHT22.getTemperatureC());
      Serial.print("C ");
      Serial.print(myDHT22.getHumidity());
      Serial.println("%");
      break;
    case DHT_ERROR_CHECKSUM:
      Serial.print("check sum error ");
      Serial.print(myDHT22.getTemperatureC());
      Serial.print("C ");
      Serial.print(myDHT22.getHumidity());
      Serial.println("%");
      break;
    case DHT_BUS_HUNG:
      Serial.println("BUS Hung ");
      break;
    case DHT_ERROR_NOT_PRESENT:
      Serial.println("Not Present ");
      break;
    case DHT_ERROR_ACK_TOO_LONG:
      Serial.println("ACK time out ");
      break;
    case DHT_ERROR_SYNC_TIMEOUT:
      Serial.println("Sync Timeout ");
      break;
    case DHT_ERROR_DATA_TIMEOUT:
      Serial.println("Data Timeout ");
      break;
    case DHT_ERROR_TOOQUICK:
      Serial.println("Polled to quick ");
      break;
  }
}
  • DHT22.h is missing.
  • What is that pins_arduino.h ? We should see that too.
  • Not sure why #include "Arduino.h" is inside extern "C" {} block; also, that should use angle brackets and usually is found only in the .h file.

HTH

Mr. Gammon, it's safe to assume when you say "It works perfectly" you tested it in 1.0, that said maybe it's something I did, like change .h and .cpp files, for this end I deleted my install and replaced off of zip file for 1.0, and there is one place in the DHT22.cpp file where I replaced "WConstants.h" with "Arduino.h", seemed like the right thing todo and either way it doesn't work. In case it means anything the WConstants.h errors are following. This is why I used Arduino.h. What I'm wondering is if there is some other kind of error I inadvertently made due to being such a newbie that crosses your mind that has more todo with install than programing? Thanks so much for your time!

C:\Users\PRANCER\Documents\Arduino\libraries\DHT22\DHT22.cpp:47:76: error: WConstants.h: No such file or directory C:\Users\PRANCER\Documents\Arduino\libraries\DHT22\DHT22.cpp: In constructor 'DHT22::DHT22(uint8_t)': C:\Users\PRANCER\Documents\Arduino\libraries\DHT22\DHT22.cpp:64: error: 'digitalPinToBitMask' was not declared in this scope C:\Users\PRANCER\Documents\Arduino\libraries\DHT22\DHT22.cpp:65: error: 'digitalPinToPort' was not declared in this scope C:\Users\PRANCER\Documents\Arduino\libraries\DHT22\DHT22.cpp:65: error: 'portInputRegister' was not declared in this scope C:\Users\PRANCER\Documents\Arduino\libraries\DHT22\DHT22.cpp:66: error: 'millis' was not declared in this scope C:\Users\PRANCER\Documents\Arduino\libraries\DHT22\DHT22.cpp: In member function 'DHT22_ERROR_t DHT22::readData()': C:\Users\PRANCER\Documents\Arduino\libraries\DHT22\DHT22.cpp:90: error: 'millis' was not declared in this scope C:\Users\PRANCER\Documents\Arduino\libraries\DHT22\DHT22.cpp:115: error: 'delayMicroseconds' was not declared in this scope C:\Users\PRANCER\Documents\Arduino\libraries\DHT22\DHT22.cpp:122: error: 'delayMicroseconds' was not declared in this scope C:\Users\PRANCER\Documents\Arduino\libraries\DHT22\DHT22.cpp: In member function 'void DHT22::clockReset()': C:\Users\PRANCER\Documents\Arduino\libraries\DHT22\DHT22.cpp:242: error: 'millis' was not declared in this scope

DHT22.h file

#ifndef _DHT22_H_
#define _DHT22_H_

#include <inttypes.h>

#define DHT22_ERROR_VALUE -99.5

typedef enum
{
  DHT_ERROR_NONE = 0,
  DHT_BUS_HUNG,
  DHT_ERROR_NOT_PRESENT,
  DHT_ERROR_ACK_TOO_LONG,
  DHT_ERROR_SYNC_TIMEOUT,
  DHT_ERROR_DATA_TIMEOUT,
  DHT_ERROR_CHECKSUM,
  DHT_ERROR_TOOQUICK
} DHT22_ERROR_t;

class DHT22
{
  private:
    uint8_t _bitmask;
    volatile uint8_t *_baseReg;
    unsigned long _lastReadTime;
    float _lastHumidity;
    float _lastTemperature;

  public:
    DHT22(uint8_t pin);
    DHT22_ERROR_t readData(void);
    float getHumidity();
    float getTemperatureC();
    void clockReset();
};

#endif /*_DHT22_H_*/

Doesn't look like an arduino library... The guidelines are here:

http://arduino.cc/en/Hacking/LibraryTutorial

(warning: WProgram.h should be replaced with Arduino.h if one is using the 1.0 IDE).

HTH

Looking like user mromani was correct, I've changed my DHT22.cpp file using their idea and it compiles now, but must run out for a while so can't yet confirm it's working altogether, will get back and check. THANKS FORUM

Acab: Mr. Gammon, it's safe to assume when you say "It works perfectly" you tested it in 1.0...

All I am saying is that a lot of libraries and examples work fine under the 0022 version.

I didn't test your code because you didn't post it.

It isn't like you have to install the latest version of Windows so that your latest video card works properly. If things work under 0022 why bother upgrading to version 1.0, when a lot of stuff doesn't work?

All Better.

went from:

#include "DHT22.h"
#include "pins_arduino.h"

extern "C" {
//#include "Arduino.h"
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
}

To this, and now works:

#include "DHT22.h"
#include "pins_arduino.h"
#include "Arduino.h"

extern "C" {
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
}