-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreference_driver.cc
64 lines (53 loc) · 1.23 KB
/
reference_driver.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* @file reference_driver.cc
* @author Simon Thür ([email protected])
* @brief Copied the reference program for the HX711
* @version 0.1
* @date 2022-03-02
*
* @copyright Copyright (c) 2022
*
*/
#include <iostream>
#include "wiringPi.h"
#define DATA_PIN_0 11
#define DATA_PIN_1 26
#define DATA_PIN_2 18
#define DATA_PIN_3 22
#define DATA_PIN_4 29
#define DATA_PIN_5 32
#define DCLK_PIN 23
/**
* @brief Reference driver (adapted) for the hx711 ADC
*
* @return unsigned long
*/
int read_value();
int main( int argc, char const* argv[] )
{
wiringPiSetupGpio();
pinMode( DATA_PIN_0, INPUT );
pinMode( DCLK_PIN, OUTPUT );
std::cout << read_value() << std::endl;
return 0;
}
int read_value()
{
int adc_val = 0;
while ( digitalRead( DATA_PIN_0 ) )
;
for ( int i = 0; i < 24; i++ )
{
digitalWrite( DCLK_PIN, HIGH );
adc_val << 1;
digitalWrite( DCLK_PIN, LOW );
if ( digitalRead( DATA_PIN_0 ) )
{
adc_val++;
}
}
digitalWrite( DCLK_PIN, HIGH );
adc_val = adc_val ^ 0x800000; // because 24 bit signed value on 32 bit int
digitalWrite( DCLK_PIN, LOW );
return adc_val;
}