ZotBins Core
Loading...
Searching...
No Matches
hx711.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Ruslan V. Uss <unclerus@gmail.com>
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * 3. Neither the name of the copyright holder nor the names of itscontributors
13 * may be used to endorse or promote products derived from this software without
14 * specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
39#ifndef __HX711_H__
40#define __HX711_H__
41
42#include <driver/gpio.h>
43#include <stdbool.h>
44#include <esp_err.h>
45
46#ifdef __cplusplus
47extern "C" {
48#endif
49
58
62typedef struct
63{
64 gpio_num_t dout;
65 gpio_num_t pd_sck;
66 hx711_gain_t gain;
67} hx711_t;
68
77esp_err_t hx711_init(hx711_t *dev);
78
86esp_err_t hx711_power_down(hx711_t *dev, bool down);
87
95esp_err_t hx711_set_gain(hx711_t *dev, hx711_gain_t gain);
96
104esp_err_t hx711_is_ready(hx711_t *dev, bool *ready);
105
113esp_err_t hx711_wait(hx711_t *dev, size_t timeout_ms);
114
125esp_err_t hx711_read_data(hx711_t *dev, int32_t *data);
126
135esp_err_t hx711_read_average(hx711_t *dev, size_t times, int32_t *data);
136
137#ifdef __cplusplus
138}
139#endif
140
142
143#endif /* __HX711_H__ */
esp_err_t hx711_power_down(hx711_t *dev, bool down)
Set device power up/down.
Definition hx711.c:102
esp_err_t hx711_init(hx711_t *dev)
Initialize device.
Definition hx711.c:90
esp_err_t hx711_read_average(hx711_t *dev, size_t times, int32_t *data)
Read average data.
Definition hx711.c:158
esp_err_t hx711_read_data(hx711_t *dev, int32_t *data)
Read raw data from device.
Definition hx711.c:146
esp_err_t hx711_set_gain(hx711_t *dev, hx711_gain_t gain)
Set device gain and channel.
Definition hx711.c:112
hx711_gain_t
Definition hx711.h:53
esp_err_t hx711_is_ready(hx711_t *dev, bool *ready)
Check if device ready to send data.
Definition hx711.c:124
esp_err_t hx711_wait(hx711_t *dev, size_t timeout_ms)
Wait for device to become ready.
Definition hx711.c:133
@ HX711_GAIN_B_32
Channel B, gain factor 32.
Definition hx711.h:55
@ HX711_GAIN_A_128
Channel A, gain factor 128.
Definition hx711.h:54
@ HX711_GAIN_A_64
Channel A, gain factor 64.
Definition hx711.h:56
Definition hx711.h:63