def main(): # New knob on AIO pin 0 knob = grove.GroveRotary(0) # Loop indefinitely while True: # Read values abs = knob.abs_value() absdeg = knob.abs_deg() absrad = knob.abs_rad() rel = knob.rel_value() reldeg = knob.rel_deg() relrad = knob.rel_rad() print("Abs values: %4d" % int(abs), " raw %4d" % int(absdeg), "deg = %5.2f" % absrad, " rad ", end=' ') print("Rel values: %4d" % int(rel), " raw %4d" % int(reldeg), "deg = %5.2f" % relrad, " rad") # Sleep for 2.5 s sleep(2.5)
def main(): # Instantiate the strip of 60 LEDs on SPI bus 0 connect Data-D11 and Clk- D13 ledStrip = mylib.APA102(60, 0, False) knob = grove.GroveRotary(0) abs = knob.abs_value() while True: # Read values abs = knob.abs_value() print("Abs values: " + str(abs)) lightValue = lightSensor.raw_value() print("Light Value: " + str(lightValue)) sleep(1) if abs < 100: print("Setting all LEDs to Green") ledStrip.setAllLeds(60, 0, 255, 0) time.sleep(2) elif abs > 100 and abs < 300: print("Setting all LEDs to Red") ledStrip.setAllLeds(60, 255, 0, 0) time.sleep(2) elif abs > 300 and abs < 600: print("Setting all LEDs to Blue") ledStrip.setAllLeds(60, 0, 0, 255) elif abs > 600 and abs < 900: print("Setting LEDs between 10 and 20 to Red") ledStrip.setLeds(10, 20, 60, 255, 0, 0) time.sleep(2) else: print("setting all LEDS off") ledStrip.setAllLeds(60, 0, 0, 0) time.sleep(2)
def main(): # New knob on AIO pin 0 mraa.addSubplatform(mraa.GROVEPI, "0") knob = grove.GroveRotary(512) # Loop indefinitely while True: # Read values abs = knob.abs_value() absdeg = knob.abs_deg() # Publish sensor data to MQTT Broker payload = "{\"sensor_id\":\"Rotary Sensor\",\"value\":" + str( int(absdeg)) + "}" ret = client1.publish("sensors/rotary/data", payload) sleep(.01)
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)
def main(): # New knob on AIO pin 0 mraa.addSubplatform(mraa.GROVEPI,"0") knob = grove.GroveRotary(512) # Loop indefinitely while True: # Read values abs = knob.abs_value() absdeg = knob.abs_deg() absrad = knob.abs_rad() print("Abs values: %4d" % int(abs) , " raw %4d" % int(absdeg), "deg = %5.2f" % absrad , " rad ", end=' ') url = "http://" + os.environ['HTTPServer_URL'] +":"+ os.environ['HTTPServer_PORT'] + "/data" payload = "{\"sensor_id\":\"Temperature Sensor\",\"value\":" + str(int(absdeg)) + "}" headers = { 'Content-Type': "application/json", 'Cache-Control': "no-cache", } response = requests.request("POST", url, data=payload, headers=headers) #Sleep for 0.1 s sleep(0.1)
#!/usr/bin/python # 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:
def main(): #POT connected to pin A0 -using this to test the pannels indivisually knob = grove.GroveRotary(0) # Instantiate the LED strip ledStrip = mylib.APA102(numberOfLEDs, 0, False) ledStrip.setAllLeds(numberOfLEDs, 0, 0, 0) #ledStrip.setLeds(2, 3, 10, 255, 0, 0) #setting 2 and 3 to red of the 10 LEDs #ledStrip.setLed(7, 10, 255, 0, 255) #setting 7 to blue only #ledStrip.setLeds(4, 5, 10, 255, 255, 0) #yellow #ledStrip.setLeds(8, 9, 10, 0, 255, 255) #sky blue #ledStrip.setLeds(6, 7, 10, 255, 0, 255) #pink #ledStrip.setLeds(6, 7, 10, 100, 100, 100) #white sleep(4) while True: # Read values abs = knob.abs_value() print("Abs values: " + str(abs)) sleep(0.5) if abs < 100: print("Testing -- Setting all LEDs to blink white") ledStrip.setAllLeds(numberOfLEDs, 100, 100, 100) #white sleep(2) ledStrip.setAllLeds(numberOfLEDs, 0, 0, 0) #white sleep(2) elif abs >= 100 and abs < 250: print("Weather condition outside - lower most panel") outTemp, outHumidity, outCondition = weather_condition.weatherData( ) print("Weather outside : " + outCondition) if outCondition == 'Rains': ledStrip.setLeds(0, 1, numberOfLEDs, 0, 0, 255) #blue for Rains elif outCondition == 'Sunny': ledStrip.setLeds(0, 1, numberOfLEDs, 255, 255, 0) #yellow else: ledStrip.setLeds(0, 1, numberOfLEDs, 100, 100, 100) #white -Cloudy,Haze,Snow showers sleep(5) elif abs >= 250 and abs < 400: print("Traffic- time to work panel") timeToWork = traffic_condition.get_time_intraffic() print("Time in traffic" + str(timeToWork)) if timeToWork <= 30: ledStrip.setLeds(2, 3, numberOfLEDs, 0, 255, 0) #green leave home now!! elif timeToWork > 30 and timeToWork > 45: ledStrip.setLeds(2, 3, numberOfLEDs, 0, 255, 255) #yellow-orange else: ledStrip.setLeds(2, 3, numberOfLEDs, 255, 0, 0) #>45 mins a lot of traffic sleep(5) elif abs >= 400 and abs < 550: print("Twitter Pannel") hastagCount = twitter_messages.tweet_count_today() print("Upcycleit hashtag count") if hastagCount <= 5: ledStrip.setLeds(4, 5, numberOfLEDs, 255, 0, 255) #pink else: ledStrip.setLeds(4, 5, numberOfLEDs, 0, 0, 255) #more than 5 blue sleep(5) elif abs >= 550 and abs < 700: print("Gmail - unread emails") numberOfEmails = gmail_check.un_read_email() print("Number of unread emails : " + str(numberOfEmails)) if numberOfEmails >= 5: ledStrip.setLeds(6, 7, numberOfLEDs, 255, 0, 0) #red else: ledStrip.setLeds(6, 7, numberOfLEDs, 0, 255, 0) #green sleep(5) elif abs >= 700 and abs < 850: print("Home - temperature and Gas") #airQualityVal = sensor_values.airQuality() temperature = sensor_values.temperature() #print ("Temperature " + str(temperature) + " C" + "Air quality: " + str(airQualityVal)) print("Temperature " + str(temperature)) if temperature < 30: ledStrip.setLeds(8, 9, numberOfLEDs, 0, 255, 0) #green don't need to turn on the AC else: ledStrip.setLeds(8, 9, numberOfLEDs, 0, 255, 0) sleep(5) elif abs >= 850 and abs < 1000: print("Party mode!--need to implement rainbow cycle algo") ledStrip.setLeds(10, numberOfLEDs, 10, 255, 0, 0) sleep(0.5) ledStrip.setLeds(10, numberOfLEDs, 10, 0, 255, 0) sleep(0.5) ledStrip.setLeds(10, numberOfLEDs, 10, 0, 0, 255) sleep(0.5) ledStrip.setLeds(10, numberOfLEDs, 10, 255, 255, 0) #yellow sleep(0.5) ledStrip.setLeds(10, numberOfLEDs, 10, 0, 255, 255) #sky blue sleep(0.5) ledStrip.setLeds(10, numberOfLEDs, 10, 255, 0, 255) #pink sleep(0.5) ledStrip.setLeds(10, 16, 10, 255, 0, 0) ledStrip.setLeds(17, 23, 10, 0, 255, 0) ledStrip.setLeds(23, numberOfLEDs, 10, 0, 0, 255) sleep(2) else: print("setting all LEDS off - pot all the way right") ledStrip.setAllLeds(numberOfLEDs, 0, 0, 0) sleep(2)
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
#Create for the Upcycle clock project using the Intel Edison -- display stuff on the Grove RGB LCD screen #Author : @CarmelitoA 05/28/2017 from time import sleep from upm import pyupm_jhd1313m1 as lcd from upm import pyupm_grove as grove import alarms, call_IFTTT import get_IP, sensor_values, weather_condition, traffic_condition import datetime sleepTime = 3 #POT connected to pin A0 knob = grove.GroveRotary(0) button1 = grove.GroveButton(2) button2 = grove.GroveButton(3) # Grove RGB LCD https://github.com/intel-iot-devkit/upm/blob/master/examples/python/jhd1313m1-lcd.py # Initialize Jhd1313m1 at 0x3E (LCD_ADDRESS) and 0x62 (RGB_ADDRESS) myLcd = lcd.Jhd1313m1(0, 0x3E, 0x62) def showOnLCD(line1, line2, color): myLcd.clear() # Set background color if (color == 'blue'): myLcd.setColor(0, 0, 255) #blue if (color == 'green'): myLcd.setColor(0, 255, 0) #Green if (color == 'red'): myLcd.setColor(255, 0, 0) #Red if (color == 'yellow'): myLcd.setColor(255, 255, 0) #yellow # Zero the cursor myLcd.setCursor(0, 0) myLcd.write(line1) myLcd.setCursor(1, 0)