Beispiel #1
0
def cleanAndExit():
    print("Cleaning...")

    if not EMULATE_HX711:
        GPIO.cleanup()

    print("Bye!")
    sys.exit()
Beispiel #2
0
    def readNextBit(self):
       # Clock HX711 Digital Serial Clock (PD_SCK).  DOUT will be
       # ready 1us after PD_SCK rising edge, so we sample after
       # lowering PD_SCL, when we know DOUT will be stable.
       GPIO.output(self.PD_SCK, True)
       GPIO.output(self.PD_SCK, False)
       value = GPIO.input(self.DOUT)

       # Convert Boolean to int and return it.
       return int(value)
Beispiel #3
0
    def set_gain(self, gain):
        if gain is 128:
            self.GAIN = 1
        elif gain is 64:
            self.GAIN = 3
        elif gain is 32:
            self.GAIN = 2

        GPIO.output(self.PD_SCK, False)

        # Read out a set of raw bytes and throw it away.
        self.readRawBytes()
Beispiel #4
0
    def power_down(self):
        # Wait for and get the Read Lock, incase another thread is already
        # driving the HX711 serial interface.
        self.readLock.acquire()

        # Cause a rising edge on HX711 Digital Serial Clock (PD_SCK).  We then
        # leave it held up and wait 100 us.  After 60us the HX711 should be
        # powered down.
        GPIO.output(self.PD_SCK, False)
        GPIO.output(self.PD_SCK, True)

        time.sleep(0.0001)

        # Release the Read Lock, now that we've finished driving the HX711
        # serial interface.
        self.readLock.release()           
Beispiel #5
0
    def power_up(self):
        # Wait for and get the Read Lock, incase another thread is already
        # driving the HX711 serial interface.
        self.readLock.acquire()

        # Lower the HX711 Digital Serial Clock (PD_SCK) line.
        GPIO.output(self.PD_SCK, False)

        # Wait 100 us for the HX711 to power back up.
        time.sleep(0.0001)

        # Release the Read Lock, now that we've finished driving the HX711
        # serial interface.
        self.readLock.release()

        # HX711 will now be defaulted to Channel A with gain of 128.  If this
        # isn't what client software has requested from us, take a sample and
        # throw it away, so that next sample from the HX711 will be from the
        # correct channel/gain.
        if self.get_gain() != 128:
            self.readRawBytes()
Beispiel #6
0
    def __init__(self, dout, pd_sck, gain=128):
        self.PD_SCK = pd_sck

        self.DOUT = dout

        # Mutex for reading from the HX711, in case multiple threads in client
        # software try to access get values from the class at the same time.
        self.readLock = threading.Lock()
        
        GPIO.setmode(GPIO.WIRINGPI)
        GPIO.setup(self.PD_SCK, GPIO.OUT)
        GPIO.setup(self.DOUT, GPIO.IN)

        self.GAIN = 0

        # The value returned by the hx711 that corresponds to your reference
        # unit AFTER dividing by the SCALE.
        self.REFERENCE_UNIT = 1
        self.REFERENCE_UNIT_B = 1

        self.OFFSET = 1
        self.OFFSET_B = 1
        self.lastVal = int(0)

        self.DEBUG_PRINTING = False

        self.byte_format = 'MSB'
        self.bit_format = 'MSB'

        self.set_gain(gain)

        # Think about whether this is necessary.
        time.sleep(1)
Beispiel #7
0
 def is_ready(self):
     return GPIO.input(self.DOUT) == 0
Beispiel #8
0
 def set_buzzer(self, state=0):
     GPIO.output(BUZZER_PIN, state)
     return 0
Beispiel #9
0
 def get_pauseBtn(self):  # to get the state of the pause button
     return GPIO.digitalRead(PAUSE_BTN_PIN)
Beispiel #10
0
 def set_stateLed(self, state=0):
     GPIO.output(STATE_LED_PIN, state)
     return 0
Beispiel #11
0
 def get_stateLed(self):
     return GPIO.digitalRead(STATE_LED_PIN)
Beispiel #12
0
 def set_pauseLed(self, state=0):
     GPIO.output(PAUSE_LED_PIN, state)
     return 0
Beispiel #13
0
 def get_pauseLed(self):
     return GPIO.digitalRead(PAUSE_LED_PIN)
Beispiel #14
0
 def set_startLed(self, state=0):
     GPIO.output(START_LED_PIN, state)
     return 0
Beispiel #15
0
 def get_startLed(self):
     return GPIO.digitalRead(START_LED_PIN)
Beispiel #16
0
 def get_stopBtn(self):  # to get the state of the start button
     return GPIO.digitalRead(STOP_BTN_PIN)
Beispiel #17
0
 def get_buzzer(self):
     return GPIO.digitalRead(BUZZER_PIN)
Beispiel #18
0
#     - a library to communicate with the MICHA board using another main code file
#     - a standalone code to test the I/O of the MICHA board

import traceback
from serial import Serial, PARITY_NONE
from umodbus.client.serial import rtu
import Odroid.GPIO as GPIO
import time

SLAVE_ID = 1

VOLTAGE_REF = 2.497  # value of the excitement voltage reference
THERMI_WIRE = 0.6  # value of the twin wire resistor

# Odroid configuration
GPIO.setmode(GPIO.BOARD)
# pin used
START_BTN_PIN = 15  # pin on which the start button is connected
PAUSE_BTN_PIN = 13  # pin on which the pause button is connected
STOP_BTN_PIN = 33  # pin on which the start button is connected
START_LED_PIN = 16  # pin on which the start led is connected
PAUSE_LED_PIN = 18  # pin on which the pause led is connected
STATE_LED_PIN = 8  # pin on which the state led is connected
BUZZER_PIN = 35  # pin on which the buzzer is connected
# pin configuration
GPIO.setup(START_BTN_PIN, GPIO.IN)
GPIO.setup(PAUSE_BTN_PIN, GPIO.IN)
GPIO.setup(STOP_BTN_PIN, GPIO.IN)
GPIO.pinMode(STOP_BTN_PIN, GPIO.PUD_UP)
GPIO.setup(START_LED_PIN, GPIO.OUT)
GPIO.setup(PAUSE_LED_PIN, GPIO.OUT)