mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.2.0 HX711_MP
This commit is contained in:
parent
5bd103d2dd
commit
6bdfb78357
@ -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
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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.2.0] - 2024-03-02
|
||||
- add fastProcessor option in **begin()** (Thanks to palmerr23)
|
||||
- updated license
|
||||
- updated GitHub/actions to v4
|
||||
|
||||
----
|
||||
|
||||
## [0.1.1] - 2023-11-04
|
||||
- update readme.md
|
||||
- minor edits
|
||||
|
||||
|
||||
## [0.1.0] - 2023-03-10
|
||||
- initial release
|
||||
- first version derived from 0.3.5 https://github.com/RobTillaart/HX711
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: HX711_MP.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.1
|
||||
// VERSION: 0.2.0
|
||||
// PURPOSE: Library for load cells for UNO
|
||||
// URL: https://github.com/RobTillaart/HX711_MP
|
||||
// URL: https://github.com/RobTillaart/HX711
|
||||
@ -25,13 +25,16 @@ HX711_MP::HX711_MP(uint8_t size)
|
||||
}
|
||||
|
||||
|
||||
HX711_MP::~HX711_MP() {}
|
||||
HX711_MP::~HX711_MP()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HX711_MP::begin(uint8_t dataPin, uint8_t clockPin)
|
||||
void HX711_MP::begin(uint8_t dataPin, uint8_t clockPin, bool fastProcessor )
|
||||
{
|
||||
_dataPin = dataPin;
|
||||
_clockPin = clockPin;
|
||||
_fastProcessor = fastProcessor;
|
||||
|
||||
pinMode(_dataPin, INPUT);
|
||||
pinMode(_clockPin, OUTPUT);
|
||||
@ -140,7 +143,11 @@ float HX711_MP::read()
|
||||
{
|
||||
// delayMicroSeconds(1) needed for fast processors?
|
||||
digitalWrite(_clockPin, HIGH);
|
||||
if (_fastProcessor)
|
||||
delayMicroseconds(1);
|
||||
digitalWrite(_clockPin, LOW);
|
||||
if (_fastProcessor)
|
||||
delayMicroseconds(1);
|
||||
m--;
|
||||
}
|
||||
|
||||
@ -196,7 +203,7 @@ float HX711_MP::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;
|
||||
@ -372,7 +379,7 @@ void HX711_MP::_insertSort(float * array, uint8_t size)
|
||||
// see datasheet page 5 for timing
|
||||
uint8_t HX711_MP::_shiftIn()
|
||||
{
|
||||
// local variables are faster.
|
||||
// local variables are faster.
|
||||
uint8_t clk = _clockPin;
|
||||
uint8_t data = _dataPin;
|
||||
uint8_t value = 0;
|
||||
@ -380,13 +387,15 @@ uint8_t HX711_MP::_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;
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: HX711_MP.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.1
|
||||
// VERSION: 0.2.0
|
||||
// PURPOSE: Library for load cells for Arduino
|
||||
// URL: https://github.com/RobTillaart/HX711_MP
|
||||
// URL: https://github.com/RobTillaart/HX711
|
||||
@ -14,7 +14,7 @@
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#define HX711_MP_LIB_VERSION (F("0.1.1"))
|
||||
#define HX711_MP_LIB_VERSION (F("0.2.0"))
|
||||
|
||||
|
||||
const uint8_t HX711_AVERAGE_MODE = 0x00;
|
||||
@ -30,7 +30,7 @@ const uint8_t HX711_RAW_MODE = 0x04;
|
||||
|
||||
|
||||
// supported values for set_gain()
|
||||
const uint8_t HX711_CHANNEL_A_GAIN_128 = 128; // default
|
||||
const uint8_t HX711_CHANNEL_A_GAIN_128 = 128; // default
|
||||
const uint8_t HX711_CHANNEL_A_GAIN_64 = 64;
|
||||
const uint8_t HX711_CHANNEL_B_GAIN_32 = 32;
|
||||
|
||||
@ -45,7 +45,7 @@ public:
|
||||
~HX711_MP();
|
||||
|
||||
// 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();
|
||||
|
||||
@ -176,12 +176,12 @@ public:
|
||||
|
||||
|
||||
private:
|
||||
uint8_t _dataPin = -1;
|
||||
uint8_t _clockPin = -1;
|
||||
uint8_t _dataPin = -1;
|
||||
uint8_t _clockPin = -1;
|
||||
|
||||
uint8_t _gain = 128; // default channel A
|
||||
uint32_t _lastRead = 0;
|
||||
uint8_t _mode = HX711_AVERAGE_MODE;
|
||||
uint8_t _gain = 128; // default channel A
|
||||
uint32_t _lastRead = 0;
|
||||
uint8_t _mode = HX711_AVERAGE_MODE;
|
||||
|
||||
void _insertSort(float * array, uint8_t size);
|
||||
uint8_t _shiftIn();
|
||||
@ -191,6 +191,7 @@ private:
|
||||
float _out[HX711_MP_MAX_SIZE];
|
||||
uint8_t _size = HX711_MP_MAX_SIZE;
|
||||
float _multiMap(float val);
|
||||
bool _fastProcessor = false;
|
||||
};
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -90,7 +90,8 @@ is more math involved for converting raw data to weights.
|
||||
Parameter sets the size of for the calibration arrays.
|
||||
Allowed range for size is 2..10.
|
||||
- **~HX711_MP()**
|
||||
- **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.
|
||||
Reset also does a power down / up cycle.
|
||||
It does not reset the calibration data.
|
||||
@ -244,8 +245,8 @@ Colour scheme wires of two devices.
|
||||
#### Temperature
|
||||
|
||||
Load cells do have a temperature related error. (see datasheet load cell)
|
||||
This can be reduced by doing the calibration at the operational temperature
|
||||
one uses for the measurements.
|
||||
This can be reduced by doing the calibration and take the tare
|
||||
at the operational temperature one uses for the measurements.
|
||||
|
||||
Another way to handle this is to add a good temperature sensor
|
||||
(e.g. DS18B20, SHT85) and compensate for the temperature
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/HX711_MP"
|
||||
},
|
||||
"version": "0.1.1",
|
||||
"version": "0.2.0",
|
||||
"license": "MIT",
|
||||
"frameworks": "*",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=HX711_MP
|
||||
version=0.1.1
|
||||
version=0.2.0
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for HX711 load cell amplifier.
|
||||
|
Loading…
Reference in New Issue
Block a user