├── README.md ├── Makefile ├── src ├── gpio.h ├── config.h ├── gpio.cpp ├── HX711_ADC.h └── HX711_ADC.cpp ├── HX711_basic_example └── HX711_basic_example.cpp └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # HX711 2 | Library that allows to drive a HX711 load cess amplifier with a Raspberry Pi 3 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: HX711 2 | 3 | HX711: main.cpp 4 | g++ -std=c++17 main.cpp HX711_ADC.cpp gpio.cpp -o HX711 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/gpio.h: -------------------------------------------------------------------------------- 1 | #ifndef GPIO_HPP 2 | #define GPIO_HPP 3 | 4 | #define LOW 0 5 | #define HIGH 1 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | enum Dir 12 | { 13 | OUTPUT, 14 | INPUT 15 | }; 16 | 17 | class Hx711Gpio 18 | { 19 | public: 20 | Hx711Gpio(std::string pin); 21 | 22 | int Enable(); 23 | int Disable(); 24 | 25 | int Mode(Dir dir); 26 | int Read(); 27 | void Write(uint8_t val); 28 | 29 | private: 30 | std::string m_pin; 31 | std::fstream m_io; 32 | 33 | std::string IOFile(); 34 | }; 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------------------- 3 | HX711_ADC 4 | Arduino library for HX711 24-Bit Analog-to-Digital Converter for Weight Scales 5 | Olav Kallhovd sept2017 6 | ------------------------------------------------------------------------------------- 7 | */ 8 | 9 | /* 10 | HX711_ADC configuration 11 | 12 | Allowed values for "SAMPLES" is 1, 2, 4, 8, 16, 32, 64 or 128. 13 | Higher value = improved filtering/smoothing of returned value, but longer setteling time and increased memory usage 14 | Lower value = visa versa 15 | 16 | The settling time can be calculated as follows: 17 | Settling time = SAMPLES + IGN_HIGH_SAMPLE + IGN_LOW_SAMPLE / SPS 18 | 19 | Example on calculating settling time using the values SAMPLES = 16, IGN_HIGH_SAMPLE = 1, IGN_LOW_SAMPLE = 1, and HX711 sample rate set to 10SPS: 20 | (16+1+1)/10 = 1.8 seconds settling time. 21 | 22 | Note that you can also overide (reducing) the number of samples in use at any time with the function: setSamplesInUse(samples). 23 | 24 | */ 25 | 26 | #ifndef HX711_ADC_config_h 27 | #define HX711_ADC_config_h 28 | 29 | //number of samples in moving average dataset, value must be 1, 2, 4, 8, 16, 32, 64 or 128. 30 | #define SAMPLES 16 //default value: 16 31 | 32 | //adds extra sample(s) to the dataset and ignore peak high/low sample, value must be 0 or 1. 33 | #define IGN_HIGH_SAMPLE 1 //default value: 1 34 | #define IGN_LOW_SAMPLE 1 //default value: 1 35 | 36 | //microsecond delay after writing sck pin high or low. This delay could be required for faster mcu's. 37 | //So far the only mcu reported to need this delay is the ESP32 (issue #35), both the Arduino Due and ESP8266 seems to run fine without it. 38 | //Change the value to '1' to enable the delay. 39 | #define SCK_DELAY 0 //default value: 0 40 | 41 | //if you have some other time consuming (>60μs) interrupt routines that trigger while the sck pin is high, this could unintentionally set the HX711 into "power down" mode 42 | //if required you can change the value to '1' to disable interrupts when writing to the sck pin. 43 | #define SCK_DISABLE_INTERRUPTS 0 //default value: 0 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/gpio.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "gpio.h" 4 | 5 | using namespace std; 6 | //constructor 7 | Hx711Gpio::Hx711Gpio(string pin) 8 | : m_pin(pin), 9 | m_io(IOFile().c_str()) 10 | { 11 | } 12 | 13 | std::string Hx711Gpio::IOFile() 14 | { 15 | Enable(); 16 | 17 | return std::string("/sys/class/gpio/gpio" + m_pin + "/value"); 18 | } 19 | 20 | int Hx711Gpio::Enable() 21 | { 22 | string path = "/sys/class/gpio/export"; 23 | ofstream file(path.c_str()); 24 | if (!file) 25 | { 26 | cout << "Failed to export GPIO" << m_pin << endl; 27 | return -1; 28 | } 29 | 30 | file << m_pin; 31 | 32 | return 0; 33 | } 34 | 35 | int Hx711Gpio::Disable() 36 | { 37 | string path = "/sys/class/gpio/unexport"; 38 | ofstream file(path.c_str()); 39 | if (!file) 40 | { 41 | cout << "Failed to unexport GPIO" << m_pin << endl; 42 | return -1; 43 | } 44 | 45 | file << m_pin; 46 | 47 | return 0; 48 | } 49 | 50 | int Hx711Gpio::Mode(Dir dir) 51 | { 52 | string dPath = "/sys/class/gpio/gpio" + m_pin + "/direction"; 53 | 54 | ofstream file(dPath.c_str()); 55 | if (!file) 56 | { 57 | cout << "Failed to set direction on GPIO" << m_pin << endl; 58 | return -1; 59 | } 60 | 61 | if (dir == OUTPUT) 62 | { 63 | cout << "Direction OUT for GPIO" << m_pin << endl; 64 | file << "out"; 65 | 66 | if (!m_io.is_open()) 67 | { 68 | cout << "Failed to open for write to GPIO" << m_pin << endl; 69 | } 70 | } 71 | else 72 | { 73 | cout << "Direction IN for GPIO" << m_pin << endl; 74 | file << "in"; 75 | 76 | if (!m_io.is_open()) 77 | { 78 | cout << "Failed to open for read from GPIO" << m_pin << endl; 79 | } 80 | } 81 | 82 | file.close(); 83 | 84 | return 0; 85 | } 86 | 87 | int Hx711Gpio::Read() 88 | { 89 | string val; 90 | int ret = 0; 91 | m_io.seekg(0); 92 | m_io >> val; 93 | 94 | if (val != "0") 95 | { 96 | ret = 1; 97 | } 98 | else 99 | { 100 | ret = 0; 101 | } 102 | 103 | return ret; 104 | } 105 | 106 | void Hx711Gpio::Write(uint8_t val) 107 | { 108 | m_io.seekp(0); 109 | if (val == 0) 110 | { 111 | m_io << "0" << flush; 112 | } 113 | else 114 | { 115 | m_io << "1" << flush; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /HX711_basic_example/HX711_basic_example.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------------- 2 | // HX711_ADC.h 3 | // Arduino master library for HX711 24-Bit Analog-to-Digital Converter for Weigh Scales 4 | // Olav Kallhovd sept2017 5 | // Tested with : HX711 asian module on channel A and YZC-133 3kg load cell 6 | // Tested with MCU : Arduino Nano 7 | //------------------------------------------------------------------------------------- 8 | // This is an example sketch on how to use this library for two ore more HX711 modules 9 | // Settling time (number of samples) and data filtering can be adjusted in the config.h file 10 | 11 | #include "HX711_ADC.h" 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | //pins: 18 | const int HX711_dout = 19; //mcu > HX711 no 1 dout pin 24 19 | const int HX711_sck = 20; //mcu > HX711 no 1 sck pin 26 20 | unsigned long t = 0; 21 | 22 | //HX711 constructor (dout pin, sck pin) 23 | HX711_ADC LoadCell(HX711_dout, HX711_sck); //HX711 4 24 | 25 | int main() { 26 | 27 | usleep(10E3); 28 | 29 | printf("Starting...\n"); 30 | 31 | float calibrationValue = 34.00; // uncomment this if you want to set this value in the sketch 32 | unsigned long stabilizingtime = 2000; // tare preciscion can be improved by adding a few seconds of stabilizing time 33 | bool _tare = true; //set this to false if you don't want tare to be performed in the next step 34 | uint8_t loadcell_rdy = 0; 35 | 36 | LoadCell.begin(); 37 | while (!loadcell_rdy) { //run startup, stabilization and tare, both modules simultaniously 38 | if (!loadcell_rdy) loadcell_rdy = LoadCell.startMultiple(stabilizingtime, _tare); 39 | } 40 | 41 | LoadCell.setCalFactor(calibrationValue); // user set calibration value (float) 42 | printf("Startup is complete\n"); 43 | 44 | 45 | while(1) { 46 | 47 | static bool newDataReady = 0; 48 | const int serialPrintInterval = 0; //increase value to slow down serial print activity 49 | 50 | // check for new data/start next conversion: 51 | if (LoadCell.update()) { newDataReady = true; } 52 | 53 | //get smoothed value from data set 54 | if ((newDataReady)) { 55 | if (LoadCell.millis() > t + serialPrintInterval) { 56 | float a = LoadCell.getData(); 57 | a = a / 10; 58 | printf("Weight:%.2f\n",a); 59 | newDataReady = 0; 60 | t = LoadCell.millis(); 61 | } 62 | } 63 | //check if last tare operation is complete 64 | if (LoadCell.getTareStatus() == true) { 65 | printf("Tare load cell complete.\n"); 66 | } 67 | } 68 | return 0; 69 | } 70 | 71 | -------------------------------------------------------------------------------- /src/HX711_ADC.h: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------------------- 3 | HX711_ADC 4 | Arduino library for HX711 24-Bit Analog-to-Digital Converter for Weight Scales 5 | Olav Kallhovd sept2017 6 | ------------------------------------------------------------------------------------- 7 | */ 8 | 9 | #ifndef HX711_ADC_h 10 | #define HX711_ADC_h 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include "config.h" 17 | #include "gpio.h" 18 | 19 | /* 20 | Note: HX711_ADC configuration values has been moved to file config.h 21 | */ 22 | 23 | #define DATA_SET SAMPLES + IGN_HIGH_SAMPLE + IGN_LOW_SAMPLE // total samples in memory 24 | 25 | #if (SAMPLES != 1) & (SAMPLES != 2) & (SAMPLES != 4) & (SAMPLES != 8) & (SAMPLES != 16) & (SAMPLES != 32) & (SAMPLES != 64) & (SAMPLES != 128) 26 | #error "number of SAMPLES not valid!" 27 | #endif 28 | 29 | #if (SAMPLES == 1) & ((IGN_HIGH_SAMPLE != 0) | (IGN_LOW_SAMPLE != 0)) 30 | #error "number of SAMPLES not valid!" 31 | #endif 32 | 33 | #if (SAMPLES == 1) 34 | #define DIVB 0 //2^0 = 1; 35 | #elif (SAMPLES == 2) 36 | #define DIVB 1 37 | #elif (SAMPLES == 4) 38 | #define DIVB 2 39 | #elif (SAMPLES == 8) 40 | #define DIVB 3 41 | #elif (SAMPLES == 16) 42 | #define DIVB 4 43 | #elif (SAMPLES == 32) 44 | #define DIVB 5 45 | #elif (SAMPLES == 64) 46 | #define DIVB 6 47 | #elif (SAMPLES == 128) 48 | #define DIVB 7 49 | #endif 50 | 51 | #define SIGNAL_TIMEOUT 100 52 | 53 | class HX711_ADC 54 | { 55 | 56 | public: 57 | HX711_ADC(uint8_t dout, uint8_t sck); //constructor 58 | ~HX711_ADC(); //constructor 59 | 60 | void setGain(uint8_t gain = 128); //value must be 32, 64 or 128* 61 | void begin(); //set pinMode, HX711 gain and power up the HX711 62 | void begin(uint8_t gain); //set pinMode, HX711 selected gain and power up the HX711 63 | void start(unsigned long t); //start HX711 and do tare 64 | void start(unsigned long t, bool dotare); //start HX711, do tare if selected 65 | int startMultiple(unsigned long t); //start and do tare, multiple HX711 simultaniously 66 | int startMultiple(unsigned long t, bool dotare); //start and do tare if selected, multiple HX711 simultaniously 67 | void tare(); //zero the scale, wait for tare to finnish (blocking) 68 | void tareNoDelay(); //zero the scale, initiate the tare operation to run in the background (non-blocking) 69 | bool getTareStatus(); //returns 'true' if tareNoDelay() operation is complete 70 | void setCalFactor(float cal); //set new calibration factor, raw data is divided by this value to convert to readable data 71 | float getCalFactor(); //returns the current calibration factor 72 | float getData(); //returns data from the moving average dataset 73 | 74 | int getReadIndex(); //for testing and debugging 75 | float getConversionTime(); //for testing and debugging 76 | float getSPS(); //for testing and debugging 77 | bool getTareTimeoutFlag(); //for testing and debugging 78 | void disableTareTimeout(); //for testing and debugging 79 | long getSettlingTime(); //for testing and debugging 80 | void powerDown(); //power down the HX711 81 | void powerUp(); //power up the HX711 82 | long getTareOffset(); //get the tare offset (raw data value output without the scale "calFactor") 83 | void setTareOffset(long newoffset); //set new tare offset (raw data value input without the scale "calFactor") 84 | uint8_t update(); //if conversion is ready; read out 24 bit data and add to dataset 85 | bool dataWaitingAsync(); //checks if data is available to read (no conversion yet) 86 | bool updateAsync(); //read available data and add to dataset 87 | void setSamplesInUse(int samples); //overide number of samples in use 88 | int getSamplesInUse(); //returns current number of samples in use 89 | void resetSamplesIndex(); //resets index for dataset 90 | bool refreshDataSet(); //Fill the whole dataset up with new conversions, i.e. after a reset/restart (this function is blocking once started) 91 | bool getDataSetStatus(); //returns 'true' when the whole dataset has been filled up with conversions, i.e. after a reset/restart 92 | float getNewCalibration(float known_mass); //returns and sets a new calibration value (calFactor) based on a known mass input 93 | bool getSignalTimeoutFlag(); //returns 'true' if it takes longer time then 'SIGNAL_TIMEOUT' for the dout pin to go low after a new conversion is started 94 | void setReverseOutput(); //reverse the output value 95 | unsigned long millis(); 96 | unsigned long micros(); 97 | protected: 98 | void conversion24bit(); //if conversion is ready: returns 24 bit data and starts the next conversion 99 | long smoothedData(); //returns the smoothed data value calculated from the dataset 100 | Hx711Gpio sckPin; //HX711 Power Down and pd_sck pin 101 | Hx711Gpio doutPin; //HX711 Serial Data Output Pin 102 | uint8_t GAIN; //HX711 GAIN 103 | float calFactor = 1.0; //calibration factor as given in function setCalFactor(float cal) 104 | float calFactorRecip = 1.0; //reciprocal calibration factor (1/calFactor), the HX711 raw data is multiplied by this value 105 | volatile long dataSampleSet[DATA_SET + 1]; // dataset, make voltile if interrupt is used 106 | std::chrono::steady_clock::time_point refTime; 107 | int tareOffset = 0; 108 | int readIndex = 0; 109 | unsigned long conversionStartTime = 0; 110 | unsigned long conversionTime = 0; 111 | uint8_t isFirst = 1; 112 | uint8_t tareTimes = 0; 113 | uint8_t divBit = DIVB; 114 | const uint8_t divBitCompiled = DIVB; 115 | bool doTare = 0; 116 | bool startStatus = 0; 117 | unsigned long startMultipleTimeStamp = 0; 118 | unsigned long startMultipleWaitTime = 0; 119 | uint8_t convRslt = 0; 120 | bool tareStatus = 0; 121 | unsigned int tareTimeOut = (SAMPLES + IGN_HIGH_SAMPLE + IGN_HIGH_SAMPLE) * 150; // tare timeout time in ms, no of samples * 150ms (10SPS + 50% margin) 122 | bool tareTimeoutFlag = 0; 123 | bool tareTimeoutDisable = 0; 124 | int samplesInUse = SAMPLES; 125 | long lastSmoothedData = 0; 126 | bool dataOutOfRange = 0; 127 | unsigned long lastDoutLowTime = 0; 128 | bool signalTimeoutFlag = 0; 129 | bool reverseVal = 0; 130 | bool dataWaiting = 0; 131 | }; 132 | 133 | #endif 134 | 135 | -------------------------------------------------------------------------------- /src/HX711_ADC.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------------------- 3 | HX711_ADC 4 | Arduino library for HX711 24-Bit Analog-to-Digital Converter for Weight Scales 5 | Yasir Shahzad sep2022 6 | ------------------------------------------------------------------------------------- 7 | */ 8 | 9 | #include "HX711_ADC.h" 10 | #include "gpio.h" 11 | 12 | HX711_ADC::HX711_ADC(uint8_t dout, uint8_t sck) //constructor 13 | : doutPin(std::to_string(dout)), sckPin(std::to_string(sck)) 14 | { 15 | sckPin.Enable(); 16 | doutPin.Enable(); 17 | 18 | refTime = std::chrono::steady_clock::now(); 19 | } 20 | 21 | void HX711_ADC::setGain(uint8_t gain) //value should be 32, 64 or 128* 22 | { 23 | if(gain < 64) GAIN = 2; //32, channel B 24 | else if(gain < 128) GAIN = 3; //64, channel A 25 | else GAIN = 1; //128, channel A 26 | } 27 | 28 | //set pinMode, HX711 gain and power up the HX711 29 | void HX711_ADC::begin() 30 | { 31 | sckPin.Mode(OUTPUT); // Set signalPin as output 32 | doutPin.Mode(INPUT); // Set data as input 33 | setGain(128); 34 | powerUp(); 35 | } 36 | 37 | //set pinMode, HX711 selected gain and power up the HX711 38 | void HX711_ADC::begin(uint8_t gain) 39 | { 40 | sckPin.Mode(OUTPUT); // Set signalPin as output 41 | doutPin.Mode(INPUT); // Set data as input 42 | setGain(gain); 43 | powerUp(); 44 | } 45 | 46 | /* start(t): 47 | * will do conversions continuously for 't' +400 milliseconds (400ms is min. settling time at 10SPS). 48 | * Running this for 1-5s in setup() - before tare() seems to improve the tare accuracy */ 49 | void HX711_ADC::start(unsigned long t) 50 | { 51 | t += 400; 52 | lastDoutLowTime = millis(); 53 | while(millis() < t) 54 | { 55 | update(); 56 | } 57 | tare(); 58 | tareStatus = 0; 59 | } 60 | 61 | /* start(t, dotare) with selectable tare: 62 | * will do conversions continuously for 't' +400 milliseconds (400ms is min. settling time at 10SPS). 63 | * Running this for 1-5s in setup() - before tare() seems to improve the tare accuracy. */ 64 | void HX711_ADC::start(unsigned long t, bool dotare) 65 | { 66 | t += 400; 67 | lastDoutLowTime = millis(); 68 | while(millis() < t) { 69 | update(); 70 | } 71 | if (dotare) { 72 | tare(); 73 | tareStatus = 0; 74 | } 75 | } 76 | 77 | /* startMultiple(t): use this if you have more than one load cell and you want to do tare and stabilization simultaneously. 78 | * Will do conversions continuously for 't' +400 milliseconds (400ms is min. settling time at 10SPS). 79 | * Running this for 1-5s in setup() - before tare() seems to improve the tare accuracy */ 80 | int HX711_ADC::startMultiple(unsigned long t) 81 | { 82 | tareTimeoutFlag = 0; 83 | lastDoutLowTime = millis(); 84 | if(startStatus == 0) { 85 | if(isFirst) { 86 | startMultipleTimeStamp = millis(); 87 | if (t < 400) 88 | { 89 | startMultipleWaitTime = t + 400; //min time for HX711 to be stable 90 | } 91 | else 92 | { 93 | startMultipleWaitTime = t; 94 | } 95 | isFirst = 0; 96 | } 97 | if((millis() - startMultipleTimeStamp) < startMultipleWaitTime) { 98 | update(); //do conversions during stabilization time 99 | return 0; 100 | } 101 | else { //do tare after stabilization time is up 102 | static unsigned long timeout = millis() + tareTimeOut; 103 | doTare = 1; 104 | update(); 105 | if(convRslt == 2) 106 | { 107 | doTare = 0; 108 | convRslt = 0; 109 | startStatus = 1; 110 | } 111 | if (!tareTimeoutDisable) 112 | { 113 | if (millis() > timeout) 114 | { 115 | tareTimeoutFlag = 1; 116 | return 1; // Prevent endless loop if no HX711 is connected 117 | } 118 | } 119 | } 120 | } 121 | return startStatus; 122 | } 123 | 124 | /* startMultiple(t, dotare) with selectable tare: 125 | * use this if you have more than one load cell and you want to (do tare and) stabilization simultaneously. 126 | * Will do conversions continuously for 't' +400 milliseconds (400ms is min. settling time at 10SPS). 127 | * Running this for 1-5s in setup() - before tare() seems to improve the tare accuracy */ 128 | int HX711_ADC::startMultiple(unsigned long t, bool dotare) 129 | { 130 | tareTimeoutFlag = 0; 131 | lastDoutLowTime = millis(); 132 | if(startStatus == 0) { 133 | if (isFirst) 134 | { 135 | startMultipleTimeStamp = millis(); 136 | if (t < 400) 137 | { 138 | startMultipleWaitTime = t + 400; // min time for HX711 to be stable 139 | } 140 | else 141 | { 142 | startMultipleWaitTime = t; 143 | } 144 | isFirst = 0; 145 | } 146 | if((millis() - startMultipleTimeStamp) < startMultipleWaitTime) { 147 | update(); //do conversions during stabilization time 148 | return 0; 149 | } 150 | else 151 | { // do tare after stabilization time is up 152 | if (dotare) 153 | { 154 | static unsigned long timeout = millis() + tareTimeOut; 155 | doTare = 1; 156 | update(); 157 | if (convRslt == 2) 158 | { 159 | doTare = 0; 160 | convRslt = 0; 161 | startStatus = 1; 162 | } 163 | if (!tareTimeoutDisable) 164 | { 165 | if (millis() > timeout) 166 | { 167 | tareTimeoutFlag = 1; 168 | return 1; // Prevent endless loop if no HX711 is connected 169 | } 170 | } 171 | } 172 | else 173 | return 1; 174 | } 175 | } 176 | return startStatus; 177 | } 178 | 179 | //zero the scale, wait for tare to finnish (blocking) 180 | void HX711_ADC::tare() 181 | { 182 | uint8_t rdy = 0; 183 | doTare = 1; 184 | tareTimes = 0; 185 | tareTimeoutFlag = 0; 186 | unsigned long timeout = millis() + tareTimeOut; 187 | while(rdy != 2) 188 | { 189 | rdy = update(); 190 | if (!tareTimeoutDisable) 191 | { 192 | if (millis() > timeout) 193 | { 194 | tareTimeoutFlag = 1; 195 | break; // Prevent endless loop if no HX711 is connected 196 | } 197 | } 198 | } 199 | } 200 | 201 | //zero the scale, initiate the tare operation to run in the background (non-blocking) 202 | void HX711_ADC::tareNoDelay() 203 | { 204 | doTare = 1; 205 | tareTimes = 0; 206 | tareStatus = 0; 207 | } 208 | 209 | //set new calibration factor, raw data is divided by this value to convert to readable data 210 | void HX711_ADC::setCalFactor(float cal) 211 | { 212 | calFactor = cal; 213 | calFactorRecip = 1/calFactor; 214 | } 215 | 216 | //returns 'true' if tareNoDelay() operation is complete 217 | bool HX711_ADC::getTareStatus() 218 | { 219 | bool t = tareStatus; 220 | tareStatus = 0; 221 | return t; 222 | } 223 | 224 | //returns the current calibration factor 225 | float HX711_ADC::getCalFactor() 226 | { 227 | return calFactor; 228 | } 229 | 230 | //call the function update() in loop or from ISR 231 | //if conversion is ready; read out 24 bit data and add to dataset, returns 1 232 | //if tare operation is complete, returns 2 233 | //else returns 0 234 | uint8_t HX711_ADC::update() 235 | { 236 | uint8_t dout = doutPin.Read(); //check if conversion is ready 237 | if (!dout) 238 | { 239 | conversion24bit(); 240 | lastDoutLowTime = millis(); 241 | signalTimeoutFlag = 0; 242 | } 243 | else 244 | { 245 | //if (millis() > (lastDoutLowTime + SIGNAL_TIMEOUT)) 246 | if (millis() - lastDoutLowTime > SIGNAL_TIMEOUT) 247 | { 248 | signalTimeoutFlag = 1; 249 | } 250 | convRslt = 0; 251 | } 252 | return convRslt; 253 | } 254 | 255 | // call the function dataWaitingAsync() in loop or from ISR to check if new data is available to read 256 | // if conversion is ready, just call updateAsync() to read out 24 bit data and add to dataset 257 | // returns 1 if data available , else 0 258 | bool HX711_ADC::dataWaitingAsync() 259 | { 260 | if (dataWaiting) { lastDoutLowTime = millis(); return 1; } 261 | uint8_t dout = doutPin.Read(); //check if conversion is ready 262 | if (!dout) 263 | { 264 | dataWaiting = true; 265 | lastDoutLowTime = millis(); 266 | signalTimeoutFlag = 0; 267 | return 1; 268 | } 269 | else 270 | { 271 | //if (millis() > (lastDoutLowTime + SIGNAL_TIMEOUT)) 272 | if (millis() - lastDoutLowTime > SIGNAL_TIMEOUT) 273 | { 274 | signalTimeoutFlag = 1; 275 | } 276 | convRslt = 0; 277 | } 278 | return 0; 279 | } 280 | 281 | // if data is available call updateAsync() to convert it and add it to the dataset. 282 | // call getData() to get latest value 283 | bool HX711_ADC::updateAsync() 284 | { 285 | if (dataWaiting) { 286 | conversion24bit(); 287 | dataWaiting = false; 288 | return true; 289 | } 290 | return false; 291 | 292 | } 293 | 294 | float HX711_ADC::getData() // return fresh data from the moving average dataset 295 | { 296 | long data = 0; 297 | lastSmoothedData = smoothedData(); 298 | data = lastSmoothedData - tareOffset ; 299 | float x = (float)data * calFactorRecip; 300 | return x; 301 | } 302 | 303 | long HX711_ADC::smoothedData() 304 | { 305 | long data = 0; 306 | long L = 0xFFFFFF; 307 | long H = 0x00; 308 | for (uint8_t r = 0; r < (samplesInUse + IGN_HIGH_SAMPLE + IGN_LOW_SAMPLE); r++) 309 | { 310 | #if IGN_LOW_SAMPLE 311 | if (L > dataSampleSet[r]) L = dataSampleSet[r]; // find lowest value 312 | #endif 313 | #if IGN_HIGH_SAMPLE 314 | if (H < dataSampleSet[r]) H = dataSampleSet[r]; // find highest value 315 | #endif 316 | data += dataSampleSet[r]; 317 | } 318 | #if IGN_LOW_SAMPLE 319 | data -= L; //remove lowest value 320 | #endif 321 | #if IGN_HIGH_SAMPLE 322 | data -= H; //remove highest value 323 | #endif 324 | //return data; 325 | return (data >> divBit); 326 | 327 | } 328 | 329 | void HX711_ADC::conversion24bit() //read 24 bit data, store in dataset and start the next conversion 330 | { 331 | conversionTime = micros() - conversionStartTime; 332 | conversionStartTime = micros(); 333 | uint32_t data = 0; 334 | uint8_t dout; 335 | convRslt = 0; 336 | 337 | for (uint8_t i = 0; i < (24 + GAIN); i++) 338 | { //read 24 bit data + set gain and start next conversion 339 | sckPin.Write(HIGH); 340 | // if(SCK_DELAY) usleep(1); // could be required for faster mcu's, set value in config.h 341 | sckPin.Write(LOW); 342 | if (i < 24) 343 | { 344 | dout = doutPin.Read(); 345 | data = (data << 1) | dout; 346 | } 347 | } 348 | 349 | /** 350 | The HX711 output range is min. 0x800000 and max. 0x7FFFFF (the value rolls over). 351 | In order to convert the range to min. 0x000000 and max. 0xFFFFFF, 352 | the 24th bit must be changed from 0 to 1 or from 1 to 0. 353 | */ 354 | data = data ^ 0x800000; // flip the 24th bit 355 | 356 | if (data > 0xFFFFFF) 357 | { 358 | dataOutOfRange = 1; 359 | //printf("dataOutOfRange"); 360 | } 361 | if (reverseVal) { 362 | data = 0xFFFFFF - data; 363 | } 364 | if (readIndex == samplesInUse + IGN_HIGH_SAMPLE + IGN_LOW_SAMPLE - 1) 365 | { 366 | readIndex = 0; 367 | } 368 | else 369 | { 370 | readIndex++; 371 | } 372 | if(data > 0) 373 | { 374 | convRslt++; 375 | dataSampleSet[readIndex] = (long)data; 376 | if(doTare) 377 | { 378 | if (tareTimes < DATA_SET) 379 | { 380 | tareTimes++; 381 | } 382 | else 383 | { 384 | tareOffset = smoothedData(); 385 | tareTimes = 0; 386 | doTare = 0; 387 | tareStatus = 1; 388 | convRslt++; 389 | } 390 | } 391 | } 392 | } 393 | 394 | //power down the HX711 395 | void HX711_ADC::powerDown() 396 | { 397 | sckPin.Write(LOW); 398 | sckPin.Write(HIGH); 399 | } 400 | 401 | //power up the HX711 402 | void HX711_ADC::powerUp() 403 | { 404 | sckPin.Write(LOW); 405 | } 406 | 407 | //get the tare offset (raw data value output without the scale "calFactor") 408 | long HX711_ADC::getTareOffset() 409 | { 410 | return tareOffset; 411 | } 412 | 413 | //set new tare offset (raw data value input without the scale "calFactor") 414 | void HX711_ADC::setTareOffset(long newoffset) 415 | { 416 | tareOffset = newoffset; 417 | } 418 | 419 | //for testing and debugging: 420 | //returns current value of dataset readIndex 421 | int HX711_ADC::getReadIndex() 422 | { 423 | return readIndex; 424 | } 425 | 426 | //for testing and debugging: 427 | //returns latest conversion time in millis 428 | float HX711_ADC::getConversionTime() 429 | { 430 | return conversionTime/1000.0; 431 | } 432 | 433 | //for testing and debugging: 434 | //returns the HX711 conversions ea seconds based on the latest conversion time. 435 | //The HX711 can be set to 10SPS or 80SPS. For general use the recommended setting is 10SPS. 436 | float HX711_ADC::getSPS() 437 | { 438 | float sps = 1000000.0/conversionTime; 439 | return sps; 440 | } 441 | 442 | //for testing and debugging: 443 | //returns the tare timeout flag from the last tare operation. 444 | //0 = no timeout, 1 = timeout 445 | bool HX711_ADC::getTareTimeoutFlag() 446 | { 447 | return tareTimeoutFlag; 448 | } 449 | 450 | void HX711_ADC::disableTareTimeout() 451 | { 452 | tareTimeoutDisable = 1; 453 | } 454 | 455 | long HX711_ADC::getSettlingTime() 456 | { 457 | long st = getConversionTime() * DATA_SET; 458 | return st; 459 | } 460 | 461 | //overide the number of samples in use 462 | //value is rounded down to the nearest valid value 463 | void HX711_ADC::setSamplesInUse(int samples) 464 | { 465 | int old_value = samplesInUse; 466 | 467 | if(samples <= SAMPLES) 468 | { 469 | if(samples == 0) //reset to the original value 470 | { 471 | divBit = divBitCompiled; 472 | } 473 | else 474 | { 475 | samples >>= 1; 476 | for(divBit = 0; samples != 0; samples >>= 1, divBit++); 477 | } 478 | samplesInUse = 1 << divBit; 479 | 480 | //replace the value of all samples in use with the last conversion value 481 | if(samplesInUse != old_value) 482 | { 483 | for (uint8_t r = 0; r < samplesInUse + IGN_HIGH_SAMPLE + IGN_LOW_SAMPLE; r++) 484 | { 485 | dataSampleSet[r] = lastSmoothedData; 486 | } 487 | readIndex = 0; 488 | } 489 | } 490 | } 491 | 492 | //returns the current number of samples in use. 493 | int HX711_ADC::getSamplesInUse() 494 | { 495 | return samplesInUse; 496 | } 497 | 498 | //resets index for dataset 499 | void HX711_ADC::resetSamplesIndex() 500 | { 501 | readIndex = 0; 502 | } 503 | 504 | //Fill the whole dataset up with new conversions, i.e. after a reset/restart (this function is blocking once started) 505 | bool HX711_ADC::refreshDataSet() 506 | { 507 | int s = getSamplesInUse() + IGN_HIGH_SAMPLE + IGN_LOW_SAMPLE; // get number of samples in dataset 508 | resetSamplesIndex(); 509 | while ( s > 0 ) { 510 | update(); 511 | if (doutPin.Read() == 0) { // HX711 dout pin is pulled low when a new conversion is ready 512 | getData(); // add data to the set and start next conversion 513 | s--; 514 | } 515 | } 516 | return true; 517 | } 518 | 519 | //returns 'true' when the whole dataset has been filled up with conversions, i.e. after a reset/restart. 520 | bool HX711_ADC::getDataSetStatus() 521 | { 522 | bool i = false; 523 | if (readIndex == samplesInUse + IGN_HIGH_SAMPLE + IGN_LOW_SAMPLE - 1) 524 | { 525 | i = true; 526 | } 527 | return i; 528 | } 529 | 530 | // returns and sets a new calibration value (calFactor) based on a known mass input 531 | float HX711_ADC::getNewCalibration(float known_mass) { 532 | float readValue = getData(); 533 | float exist_calFactor = getCalFactor(); 534 | float new_calFactor; 535 | new_calFactor = (readValue * exist_calFactor) / known_mass; 536 | setCalFactor(new_calFactor); 537 | return new_calFactor; 538 | } 539 | 540 | // returns 'true' if it takes longer time then 'SIGNAL_TIMEOUT' for the dout pin to go low after a new conversion is started 541 | bool HX711_ADC::getSignalTimeoutFlag() { 542 | return signalTimeoutFlag; 543 | } 544 | 545 | // reverse the output value (flip positive/negative value) 546 | // tare/zero-offset must be re-set after calling this. 547 | void HX711_ADC::setReverseOutput() { 548 | reverseVal = true; 549 | } 550 | 551 | unsigned long HX711_ADC::millis() { 552 | unsigned long value_ms = std::chrono::duration_cast(std::chrono::steady_clock::now() - refTime).count(); 553 | return value_ms; 554 | } 555 | 556 | unsigned long HX711_ADC::micros() { 557 | unsigned long value_us = std::chrono::duration_cast(std::chrono::steady_clock::now() - refTime).count(); 558 | return value_us; 559 | } 560 | 561 | HX711_ADC::~HX711_ADC() { 562 | sckPin.Write(HIGH); 563 | sckPin.Disable(); 564 | doutPin.Disable(); 565 | } 566 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | --------------------------------------------------------------------------------