I am trying to read from this popular HX711 breakout board with an Adafruit Huzzah ESP8266 and a stock esp8266-20161110-v1.8.6.bin
This is the component for a digital scale, sparkfun has some pictures.
This chip has a non-standard protocol, the datasheet describes:
My load cell and the HX711 board do work fineSerial Interface
Pin PD_SCK and DOUT are used for data retrieval, input selection, gain selection and power down controls.
When output data is not ready for retrieval, digital output pin DOUT is high. Serial clock input PD_SCK should be low. When DOUT goes to low, it indicates data is ready for retrieval. By applying 25~27 positive clock pulses at the PD_SCK pin, data is shifted out from the DOUT output pin. Each PD_SCK pulse shifts out one bit, starting with the MSB bit first, until all 24 bits are shifted out. The 25th pulse at PD_SCK input will pull DOUT pin back to high (Fig.2).
- with an Arduino UNO and 5V
- with an Arduino UNO and 3.3V
both times with the popular library.
There is a RPi.GPIO-based implementation available.
Here is MY problem with MY code:
All I get back is "1" from the data pin.
The code (I just print out the values from the data pin, not doing any bit operations (or struct) yet) is as following:
Code: Select all
# -*- coding: utf-8 -*-
"""
An implementation of the HX711 board reading load cell(s).
"""
import time
import ustruct as struct # pylint: disable=import-error
from machine import Pin # pylint: disable=import-error
class HX711:
""" Reading from a HX711 board by s simple serial protocol.
"""
def __init__(self, pd_sck=4, dout=5, gain=128):
self.gain = gain #unused, todo: 128 = 3 times sck high->low
self.dataPin = Pin(dout, Pin.IN)
self.pdsckPin = Pin(pd_sck, Pin.OUT, value=0)
self.pdsckPin.low()
time.sleep(1)
self.powerDown()
self.powerUp()
self.read()
def isready(self):
"""When output data is not ready for retrieval,
digital output pin DOUT is high.
"""
print("<waiting> dataPin: {}, sckPin: {}".format(self.dataPin.value(), self.pdsckPin.value()))
return self.dataPin.value() == 0
def read(self):
"""Reading from the board.
"""
self.powerUp()
while not self.isready():
pass
print("<waiting finished> dataPin: {}, sckPin: {}".format(self.dataPin.value(), self.pdsckPin.value()))
for i in range(24):
self.pdsckPin.high()
time.sleep_us(2)
print("<{}> dataPin: {}, sckPin: {}".format(i, self.dataPin.value(), self.pdsckPin.value()))
self.pdsckPin.low()
#print(i, self.dataPin.value(), self.pdsckPin.value())
time.sleep_us(2)
for i in range(3):
#print(i)
self.pdsckPin.high()
time.sleep_us(2)
print(i, self.dataPin.value(), self.pdsckPin.value())
self.pdsckPin.low()
time.sleep_us(2)
self.powerDown()
time.sleep(2)
def powerDown(self):
"""Power the HX711 down as per datasheet: Setting high longer than 60 microseconds.
"""
self.pdsckPin.low()
self.pdsckPin.high()
time.sleep_us(80)
def powerUp(self):
"""Power the HX711 up.
"""
self.pdsckPin.low()
Code: Select all
dataPin: 1, sckPin: 0
<waiting> dataPin: 1, sckPin: 0
<waiting> dataPin: 1, sckPin: 0
<waiting> dataPin: 1, sckPin: 0
<waiting> dataPin: 1, sckPin: 0
<waiting finished> dataPin: 0, sckPin: 0
<0> dataPin: 1, sckPin: 1
<1> dataPin: 1, sckPin: 1
<2> dataPin: 1, sckPin: 1
<3> dataPin: 1, sckPin: 1
<4> dataPin: 1, sckPin: 1
<5> dataPin: 1, sckPin: 1
<6> dataPin: 1, sckPin: 1
<7> dataPin: 1, sckPin: 1
<8> dataPin: 1, sckPin: 1
<9> dataPin: 1, sckPin: 1
<10> dataPin: 1, sckPin: 1
<11> dataPin: 1, sckPin: 1
<12> dataPin: 1, sckPin: 1
<13> dataPin: 1, sckPin: 1
<14> dataPin: 1, sckPin: 1
<15> dataPin: 1, sckPin: 1
<16> dataPin: 1, sckPin: 1
<17> dataPin: 1, sckPin: 1
<18> dataPin: 1, sckPin: 1
<19> dataPin: 1, sckPin: 1
<20> dataPin: 1, sckPin: 1
<21> dataPin: 1, sckPin: 1
<22> dataPin: 1, sckPin: 1
<23> dataPin: 1, sckPin: 1
0 1 1
1 1 1
2 1 1
Has anybody a digital scale working? That board is seemingly ubiquitous and the very same hardware works with my Arduino. So it _must_ be my code -- maybe someone spots a problem?
Asks with best regards,
Chris