This works by placing one load cell ahead of the cog (say at the leading edge of the wing) and one behind (at the trailing edge). From the distribution of weight between the 2 load cells, one can calculate the position of the cog. There are several examples of such devices using an Arduino to be found on the web, but I would like to use a Pico.
As a first step, I programmed the PIO to communicate with the HX711 load cell amplifier.
My biggest problem was the lack of documentation to program and use the PIO with Python.
So if anyone can point me to some more complete documentation than available from raspberrypi.org, that would be much appreciated.
At the moment I have one specific question: How can I find out in Python, whether data is available in the FIFO?
Currently, I just wait for some time and hope that data is available.
Anyway, here is the code I have written so far:
Code: Select all
#PIO program to read HX711 load cell amplifier channel A with gain 128
'''
*
*
* The MIT License (MIT)
*
* Copyright (c) 2021 Lutz Paelke
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
'''
import time
import rp2
from machine import Pin
@rp2.asm_pio(sideset_init=rp2.PIO.OUT_LOW, set_init=rp2.PIO.IN_LOW)
def hx711():
set(x, 24) #generate 25 Pulses 1us on 1us off to initialise hx711 for channel A with gain 128
label("loop1")
nop() .side(1) [7]
nop() [1]
nop() .side(0) [6]
nop() [1]
jmp(x_dec, "loop1")
wrap_target()
wait(0,pin,0) #wait for data ready, indicated by low level
set(x, 23) #generate 24 Pulses...
label("loop2")
nop() .side(1) [7]
nop() [1]
nop() .side(0) [5]
in_(pins, 1) #... to read read 24 bits
nop() [1]
jmp(x_dec, "loop2")
nop() .side(1) [7] #generate 1 more pulse to get to 25 pulses
nop() [1]
nop() .side(0) [7]
nop() [1]
push() #write data to FIFO
wrap()
#Test Program
sm = rp2.StateMachine(0, hx711, freq=10_000_000, sideset_base=Pin(16), in_base=Pin(17))
sm.active(1)
while True:
time.sleep(0.1) #THIS IS THE PART I WOULD LIKE TO IMPROVE! (by checking, whether data is available)
Data=sm.get() #read Data from FIFO
print((Data-139700)/257) #write calibrated Data to console