예제 #1
0
def end_read(signal, frame):
    global continue_reading
    print "Ctrl+C captured, ending read."
    lcd_byte(0x01, LCD_CMD)
    continue_reading = False
    GPIO.cleanup()
    dbaccessor.closeConnection()
예제 #2
0
파일: dkekeg.py 프로젝트: rkelly07/dkekeg
def end_read(signal,frame):
    global continue_reading
    print "Ctrl+C captured, ending read."
    lcd_byte(0x01, LCD_CMD)
    continue_reading = False
    GPIO.cleanup()
    dbaccessor.closeConnection()
예제 #3
0
    print(time_str)

    if not is_lesson:
        logging.debug('No lesson today..')
        fail_led()
        print('No lesson today.. ')
    else:
        logging.debug('Lesson today - updates active')
        ack_led()
        print('Time to take roll.. ')

    eventHandler = EventHandler()
    wm = pyinotify.WatchManager()
    mask = pyinotify.IN_CLOSE_NOWRITE
    notifier = pyinotify.Notifier(wm, eventHandler)
    wdd1 = wm.add_watch(scroll_path + 'activate', mask)
    wdd2 = wm.add_watch(update_path + 'activate', mask)
    notifier.loop()


if __name__ == '__main__':

    try:
        main()
    except KeyboardInterrupt:
        logging.warning('Interrupted')
        lcd_i2c.lcd_byte(0x01, lcd_i2c.LCD_CMD)
        GPIO.cleanup()
    finally:
        GPIO.cleanup()
예제 #4
0
 def clear(self):
     lcd_i2c.lcd_byte(0x01, lcd_i2c.LCD_CMD)
예제 #5
0

def print_ip():
    lcd.lcd_string('eth1:', lcd.LCD_LINE_1)
    try:
        lcd.lcd_string(get_ip_address('eth1'), lcd.LCD_LINE_2)
    except:
        lcd.lcd_string('Not connected', lcd.LCD_LINE_2)


try:
    lcd.lcd_init()

    print_cluster_info()
    time.sleep(DISPLAY_DELAY)

    while True:
        print_ip()
        time.sleep(DISPLAY_DELAY)

        print_number_of_nodes()
        time.sleep(DISPLAY_DELAY)

        print_pods_in_openfaas()
        time.sleep(DISPLAY_DELAY)

except KeyboardInterrupt:
    pass
finally:
    lcd.lcd_byte(0x01, lcd.LCD_CMD)
예제 #6
0
def main():
    # Accepted arguments
    parser = argparse.ArgumentParser()
    parser.add_argument("gpio", help="Pin num of DHT22 sensor", type=int)
    parser.add_argument("--led", help="Pin num of LED", type=int)
    parser.add_argument("--max_temp",
                        help="Maximum acceptable temp, default 70F",
                        type=float)
    parser.add_argument("--min_temp",
                        help="Minimum acceptable temp, default 32F",
                        type=float)
    parser.add_argument("--max_rh",
                        help="Maximum acceptable humidity, default 50",
                        type=float)
    parser.add_argument("--min_rh",
                        help="Minimum acceptable humidity, default 30",
                        type=float)
    parser.add_argument("--email", help="Email destination for warnings")
    parser.add_argument("--gsheets",
                        help="Turn on Google Sheets logging, must configure",
                        action='store_true')
    args = parser.parse_args()

    try:
        # get lcd ready
        lcd.lcd_init()
        lcd.lcd_string("Starting monitor", lcd.LCD_LINE_1)
        lcd.lcd_string("script...", lcd.LCD_LINE_2)
        time.sleep(2)
        lcd.lcd_string(time.strftime("%x"), lcd.LCD_LINE_1)
        lcd.lcd_string(time.strftime("%I:%M:%S %p"), lcd.LCD_LINE_2)
        time.sleep(2)

        # get led gpio pin ready and flash it
        if args.led:
            GPIO.setmode(GPIO.BCM)
            GPIO.setup(args.led, GPIO.OUT)
            GPIO.output(args.led, True)
            time.sleep(.4)
            GPIO.output(args.led, False)

        # Get temp/humidity reading
        humidity, temp_c = dht.read_retry(dht.DHT22, args.gpio)
        fahr = 9.0 / 5.0 * temp_c + 32

        # Send reading to LCD
        lcd.lcd_string("Temp={0:0.2f}'F".format(fahr), lcd.LCD_LINE_1)
        lcd.lcd_string("Humidity={0:0.2f}%".format(humidity), lcd.LCD_LINE_2)

        # Check reading for alarm conditions if email is on:
        warned = warning_condition(fahr,
                                   humidity,
                                   email=args.email,
                                   max_temp=args.max_temp or 70.00,
                                   min_temp=args.min_temp or 32.00,
                                   max_rh=args.max_rh or 50.00,
                                   min_rh=args.min_rh or 30.00)

        # Write data to file
        with open("/home/pi/pem-pi/data/temperature_humidity.txt",
                  "a") as myfile:
            myfile.write(dt.now().strftime('%Y-%m-%d %H:%M') + "\t" +
                         "{0:.2f}".format(fahr) + "\t" +
                         "{0:.2f}".format(humidity))
            myfile.write("\n")
            # optionally, send data to google sheets
            if args.gsheets:
                write_spreadsheet([
                    dt.now().strftime('%Y-%m-%d %H:%M'),
                    "{0:.2f}".format(fahr), "{0:.2f}".format(humidity)
                ])

    except KeyboardInterrupt:
        print "Quitting..."
        lcd.lcd_byte(0x01, lcd.LCD_CMD)
    finally:
        # clean up
        GPIO.cleanup()
예제 #7
0
def rover(full_i2c):

    # Re-direct our output to standard error, we need to ignore standard out
    # to hide some nasty print statements from pygame
    sys.stdout = sys.stderr

    # Setup the PicoBorg Reverse
    PBR = PicoBorgRev.PicoBorgRev()
    # Uncomment and change the value if you have changed the board address
    # PBR.i2cAddress = 0x44
    PBR.Init()
    if not PBR.foundChip:
        boards = PicoBorgRev.ScanForPicoBorgReverse()
        if len(boards) == 0:
            print('No PicoBorg Reverse found, check you are attached :)')
        else:
            print('No PicoBorg Reverse at address %02X,'
                  'but we did find boards:' % (PBR.i2cAddress))
            for board in boards:
                print('    %02X (%d)' % (board, board))
            print('If you need to change the I�C address change the setup'
                  'line so it is correct, e.g.')
            print('PBR.i2cAddress = 0x%02X' % (boards[0]))
        sys.exit()
    # PBR.SetEpoIgnore(True)     # Uncomment to disable EPO latch,
    #                            # needed if you do not have a switch / jumper
    # Ensure the communications failsafe has been enabled!
    failsafe = False
    for i in range(5):
        PBR.SetCommsFailsafe(True)
        failsafe = PBR.GetCommsFailsafe()
        if failsafe:
            break
    if not failsafe:
        print('Board %02X failed to report in failsafe mode!' %
              (PBR.i2cAddress))
        sys.exit()
    PBR.ResetEpo()

    # Settings for the joystick
    axisUpDown = 1  # Joystick axis to read for up / down position
    axisUpDownInverted = False  # Set this to True if up and down appear to be swapped
    axisLeftRight = 0  # Joystick axis to read for left / right position
    axisLeftRightInverted = False  # Set this to True if left and right appear to be swapped
    buttonResetEpo = 4  # Joystick button number to perform an EPO reset (Start)
    buttonSlow = 0  # Joystick button number for driving slowly whilst held (L2)
    slowFactor = 0.5  # Speed to slow to when the drive slowly button is held, e.g. 0.5 would be half speed
    buttonFastTurn = 2  # Joystick button number for turning fast (R2)
    interval = 0.10  # Time between updates in seconds, smaller responds faster but uses more processor time

    # buttonRight = 7
    # buttonUp = 6
    # buttonLeft = 5
    # buttonDown = 4

    pitch = 0.0
    # pitch_delta = 0.02
    direction = 0.0
    # direction_delta = 0.02

    if (full_i2c):
        time.sleep(1)
        UB = UltraBorg.UltraBorg()
        UB.Init()
        UB.SetServoPosition1(pitch)
        UB.SetServoPosition2(direction)
        time.sleep(1)

        XLoBorg.Init()
        time.sleep(1)

        # Initialise display
        lcd_i2c.lcd_init()

        cp = compass.Compass()

    doCalibration = -1
    isCalibrated = 0
    delayReadCount = 0

    # Power settings
    voltageIn = 12.0  # Total battery voltage to the PicoBorg Reverse
    voltageOut = 12.0 * 0.95  # Maximum motor voltage, we limit it to 95% to allow the RPi to get uninterrupted power

    # Setup the power limits
    if voltageOut > voltageIn:
        maxPower = 1.0
    else:
        maxPower = voltageOut / float(voltageIn)

    # Setup pygame and wait for the joystick to become available
    PBR.MotorsOff()
    os.environ[
        "SDL_VIDEODRIVER"] = "dummy"  # Removes the need to have a GUI window
    pygame.init()
    # pygame.display.set_mode((1,1))
    print('Waiting for joystick... (press CTRL+C to abort)')
    while True:
        try:
            try:
                pygame.joystick.init()
                # Attempt to setup the joystick
                if pygame.joystick.get_count() < 1:
                    # No joystick attached, toggle the LED
                    PBR.SetLed(not PBR.GetLed())
                    pygame.joystick.quit()
                    time.sleep(0.5)
                else:
                    # We have a joystick, attempt to initialise it!
                    joystick = pygame.joystick.Joystick(0)
                    break
            except pygame.error:
                # Failed to connect to the joystick, toggle the LED
                PBR.SetLed(not PBR.GetLed())
                pygame.joystick.quit()
                time.sleep(0.5)
        except KeyboardInterrupt:
            # CTRL+C exit, give up
            print('\nUser aborted')
            PBR.SetLed(True)
            sys.exit()
    print('Joystick found')
    joystick.init()
    PBR.SetLed(False)

    try:
        print('Press CTRL+C to quit')
        driveLeft = 0.0
        driveRight = 0.0
        running = True
        hadEvent = False
        upDown = 0.0
        leftRight = 0.0
        # Loop indefinitely
        while running:
            # Get the latest events from the system
            hadEvent = False
            events = pygame.event.get()
            # Handle each event individually
            for event in events:
                if event.type == pygame.QUIT:
                    # User exit
                    running = False
                elif event.type == pygame.JOYBUTTONDOWN:
                    # A button on the joystick just got pushed down
                    hadEvent = True
                elif event.type == pygame.JOYAXISMOTION:
                    # A joystick has been moved
                    hadEvent = True
                if hadEvent:

                    # Read axis positions (-1 to +1)
                    if axisUpDownInverted:
                        upDown = -joystick.get_axis(axisUpDown)
                    else:
                        upDown = joystick.get_axis(axisUpDown)
                    if axisLeftRightInverted:
                        leftRight = -joystick.get_axis(axisLeftRight)
                    else:
                        leftRight = joystick.get_axis(axisLeftRight)
                    # Apply steering speeds
                    if not joystick.get_button(buttonFastTurn):
                        leftRight *= 0.5
                    # Determine the drive power levels
                    driveLeft = -upDown
                    driveRight = -upDown
                    if leftRight < -0.05:
                        # Turning left
                        driveLeft *= 1.0 + (2.0 * leftRight)
                    elif leftRight > 0.05:
                        # Turning right
                        driveRight *= 1.0 - (2.0 * leftRight)
                    # Check for button presses
                    if joystick.get_button(buttonResetEpo):
                        PBR.ResetEpo()
                    if joystick.get_button(buttonSlow):
                        driveLeft *= slowFactor
                        driveRight *= slowFactor

                    pitch = joystick.get_axis(4)
                    direction = -joystick.get_axis(3)
                    #                if joystick.get_button(buttonUp):
                    #                    if pitch < 1.0:
                    #                        pitch += pitch_delta;
                    #                if joystick.get_button(buttonDown):
                    #                    if pitch > -1.0:
                    #                        pitch -= pitch_delta;
                    #                if joystick.get_button(buttonLeft):
                    #                    if direction > -1.0:
                    #                        direction -= direction_delta;
                    #                if joystick.get_button(buttonRight):
                    #                    if direction < 1.0:
                    #                        direction += direction_delta;
                    if (full_i2c):
                        if joystick.get_button(1):
                            if (doCalibration != 1):
                                lcd_i2c.lcd_string("Calibrating...",
                                                   lcd_i2c.LCD_LINE_1)
                                lcd_i2c.lcd_string("Drive in circles",
                                                   lcd_i2c.LCD_LINE_2)
                                time.sleep(2)
                                lcd_i2c.lcd_byte(
                                    0x01,
                                    lcd_i2c.LCD_CMD)  # 000001 Clear display
                                doCalibration = 1
                        if joystick.get_button(3):
                            if (doCalibration == 1):
                                lcd_i2c.lcd_string("Calibration",
                                                   lcd_i2c.LCD_LINE_1)
                                lcd_i2c.lcd_string("stopped",
                                                   lcd_i2c.LCD_LINE_2)
                                time.sleep(2)
                                lcd_i2c.lcd_byte(
                                    0x01,
                                    lcd_i2c.LCD_CMD)  # 000001 Clear display
                                doCalibration = 0
                                cp.calibrate_compass()
                                print("number of samples: %d" % len(cp.rawX))
                                print("D1 origin: %d, scale %d" %
                                      (cp.origin_D1, cp.scale_D1))
                                print("D2 origin: %d, scale %d" %
                                      (cp.origin_D2, cp.scale_D2))
                                isCalibrated = 1
                        UB.SetServoPosition1(pitch)
                        UB.SetServoPosition2(direction)
                        # UB.SetServoPosition1(upDown)
                        # UB.SetServoPosition2(leftRight)

                    # Set the motors to the new speeds
                    PBR.SetMotor1(driveRight * maxPower)
                    PBR.SetMotor2(-driveLeft * maxPower)
                    print("joystick up/down: %.2f left/right %.2f" %
                          (upDown, leftRight))
                    print("direction:%.2f pitch: %.2f" % (direction, pitch))

            # Change the LED to reflect the status of the EPO latch
            PBR.SetLed(PBR.GetEpo())
            # Wait for the interval period
            time.sleep(interval)

            if (doCalibration == 1):
                mx, my, mz = XLoBorg.ReadCompassRaw()
                cp.push_calibration_value(mx, my, mz)
    #            print("Raw data: %d %d %d" % (mx, my, mz))
    #            lcd_i2c.lcd_string("calibrating...",lcd_i2c.LCD_LINE_1)
            if (isCalibrated == 1):
                if (delayReadCount < 10):
                    delayReadCount += 1
                else:
                    mx, my, mz = XLoBorg.ReadCompassRaw()
                    heading = cp.get_heading(mx, my, mz)
                    #            print("Direction: %d" % heading)
                    lcd_i2c.lcd_string("Direction: %d" % heading,
                                       lcd_i2c.LCD_LINE_1)
                    delayReadCount = 0
        # Disable all drives
        PBR.MotorsOff()
    except KeyboardInterrupt:
        # CTRL+C exit, disable all drives
        PBR.MotorsOff()
        if (full_i2c):
            UB.SetServoPosition1(0.0)
            UB.SetServoPosition2(0.0)
예제 #8
0
파일: rover.py 프로젝트: huegli/resin-hgbot
 #                    if pitch > -1.0:
 #                        pitch -= pitch_delta;
 #                if joystick.get_button(buttonLeft):
 #                    if direction > -1.0:
 #                        direction -= direction_delta;
 #                if joystick.get_button(buttonRight):
 #                    if direction < 1.0:
 #                        direction += direction_delta;
 if joystick.get_button(12):
     if (doCalibration != 1):
         lcd_i2c.lcd_string("Calibrating...",
                            lcd_i2c.LCD_LINE_1)
         lcd_i2c.lcd_string("Drive in circles",
                            lcd_i2c.LCD_LINE_2)
         time.sleep(2)
         lcd_i2c.lcd_byte(
             0x01, lcd_i2c.LCD_CMD)  # 000001 Clear display
         doCalibration = 1
 if joystick.get_button(14):
     if (doCalibration == 1):
         lcd_i2c.lcd_string("Calibration", lcd_i2c.LCD_LINE_1)
         lcd_i2c.lcd_string("stopped", lcd_i2c.LCD_LINE_2)
         time.sleep(2)
         lcd_i2c.lcd_byte(
             0x01, lcd_i2c.LCD_CMD)  # 000001 Clear display
         doCalibration = 0
         cp.calibrate_compass()
         print("number of samples: %d" % len(cp.rawX))
         print("D1 origin: %d, scale %d" %
               (cp.origin_D1, cp.scale_D1))
         print("D2 origin: %d, scale %d" %
               (cp.origin_D2, cp.scale_D2))