BayEOSArduino Library
HX711Array.h
1 #ifndef HX711Array_h
2 #define HX711Array_h
3 
4 #include "Arduino.h"
5 
6 class HX711Array {
7 private:
8  uint8_t _pd_sck; // Power Down and Serial Clock Input Pin
9  uint8_t* _dout; // Serial Data Output Pins
10  uint8_t _length;
11  uint8_t GAIN; // amplification factor
12  long _values[4];
13  uint8_t* _p;
14  void shiftIn(uint8_t nr);
15  bool no_sleep;
16 
17 public:
18  HX711Array();
19  virtual ~HX711Array();
20  // define clock and data pins channel, and gain factor
21  // channel selection is made by passing the appropriate gain: 128 or 64 for channel A, 32 for channel B
22  // gain: 128 or 64 for channel A; channel B works with 32 gain factor only
23  void begin(uint8_t* dout, uint8_t length, uint8_t pd_sck,
24  uint8_t gain = 128);
25  // check if HX711Array is ready
26  // from the datasheet: When output data is not ready for retrieval, digital output pin _dout is high. Serial clock
27  // input _pd_sck should be low. When _dout goes to low, it indicates data is ready for retrieval.
28  bool is_ready();
29 
30  // set the gain factor; takes effect only after a call to read()
31  // channel A can be set for a 128 or 64 gain; channel B has a fixed 32 gain
32  // depending on the parameter, the channel is also set to either A or B
33  void set_gain(uint8_t gain = 128);
34 
35  // waits for the chip to be ready and returns a reading
36  long read(uint8_t timeout = 128);
37 
38  // returns pointer to last single reads
39  const long* get_single_readings();
40 
41  // returns an average reading; times = how many times to read
42  long read_average(uint8_t times = 10, uint8_t timeout = 128);
43 
44  // fills res array with average reading; times = how many times to read
45  uint8_t read_average(long* res, uint8_t times = 10, uint8_t timeout = 128);
46 
47  // This function calculates a median out of 5 measurements
48  // After taking the median, have of the measurements has to be inside a max_dev range around the median
49  // returns an average reading; times = how many times to read
50  long read_average_with_filter(long* res, unsigned long max_dev=5000, uint8_t* counts=NULL, uint8_t times = 10, uint8_t timeout = 128);
51 
52  // puts the chip into power down mode
53  void power_down();
54 
55  // wakes up the chip after power down mode
56  void power_up();
57 
58  //set no sleep mode
59  void set_no_sleep(bool ns);
60 };
61 
63 private:
64  int eeprom_offset;
65  float t_conf[2];
66  long adc_conf[4];
67  float scale_weight, tare_weight;
68  uint8_t i;
69  uint8_t* p;
70 public:
71  Scale4PointCal(int o = 0);
72  void setConfPoint(float t, uint8_t t_index, long adc, uint8_t adc_index);
73  void setConf(float w, float* t, long* a);
74  void getConf(float &w, float* t, long* a);
75  void setScaleWeight(float w);
76  void setTare(long adc,float t);
77  void saveConf(void);
78  void readConf(void);
79  void printConf(void);
80 
81  float getWeight(long adc,float t);
82 };
83 
84 
86 private:
87  long last_adc;
88 public:
89  long getRaw(void);
90  void tare(float t);
91  void readADC(uint8_t c = 20);
92 };
93 
94 
95 class ScaleTCal {
96  private:
97  int eeprom_offset;
98  float m[4]; //Modell ADC = m[0]+m[1]*t+m[2]*dt+m[3]*dt^2
99  float slope;
100  public:
101  ScaleTCal(int o=0);
102  void saveConf(float _slope,float* _m);
103  void readConf(void);
104  float getWeight(long adc,float t,float dt);
105 };
106 
107 #endif /* HX711Array_h */
Definition: HX711Array.h:85
Definition: HX711Array.h:6
Definition: HX711Array.h:62
Definition: HX711Array.h:95