mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.4.0 HX711
This commit is contained in:
parent
6bdfb78357
commit
2d1ce39862
@ -6,7 +6,7 @@ jobs:
|
|||||||
lint:
|
lint:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- uses: arduino/arduino-lint-action@v1
|
- uses: arduino/arduino-lint-action@v1
|
||||||
with:
|
with:
|
||||||
library-manager: update
|
library-manager: update
|
||||||
|
@ -8,7 +8,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- uses: ruby/setup-ruby@v1
|
- uses: ruby/setup-ruby@v1
|
||||||
with:
|
with:
|
||||||
ruby-version: 2.6
|
ruby-version: 2.6
|
||||||
|
@ -10,7 +10,7 @@ jobs:
|
|||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- name: json-syntax-check
|
- name: json-syntax-check
|
||||||
uses: limitusus/json-syntax-check@v1
|
uses: limitusus/json-syntax-check@v1
|
||||||
with:
|
with:
|
||||||
|
@ -5,11 +5,17 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
|||||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
|
|
||||||
|
## [0.4.0] - 2024-03-02
|
||||||
|
- add fastProcessor option in **begin()** (Thanks to palmerr23)
|
||||||
|
- updated license
|
||||||
|
- updated GitHub/actions to v4
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
## [0.3.9] - 2023-11-04
|
## [0.3.9] - 2023-11-04
|
||||||
- update readme.md
|
- update readme.md
|
||||||
- minor edits
|
- minor edits
|
||||||
|
|
||||||
|
|
||||||
## [0.3.8] - 2023-08-26
|
## [0.3.8] - 2023-08-26
|
||||||
- fix #41 #40 add example **HX_loadcell_array.ino**
|
- fix #41 #40 add example **HX_loadcell_array.ino**
|
||||||
- test support array of loadcells.
|
- test support array of loadcells.
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
//
|
//
|
||||||
// FILE: HX711.cpp
|
// FILE: HX711.cpp
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// VERSION: 0.3.9
|
// VERSION: 0.4.0
|
||||||
// PURPOSE: Library for load cells for UNO
|
// PURPOSE: Library for load cells for UNO
|
||||||
|
// URL: https://github.com/RobTillaart/HX711_MP
|
||||||
// URL: https://github.com/RobTillaart/HX711
|
// URL: https://github.com/RobTillaart/HX711
|
||||||
|
|
||||||
|
|
||||||
@ -20,10 +21,11 @@ HX711::~HX711()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HX711::begin(uint8_t dataPin, uint8_t clockPin)
|
void HX711::begin(uint8_t dataPin, uint8_t clockPin, bool fastProcessor )
|
||||||
{
|
{
|
||||||
_dataPin = dataPin;
|
_dataPin = dataPin;
|
||||||
_clockPin = clockPin;
|
_clockPin = clockPin;
|
||||||
|
_fastProcessor = fastProcessor;
|
||||||
|
|
||||||
pinMode(_dataPin, INPUT);
|
pinMode(_dataPin, INPUT);
|
||||||
pinMode(_clockPin, OUTPUT);
|
pinMode(_clockPin, OUTPUT);
|
||||||
@ -83,7 +85,7 @@ bool HX711::wait_ready_timeout(uint32_t timeout, uint32_t ms)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// READ
|
// READ
|
||||||
//
|
//
|
||||||
@ -134,7 +136,11 @@ float HX711::read()
|
|||||||
{
|
{
|
||||||
// delayMicroSeconds(1) needed for fast processors?
|
// delayMicroSeconds(1) needed for fast processors?
|
||||||
digitalWrite(_clockPin, HIGH);
|
digitalWrite(_clockPin, HIGH);
|
||||||
|
if (_fastProcessor)
|
||||||
|
delayMicroseconds(1);
|
||||||
digitalWrite(_clockPin, LOW);
|
digitalWrite(_clockPin, LOW);
|
||||||
|
if (_fastProcessor)
|
||||||
|
delayMicroseconds(1);
|
||||||
m--;
|
m--;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,7 +320,7 @@ bool HX711::tare_set()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// GAIN
|
// GAIN
|
||||||
//
|
//
|
||||||
@ -344,9 +350,9 @@ uint8_t HX711::get_gain()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// CALIBRATION AND SETUP
|
// CALIBRATION
|
||||||
//
|
//
|
||||||
bool HX711::set_scale(float scale)
|
bool HX711::set_scale(float scale)
|
||||||
{
|
{
|
||||||
@ -381,9 +387,9 @@ void HX711::calibrate_scale(uint16_t weight, uint8_t times)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// POWER
|
// POWER MANAGEMENT
|
||||||
//
|
//
|
||||||
void HX711::power_down()
|
void HX711::power_down()
|
||||||
{
|
{
|
||||||
@ -399,7 +405,7 @@ void HX711::power_up()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// MISC
|
// MISC
|
||||||
//
|
//
|
||||||
@ -409,7 +415,7 @@ uint32_t HX711::last_read()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// PRIVATE
|
// PRIVATE
|
||||||
//
|
//
|
||||||
@ -445,12 +451,14 @@ uint8_t HX711::_shiftIn()
|
|||||||
while (mask > 0)
|
while (mask > 0)
|
||||||
{
|
{
|
||||||
digitalWrite(clk, HIGH);
|
digitalWrite(clk, HIGH);
|
||||||
delayMicroseconds(1); // T2 >= 0.2 us
|
if(_fastProcessor) // T2 >= 0.2 us
|
||||||
|
delayMicroseconds(1);
|
||||||
if (digitalRead(data) == HIGH)
|
if (digitalRead(data) == HIGH)
|
||||||
{
|
{
|
||||||
value |= mask;
|
value |= mask;
|
||||||
}
|
}
|
||||||
digitalWrite(clk, LOW);
|
digitalWrite(clk, LOW);
|
||||||
|
if(_fastProcessor)
|
||||||
delayMicroseconds(1); // keep duty cycle ~50%
|
delayMicroseconds(1); // keep duty cycle ~50%
|
||||||
mask >>= 1;
|
mask >>= 1;
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,9 @@
|
|||||||
//
|
//
|
||||||
// FILE: HX711.h
|
// FILE: HX711.h
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// VERSION: 0.3.9
|
// VERSION: 0.4.0
|
||||||
// PURPOSE: Library for load cells for Arduino
|
// PURPOSE: Library for load cells for Arduino
|
||||||
|
// URL: https://github.com/RobTillaart/HX711_MP
|
||||||
// URL: https://github.com/RobTillaart/HX711
|
// URL: https://github.com/RobTillaart/HX711
|
||||||
//
|
//
|
||||||
// NOTES
|
// NOTES
|
||||||
@ -13,7 +14,7 @@
|
|||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
#define HX711_LIB_VERSION (F("0.3.9"))
|
#define HX711_LIB_VERSION (F("0.4.0"))
|
||||||
|
|
||||||
|
|
||||||
const uint8_t HX711_AVERAGE_MODE = 0x00;
|
const uint8_t HX711_AVERAGE_MODE = 0x00;
|
||||||
@ -41,7 +42,7 @@ public:
|
|||||||
~HX711();
|
~HX711();
|
||||||
|
|
||||||
// fixed gain 128 for now
|
// fixed gain 128 for now
|
||||||
void begin(uint8_t dataPin, uint8_t clockPin);
|
void begin(uint8_t dataPin, uint8_t clockPin, bool fastProcessor = false);
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
@ -56,6 +57,11 @@ public:
|
|||||||
// max timeout
|
// max timeout
|
||||||
bool wait_ready_timeout(uint32_t timeout = 1000, uint32_t ms = 0);
|
bool wait_ready_timeout(uint32_t timeout = 1000, uint32_t ms = 0);
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// READ
|
||||||
|
//
|
||||||
// raw read
|
// raw read
|
||||||
float read();
|
float read();
|
||||||
|
|
||||||
@ -77,6 +83,10 @@ public:
|
|||||||
float read_runavg(uint8_t times = 7, float alpha = 0.5);
|
float read_runavg(uint8_t times = 7, float alpha = 0.5);
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// MODE
|
||||||
|
//
|
||||||
// get set mode for get_value() and indirect get_units().
|
// get set mode for get_value() and indirect get_units().
|
||||||
// in median and medavg mode only 3..15 samples are allowed.
|
// in median and medavg mode only 3..15 samples are allowed.
|
||||||
void set_raw_mode();
|
void set_raw_mode();
|
||||||
@ -102,6 +112,10 @@ public:
|
|||||||
bool tare_set();
|
bool tare_set();
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// GAIN
|
||||||
|
//
|
||||||
// CORE "CONSTANTS" -> read datasheet
|
// CORE "CONSTANTS" -> read datasheet
|
||||||
// CHANNEL GAIN notes
|
// CHANNEL GAIN notes
|
||||||
// -------------------------------------
|
// -------------------------------------
|
||||||
@ -118,7 +132,10 @@ public:
|
|||||||
uint8_t get_gain();
|
uint8_t get_gain();
|
||||||
|
|
||||||
|
|
||||||
// CALIBRATION & SETUP
|
///////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// CALIBRATION
|
||||||
|
//
|
||||||
// SCALE > 0
|
// SCALE > 0
|
||||||
// returns false if scale == 0;
|
// returns false if scale == 0;
|
||||||
bool set_scale(float scale = 1.0);
|
bool set_scale(float scale = 1.0);
|
||||||
@ -136,7 +153,10 @@ public:
|
|||||||
void calibrate_scale(uint16_t weight, uint8_t times = 10);
|
void calibrate_scale(uint16_t weight, uint8_t times = 10);
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
// POWER MANAGEMENT
|
// POWER MANAGEMENT
|
||||||
|
//
|
||||||
void power_down();
|
void power_down();
|
||||||
void power_up();
|
void power_up();
|
||||||
|
|
||||||
@ -160,10 +180,11 @@ private:
|
|||||||
float _scale = 1;
|
float _scale = 1;
|
||||||
uint32_t _lastRead = 0;
|
uint32_t _lastRead = 0;
|
||||||
float _price = 0;
|
float _price = 0;
|
||||||
uint8_t _mode = 0;
|
uint8_t _mode = HX711_AVERAGE_MODE;
|
||||||
|
|
||||||
void _insertSort(float * array, uint8_t size);
|
void _insertSort(float * array, uint8_t size);
|
||||||
uint8_t _shiftIn();
|
uint8_t _shiftIn();
|
||||||
|
bool _fastProcessor = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2019-2023 Rob Tillaart
|
Copyright (c) 2019-2024 Rob Tillaart
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -111,7 +111,8 @@ Steps to take for calibration
|
|||||||
|
|
||||||
- **HX711()** constructor.
|
- **HX711()** constructor.
|
||||||
- **~HX711()**
|
- **~HX711()**
|
||||||
- **void begin(uint8_t dataPin, uint8_t clockPin)** sets a fixed gain 128 for now.
|
- **void begin(uint8_t dataPin, uint8_t clockPin, bool fastProcessor)** sets a fixed gain 128 for now.
|
||||||
|
The fastProcessor option adds a 1 uS delay for each clock half-cycle to keep the time greater than 200 nS.
|
||||||
- **void reset()** set internal state to start condition.
|
- **void reset()** set internal state to start condition.
|
||||||
Since 0.3.4 reset also does a power down / up cycle.
|
Since 0.3.4 reset also does a power down / up cycle.
|
||||||
- **bool is_ready()** checks if load cell is ready to read.
|
- **bool is_ready()** checks if load cell is ready to read.
|
||||||
@ -126,7 +127,7 @@ times = 3..15 - odd numbers preferred.
|
|||||||
times = 3..15 - odd numbers preferred.
|
times = 3..15 - odd numbers preferred.
|
||||||
- **float read_runavg(uint8_t times = 7, float alpha = 0.5)** get running average over times measurements.
|
- **float read_runavg(uint8_t times = 7, float alpha = 0.5)** get running average over times measurements.
|
||||||
The weight alpha can be set to any value between 0 and 1, times >= 1.
|
The weight alpha can be set to any value between 0 and 1, times >= 1.
|
||||||
- **uint32_t last_read()** returns timestamp in milliseconds.
|
- **uint32_t last_read()** returns timestamp in milliseconds of last read.
|
||||||
|
|
||||||
|
|
||||||
#### Gain + channel
|
#### Gain + channel
|
||||||
@ -158,7 +159,7 @@ next call to **read()** will return info from the selected channel/gain.
|
|||||||
According to the datasheet the gain/channel change may take up to 400ms (table page 3).
|
According to the datasheet the gain/channel change may take up to 400ms (table page 3).
|
||||||
|
|
||||||
Warning 1: if you use **set_gain()** in your program the HX711 can be in different states.
|
Warning 1: if you use **set_gain()** in your program the HX711 can be in different states.
|
||||||
If there is a expected or unexpected reboot of the MCU, this could lead
|
If there is an expected or unexpected reboot of the MCU, this could lead
|
||||||
to an unknown state at the reboot of the code.
|
to an unknown state at the reboot of the code.
|
||||||
So in such case it is strongly advised to call **set_gain()** explicitly in **setup()**
|
So in such case it is strongly advised to call **set_gain()** explicitly in **setup()**
|
||||||
so the device is in a known state.
|
so the device is in a known state.
|
||||||
@ -195,7 +196,7 @@ to keep memory footprint relative low.
|
|||||||
#### Get values
|
#### Get values
|
||||||
|
|
||||||
Get values from the HX711 corrected for offset and scale.
|
Get values from the HX711 corrected for offset and scale.
|
||||||
Note that in **HX711_RAW_MODE** times will be ignored => just call **read()** once.
|
Note that in **HX711_RAW_MODE** the times parameter will be ignored => just call **read()** once.
|
||||||
|
|
||||||
- **float get_value(uint8_t times = 1)** read value, corrected for offset.
|
- **float get_value(uint8_t times = 1)** read value, corrected for offset.
|
||||||
- **float get_units(uint8_t times = 1)** read value, converted to proper units.
|
- **float get_units(uint8_t times = 1)** read value, converted to proper units.
|
||||||
@ -298,7 +299,7 @@ Use calibrate to find your favourite values.
|
|||||||
Colour scheme wires of two devices.
|
Colour scheme wires of two devices.
|
||||||
|
|
||||||
| HX711 Pin | Colour dev 1 | Colour dev 2 |
|
| HX711 Pin | Colour dev 1 | Colour dev 2 |
|
||||||
|:---------:|:--------------:|:--------------:|
|
|:-----------:|:---------------:|:---------------:|
|
||||||
| E+ | red | red |
|
| E+ | red | red |
|
||||||
| E- | black | black |
|
| E- | black | black |
|
||||||
| A- | white | blue |
|
| A- | white | blue |
|
||||||
|
@ -19,6 +19,9 @@ read_median KEYWORD2
|
|||||||
read_medavg KEYWORD2
|
read_medavg KEYWORD2
|
||||||
read_runavg KEYWORD2
|
read_runavg KEYWORD2
|
||||||
|
|
||||||
|
get_value KEYWORD2
|
||||||
|
get_units KEYWORD2
|
||||||
|
|
||||||
set_raw_mode KEYWORD2
|
set_raw_mode KEYWORD2
|
||||||
set_average_mode KEYWORD2
|
set_average_mode KEYWORD2
|
||||||
set_median_mode KEYWORD2
|
set_median_mode KEYWORD2
|
||||||
@ -26,9 +29,6 @@ set_medavg_mode KEYWORD2
|
|||||||
set_runavg_mode KEYWORD2
|
set_runavg_mode KEYWORD2
|
||||||
get_mode KEYWORD2
|
get_mode KEYWORD2
|
||||||
|
|
||||||
get_value KEYWORD2
|
|
||||||
get_units KEYWORD2
|
|
||||||
|
|
||||||
tare KEYWORD2
|
tare KEYWORD2
|
||||||
get_tare KEYWORD2
|
get_tare KEYWORD2
|
||||||
tare_set KEYWORD2
|
tare_set KEYWORD2
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/RobTillaart/HX711"
|
"url": "https://github.com/RobTillaart/HX711"
|
||||||
},
|
},
|
||||||
"version": "0.3.9",
|
"version": "0.4.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"frameworks": "*",
|
"frameworks": "*",
|
||||||
"platforms": "*",
|
"platforms": "*",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name=HX711
|
name=HX711
|
||||||
version=0.3.9
|
version=0.4.0
|
||||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||||
sentence=Arduino library for HX711 load cell amplifier
|
sentence=Arduino library for HX711 load cell amplifier
|
||||||
|
@ -188,4 +188,6 @@ unittest(test_operational_mode)
|
|||||||
|
|
||||||
unittest_main()
|
unittest_main()
|
||||||
|
|
||||||
// --------
|
|
||||||
|
// -- END OF FILE --
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user