# HX711 for Raspbery Pi
This code is credited to [underdoeg](https://github.com/underdoeg/)'s gist [ HX711.py](https://gist.github.com/underdoeg/98a38b54f889fce2b237).
I've only made a few modifications on the way the captured bits are processed and to support Two's Complement, which it didn't.
I'm currently trying to improve this version. It's actually working, I'd use `hx711v_0_5_1.py`.
## Warning: Possible random values
> **Possible random values!**
> Polling the bits from the HX711 is a time sensitive process as explained in the HX711 the datasheet. Raspberry runs on Linux which is not a good tool for time sensitive operations using the GPIO pins because tasks are prioritized by the Operative System which might delay a GPIO operation, causing the library to fail to poll the bits following the specified timing in the datasheet. It could also happen that the commands that poll the pins up and down run too fast for the HX711.
>
> If there is a right way to precisely poll the bits with a Raspberry Pi (i.e. Linux OS) following the datasheet's timing specifications, which is in microseconds, which is a millionth of a second, then this code is probably not doing it in that right way and might return random values if other processes are running simultanously, delaying the GPIO operations, or if the processor is not busy with anything else at all, allowing the GPIO operations to happen too fast.
>
> I know very little about OS architecture, but it seems to me that this two scenarios could happen. I'm not event a developer as you can see by how ugly the code and my commits are, so I'd think twice before trusting this code, haha.
>
> I'm think that a better idea is to wire the HX711 to an MCU and the MCU to the Raspberry Pi. The MCU could poll a pin to trigger an event on the Raspberry Pi so that the Pi could retrieve the data from the MCU using 1-Wire or I2C, probably. Maybe a feature for the future.
>
> So, at the risk of repeating myself, I do recommend using an Arduino or any MCU instead of a Raspberry Pi to poll bits from the HX711. and if you really need an Raspberry involved, then have the Arduino send the information to the Raspberry Pi vía I2C or 1-Wire. Hope this library helps, though.
## Table of contents
1. [Files description](#files-description)
2. [Instructions](#instructions)
3. [Usage with two channels](#usage-with-two-channels)
4. [Changelog](#changelog)
## Files description
File descriptions:
- `hx711.py`: v0.1 code. Readings are not near as frequent as they could be. Currently, it's barely doing 1 reading per second when the HX711 allows for 10SPS (Samples Per Second), which translates to 10 readings per second.
- `example.py`: Example of how to use `hx711.py`. The exaplanation is not good at all.
- `hx711_emulator.py`: This is a class that emulates the behaviour of my original HX711 class. It's actually more a simulator than an emulator.
- `example_emulator.py`: Show an example but using the emulator class.
- `hx711v0_5_1.py`: This a new version I've just created, _**tested and working pretty well**_, with the objective of allowing 10 readings per second. They will be provided by some sort of event I still need to figure out how to create and how to throttle somehow.
- `example_hx711v0_5_1.py`:
## Instructions
### New Version
No "setup.py" required if you're on Raspbian OS. I'm actually using the Lite Version without GUI to avoid processes messing up with the bit polling process.
#### Interrupt based
```bash
clone git@github.com:tatobari/hx711py.git
python example_hx711v0_5_1.py
```
![Interrupt based](./resources/HX711PY-example-interrupt-based.gif)
#### Polling based
```bash
clone git@github.com:tatobari/hx711py.git
python example_hx711v0_5_1.py --polling-based
```
![Interrupt based](./resources/HX711PY-example-polling-based.gif)
### Legacy Version
To install the old version (hx711.py):
```bash
clone git@github.com:tatobari/hx711py.git
python setup.py install
python example.py
```
## About using the two channels of one breakout board
This is a completely unnecessary feature that I, for some reason, decided to include in the original code. Anyway, in theory, it allows using two loadcells at the same time but they would have different two gains. So, though they would provide different raw values, both provide weights, just with different accuracy.
I haven't tested the use of two loadcells on the same breakout board at the same time. It might not work.
Channel A has selectable gain of 128 or 64. Using set_gain(128) or set_gain(64) selects channel A with the specified gain.
Using set_gain(32) selects channel B at the fixed gain of 32. The tare_B(), get_value_B() and get_weight_B() functions do this for you.
This info was obtained from an HX711 datasheet located at:
https://cdn.sparkfun.com/datasheets/Sensors/ForceFlex/hx711_english.pdf
## Changelog
### 03/03/2023
- Changed the filename of the new version to make a bit more sense (Sorry for not making a new branch for the new verison.).
- Added example file for v0.5.1.
- Added GIF examples of new library to README.md.
- Added example commands to README.md.
- **Tested v0.5.1 and working.**
### 28/02/2023
I'm only using my lunch time to commit changes in order to close all the HX711 environment on my mac because I need more processing power.
This version adds new methods to allow the use of interrupts as an alternative to polling.
### 25/02/2023
Funily enough and by pure accident, exactly two years after updating the README.md file with false promises, I'm back making a few changes.
My motivation to update this code is to improve the reading frequency.
### 25/02/2021
For the past years I haven't been able to maintain this library because I had too much workload. Now I'm back and I've been working on a few fixes and modifications to simplify this library, and I might be commiting the branch by mid-March. I will also publish it to PIP.
没有合适的资源?快使用搜索试试~ 我知道了~
嵌入式人工智能(树莓派4B基础实验代码等)
共104个文件
py:78个
xml:5个
ttf:2个
1 下载量 23 浏览量
2024-08-04
12:56:25
上传
评论 1
收藏 18.91MB RAR 举报
温馨提示
本系列实验不仅让同学们了解树莓派开发板,而且在此基础上对物联网传感器,云计算。人工智能、大数据也有一定的认识,尤其是为同学们今后职业方向--嵌入式人工智能打下坚实的基础。使同学们在平时课程学习的时候有一定的针对性和方向性,能为同学们参加学科类技能竞赛提供帮助,为同学们毕业设计提供资料,为同学们准备或进行创新创业等项目上拓宽眼界,启发思维、引导创新奠定基础。如果本专栏实验能做到以上任何一点点,都是我的荣幸。
资源推荐
资源详情
资源评论
收起资源包目录
嵌入式人工智能(树莓派4B基础实验代码等) (104个子文件)
32_rtc_ds1302 13KB
32_rtc_ds1302.c 7KB
dht11.c 2KB
lircd.conf 15KB
dht11 69KB
HX711PY-example-interrupt-based.gif 2.38MB
HX711PY-example-polling-based.gif 2.03MB
.gitignore 184B
.gitignore 31B
adafruit-circuitpython-fingerprint-2.2.15.tar.gz 33KB
Embed_Python.iml 412B
2.jpg 6KB
LICENSE 11KB
README.md 6KB
32_rtc_ds1302.o 6KB
HX711-Aviasemiconductor.pdf 157KB
hx711v0_5_1.py 14KB
hx711.py 12KB
hx711.py 12KB
hx711_emulator.py 9KB
TM1638.py 9KB
TM1638.py 8KB
TM1638.py 8KB
TM1638.py 8KB
TM1638.py 8KB
fingerprint_simpletest_rpi.py 8KB
bmp280_Smbus.py 6KB
ds1302.py 4KB
Encode11.py 4KB
pca9685.py 4KB
example_hx711v0_5_1.py 4KB
tm1638test.py 4KB
Fingerprint_Oled.py 3KB
LCD1602.py 3KB
noActBeep.py 3KB
ds1302_Dispaly.py 3KB
HMC5883L.py 3KB
example.py 3KB
Themistor_Value.py 3KB
Oled_IP.py 3KB
Infrared.py 2KB
Setp_Motor.py 2KB
MPU6050_1.py 2KB
OLED_HX711.py 2KB
HC_SR04.py 2KB
My_ds1302.py 2KB
MFRC522.py 2KB
Fingerprint.py 2KB
显示图片.py 2KB
My_PCF8591.py 2KB
MQ_DQ_Beep.py 2KB
ds18b20.py 2KB
电子称.py 2KB
Mysql_func.py 2KB
Mysql_func.py 2KB
Button_Interrupt.py 2KB
Mysql_func.py 2KB
Syn6288.py 2KB
Threading.py 2KB
PCF8574_lcd1602.py 2KB
BH1750.py 2KB
FW_tm1638.py 1KB
ServoMotor.py 1KB
1.py 1KB
显示中文.py 1KB
AT-09BT.py 1KB
MQ3_AO.py 1KB
Dc_Motor.py 1KB
test.py 1KB
LEDS_PWM.py 1KB
Temp_To_DB.py 1KB
1-上拉电阻实现LED控制.py 1KB
Voice_SensorDo.py 1KB
Relay.py 1KB
Breath.py 1KB
Servo.py 961B
Voice_SensorAO.py 913B
sw420.py 794B
beep.py 766B
Photosensor.py 741B
dht11.py 740B
tcs34725.py 735B
Serial.py 733B
Keyboard_Interrupt.py 671B
ircontrol.py 668B
Infra.py 624B
bmp280_demo.py 602B
CSI_Test.py 565B
example_emulator.py 558B
MPU6050_2.py 545B
ky003.py 544B
Led.py 478B
PWM_Led.py 400B
setup.py 197B
TM1638.cpython-311.pyc 14KB
BMP280libraries.rar 63KB
STKAITI.TTF 12.15MB
SIMKAI.TTF 11.24MB
workspace.xml 15KB
deployment.xml 1KB
共 104 条
- 1
- 2
资源评论
u010152658
- 粉丝: 1046
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- apache-maven-3.6.1-bin.zip
- c593f5fc-d4a7-4b43-8ab2-51afc90f3f62
- IIR滤波器参数计算函数
- WPF树菜单拖拽功能,下级目录拖到上级目录,上级目录拖到下级目录.zip
- CDH6.3.2版本hive2.1.1修复HIVE-14706后的jar包
- 鸿蒙项目实战-天气项目(当前城市天气、温度、湿度,24h天气,未来七天天气预报,生活指数,城市选择等)
- Linux环境下oracle数据库服务器配置中文最新版本
- Linux操作系统中Oracle11g数据库安装步骤详细图解中文最新版本
- SMA中心接触件插合力量(插入力及分离力)仿真
- 变色龙记事本,有NPP功能,JSONview功能
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功