error Class has no member named .........

Hi guys,
Im trying to collect different existing codes for single sensor boards into one library for multisensor board. this is first time im tryin to create library. its first part yet and I stuck with error message

Arduino: 1.5.8 (Windows 7), Board: "Arduino Uno"
gy80.ino: In function 'void setup()':gy80.ino:10:8: error: 'class gy80' has no member named 'Gyroinit'
Error compiling.

I appreciate anyhelp

this is sketch

#include <gy80.h>
gy80 doh10;

void setup(){
  Serial.begin(9600);
  Serial.println("starting up L3G4200D");
  doh10.Gyroinit(2000); // Configure L3G4200  - 250, 500 or 2000 deg/sec
  delay(1500); //wait for the sensor to be ready 
}

void loop(){
  Serial.print("Gx:");
  Serial.print(doh10.GyroX());
  Serial.print(" Gy:");
  Serial.print(doh10.GyroY());
  Serial.print(" Gz:");
  Serial.println(doh10.GyroZ());
  delay(100); //Just here to slow down the serial to make it more readable
}

H file

#ifndef gy80_h
#define gy80_h
#include "Arduino.h"

#define Gyro_who_amI 0x0F
#define CTRL_REG1 0x20
#define CTRL_REG2 0x21
#define CTRL_REG3 0x22
#define CTRL_REG4 0x23
#define CTRL_REG5 0x24
#define L3G4200D_Addr 105 //I2C address of the L3G4200D
#define ADXL345_Addr  83 // I2C address of ADXL345
#define HMC5883L_Addr  30 // I2C address HMC5883
#define BMP085_Addr 119 //  I2C address of BMP085

class gy80 {
public:
  gy80();
  ~gy80();
  void GyroInit(int scale);
  int GyroX(void);
  int GyroY(void);
  int GyroZ(void);
private:
  int readRegister(int devAddr, uint8_t addr);
  void writeRegister(int deveAddr, uint8_t addr, uint8_t val);
};
#endif

and cpp

#include "gy80.h"
#include "Wire.h"

void gy80::GyroInit(int scale){
  wire.begin();

  writeRegister(L3G4200D_Addr, CTRL_REG1, 0b00001111); // (datarate1,datarate0,Bandwidth1,Bandwidth0,powerdown,Zen,Yen,Xen) power up and enable x, y, z
  writeRegister(L3G4200D_Addr, CTRL_REG2, 0b00000000);  // High pass filter default mode
  writeRegister(L3G4200D_Addr, CTRL_REG3, 0b00001000);  // l1_int:dis, l1_boot:dis, HL_active:dis; PushPull_Opendrain:dis, DateReady_on_int2:enable, FIFOwatermark:dis, FIFOoverrun:dis, FIFOemty:dis
    switch (scale) {
    case 250:   writeRegister(L3G4200D_Addr, CTRL_REG4, 0b00000000); // (BDU,BLE,FS!1_FS0,- ,ST1-ST0,,SIM0) BlockDataUpdate:0 endiaDataSel:0
    case 500:   writeRegister(L3G4200D_Addr, CTRL_REG4, 0b00010000); // FS1-FS0 00:250 01:500 10:2000 11:2000
    case 2000:  writeRegister(L3G4200D_Addr, CTRL_REG4, 0b00110000); // SeriaInterfaceModeSelect:0 (4wire)
    }
  writeRegister(L3G4200D_Addr, CTRL_REG5, 0b00000000);  // noot:normal, FIFO:disable, HighpasFilter:disable, INT1select:0, OUTselect:0
}

void gy80::writeRegister(int deviceAddr, uint8_t addr, uint8_t val) {
  Wire.beginTransmission(deviceAddr); // Begin I2C trans
  Wire.write(addr);       // send address
  Wire.write(val);         // send value
  Wire.endTransmission();     // end trans
}

int gy80::readRegister(int deviceAddr, uint8_t addr){
  int v;
  Wire.beginTransmission(deviceAddr);
  Wire.write(addr); // register to read
  Wire.endTransmission();
  Wire.requestFrom(deviceAddr, 1); // read a byte
  while(!Wire.available()) {
    }
  v = Wire.read();
  return v;
}

int gy80::GyroX (void) {
uint8_t outXH = readRegister(L3G4200D_Addr, 0x29); // register OUT_X_H hex29
uint8_t outXL = readRegister(L3G4200D_Addr, 0x28); // register OUT_X_L hex28
return ((outXH << 8) | outXL);
}

int gy80::GyroY (void) {
uint8_t outYH = readRegister(L3G4200D_Addr, 0x2B); // register OUT_Y_H hex2B
uint8_t outYL = readRegister(L3G4200D_Addr, 0x2A); // register OUT_X_L hex2A
return ((outYH << 8) | outYL);
}

int gy80::GyroZ (void) {
uint8_t outZH = readRegister(L3G4200D_Addr, 0x2D); // register OUT_Z_H hex2D
uint8_t outZL = readRegister(L3G4200D_Addr, 0x2C); // register OUT_Z_L hex2C
return ((outZH << 8) | outZL);
}

Gyroinit vs GyroInit? :slight_smile:

Gyroinit != GyroInit

changed to GyroInit() didnt changed anything still same error.

gy80.ino:10:8: error: 'class gy80' has no member named 'GyroInit'

In your sketch, try changing the include to be:

#include "gy80.h"

Also correct "wire" in the library file to be:

Wire.begin();

EDIT

You also need to add constructor and destructor definitions in the .cpp file.

And there ought to be #include <Wire.h> statements in the sketch and .h files.

UNfortunately nothing changed, changed my libraries as #include "gy80.h" and main libraries with #include < ... > I corrected cpl typos and added deconstructor to cpp file. still getin same error.

Arduino: 1.5.8 (Windows 7), Board: "Arduino Uno"

gy80.ino: In function 'void setup()':
gy80.ino:10:9: error: 'class gy80' has no member named 'GyroInit'
Error compiling.

include "gy80.h"



gy80 dof10;

void setup(){
  Serial.begin(9600);
  Serial.println("starting up L3G4200D");
  dof10.GyroInit(2000); // Configure L3G4200  - 250, 500 or 2000 deg/sec
  delay(1500); //wait for the sensor to be ready 
}

void loop(){
  
  Serial.print("Gx:");
  Serial.print(dof10.GyroX());
  Serial.print(" Gy:");
  Serial.print(dof10.GyroY());
  Serial.print(" Gz:");
  Serial.println(dof10.GyroZ());
  delay(100); //Just here to slow down the serial to make it more readable
}
#ifndef gy80_h
#define gy80_h
#include <Arduino.h>
#include <Wire.h>

#define Gyro_who_amI 0x0F
#define CTRL_REG1 0x20
#define CTRL_REG2 0x21
#define CTRL_REG3 0x22
#define CTRL_REG4 0x23
#define CTRL_REG5 0x24
#define L3G4200D_Addr 105 //I2C address of the L3G4200D
#define ADXL345_Addr  83 // I2C address of ADXL345
#define HMC5883L_Addr  30 // I2C address HMC5883
#define BMP085_Addr 119 //  I2C address of BMP085

class gy80 {
public:
  gy80();
  ~gy80();
  void GyroInit(int scale);
  int GyroX(void);
  int GyroY(void);
  int GyroZ(void);
private:
  int readRegister(int devAddr, uint8_t addr);
  void writeRegister(int deveAddr, uint8_t addr, uint8_t val);
};
#endif
#include "gy80.h"
#include <Wire.h>

gy80::gy80();
gy80::~gy80();

void gy80::GyroInit(int scale){
  Wire.begin();

  writeRegister(L3G4200D_Addr, CTRL_REG1, 0b00001111); // (datarate1,datarate0,Bandwidth1,Bandwidth0,powerdown,Zen,Yen,Xen) power up and enable x, y, z
  writeRegister(L3G4200D_Addr, CTRL_REG2, 0b00000000);  // High pass filter default mode
  writeRegister(L3G4200D_Addr, CTRL_REG3, 0b00001000);  // l1_int:dis, l1_boot:dis, HL_active:dis; PushPull_Opendrain:dis, DateReady_on_int2:enable, FIFOwatermark:dis, FIFOoverrun:dis, FIFOemty:dis
    switch (scale) {
    case 250:   writeRegister(L3G4200D_Addr, CTRL_REG4, 0b00000000); // (BDU,BLE,FS!1_FS0,- ,ST1-ST0,,SIM0) BlockDataUpdate:0 endiaDataSel:0
    case 500:   writeRegister(L3G4200D_Addr, CTRL_REG4, 0b00010000); // FS1-FS0 00:250 01:500 10:2000 11:2000
    case 2000:  writeRegister(L3G4200D_Addr, CTRL_REG4, 0b00110000); // SeriaInterfaceModeSelect:0 (4wire)
    }
  writeRegister(L3G4200D_Addr, CTRL_REG5, 0b00000000);  // noot:normal, FIFO:disable, HighpasFilter:disable, INT1select:0, OUTselect:0
}



void gy80::writeRegister(int deviceAddr, uint8_t addr, uint8_t val) {
  Wire.beginTransmission(deviceAddr); // Begin I2C trans
  Wire.write(addr);       // send address
  Wire.write(val);         // send value
  Wire.endTransmission();     // end trans
}

int gy80::readRegister(int deviceAddr, uint8_t addr){
  int v;
  Wire.beginTransmission(deviceAddr);
  Wire.write(addr); // register to read
  Wire.endTransmission();
  Wire.requestFrom(deviceAddr, 1); // read a byte

  while(!Wire.available()) {
    // waiting
  }
  v = Wire.read();
  return v;
}

int gy80::GyroX (void) {
uint8_t outXH = readRegister(L3G4200D_Addr, 0x29); // register OUT_X_H hex29
uint8_t outXL = readRegister(L3G4200D_Addr, 0x28); // register OUT_X_L hex28
return ((outXH << 8) | outXL);

}

int gy80::GyroY (void) {
uint8_t outYH = readRegister(L3G4200D_Addr, 0x2B); // register OUT_Y_H hex2B
uint8_t outYL = readRegister(L3G4200D_Addr, 0x2A); // register OUT_X_L hex2A
return ((outYH << 8) | outYL);

}

int gy80::GyroZ (void) {
uint8_t outZH = readRegister(L3G4200D_Addr, 0x2D); // register OUT_Z_H hex2D
uint8_t outZL = readRegister(L3G4200D_Addr, 0x2C); // register OUT_Z_L hex2C
return ((outZH << 8) | outZL);

}

Can't see constructor gy80::gy80() in .cpp file.

Destructor should be gy80::~gy80().

void gy80::~GyroInit(int Scale) { }

What is that?

changed , and const/dest added as hackscribbe told. Nothing changed. Still getin same error. I dont know much about C++ , I just tried to create library as tutorial showed on morse code example.

anybody actually can verify same code on your computer? I m not even know if code has problem or im doin something else wrong.

newestbie:
changed , and const/dest added as hackscribbe told. Nothing changed. Still getin same error. I dont know much about C++ , I just tried to create library as tutorial showed on morse code example.

anybody actually can verify same code on your computer? I m not even know if code has problem or im doin something else wrong.

I don't have the code to try. Post it all, the current version now that you've added those things.

here last code. As I said im not good at this thing, IM just tryin to combine some example codes i found into single library. I appreciate if u can try

gy80.ino

#include "gy80.h"

gy80 dof10;

void setup(){
  Serial.begin(9600);
  Serial.println("starting up L3G4200D");
  dof10.GyroInit(2000); // Configure L3G4200  - 250, 500 or 2000 deg/sec
  delay(1500); //wait for the sensor to be ready 
}

void loop(){
  
  Serial.print("Gx:");
  Serial.print(dof10.GyroX());
  Serial.print(" Gy:");
  Serial.print(dof10.GyroY());
  Serial.print(" Gz:");
  Serial.println(dof10.GyroZ());
  delay(100); //Just here to slow down the serial to make it more readable
}

gy80.h

#ifndef gy80_h
#define gy80_h
#include <Arduino.h>
#include <Wire.h>

#define Gyro_who_amI 0x0F
#define CTRL_REG1 0x20
#define CTRL_REG2 0x21
#define CTRL_REG3 0x22
#define CTRL_REG4 0x23
#define CTRL_REG5 0x24
#define L3G4200D_Addr 105 //I2C address of the L3G4200D
#define ADXL345_Addr  83 // I2C address of ADXL345
#define HMC5883L_Addr  30 // I2C address HMC5883
#define BMP085_Addr 119 //  I2C address of BMP085

class gy80 {
public:
  gy80();
  ~gy80();
  void GyroInit(int scale);
  int GyroX(void);
  int GyroY(void);
  int GyroZ(void);
private:
  int readRegister(int devAddr, uint8_t addr);
  void writeRegister(int deveAddr, uint8_t addr, uint8_t val);
};
#endif

gy80.cpp

#include "gy80.h"
#include <Wire.h>

gy80::gy80();
gy80::~gy80();



void gy80::GyroInit(int scale){
  Wire.begin();

  writeRegister(L3G4200D_Addr, CTRL_REG1, 0b00001111); // (datarate1,datarate0,Bandwidth1,Bandwidth0,powerdown,Zen,Yen,Xen) power up and enable x, y, z
  writeRegister(L3G4200D_Addr, CTRL_REG2, 0b00000000);  // High pass filter default mode
  writeRegister(L3G4200D_Addr, CTRL_REG3, 0b00001000);  // l1_int:dis, l1_boot:dis, HL_active:dis; PushPull_Opendrain:dis, DateReady_on_int2:enable, FIFOwatermark:dis, FIFOoverrun:dis, FIFOemty:dis
    switch (scale) {
    case 250:   writeRegister(L3G4200D_Addr, CTRL_REG4, 0b00000000); // (BDU,BLE,FS!1_FS0,- ,ST1-ST0,,SIM0) BlockDataUpdate:0 endiaDataSel:0
    case 500:   writeRegister(L3G4200D_Addr, CTRL_REG4, 0b00010000); // FS1-FS0 00:250 01:500 10:2000 11:2000
    case 2000:  writeRegister(L3G4200D_Addr, CTRL_REG4, 0b00110000); // SeriaInterfaceModeSelect:0 (4wire)
    }
  writeRegister(L3G4200D_Addr, CTRL_REG5, 0b00000000);  // noot:normal, FIFO:disable, HighpasFilter:disable, INT1select:0, OUTselect:0
}



void gy80::writeRegister(int deviceAddr, uint8_t addr, uint8_t val) {
  Wire.beginTransmission(deviceAddr); // Begin I2C trans
  Wire.write(addr);       // send address
  Wire.write(val);         // send value
  Wire.endTransmission();     // end trans
}

int gy80::readRegister(int deviceAddr, uint8_t addr){
  int v;
  Wire.beginTransmission(deviceAddr);
  Wire.write(addr); // register to read
  Wire.endTransmission();
  Wire.requestFrom(deviceAddr, 1); // read a byte

  while(!Wire.available()) {
    // waiting
  }
  v = Wire.read();
  return v;
}

int gy80::GyroX (void) {
uint8_t outXH = readRegister(L3G4200D_Addr, 0x29); // register OUT_X_H hex29
uint8_t outXL = readRegister(L3G4200D_Addr, 0x28); // register OUT_X_L hex28
return ((outXH << 8) | outXL);

}

int gy80::GyroY (void) {
uint8_t outYH = readRegister(L3G4200D_Addr, 0x2B); // register OUT_Y_H hex2B
uint8_t outYL = readRegister(L3G4200D_Addr, 0x2A); // register OUT_X_L hex2A
return ((outYH << 8) | outYL);

}

int gy80::GyroZ (void) {
uint8_t outZH = readRegister(L3G4200D_Addr, 0x2D); // register OUT_Z_H hex2D
uint8_t outZL = readRegister(L3G4200D_Addr, 0x2C); // register OUT_Z_L hex2C
return ((outZH << 8) | outZL);

}

In the .cpp file

gy80::gy80();
gy80::~gy80();

Should be:

gy80::gy80(){}
gy80::~gy80(){}

When I do that and add an include for Wire in the .ino file it compiles fine for me.

Delta_G:
In the .cpp file

gy80::gy80();

gy80::~gy80();




Should be:



gy80::gy80(){}
gy80::~gy80(){}




When I do that and add an include for Wire in the .ino file it compiles fine for me.

Question - if the incorrect syntax constructor / destructor is removed it should also compile.
Can you verify that at your convenience, please?
Thanks

vaclav and DeltaG , Thank you so much guys, Problem solved. This is not code related issue.

I made changes you suggested but still received same error. then installed arduino IDE 1.0.6 on other computer and it works fine. mine runing beta 1.5.8 , even I reinstalled , got still got problem, also might messed up with lib paths may be the problem.

constructor/ deconstructer is not issue as long as you add them on both .h and .cpp file, or not to add at all.

it really requires to include wire.h in main sketch and I dont understand why. it already included in library files and nothing in ino file directly uses wire.h , do we need to add all libraries used in h and cpp files in ino too?

it really requires to include wire.h in main sketch and I dont understand why.

It is a characteristic of the Arduino IDE. More info here: http://arduino.land/FAQ/content/1/3/en/what-does-the-ide-change-in-my-sketch.html