OneWire

The OneWire library example sketch compiles without any problem under Arduino 0022. However, it fails to compile under the new Arduino (1.0 rc2).

Does anybody have an idea how to solve this problem.

Does anybody have an idea how to solve this problem.

Be a lot easier if you showed the code and the error messages... The Psychic Hotline is closed on Fridays.

Is it Friday?

This sample sketch:

#include <OneWire.h>

/* DS18S20 Temperature chip i/o */

OneWire  ds(10);  // on pin 10

void setup(void) {
  Serial.begin(9600);
}

void loop(void) {
  byte i;
  byte present = 0;
  byte data[12];
  byte addr[8];
  
  if ( !ds.search(addr)) {
    Serial.print("No more addresses.\n");
    ds.reset_search();
    delay(250);
    return;
  }
  
  Serial.print("R=");
  for( i = 0; i < 8; i++) {
    Serial.print(addr[i], HEX);
    Serial.print(" ");
  }

  if ( OneWire::crc8( addr, 7) != addr[7]) {
      Serial.print("CRC is not valid!\n");
      return;
  }
  
  if ( addr[0] != 0x10) {
      Serial.print("Device is not a DS18S20 family device.\n");
      return;
  }

  // The DallasTemperature library can do all this work for you!

  ds.reset();
  ds.select(addr);
  ds.write(0x44,1);         // start conversion, with parasite power on at the end
  
  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.
  
  present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE);         // Read Scratchpad

  Serial.print("P=");
  Serial.print(present,HEX);
  Serial.print(" ");
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
    Serial.print(data[i], HEX);
    Serial.print(" ");
  }
  Serial.print(" CRC=");
  Serial.print( OneWire::crc8( data, 8), HEX);
  Serial.println();
}

Compiles fine under 0022 IDE.

Under 1.0 rc2 it gives:

/Users/nick/Documents/Arduino/libraries/OneWire/OneWire.cpp:85:24: error: WConstants.h: No such file or directory
/Users/nick/Documents/Arduino/libraries/OneWire/OneWire.cpp: In constructor 'OneWire::OneWire(uint8_t)':
/Users/nick/Documents/Arduino/libraries/OneWire/OneWire.cpp:93: error: 'digitalPinToBitMask' was not declared in this scope
/Users/nick/Documents/Arduino/libraries/OneWire/OneWire.cpp:94: error: 'digitalPinToPort' was not declared in this scope
/Users/nick/Documents/Arduino/libraries/OneWire/OneWire.cpp:94: error: 'portInputRegister' was not declared in this scope
/Users/nick/Documents/Arduino/libraries/OneWire/OneWire.cpp: In member function 'uint8_t OneWire::reset()':
/Users/nick/Documents/Arduino/libraries/OneWire/OneWire.cpp:127: error: 'delayMicroseconds' was not declared in this scope
/Users/nick/Documents/Arduino/libraries/OneWire/OneWire.cpp:134: error: 'delayMicroseconds' was not declared in this scope
/Users/nick/Documents/Arduino/libraries/OneWire/OneWire.cpp: In member function 'void OneWire::write_bit(uint8_t)':
/Users/nick/Documents/Arduino/libraries/OneWire/OneWire.cpp:157: error: 'delayMicroseconds' was not declared in this scope
/Users/nick/Documents/Arduino/libraries/OneWire/OneWire.cpp:165: error: 'delayMicroseconds' was not declared in this scope
/Users/nick/Documents/Arduino/libraries/OneWire/OneWire.cpp: In member function 'uint8_t OneWire::read_bit()':
/Users/nick/Documents/Arduino/libraries/OneWire/OneWire.cpp:185: error: 'delayMicroseconds' was not declared in this scope

Well I’ve been fiddling around for 15 minutes and I can’t get it to compile.

Isn’t “delayMicroseconds” a core function? Why doesn’t that get recognized?

from: http://code.google.com/p/arduino/wiki/Arduino1

there you find the info:

Internals

    Renamed WProgram.h to Arduino.h.

So OneWire includes WProgramm.h which is no longer in Arduino 1.0Rc2, so you have to fix the include in OneWire to "Arduino.h", i think this should work.

Regards Dirk

Looking through onewire.h i cant find the offending reference, but my compilation fails on a reference to Wcontstants.h , which I have changed. I now get lots of conflicts elsewhere on compilation, for example:

In file included from C:\arduino-1.0-beta1\hardware\arduino\cores\arduino/Arduino.h:182,
                 from C:\arduino-1.0-beta1\libraries\OneWire\OneWire.cpp:85:
C:\arduino-1.0-beta1\hardware\arduino\cores\arduino/WString.h:116: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, const char*)' conflicts with
C:\arduino-1.0-beta1\hardware\arduino\cores\arduino/WString.h:115: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, const String&)' here
C:\arduino-1.0-beta1\hardware\arduino\cores\arduino/WString.h:117: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, char)' conflicts with
C:\arduino-1.0-beta1\hardware\arduino\cores\arduino/WString.h:116: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, const char*)' here
C:\arduino-1.0-beta1\hardware\arduino\cores\arduino/WString.h:118: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, unsigned char)' conflicts with
C:\arduino-1.0-beta1\hardware\arduino\cores\arduino/WString.h:117: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, char)' here
C:\arduino-1.0-beta1\hardware\arduino\cores\arduino/WString.h:119: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, int)' conflicts with
C:\arduino-1.0-beta1\hardware\arduino\cores\arduino/WString.h:118: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, unsigned char)' here
C:\arduino-1.0-beta1\hardware\arduino\cores\arduino/WString.h:120: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, unsigned int)' conflicts with
C:\arduino-1.0-beta1\hardware\arduino\cores\arduino/WString.h:119: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, int)' here
C:\arduino-1.0-beta1\hardware\arduino\cores\arduino/WString.h:121: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, long int)' conflicts with
C:\arduino-1.0-beta1\hardware\arduino\cores\arduino/WString.h:120: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, unsigned int)' here
C:\arduino-1.0-beta1\hardware\arduino\cores\arduino/WString.h:122: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, long unsigned int)' conflicts with
C:\arduino-1.0-beta1\hardware\arduino\cores\arduino/WString.h:121: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, long int)' here
In file included from C:\arduino-1.0-beta1\libraries\OneWire\OneWire.cpp:85:
C:\arduino-1.0-beta1\hardware\arduino\cores\arduino/Arduino.h:186: error: declaration of C function 'uint16_t makeWord(byte, byte)' conflicts with
C:\arduino-1.0-beta1\hardware\arduino\cores\arduino/Arduino.h:185: error: previous declaration 'uint16_t makeWord(uint16_t)' here
C:\arduino-1.0-beta1\hardware\arduino\cores\arduino/Arduino.h:196: error: declaration of C function 'long int random(long int)' conflicts with
c:/arduino-1.0-beta1/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:504: error: previous declaration 'long int random()' here
C:\arduino-1.0-beta1\hardware\arduino\cores\arduino/Arduino.h:197: error: declaration of C function 'long int random(long int, long int)' conflicts with
C:\arduino-1.0-beta1\hardware\arduino\cores\arduino/Arduino.h:196: error: previous declaration 'long int random(long int)' here

If the file has just been renamed, you could hack around that by creating your own WProgram.h which just #includes Arduino.h.

I have no idea what other changes there are, though. If the API has changed significantly, it needs somebody who understands the changes and understands that sample sketch to go through and port it to the new API.