def main():
    from gpiozero import MCP3002, AngularServo
    from time import sleep

    pot1 = MCP3002(1, max_voltage=5, clock_pin=11, mosi_pin=10, miso_pin=9, select_pin=8)
    pot2 = MCP3002(1, max_voltage=5, clock_pin=15, mosi_pin=14, miso_pin=13, select_pin=12)

    servo1 = AngularServo(17, min_angle=0, max_angle=159)
    servo1.angle = 0
    servo2 = AngularServo(18, min_angle=-60, max_angle=240)
    servo2.angle = -60

    while True:
        print(f"pot1: value = {pot1.value:0.2f}\tvoltage = {pot1.voltage:0.2f}\traw value = {pot1.raw_value:0.2f}")
        servo1.angle = 159 * pot1.value

        print(f"pot2: value = {pot2.value:0.2f}\tvoltage = {pot2.voltage:0.2f}\traw value = {pot2.raw_value:0.2f}")
        servo2.angle = -60 + 300 * pot2.value

        sleep(0.1)
Ejemplo n.º 2
0
def main():
    # 計算用の3.3V
    Vref = 3.3

    # 初期化
    factory = PiGPIOFactory()
    adc_ch0 = MCP3002(channel=0, max_voltage=Vref, pin_factory=factory)

    while True:
        # MCP3002からの出力値と電圧値を表示
        print(f'value:{adc_ch0.value:.2f}, Volt:{adc_ch0.value * Vref:.2f}')
        sleep(1)
    return
Ejemplo n.º 3
0
def runFan():
    pot = MCP3002(channel=0, device=1)
    volts = pot.value * 3.3
    # convert volts to degrees F,
    # 0 to 1 volts = -56 to 156 degrees C, then convert to degrees F
    temperature = pot.value * 629.64 - 68.8
    avgTemp = tAvg.value(temperature)
    if debug:
        print("pot value = %2.3f   volts = %2.3f   temperature = %3.3f" %
              (pot.value, volts, avgTemp))
    # Note that pwm value may range from 0 (fully off) to 1.0 (fully on)
    if (avgTemp > 95):
        if (avgTemp > 110):
            fan.value = 1.0
        else:
            fan.value = 0.5
    else:
        fan.value = 0
    return avgTemp
Ejemplo n.º 4
0
# this script exists on the rapberrypi Desktop and is the source of this script usage
from gpiozero import MCP3002

reading = MCP3002(0)
print(reading.value * 1000)
Ejemplo n.º 5
0
GPIO.setmode(GPIO.BCM)

# 気温センサインスタンス
instance = dht11.DHT11(pin=18)

# 気圧センサ初期化
bus = smbus.SMBus(1)
bus.write_byte_data(ADDR, CTRL_REG1, WRITE_REG1)

# 定期的にシートを更新しないとエラーになる?

# 土壌センサ(A/Dコンバータ)初期化

Vref = 3.3
factory = PiGPIOFactory()
adc_ch0 = MCP3002(channel=0, max_voltage=Vref, pin_factory=factory)
adc_ch1 = MCP3002(channel=1, max_voltage=Vref, pin_factory=factory)


def get_sheet():
    scope = [
        "https://www.googleapis.com/auth/spreadsheets",
        "https://www.googleapis.com/auth/drive"
    ]
    credentials = ServiceAccountCredentials.from_json_keyfile_name(
        "line-bot-project1-0a7f2b46fc9e.json", scope)
    gc = gspread.authorize(credentials)
    workbook = gc.open_by_key(SPREADSHEET_KEY)
    sh1 = workbook.worksheet("シート1")
    sh2 = workbook.worksheet("シート2")
    return sh1, sh2
Ejemplo n.º 6
0
            light_led.off()

        # should the thread continue reading form the sensor
        if continue_sensing:
            sleep(1)
        else:
            break


if __name__ == "__main__":
    # create the leds
    temp_led = LED("GPIO27")
    light_led = LED("GPIO22")

    # create the sensor channels on the MCP3002
    temp_sensor = MCP3002(channel=0)
    light_sensor = MCP3002(channel=1)

    # create a separate thread for each sensor
    temp_thread = threading.Thread(target=monitor_temp,
                                   args=(temp_sensor, temp_led))
    light_thread = threading.Thread(target=monitor_light,
                                    args=(light_sensor, light_led))
    print("Hit 'Q' to Quit")

    # start checking each sensor
    temp_thread.start()
    light_thread.start()

    # allow the user to exit the program by pressing 'q'
    while continue_sensing: