0.3.5 HX711

This commit is contained in:
rob tillaart 2023-03-10 11:00:03 +01:00
parent ffb23b3936
commit 29389fda70
12 changed files with 145 additions and 35 deletions

View File

@ -6,7 +6,7 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- 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@v2
- uses: actions/checkout@v3
- 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@v2
- uses: actions/checkout@v3
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
with:

View File

@ -5,7 +5,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.3.4]
## [0.3.5] - 2023-03-10
- update readme.md
- update GitHub actions
- update license 2023
- add MulitMap example
- minor edits
## [0.3.4] - 2022-11-11
- simplified changelog
- add RP2040 to build-CI
- refactored **set_gain()** to return bool to confirm valid parameter.

View File

@ -1,11 +1,9 @@
//
// FILE: HX711.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.3.4
// VERSION: 0.3.5
// PURPOSE: Library for load cells for UNO
// URL: https://github.com/RobTillaart/HX711
//
// HISTORY: see CHANGELOG.md
#include "HX711.h"
@ -226,7 +224,7 @@ float HX711::read_medavg(uint8_t times)
}
_insertSort(samples, times);
float sum = 0;
// iterate over 1/4 to 3/4 of the array
// iterate over 1/4 to 3/4 of the array
uint8_t count = 0;
uint8_t first = (times + 2) / 4;
uint8_t last = times - first - 1;
@ -308,7 +306,7 @@ float HX711::get_units(uint8_t times)
void HX711::power_down()
{
// at least 60 us HIGH
// at least 60 us HIGH
digitalWrite(_clockPin, HIGH);
delayMicroseconds(64);
}
@ -324,7 +322,7 @@ void HX711::power_up()
// see datasheet page 5 for timing
uint8_t HX711::_shiftIn()
{
// local variables are faster.
// local variables are faster.
uint8_t clk = _clockPin;
uint8_t data = _dataPin;
uint8_t value = 0;
@ -345,5 +343,5 @@ uint8_t HX711::_shiftIn()
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -2,12 +2,10 @@
//
// FILE: HX711.h
// AUTHOR: Rob Tillaart
// VERSION: 0.3.4
// VERSION: 0.3.5
// PURPOSE: Library for load cells for Arduino
// URL: https://github.com/RobTillaart/HX711
//
// HISTORY: see CHANGELOG.md
//
// NOTES
// Superset of interface of HX711 class of Bogde
// float instead of long as float has 23 bits mantissa.
@ -15,7 +13,7 @@
#include "Arduino.h"
#define HX711_LIB_VERSION (F("0.3.4"))
#define HX711_LIB_VERSION (F("0.3.5"))
const uint8_t HX711_AVERAGE_MODE = 0x00;

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2019-2022 Rob Tillaart
Copyright (c) 2019-2023 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

@ -56,6 +56,9 @@ Steps to take for calibration
## Interface
```cpp
#include "HX711.h"
```
#### Base
@ -124,7 +127,7 @@ Get and set the operational mode for **get_value()** and indirect **get_units()*
Constants (see .h file)
- **HX711_RAW_MODE** new in 0.3.3
- **HX711_RAW_MODE** new in 0.3.3
- **HX711_AVERAGE_MODE**
- **HX711_MEDIAN_MODE**
- **HX711_MEDAVG_MODE**
@ -134,7 +137,7 @@ Constants (see .h file)
In **HX711_MEDIAN_MODE** and **HX711_MEDAVG_MODE** mode only 3..15 samples are allowed
to keep memory footprint relative low.
- **void set_raw_mode()** - will cause **read()** to be called only once!
- **void set_raw_mode()** will cause **read()** to be called only once!
- **void set_average_mode()** take the average of n measurements.
- **void set_median_mode()** take the median of n measurements.
- **void set_medavg_mode()** take the average of n/2 median measurements.
@ -195,7 +198,7 @@ For weight conversion functions see https://github.com/RobTillaart/weight
## Notes
### Scale values for load cells
#### Scale values for load cells
These scale values worked pretty well with a set of load cells I have,
Use calibrate to find your favourite values.
@ -204,7 +207,7 @@ Use calibrate to find your favourite values.
- 20 KG load cell scale.set_scale(127.15);
### Connections HX711
#### Connections HX711
- A+/A- uses gain of 128 or 64
- B+/B- uses gain of 32
@ -221,7 +224,7 @@ Colour scheme wires of two devices.
| B+ | not connected | not connected |
### Temperature
#### Temperature
Load cells do have a temperature related error. (see datasheet load cell)
This can be reduced by doing the calibration and take the tare
@ -232,21 +235,19 @@ Another way to handle this is to add a good temperature sensor
differences in your code.
## Operation
See examples
## Future
#### must
- update documentation
#### Must
- update documentation HX711
- test B channel explicitly.
- test reset and reboot behaviours.
- keep in sync with HX711_MP
#### should
#### Should
- add examples
- optimize the build-in **ShiftIn()** function to improve performance again.
- investigate read()
@ -258,13 +259,15 @@ See examples
- code moves to both get/set_gain() so footprint might rise.
#### could
#### Could
- test different load cells
- make enum of the MODE's
- move code to .cpp
- example the adding scale
- void weight_clr(), void weight_add(), float weight_get() - adding scale
#### the adding scale
- void weight_clr(), void weight_add(), float weight_get() - adding scale
- might be a nice example
#### Wont

View File

@ -0,0 +1,29 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:
packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
# - due
# - zero
# - leonardo
- m4
- esp32
# - esp8266
# - mega2560
- rpipico
libraries:
- "MultiMap"

View File

@ -0,0 +1,74 @@
//
// FILE: HX_plotter_multimap.ino
// AUTHOR: Rob Tillaart
// PURPOSE: HX711 demo
// URL: https://github.com/RobTillaart/HX711
#include "MultiMap.h"
// inkg[] holds the weights from the linear calibrated HX711 sensor
float inkg[] = { 0, 6.25, 11.50, 14.50, 30.00, 34.10, 38.20, 44.50, 50.00};
// outkg[] holds the corrected weight
float outkg[] = { 0, 5, 10, 15, 30, 35, 40, 45, 50};
#include "HX711.h"
HX711 scale;
uint8_t dataPin = 6;
uint8_t clockPin = 7;
uint32_t start, stop;
float raw, corrected;
void setup()
{
Serial.begin(115200);
// Serial.println(__FILE__);
// Serial.print("LIBRARY VERSION: ");
// Serial.println(HX711_LIB_VERSION);
Serial.println();
scale.begin(dataPin, clockPin);
// TODO find a nice solution for this calibration..
// load cell factor 20 KG
// scale.set_scale(127.15);
// load cell factor 5 KG
scale.set_scale(420.0983); // TODO you need to calibrate this yourself.
// reset the scale to zero = 0
scale.tare();
// dump whole range 0..50 kg
for (float w = 0; w <= 50; w += 0.1)
{
Serial.print(w, 3);
Serial.print('\t');
corrected = multiMap<float>(w, inkg, outkg, 9); // 9 is the size of the arrays!
Serial.println(corrected, 3);
}
delay(50000);
}
void loop()
{
raw = scale.get_units(5);
corrected = multiMap<float>(raw, inkg, outkg, 9); // 9 is the size of the arrays!
Serial.print(raw, 3);
Serial.print('\t');
Serial.println(corrected, 3);
delay(250);
}
// -- END OF FILE --

View File

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

View File

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