Error compiling

Hello All

I am relatively new to Arduino and have completed a lot of the tutorials, since then i have worked on my own project that includes a load cell, relay board, temp, and humidity. i had it all working with out flaw until i wanted to add grams then i got the “Error Compiling” Error. I must of fat fingered something but I am not sure what.

I have 3 Tabs in my project My main program in Tab 1 HX711.cpp in Tab 2 and HX711.h in tab 3 The HX711.cpp and HX711.h i found on a Chinese website to get the load cell to work, and it functioned well.

First Tab DHT11_serial_file_Works

// AUTHOR: Vernon Brown
// Co Author Thanks to Kristian Blåsol for his tutorial
// Kristian’s youtube channel Using a DHT11 and ATtiny to control humidity moisture and temperature - Anything Arduino ep 4 - YouTube
// VERSION: 0.1.00
// PURPOSE: Hive Monitoring Temps and Humidity

#include <dht.h>
#include “HX711.h”
#include <SPI.h>

dht DHT;

#define DHT11_PIN 10
int Fan = 6;
int heater = 7;
int ledgreen = 14;
int ledred = 13;
int Weight = 0;
int Grams;
int Ounces;
int Lbs;
int Cal;

void setup()
{

Serial.begin(115200);
Serial.println(“Beehive Climate Control”);

pinMode(Fan, OUTPUT);
pinMode(heater, OUTPUT);
pinMode(ledgreen, OUTPUT);
pinMode(ledred, OUTPUT);

}

void loop()
{
// READ DATA

int chk = DHT.read11(DHT11_PIN);
Weight = Get_Weight(); //Get Weight
Cal = (Weight - 9102.05);
Ounces = (Cal * 0.038);
Lbs = (Ounces / 16);

// now convert to Fahrenheit
float temperatureF = (DHT.temperature * 9.0 / 5.0) + 32.0;

// now convert humidity
float humidity = (DHT.humidity, 1);

// DISPLAY DATA

Serial.print(temperatureF); Serial.println(" degrees F");
Serial.print(DHT.humidity, 1); Serial.println("%");
Serial.print(Grams); //Serial Display
Serial.print(Ounces); Serial.println(" Ounces");
Serial.print(Lbs); Serial.println(" Pounds");

delay(1000);

//Script below turns on and off the heater and Fan

//if (DHT.humidity>55) {
if (DHT.humidity>40) {
digitalWrite(Fan,HIGH);
} else {
digitalWrite(Fan,LOW);
}

//if (DHT.humidity>55) {
if (DHT.humidity>40) {
digitalWrite(ledgreen,HIGH);
} else {
digitalWrite(ledgreen,LOW);
}

//if (DHT.temperature<18) {
if (DHT.temperature<26) {
digitalWrite(heater,HIGH);
} else {
digitalWrite(heater,LOW);
}

//if (DHT.temperature<18) {
if (DHT.temperature<26) {
digitalWrite(ledred,HIGH);
} else {
digitalWrite(ledred,LOW);
}

}
//
// END OF FILE
//

Second Tab HX711.cpp

#include “hx711.h”

long HX711_Buffer = 0;
long Weight_Maopi = 0,Weight_Shiwu = 0;

//****************************************************
//初始化HX711
//****************************************************
void Init_Hx711()
{
pinMode(HX711_SCK, OUTPUT);
pinMode(HX711_DT, INPUT);
}

//****************************************************
//获取毛皮重量
//****************************************************
void Get_Maopi()
{
HX711_Buffer = HX711_Read();
Weight_Maopi = HX711_Buffer/100;
}

//****************************************************
//称重
//****************************************************
unsigned int Get_Weight()
{
HX711_Buffer = HX711_Read();
HX711_Buffer = HX711_Buffer/100;

Weight_Shiwu = HX711_Buffer;
Weight_Shiwu = Weight_Shiwu - Weight_Maopi; //获取实物的AD采样数值。

Weight_Shiwu = (unsigned int)((float)Weight_Shiwu/7.35+0.05);
//计算实物的实际重量
//因为不同的传感器特性曲线不一样,因此,每一个传感器需要矫正这里的4.30这个除数。
//当发现测试出来的重量偏大时,增加该数值。
//如果测试出来的重量偏小时,减小改数值。
//该数值一般在7.16左右。因传感器不同而定。
//+0.05是为了四舍五入百分位

return Weight_Shiwu;
}

//****************************************************
//读取HX711
//****************************************************
unsigned long HX711_Read(void) //增益128
{
unsigned long count;
unsigned char i;
bool Flag = 0;

digitalWrite(HX711_DT, HIGH);
delayMicroseconds(1);

digitalWrite(HX711_SCK, LOW);
delayMicroseconds(1);

count=0;
while(digitalRead(HX711_DT));
for(i=0;i<24;i++)
{
digitalWrite(HX711_SCK, HIGH);
delayMicroseconds(1);
count=count<<1;
digitalWrite(HX711_SCK, LOW);
delayMicroseconds(1);
if(digitalRead(HX711_DT))
count++;
}
digitalWrite(HX711_SCK, HIGH);
count ^= 0x800000;
delayMicroseconds(1);
digitalWrite(HX711_SCK, LOW);
delayMicroseconds(1);

return(count);
}

Third Tab HX711.h

#ifndef HX711__H
#define HX711__H

#include <Arduino.h>

#define HX711_SCK 2
#define HX711_DT 3

extern void Init_Hx711();
extern unsigned long HX711_Read(void);
extern unsigned int Get_Weight();
extern void Get_Maopi();

#endif

Error

HX711_3Kg/HX711.cpp.o: In function HX711_Read()': /Users/vernonbrown/Dropbox/Arduino/Arduino/libraries/HX711_3Kg/HX711.cpp:50: multiple definition of HX711_Read()’
HX711.cpp.o:HX711.cpp:50: first defined here
HX711_3Kg/HX711.cpp.o: In function Get_Weight()': /Users/vernonbrown/Dropbox/Arduino/Arduino/libraries/HX711_3Kg/HX711.cpp:30: multiple definition of Get_Weight()’
HX711.cpp.o:HX711.cpp:30: first defined here
HX711_3Kg/HX711.cpp.o: In function HX711_Read()': /Users/vernonbrown/Dropbox/Arduino/Arduino/libraries/HX711_3Kg/HX711.cpp:50: multiple definition of HX711_Buffer’
HX711.cpp.o:HX711.cpp:50: first defined here
HX711_3Kg/HX711.cpp.o: In function HX711_Read()': /Users/vernonbrown/Dropbox/Arduino/Arduino/libraries/HX711_3Kg/HX711.cpp:50: multiple definition of Weight_Maopi’
HX711.cpp.o:HX711.cpp:50: first defined here
HX711_3Kg/HX711.cpp.o: In function HX711_Read()': /Users/vernonbrown/Dropbox/Arduino/Arduino/libraries/HX711_3Kg/HX711.cpp:50: multiple definition of Weight_Shiwu’
HX711.cpp.o:HX711.cpp:50: first defined here
HX711_3Kg/HX711.cpp.o: In function Get_Maopi()': /Users/vernonbrown/Dropbox/Arduino/Arduino/libraries/HX711_3Kg/HX711.cpp:21: multiple definition of Get_Maopi()’
HX711.cpp.o:HX711.cpp:21: first defined here
HX711_3Kg/HX711.cpp.o: In function Init_Hx711()': /Users/vernonbrown/Dropbox/Arduino/Arduino/libraries/HX711_3Kg/HX711.cpp:11: multiple definition of Init_Hx711()’
HX711.cpp.o:HX711.cpp:11: first defined here

The HX711.ccp and HX711.h files are a library - create a folder called HX711 in the libraries sub-folder of your sketchbook directory (that's where personal libraries live), and put them their, not inside your sketch folder.

I'm not sure why you're seeing it twice - perhaps you already installed it as a library too?

There’s no problem with having the library files in the same folder as the sketch. It just keeps them from being available for other sketches. I like that sometimes when I’m working on something because it opens the library files on tabs in the IDE when you open the sketch.

The problem here appears to be the fact that there are no include guards on the .h file.

You need something like this:

#ifndef HX711_h           // This part is the very first thing in the file
#define HX711_h

//  All the code in the .h file

#endif  // this line at the very very end.  Last thing in the file

Mark and Delta

Thanks for the advice. It seems that i had several copies of the code. once I deleted all but the original, and setup my libraries, the code would compile again with no errors.

I really appreciate your input. Thanks for getting me pointed in the right direction.

Vern