0.4.0 HX711

This commit is contained in:
Rob Tillaart 2024-03-03 10:23:43 +01:00
parent 6bdfb78357
commit 2d1ce39862
12 changed files with 78 additions and 40 deletions

View File

@ -6,7 +6,7 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update

View File

@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6

View File

@ -10,7 +10,7 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
with:

View File

@ -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/).
## [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
- update readme.md
- minor edits
## [0.3.8] - 2023-08-26
- fix #41 #40 add example **HX_loadcell_array.ino**
- test support array of loadcells.

View File

@ -1,8 +1,9 @@
//
// FILE: HX711.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.3.9
// VERSION: 0.4.0
// PURPOSE: Library for load cells for UNO
// URL: https://github.com/RobTillaart/HX711_MP
// 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;
_clockPin = clockPin;
_fastProcessor = fastProcessor;
pinMode(_dataPin, INPUT);
pinMode(_clockPin, OUTPUT);
@ -83,7 +85,7 @@ bool HX711::wait_ready_timeout(uint32_t timeout, uint32_t ms)
}
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
//
// READ
//
@ -134,7 +136,11 @@ float HX711::read()
{
// delayMicroSeconds(1) needed for fast processors?
digitalWrite(_clockPin, HIGH);
if (_fastProcessor)
delayMicroseconds(1);
digitalWrite(_clockPin, LOW);
if (_fastProcessor)
delayMicroseconds(1);
m--;
}
@ -314,7 +320,7 @@ bool HX711::tare_set()
}
///////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
//
// GAIN
//
@ -344,9 +350,9 @@ uint8_t HX711::get_gain()
}
///////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
//
// CALIBRATION AND SETUP
// CALIBRATION
//
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()
{
@ -399,7 +405,7 @@ void HX711::power_up()
}
///////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
//
// MISC
//
@ -409,7 +415,7 @@ uint32_t HX711::last_read()
}
/////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
//
// PRIVATE
//
@ -445,13 +451,15 @@ uint8_t HX711::_shiftIn()
while (mask > 0)
{
digitalWrite(clk, HIGH);
delayMicroseconds(1); // T2 >= 0.2 us
if(_fastProcessor) // T2 >= 0.2 us
delayMicroseconds(1);
if (digitalRead(data) == HIGH)
{
value |= mask;
}
digitalWrite(clk, LOW);
delayMicroseconds(1); // keep duty cycle ~50%
if(_fastProcessor)
delayMicroseconds(1); // keep duty cycle ~50%
mask >>= 1;
}
return value;

View File

@ -2,8 +2,9 @@
//
// FILE: HX711.h
// AUTHOR: Rob Tillaart
// VERSION: 0.3.9
// VERSION: 0.4.0
// PURPOSE: Library for load cells for Arduino
// URL: https://github.com/RobTillaart/HX711_MP
// URL: https://github.com/RobTillaart/HX711
//
// NOTES
@ -13,7 +14,7 @@
#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;
@ -41,7 +42,7 @@ public:
~HX711();
// 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();
@ -56,6 +57,11 @@ public:
// max timeout
bool wait_ready_timeout(uint32_t timeout = 1000, uint32_t ms = 0);
///////////////////////////////////////////////////////////////
//
// READ
//
// raw read
float read();
@ -77,6 +83,10 @@ public:
float read_runavg(uint8_t times = 7, float alpha = 0.5);
///////////////////////////////////////////////////////////////
//
// MODE
//
// get set mode for get_value() and indirect get_units().
// in median and medavg mode only 3..15 samples are allowed.
void set_raw_mode();
@ -102,6 +112,10 @@ public:
bool tare_set();
///////////////////////////////////////////////////////////////
//
// GAIN
//
// CORE "CONSTANTS" -> read datasheet
// CHANNEL GAIN notes
// -------------------------------------
@ -118,7 +132,10 @@ public:
uint8_t get_gain();
// CALIBRATION & SETUP
///////////////////////////////////////////////////////////////
//
// CALIBRATION
//
// SCALE > 0
// returns false if scale == 0;
bool set_scale(float scale = 1.0);
@ -136,7 +153,10 @@ public:
void calibrate_scale(uint16_t weight, uint8_t times = 10);
///////////////////////////////////////////////////////////////
//
// POWER MANAGEMENT
//
void power_down();
void power_up();
@ -160,10 +180,11 @@ private:
float _scale = 1;
uint32_t _lastRead = 0;
float _price = 0;
uint8_t _mode = 0;
uint8_t _mode = HX711_AVERAGE_MODE;
void _insertSort(float * array, uint8_t size);
uint8_t _shiftIn();
bool _fastProcessor = false;
};

View File

@ -1,6 +1,6 @@
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
of this software and associated documentation files (the "Software"), to deal

View File

@ -111,7 +111,8 @@ Steps to take for calibration
- **HX711()** constructor.
- **~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.
Since 0.3.4 reset also does a power down / up cycle.
- **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.
- **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.
- **uint32_t last_read()** returns timestamp in milliseconds.
- **uint32_t last_read()** returns timestamp in milliseconds of last read.
#### 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).
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.
So in such case it is strongly advised to call **set_gain()** explicitly in **setup()**
so the device is in a known state.
@ -195,7 +196,7 @@ to keep memory footprint relative low.
#### Get values
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_units(uint8_t times = 1)** read value, converted to proper units.
@ -297,14 +298,14 @@ Use calibrate to find your favourite values.
Colour scheme wires of two devices.
| HX711 Pin | Colour dev 1 | Colour dev 2 |
|:---------:|:--------------:|:--------------:|
| E+ | red | red |
| E- | black | black |
| A- | white | blue |
| A+ | green | white |
| B- | not connected | not connected |
| B+ | not connected | not connected |
| HX711 Pin | Colour dev 1 | Colour dev 2 |
|:-----------:|:---------------:|:---------------:|
| E+ | red | red |
| E- | black | black |
| A- | white | blue |
| A+ | green | white |
| B- | not connected | not connected |
| B+ | not connected | not connected |
#### Temperature

View File

@ -19,6 +19,9 @@ read_median KEYWORD2
read_medavg KEYWORD2
read_runavg KEYWORD2
get_value KEYWORD2
get_units KEYWORD2
set_raw_mode KEYWORD2
set_average_mode KEYWORD2
set_median_mode KEYWORD2
@ -26,9 +29,6 @@ set_medavg_mode KEYWORD2
set_runavg_mode KEYWORD2
get_mode KEYWORD2
get_value KEYWORD2
get_units KEYWORD2
tare KEYWORD2
get_tare KEYWORD2
tare_set KEYWORD2

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/HX711"
},
"version": "0.3.9",
"version": "0.4.0",
"license": "MIT",
"frameworks": "*",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=HX711
version=0.3.9
version=0.4.0
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for HX711 load cell amplifier

View File

@ -188,4 +188,6 @@ unittest(test_operational_mode)
unittest_main()
// --------
// -- END OF FILE --