Does anyone have the Code for the sensors that come in the grove pi starter kit. I have the temp humidity working but I want to use all of them?
Any help or direction would be appreciated.
Does anyone have the Code for the sensors that come in the grove pi starter kit. I have the temp humidity working but I want to use all of them?
Any help or direction would be appreciated.
Here’s some project examples by Dexter Ind:
Hi @jarrells,
We have examples for almost all of the sensors of starter kit in Python here, If you wish to use some other language, there might not be examples for a few sensors and you can refer to the link @graykevinb has posted for other programming languages.
-Shoban
Thank you that helps. Now my question is about combining scripts.
I have them running separately,
the temp and humidy on the display
the rain notifier led blink light
the air quality sensor
Can I combine them, I have tried moving scripts and it always seems to be the top script that runs.
Also, how do I change Celcius to Farenhight in the temp/humidy script
Thanks for all of the help, I see a light at the end of the tunnel.
Hi @jarrells,
Can you post a screenshot of the combined code that you have tried and also its output.
Regarding the conversion of Celsius to Fahrenheit, I think you will be using this example, so in this example after line 53 add this line temp = (temp*1.8) + 32
to convert it to Fahrenheit, then temperature values will be in Fahrenheit.
Please let us know if this helps,
-Shoban
Ok First let me qualify my code
I really don’t understand how the code works, just tried putting them together by structure.
‘’’
The MIT License (MIT)
GrovePi for the Raspberry Pi: an open source platform for connecting Grove Sensors to the Raspberry Pi.
Copyright © 2015 Dexter Industries
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
’’'
from grovepi import *
from grove_rgb_lcd import*
import time
import grovepi
from grovepi import *
from grove_rgb_lcd import *
dht_sensor_port = 7 # Connect the DHt sensor to port 7
dht_sensor_type = 0 # change this depending on your sensor type - see header comment
while True:
try:
[ temp,hum ] = dht(dht_sensor_port,dht_sensor_type) #Get the temperature and Humidity from the DHT sensor
print(“temp”, temp, “F\thumidity =”, hum,"%")
t = str(temp)
h = str(hum)
grovepi.pinMode(air_sensor,“INPUT”)
while True:
try:
# Get sensor value
sensor_value = grovepi.analogRead(air_sensor)
a = str(air)
if sensor_value > 700:
print ("High pollution")
elif sensor_value > 300:
print ("Low pollution")
else:
# This is a project that uses the Grove LED attached to an umbrella to remind
zipcode = ‘34212’
api_key = ‘c57eb776b61ce4c9’
clearled = 8 print (“Air fresh”)
print("sensor_value =", sensor_value)
time.sleep(.5)
BLINK = True
DELAY = 5*60 # in seconds
METRIC = 1
RAIN_THRESHOLD = 1
rainled = 7
############################################################################
############################################################################
import urllib2
import json
from grovepi import *
import time
import sys
def clear_led(status):
""" change clear sky LED status “”"
if clearled > -1:
digitalWrite(clearled, status)
def assign_rain(status, blink):
""" controls the LEDs status
Arguments:
status: True if it will be raining
False if there's no rain in the forecast
blink: True if the rain led should blink when on
False if the rain led does not need blinking
no return value
"""
if status is True: # there will be rain
clear_led(0) # Turn off the CLEAR LED on the umbrella
# Light the RAIN LED on the umbrella
# first check if it needs to be blinking
if blink is True:
led_blink(DELAY) # no sleep required here
else:
digitalWrite(rainled, 1)
time.sleep(DELAY)
else: # no rain in forecast
# turn off the RAIN LED on the umbrella
digitalWrite(rainled, 0)
# Turn on the CLEAR LED on the umbrella
clear_led(1)
time.sleep(DELAY)
def led_blink(blinkdelay):
""" forces the rain LED to blink
rain LED will blink at a rate of 0.2 secs on, and 0.2 secs off
it will blink for a duration set by blinkdelay
no additional sleep() is required as it’s incorporated in the blinking
"""
count = 0.0
blinkrate = 0.4
while count < float(blinkdelay):
digitalWrite(rainled, 1)
time.sleep(blinkrate)
digitalWrite(rainled, 0)
time.sleep(blinkrate)
count += (2*blinkrate)
#########################################################################
url = ‘http://api.wunderground.com/api/’ + api_key
url = url + ‘/geolookup/conditions/q/’ + zipcode + ‘.json’
pinMode(rainled, “OUTPUT”)
if clearled > -1:
pinMode(clearled, “OUTPUT”)
if len(sys.argv) > 1 and sys.argv[1] == ‘test’:
try:
clear_led(1)
led_blink(5)
clear_led(0)
except KeyboardInterrupt:
digitalWrite(clearled, 0)
digitalWrite(rainled, 0)
quit()
try:
while True:
f = urllib2.urlopen(url)
json_string = f.read()
f.close()
parsed_json = json.loads(json_string)
location = parsed_json[‘location’][‘city’]
if METRIC is 0:
precip_today = parsed_json[‘current_observation’][‘precip_today_in’]
else:
precip_today = parsed_json[‘current_observation’][‘precip_today_metric’]
print(“Current precipitation in %s is: %s” % (location, precip_today))
if float(precip_today) > float(RAIN_THRESHOLD):
print("Rain today, take the umbrella")
assign_rain(True, BLINK)
else:
print("No Rain today")
assign_rain(False, BLINK)
setRGB(0,128,64)
setRGB(0,255,0)
setText("Temp:" + t "F " + "Humidity :" + h + "%" + "Air Quality" + a + "parts" )
except (IOError,TypeError) as e:
print("Error")
except KeyboardInterrupt:
clear_led(0)
digitalWrite(rainled, 0)
when I run it today (don’t know how I changed it last night) it says there is an unexpected indent right beg=fore the line
grovepi.pinMode(air_sensor,“INPUT”)
Thanks for the help
Hey @jarrells, just looking at this code, it looks like you’re on the right track. I think anyone with some basic python knowledge will be able to help you square the functions away to run in sequence. What you’ll need to do is rather than drop them all into the same document, you’ll need to take each sensor’s program, turn it into a function, and call it from below a “main” statement. This should be pretty easy to do with Python, but you might need to study up the basic structures of Python first, or find someone who can help you do this.