problema libreria onewire

ormai sono giorni che cerco di capire dove sbaglio, ma non riesco più a connettere, ormai sono fuso.
Arduino uno r3, libreria OneWire per lettura temo ds18b20, ho sempre lo stesso errore:sketch_jul16b:3: error: 'OneWire' does not name a type
sketch_jul16b.cpp: In function 'void writeTimeToScratchpad(byte*)':
sketch_jul16b:15: error: 'ow' was not declared in this scope
sketch_jul16b.cpp: In function 'void readTimeFromScratchpad(byte*, byte*)':
sketch_jul16b:26: error: 'ow' was not declared in this scope
aiutatemi.

Hai installato la libreria?
In C:\arduino-1.0.1\libraries\ devi copiare la cartella OneWire che ti allego per comodità

Ciao

OneWire.zip (13.6 KB)

ciao, capisco l'emergenza ma la tua è un'entrata a gamba tesa :fearful:
Allora la prima cosa è gentilmente spostare il Topic nella specifica sezione software (sono attive proprio da oggi), la seconda è quella di dargli un titolo adeguato invece di questo urlo straziante :D, come scritto e riscritto nelle regole e nei consigli iniziali che, preso dalla preoccupazione avrai omesso di leggere :wink:
puoi fare queste cose gentilmente? aiuti te stesso e chi potrebbe aiutarti :wink:
intanto segui il consigli di flz, che magari sposterà anche lui replicandoi nel nuovo topic.
Grazie a tutti per la collaborazione.

Non ti ha risposto nessuno perché hai messo un titolo da non mettere mai! Dovevi scrivere ad esempio: "Problema libreria OneWire"
Ad ogni modo sembra che hai scordato di inserire

#include <OneWire.h>

Oppure non hai copiato i file della libreria (o tutti e due), il messaggio di errore dice che il compilatore non trova le funzioni che chiami..

Per provare la libreria che ti ho allegato prova questo codice in un nuovo sketch:

// Sample DS18B20
#include <OneWire.h>

// Sensor on pin 9
OneWire  ds(9);

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

byte deviceFounds = 0;
void loop() {
  byte data[12];
  byte addr[8];
  float celsius;
  
  // Search for the next device. The addrArray is an 8 byte array. If a device is found, addrArray is filled with the device's address and true is returned. 
  // If no more devices are found, false is returned.
  if (!ds.search(addr)) {
    if(deviceFounds == 0)
    {
      Serial.println("No devices found"); // No more addresses     
      Serial.println("Try check probe"); // No more addresses     
      delay(1000);
    }
    deviceFounds = 0;
    
    // Begin a new search. The next use of search will begin at the first device.
    ds.reset_search();
    delay(250);
    return;
  }else{
   deviceFounds++; 
  }
  
  // Compute a CRC check on an array of data.
  if (OneWire::crc8(addr, 7) != addr[7]) {    
      Serial.println("Address Error");      
      Serial.println("CRC is not valid");
      delay(1000);
      return;
  }    

  // Reset the 1-wire bus. Usually this is needed before communicating with any device.
  ds.reset();
  // Select a device based on its address. After a reset, this is needed to choose which device you will use, 
  // and then all communication will be with that device, until another reset.
  ds.select(addr);  
  // Write a byte, and leave power applied to the 1 wire bus.
  ds.write(0x44);         // start conversion, with parasite power on at the end
    
  // from Datasheet max conversion time is 750ms
  delay(750);
  
  ds.reset();  
  ds.select(addr);    
  ds.write(0xBE);         // Read Scratchpad
    for (byte i = 0; i < 9; i++) {  // we need 9 bytes
    data[i] = ds.read();
  }

  // Check data with CRC
  if (OneWire::crc8(data, 8) != data[8]) {      
      Serial.println("Data Error");      
      Serial.println("CRC is not valid");
      delay(1000);
      return;
  }
  
  // convert the data to actual temperature
  int raw = (data[1] << 8) | data[0];
  byte cfg = (data[4] & 0x60); // default is 12 bit resolution, 750 ms conversion time
  
  celsius = (float)raw / 16.0;
  Serial.println("Temperatura");
  /*
  for( i = 0; i < 8; i++) {   
     Serial.println(addr[i], HEX);
  }  */ 
  Serial.println(celsius);
}

Fammi sapere
Ciao!

come lo sposto?
grazie

uso un mac, ho caricato la libreria in documenti/arduino/libreria/OneWire
dal programma arduino apro la tendina "apri" carico l'esempio però mi da l'errore che ti ho indicato.
ti carico l'esempio#include <OneWire.h>

//init the one wire interface on pin 10
OneWire ds(10);

//write here the address you receive from the other program
byte sensor[8] = {0x28,0xAA,0x33,0xF0,0x02,0x00,0x00,0x79}; //SONDA "b296" DS18B20

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

void writeTimeToScratchpad(byte* address){
//reset the bus
ow.reset();
//select our sensor
ow.select(address);
//CONVERT T function call (44h) which puts the temperature into thescratchpad
ow.write(0x44,1);
//sleep a second for the write to take place
delay(1000);
}

void readTimeFromScratchpad(byte* address, byte* data){
//reset the bus
ow.reset();
//select our sensor
ow.select(address);
//read the scratchpad (BEh)
ow.write(0xBE);
for (byte i=0;i<9;i++){
data = ow.read();

  • }*
    }

float getTemperature(byte* address){

  • int tr;*

  • byte data[12];*

  • writeTimeToScratchpad(address);*

  • readTimeFromScratchpad(address,data);*

  • //put in temp all the 8 bits of LSB (least significant byte)*

  • tr = data[0];*

  • //check for negative temperature*

  • if (data[1] > 0x80){*

  • tr = !tr + 1; //two's complement adjustment*
    _ tr = tr * -1; //flip value negative._

  • }*

  • //COUNT PER Celsius degree (10h)*

  • int cpc = data[7];*

  • //COUNT REMAIN (0Ch)*

  • int cr = data[6];*

  • //drop bit 0*

  • tr = tr >> 1;*

  • //calculate the temperature based on this formula :*

  • //TEMPERATURE = TEMP READ - 0.25 + (COUNT PER Celsius Degree - COUNT REMAIN) / (COUNT PER Celsius Degree)*

  • return tr - (float)0.25 + (cpc - cr)/(float)cpc;*
    }

//fahrenheit to celsius conversion
float f2c(float val){

  • float aux = val - 32;*
    _ return (aux * 5 / 9);_
    }

//celsius to fahrenheit conversion
float c2f(float val){
_ float aux = (val * 9 / 5);_

  • return (aux + 32);*
    }

void loop(void) {

  • float temp;*

  • float tmp2;*

  • tmp2 = getTemperature(sensor);*

  • temp = c2f(tmp2);*

  • Serial.print("Temp = ");*

  • Serial.print(temp);*

  • Serial.print(" F or ");*

  • Serial.print(tmp2);*

  • Serial.println(" C");*
    // Serial.flush();

  • //wait 1 second/s*

  • delay(1000);*
    }
    sketch_jul16b:3: error: 'OneWire' does not name a type
    sketch_jul16b.cpp: In function 'void writeTimeToScratchpad(byte*)':
    sketch_jul16b:15: error: 'ow' was not declared in this scope
    sketch_jul16b.cpp: In function 'void readTimeFromScratchpad(byte*, byte*)':
    sketch_jul16b:26: error: 'ow' was not declared in this scope

Allora con la riga

OneWire  ds(10);

dici che vuoi una variabile chiamata "ds" di tipo OneWire ma poi usi nel codice una variabile chiamata "ow" che quindi non è dichiarata da nessuna parte, sostituisci "ds" con "ow" per risolvere il problema.

Se non risolvi fai una cosa, cancella la cartella OneWire che hai al momento e creane una nuova coi file che ti ho inviato e prova l'esempio che ti ho scritto prima. Questo perché ci sono in giro diverse versioni della libreria OneWire, non tutte compatibili tra loro

Ciao
PS: Aspettiamo info su come spostare la discussione

Ok provo subito.
Grazie

niente da fare, sempre lo stesso errore,
la riga #include<OneWire.h> deve essere di colore arancio, come LiquidCrystal?

Ma hai copiato i file nella cartella giusta?
Devi copiarli dove è installato arduino, dovresti vedere anche altre librerie come LiquidCrystal, Servo, Stepper, etc..
Nel mio pc ad esempio la cartella è in C:\arduino-1.0.1\libraries, dipende dove l'hai scompattata
Se non sai dov'è guarda dov'è il file exe che lanci per aprire il programma Arduino, su Win bisogna andare su proprietà nel collegamento, su Mac non so..

Ciao

Infatti credo che il problema sia proprio quello, non capisco dove devo scompattare la libreria, ho un mac ma non installa arduino, boh

Se metti la cartella della libreria OneWire assieme al tuo programma mi sembra devi scrivere

#include "OneWire.h" invece che

#include <OneWire.h>

Ciao

Grazie flz47655, ho risolto il problema stava nella posizione della libreria, mac ha un altro sistema,
Bastava cliccare sull app arduino e poi mostra contenuto, li ho trovato la cartella libreria,
Grazie grazie grazie
Daniele

Di niente

Ciao!