示例#1
0
文件: grovetemp.py 项目: zzas11/upm
def main():
    # Create the temperature sensor object using AIO pin 0
    temp = grove.GroveTemp(0)
    print(temp.name())

    # Read the temperature ten times, printing both the Celsius and
    # equivalent Fahrenheit temperature, waiting one second between readings
    for i in range(0, 10):
        celsius = temp.value()
        fahrenheit = celsius * 9.0/5.0 + 32.0;
        print("%d degrees Celsius, or %d degrees Fahrenheit" \
            % (celsius, fahrenheit))
        time.sleep(1)

    # Delete the temperature sensor object
    del temp
示例#2
0
    def __init__(self, commander, sensor_room, sensor_name, sensor_id, \
        temp_sensor_pin, temp_sensor_only=False):
        '''Init method for Sensor object.

        Note: 'has_passed_threshold' is a flag for tracking when sensor has passed 
        uppoer or lower threshold (to help track whether to evaluate calling 
        closeValve()).

        :param MissionControl commander: MissionControl object instance that 
            started the sensor.
        :param str sensor_room: Room name where physical sensor HW module is located.
        :param str sensor_name: Name of individual sensor HW module in the room.
        :param int temp_sensor_pin: AIO pin that temp sensor is on (typically 0).
        :param bool temp_sensor_only: Optional param to indicate that the module only
            has a temperature sensor (typically for demo purposes).

        :return: Sensor object
        '''

        self.commander = commander
        self.sensor_room = sensor_room
        self.sensor_name = sensor_name
        self.sensor_id = sensor_id
        self.temp_sensor_pin = temp_sensor_pin
        self.temp_sensor_only = temp_sensor_only
        self.latest_temp_c = None
        self.latest_temp_f = None
        self.has_passed_threshold = False
        self.valve_open = False

        self.temp = grove.GroveTemp(
            self.temp_sensor_pin)  # Create temp sensor obj

        if not self.temp_sensor_only:
            # Instantiate a Stepper motor on a ULN200XA Darlington Motor Driver
            # This was tested with the Grove Geared Step Motor with Driver
            # Instantiate a ULN2003XA stepper object
            # Note: The other numbers are pins it's connected to on the board
            self.stepperMotor = upmULN200XA.ULN200XA(STEPPER_STEPS, 8, 9, 10,
                                                     11)
            atexit.register(self.exitHandler)  # Register exit handlers
            signal.signal(signal.SIGINT, self.SIGINTHandler)
            self.stepperMotor.setSpeed(STEPPER_SPEED)

            # Set up the LCD
            self.lcd = lcd.Jhd1313m1(0, 0x3E, 0x62)
示例#3
0
def main():
    #POT connected to AIO pin 0
    knob = grove.GroveRotary(0)
    #Temperature sensor connected to AIO pin 1
    temp = grove.GroveTemp(1)
    # Initialize Jhd1313m1 at 0x3E (LCD_ADDRESS) and 0x62 (RGB_ADDRESS)
    myLcd = lcd.Jhd1313m1(0, 0x3E, 0x62)
    # Loop indefinitely
    while True:
        # Read values
        abs = knob.abs_value()
        print("Abs values: " + str(abs))
        sleep(1)
        if abs < 100:
            myLcd.clear()
            # Set background color to Blue
            myLcd.setColor(0, 0, 255)  #RGB
            # Zero the cursor
            myLcd.setCursor(0, 0)
            # Print the IP address for wlan0
            ip = get_ip_address('wlan0')
            myLcd.write("IP " + ip)
            sleep(1)
        elif abs > 100 and abs < 500:
            #Getting grove temperature value
            print(temp.name())
            for i in range(0, 10):
                celsius = temp.value()
                fahrenheit = celsius * 9.0 / 5.0 + 32.0
                print("%d degrees Celsius, or %d degrees Fahrenheit" \
                         % (celsius, fahrenheit))
                sleep(1)
            myLcd.clear()
            myLcd.setColor(255, 0, 0)  #RGB
            myLcd.setCursor(0, 0)
            myLcd.write("Temp " + str(fahrenheit) + " F")
        else:
            #Printing a big thank you!
            myLcd.clear()
            myLcd.setColor(0, 255, 0)  #RGB
            myLcd.setCursor(0, 0)
            myLcd.write("Thanks element14")
            myLcd.setCursor(1, 0)
            myLcd.write("and Intel")
            sleep(1)
示例#4
0
def main():
    # Initialize Jhd1313m1 at 0x3E (LCD_ADDRESS) and 0x62 (RGB_ADDRESS)
    myLcd = lcd.Jhd1313m1(0, 0x3E, 0x62)

    myLcd.setCursor(0, 0)  # Set LCD cursory to write out the top line
    myLcd.setColor(0, 0, 255)  # By default, set LCD color to blue
    myLcd.write("Current temp:")  # Write out label for temperature

    # Create the temperature sensor object using AIO pin 0
    temp = grove.GroveTemp(0)
    # print(temp.name())

    # Read the temperature ten times, printing both the Celsius and
    # equivalent Fahrenheit temperature, waiting one second between readings
    for i in range(0, 30):
        celsius = temp.value()
        fahrenheit = celsius * 9.0 / 5.0 + 32.0
        # print("%d degrees Celsius, or %d degrees Fahrenheit" \
        #     % (celsius, fahrenheit))
        tempString = "%s C / %s F" % (celsius, fahrenheit)

        # Update LCD output
        myLcd.setCursor(1, 0)  # Move cursor to next line
        if celsius >= 25:  # If it gets above 24 C, turn screen red
            myLcd.setColor(255, 0, 0)
            myLcd.write(tempString)
        elif (celsius == 24):
            myLcd.setColor(0, 255, 0)
            myLcd.write(tempString)
        else:  # TODO: Is there a getColor method?
            myLcd.setColor(0, 0, 255)
            myLcd.write(tempString)

        time.sleep(1)

    # Delete the temperature sensor object
    del temp
示例#5
0
# Create by Carmelito to send sensor data to IFTTT so that you work your magic,this is based on
# Grove Light sensor https://github.com/intel-iot-devkit/upm/blob/master/examples/python/grovelight.py
# Grove Temp https://github.com/intel-iot-devkit/upm/blob/master/examples/python/grovetemp.py
# Grove Pot https://github.com/intel-iot-devkit/upm/blob/master/examples/python/groverotary.py
import requests
from time import sleep
from upm import pyupm_grove as grove

#get the api key from Maker Webhooks channel https://ifttt.com/services/maker_webhooks/settings
#example URL https://maker.ifttt.com/use/xxxxxxxxxxxxxxxxxxxxx
api_key = 'xxxxxxxxxxxxxxxxxxxxx'
event = 'from_edison'
#Grove Pot connected to connected A0 on the Grove shield
potSensor = grove.GroveRotary(0)
#Grove Temperature sensor connected A1
tempSensor = grove.GroveTemp(1)
#Grove Light sensor connected A2
lightSensor = grove.GroveLight(2)


def send_IFTTT_event(api_key,
                     event,
                     temp=None,
                     lightValue=None,
                     potValue=None):
    #posting data to IFTTT
    url = "https://maker.ifttt.com/trigger/{e}/with/key/{k}/".format(e=event,
                                                                     k=api_key)
    payload = {'value1': temp, 'value2': lightValue, 'value3': potValue}
    try:
        requests.post(url, data=payload)
示例#6
0
#Create for the Upcycle clock project using the Intel Edison -- to get the sensor values connected to the Grove shield
#Author : @CarmelitoA 05/28/2017
#Based on the python examples intels UPM - https://github.com/intel-iot-devkit/upm/tree/master/examples/python
from time import sleep
from upm import pyupm_grove as grove
from upm import pyupm_gas as TP401
#Grove temperature sensor connected A2 on the Grove connector shield
temp = grove.GroveTemp(2)
#Grove light sensor connected to pin A3
light = grove.GroveLight(3)
#Grove Air Quality Sensor on A1 - note the sensor take 3 mins to heat up and get ready
airSensor = TP401.TP401(1)

#getting the temperature in C
#Grove temperature sensor- https://github.com/intel-iot-devkit/upm/blob/master/examples/python/grovetemp.py
def temperature():
    celsius = temp.value()
    fahrenheit = celsius * 9.0/5.0 + 32.0;
    print("%d degrees Celsius, or %d degrees Fahrenheit" \
        % (celsius, fahrenheit))
    return celsius

# Grove light sensor - https://github.com/intel-iot-devkit/upm/blob/master/examples/python/grovelight.py
def lightValue():
    # Read values of the light sensor , in approx lux
    lightLux = light.value()
    print(light.name() + " raw value is %d" % light.raw_value() + \
        ", which is roughly %d" % light.value() + " lux");
    return lightLux

# Grove Air quality sensor v1.3- https://software.intel.com/en-us/iot/hardware/sensors/air-quality-sensor
示例#7
0
def io_setup():
    """
    io_setup: I/O setup for GPIO and Grove sensors
    Red, Green, Blue LEDs are initialized with PWM pins, period = PWM_PER us
    Rotary encoder, sound, temperature, and light sensors
    JHD1313M1 I2C display driver

    @return device_list: (list) list of all created mraa/upm objects
    Example usage: io_setup()
    """
    
    global red_led, green_led, blue_led
    global rotary_enc, sound_sensor, temp_sensor, light_sensor
    global lcd, buzzer

    devices = {}


    red_led = mraa.Pwm(RED_PIN)
    green_led = mraa.Pwm(GREEN_PIN)
    blue_led = mraa.Pwm(BLUE_PIN)

    # PWM_PER = 500 us == 2 kHz freq.
    red_led.period_us(PWM_PER)
    green_led.period_us(PWM_PER)
    blue_led.period_us(PWM_PER)

    # enable PWM and turn off LEDs
    red_led.enable(True)
    red_led.write(0)
    green_led.enable(True)
    green_led.write(0)
    blue_led.enable(True)
    blue_led.write(0)

    devices["redLED"] = red_led
    devices["greenLED"] = green_led
    devices["blueLED"] = blue_led

    # I2C addresses: 0x3E (LCD_ADDRESS), 0x62 (RGB_ADDRESS)
    lcd = groveLCD.Jhd1313m1(0, 0x3E, 0x62)
    lcd.clear()
    lcd.backlightOn()
    lcd.setColor(255, 255, 255)
    devices["lcd"] = lcd

    rotary_enc = grove.GroveRotary(ROT_PIN)
    sound_sensor = mraa.Aio(SOUND_PIN)
    temp_sensor = grove.GroveTemp(TEMP_PIN)
    light_sensor = grove.GroveLight(LIGHT_PIN)

    devices["rot"] = rotary_enc
    devices["sound"] = sound_sensor
    devices["temp"] = temp_sensor
    devices["light"] = light_sensor

    buzzer = groveBuzzer.Buzzer(BUZZ_PIN)
    buzzer.stopSound()
    buzzer.setVolume(0.125)
    devices["buzz"] = buzzer

    return devices