cleeee
September 6, 2022, 10:04am
1
Hi,
I would like to read out the data of the HX711 in a uint32_t variable directly. But it does not work. I step into the code of the HX711 library (GitHub - bogde/HX711: An Arduino library to interface the Avia Semiconductor HX711 24-Bit Analog-to-Digital Converter (ADC) for Weight Scales. ) and I saw, that the proper function reads out 3 uint8t variables corresponding to 3 8 bits instead of reading out the whole 24 bits in a uint32_t.
Here is my code segement trying to read 24 bit in a uint32t:
uint32_t dataT = { 0 };
for (int i = 0; i<24; i++)
{
digitalWrite(m_pd_sck, HIGH);
dataT |= static_cast<uint32_t>(digitalRead(m_dOut)) << (23 - i);
digitalWrite(m_pd_sck, LOW);
}
in comparison the segement of the HX711 library:
data[2] = shiftIn(DOUT, PD_SCK, MSBFIRST);
data[1] = shiftIn(DOUT, PD_SCK, MSBFIRST);
data[0] =shiftIn(DOUT, PD_SCK, MSBFIRST);
Can anybody help me or give me a hint what is wrong with my code?
KR, Cleeee
The read function of the library returns a 32 bit long which may be cast to uint32_t.
#include "HX711.h"
// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 2;
const int LOADCELL_SCK_PIN = 3;
HX711 scale;
void setup() {
Serial.begin(57600);
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
}
void loop() {
if (scale.is_ready()) {
long reading = scale.read();
Serial.print("HX711 reading: ");
Serial.println(reading);
} else {
This file has been truncated. show original
cleeee
September 6, 2022, 6:26pm
3
I would like to write my own read function. The code sequence which I described in my first post is inside the read()-function. Inside the read-function, the 24 bits coming from the 24-bit-ADC are read by 3 times 8 bits with the shiftIn-function. My attempt is to read the 24 bits at once in an uint32_t and there are the problem that the value is not the same as with the read-function of the HX711 library.
gfvalvo
September 6, 2022, 6:37pm
4
Why don't you just stick with what works?
cleeee
September 7, 2022, 7:38am
5
I would like to understand why something works and others not, respectively.
post expected outcome vs actual
system
Closed
March 6, 2023, 7:48am
7
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.