call:
getTemperature(*sonde_Ballon) ;
I got these errors I don't really understand:
Monitor_Chaudiere.cpp: In function ‘void getTemperature(byte)’:
Monitor_Chaudiere.cpp:721:29: error: invalid conversion from ‘byte’ to ‘const uint8_t*’
Monitor_Chaudiere.cpp:721:29: error: initializing argument 1 of ‘static uint8_t OneWire::crc8(const uint8_t*, uint8_t)’
Monitor_Chaudiere.cpp:721:41: error: invalid types ‘byte[int]’ for array subscript
Monitor_Chaudiere.cpp:722:12: error: return-statement with a value, in function returning 'void'
Monitor_Chaudiere.cpp:732:18: error: invalid conversion from ‘byte’ to ‘const uint8_t*’
Monitor_Chaudiere.cpp:732:18: error: initializing argument 1 of ‘void OneWire::select(const uint8_t*)’
Monitor_Chaudiere.cpp:738:18: error: invalid conversion from ‘byte’ to ‘const uint8_t*’
Monitor_Chaudiere.cpp:738:18: error: initializing argument 1 of ‘void OneWire::select(const uint8_t*)’
Monitor_Chaudiere.cpp:745:4: error: invalid type argument of unary ‘*’
Monitor_Chaudiere.cpp: At global scope:
Monitor_Chaudiere.cpp:841:1: error: expected declaration before ‘}’ token
Is there a problem with the byte variable. I don't find good example on the web.
Thanks for your help
with Arduino.h included and without the * pointer I got these same errors messages: Yes, I use DS18B20.
Monitor_Chaudiere.cpp: In function ‘void getTemperature(byte)’:
Monitor_Chaudiere.cpp:722:29: error: invalid conversion from ‘byte’ to ‘const uint8_t*’
Monitor_Chaudiere.cpp:722:29: error: initializing argument 1 of ‘static uint8_t OneWire::crc8(const uint8_t*, uint8_t)’
Monitor_Chaudiere.cpp:722:41: error: invalid types ‘byte[int]’ for array subscript
Monitor_Chaudiere.cpp:723:12: error: return-statement with a value, in function returning 'void'
Monitor_Chaudiere.cpp:733:18: error: invalid conversion from ‘byte’ to ‘const uint8_t*’
Monitor_Chaudiere.cpp:733:18: error: initializing argument 1 of ‘void OneWire::select(const uint8_t*)’
Monitor_Chaudiere.cpp:739:18: error: invalid conversion from ‘byte’ to ‘const uint8_t*’
Monitor_Chaudiere.cpp:739:18: error: initializing argument 1 of ‘void OneWire::select(const uint8_t*)’
Monitor_Chaudiere.cpp:746:4: error: invalid type argument of unary ‘’
Monitor_Chaudiere.cpp: In function ‘void loop()’:
Monitor_Chaudiere.cpp:814:33: error: invalid conversion from ‘byte’ to ‘byte’
Monitor_Chaudiere.cpp:814:33: error: initializing argument 1 of ‘void getTemperature(byte)’
Monitor_Chaudiere.cpp: At global scope:
Monitor_Chaudiere.cpp:842:1: error: expected declaration before ‘}’ token
the complete subroutine is there:
void getTemperature( byte Sonde) {
// boolean getTemperature(float *temp)
byte data[9], addr[8];
// data : Données lues depuis le scratchpad
// addr : adresse du module 1-Wire détecté
if (OneWire::crc8(Sonde, 7) != Sonde[7]) // Vérifie que l'adresse a été correctement reçue
return false; // Si le message est corrompu on retourne une erreur
/* if (Sonde[0] != DS18B20) // Vérifie qu'il s'agit bien d'un DS18B20
return false; // Si ce n'est pas le cas on retourne une erreur
// Serial.print("0x");
for (int i=0; i<8; i++) {
if (Sonde[i]<0x10) {Serial.print("0");}
Serial.print(Sonde[i],HEX);
Serial.print(" "); } */
ds.reset(); // On reset le bus 1-Wire
ds.select(Sonde); // On sélectionne le DS18B20
ds.write(0x44, 1); // On lance une prise de mesure de température
delay(800); // Et on attend la fin de la mesure
ds.reset(); // On reset le bus 1-Wire
ds.select(Sonde); // On sélectionne le DS18B20
ds.write(0xBE); // On envoie une demande de lecture du scratchpad
for (byte i = 0; i < 9; i++) // On lit le scratchpad
data[i] = ds.read(); // Et on stock les octets reçus
// Calcul de la température en degré Celsius
*temp = ((data[1] << 8) | data[0]) * 0.0625;
// Pas d'erreur
// return true;
}
this routine work perfectly without argument and a ds.select(address); anyone ds18B20 plugged.
That code looks really pretty mostly in italics and the cool smiley makes a change from normal boring looking code too..
Please post it again in code tags as suggested in the stickies at the top of this forum. That will stop it being mangled when it comes across[i]in the code which turns on italics, and will prevent 8) turning into a smiley.
Once we can read the code we may be able to give some help.
here is the example which works, followed bythe example which works:
#include <OneWire.h> // Inclusion de la librairie OneWire
#define DS18B20 0x28 // Adresse 1-Wire du DS18B20
#define BROCHE_ONEWIRE 10 // Broche utilisée pour le bus 1-Wire
OneWire ds(BROCHE_ONEWIRE); // Création de l'objet OneWire ds
byte sonde_Ballon[8] = {0x28 , 0xA5 , 0xDD , 0x5A , 0x03 , 0x00 , 0x00 , 0x3C } ;
// Fonction récupérant la température depuis le DS18B20
// Retourne true si tout va bien, ou false en cas d'erreur
boolean getTemperature(float *temp){
byte data[9], addr[8];
// data : Données lues depuis le scratchpad
// addr : adresse du module 1-Wire détecté
if (!ds.search(sonde_Ballon)) {
// Serial.println("pas trouvee") ;
// if (!ds.search(addr)) { // Recherche un module 1-Wire
ds.reset_search(); // Réinitialise la recherche de module
return false; // Retourne une erreur
}
if (OneWire::crc8(sonde_Ballon, 7) != sonde_Ballon[7]) // Vérifie que l'adresse a été correctement reçue
return false; // Si le message est corrompu on retourne une erreur
if (sonde_Ballon[0] != DS18B20) // Vérifie qu'il s'agit bien d'un DS18B20
return false; // Si ce n'est pas le cas on retourne une erreur
// Serial.print("0x");
for (int i=0; i<8; i++) {
if (sonde_Ballon[i]<0x10) {Serial.print("0");}
Serial.print(sonde_Ballon[i],HEX);
Serial.print(" "); }
ds.reset(); // On reset le bus 1-Wire
ds.select(sonde_Ballon); // On sélectionne le DS18B20
ds.write(0x44, 1); // On lance une prise de mesure de température
delay(800); // Et on attend la fin de la mesure
ds.reset(); // On reset le bus 1-Wire
ds.select(sonde_Ballon); // On sélectionne le DS18B20
ds.write(0xBE); // On envoie une demande de lecture du scratchpad
for (byte i = 0; i < 9; i++) // On lit le scratchpad
data[i] = ds.read(); // Et on stock les octets reçus
// Calcul de la température en degré Celsius
*temp = ((data[1] << 8) | data[0]) * 0.0625;
// Pas d'erreur
return true;
}
// setup()
void setup() {
Serial.begin(9600); // Initialisation du port série
}
// loop()
void loop() {
float temp;
// Lit la température ambiante à ~1Hz
if(getTemperature(&temp)) {
and the exemple which works:
// Affiche la température
Serial.print("Temperature : ");
Serial.print(temp);
Serial.write(176); // caractère °
Serial.write('C');
Serial.println();
}
and my routine, I just want to pass the id of DS18B20 as an argument:
[code]void getTemperature( byte Sonde) {
// boolean getTemperature(float *temp)
byte data[9], addr[8];
// data : Données lues depuis le scratchpad
// addr : adresse du module 1-Wire détecté
if (OneWire::crc8(Sonde, 7) != Sonde[7]) // Vérifie que l'adresse a été correctement reçue
return false; // Si le message est corrompu on retourne une erreur
/* if (Sonde[0] != DS18B20) // Vérifie qu'il s'agit bien d'un DS18B20
return false; // Si ce n'est pas le cas on retourne une erreur
// Serial.print("0x");
for (int i=0; i<8; i++) {
if (Sonde[i]<0x10) {Serial.print("0");}
Serial.print(Sonde[i],HEX);
Serial.print(" "); } */
ds.reset(); // On reset le bus 1-Wire
ds.select(Sonde); // On sélectionne le DS18B20
ds.write(0x44, 1); // On lance une prise de mesure de température
delay(800); // Et on attend la fin de la mesure
ds.reset(); // On reset le bus 1-Wire
ds.select(Sonde); // On sélectionne le DS18B20
ds.write(0xBE); // On envoie une demande de lecture du scratchpad
for (byte i = 0; i < 9; i++) // On lit le scratchpad
data[i] = ds.read(); // Et on stock les octets reçus
// Calcul de la température en degré Celsius
*temp = ((data[1] << 8) | data[0]) * 0.0625;
// Pas d'erreur
// return true;
}
Monitor_Chaudiere.cpp: In function ‘void getTemperature(byte*)’:
Monitor_Chaudiere.cpp:722:12: error: return-statement with a value, in function returning 'void'
Monitor_Chaudiere.cpp:745:4: error: invalid type argument of unary ‘’
Monitor_Chaudiere.cpp: In function ‘void loop()’:
Monitor_Chaudiere.cpp:813:34: error: invalid conversion from ‘byte’ to ‘byte’
Monitor_Chaudiere.cpp:813:34: error: initializing argument 1 of ‘void getTemperature(byte*)’
Monitor_Chaudiere.cpp: At global scope:
Monitor_Chaudiere.cpp:841:1: error: expected declaration before ‘}’ token
That's because you have unrelated errors. The first of them refers to trying to return a boolean from a function you've declared to be void rather than bool.
sorry in the code I attached I mixed the example followed by my routine. In the example there is a return boolean but in my code there is not I comment.
void getTemperature( byte *Sonde) {
byte data[9], addr[8];
if (OneWire::crc8(Sonde, 7) != Sonde[7]) // Vérifie que l'adresse a été correctement reçue
return false; // Si le message est corrompu on retourne une erreur
if (OneWire::crc8(Sonde, 7) != Sonde[7]) // Vérifie que l'adresse a été correctement reçue
return false; // Si le message est corrompu on retourne une erreur
thank you, errors was coming from the 2 return false but also from the end comment on this line "Serial.print(" "); } */"
I use kate as editor is there someone who can explain why the line in error is not the good number. In my case I have to substract -12
The arduino IDE adds your sketch into a template that contains a main function to make it a valid C++ program. That means that there is extra content that you don't see which throws off the line numbers in gcc error messages. The more recent versions of the IDE seem to be better at showing the actual line where the issue is.