CJA3D
Published © LGPL

Inside-Outside Weather Station

This is a great weekend IoT project which uses the BeagleBone Green to display Temperature Humidity inside and outside your home and more..

IntermediateFull instructions provided5 hours3,735
Inside-Outside Weather Station

Things used in this project

Hardware components

SeeedStudio BeagleBone Green
BeagleBoard.org SeeedStudio BeagleBone Green
×1
Grove starter kit plus for Intel Edison
Seeed Studio Grove starter kit plus for Intel Edison
×1
Seeed Studio Grove - Temperature&Humidity Sensor Pro
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1

Software apps and online services

dweet.io
OpenWeatherMap
Freeboard.io

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Soldering iron (generic)
Soldering iron (generic)
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Custom parts and enclosures

BeagleBone Green Bottom Holder

3D printed case BeagleBone Green Bottom Holder

BeagleBone Green Top

BeagleBone Green Top holder with sensor cut out for
Grove LCD
Potentiometer
Grove Temperature and Humidity

Schematics

Circuit

- Connect the Temperature and Humidity sensor to P8_11
-Connect the LCD to the I2C pins on the BBG,
SCL to P9_19
SDA to P9_20
Connect the Vcc to the 5V pin (if you connect this to the 3.3v pin you will
not see the text appear)
- Connect the POT to P9_33 and red wire to P9_32 and black wire to P9_34,
here note the analog refrence voltage on the BBG is 1.8V

Code

weatherStationBasic.py

Python
run it using Python weatherStationBasic.py
Before you run the code modify
APIKey
placeName
appName for dweet.io
#!/usr/bin/python
#Code for the Inside-outside weather station using BeagleBone Green project
#Written by - Carmelito
import time
import Adafruit_BBIO.ADC as ADC 
from Adafruit_I2C import Adafruit_I2C
#pip install pyowm
import pyowm 
#apt-get install python-requests
import requests
#https://github.com/adafruit/DHT-sensor-library
import Adafruit_DHT
sensor = Adafruit_DHT.AM2302
sensorPin = 'P8_11'
analogPinPOT = "P9_33" 

dweetIO = "https://dweet.io/dweet/for/"
appName = "BBGTorontoCanada" #change this to you city
#get the API key from Openweathermap.org
APIKey = 'XXXXXXXXXXXXXXXXXXXXXX'
placeName = 'Toronto,CA'#change this to your city
owm = pyowm.OWM(APIKey)


observation = owm.weather_at_place(placeName)
w = observation.get_weather() #WIP need to add a refresh interval
temp = w.get_temperature(unit='celsius')['temp']
status = w.get_status()
windSpeed = w.get_wind()['speed']
humidity = w.get_humidity()
pressure = w.get_pressure()['press']

print ('Temperature : '+ str(temp) + ' C')
print ('Weather Condition : ' + status)
print ('Wind Speed : '+ str(windSpeed) + ' m/s')
print ('Humidity : ' + str(humidity) + ' %')
print ('Pressure : ' + str(pressure) + ' hpa')


# Grove-LCD this device has two I2C addresses
#Code for LCD based on code at http://www.seeedstudio.com/recipe/256-a-smart-
#home-monitoring-equipment-by-bbg.html by kevin-lee
DisplayRGB = Adafruit_I2C(0x62)
DisplayText = Adafruit_I2C(0x3e)

dot = [0b00111,\
       0b00101,\
       0b00111,\
       0b00000,\
       0b00000,\
       0b00000,\
       0b00000,\
       0b00000]
# set backlight to (R,G,B) (values from 0..255 for each)
def setRGB(r,g,b):
    DisplayRGB.write8(0,0)
    DisplayRGB.write8(1,0)
    DisplayRGB.write8(0x08,0xaa)
    DisplayRGB.write8(4,r)
    DisplayRGB.write8(3,g)
    DisplayRGB.write8(2,b)
# send command to display (no need for external use)    
def textCommand(cmd):
    DisplayText.write8(0x80,cmd)
    #bus.write_byte_data(DISPLAY_TEXT_ADDR,0x80,cmd)
# set display text \n for second line(or auto wrap)     
def setText(text):
    textCommand(0x01) # clear display
    time.sleep(.05)
    textCommand(0x08 | 0x04) # display on, no cursor
    textCommand(0x28) # 2 lines
    time.sleep(.05)
    count = 0
    row = 0
    for c in text:
        if c == '\n' or count == 16:
            count = 0
            row += 1
            if row == 2:
                break
            textCommand(0xc0)
            if c == '\n':
                continue
        count += 1
        DisplayText.write8(0x40,ord(c))

def createChar(location, charmap):
    data = [0 for i in range(10)];
    for i in range(0,8):
        data[i] = charmap[i]
    data.insert(0,(0x40|(location<<4)))
    data.insert(1,0x40)
    DisplayText.writeList(0x80,data)
def uploadDweet():
    humidSensor, tempSensor = Adafruit_DHT.read_retry(sensor, sensorPin)
    if humidSensor is not None and tempSensor is not None:
    	print 'Temp={0:0.1f}*C  Humidity={1:0.1f}%'.format(tempSensor, humidSensor)
    else :
    	print 'Failed to get reading. Try again!'
    requestString = dweetIO + appName + '?' + 'Temperature=' + str(tempSensor)
    requestString = requestString + '&Humidity='+str(humidSensor)
    requestString = requestString + '&WindSpeed='+str(windSpeed)
    requestString = requestString + '&Pressure='+str(pressure)
    requestString = requestString + '&OutSideTemp='+str(temp)
    requestString = requestString + '&OutSideHumid='+str(humidity)
    print requestString
    rqs = requests.get(requestString)
    print rqs.status_code
    print rqs.headers
    print rqs.content
    time.sleep(3)
        
def runPOTloop():
    potVal = ADC.read(analogPinPOT)
    print ("Pot Value : " + str(potVal))
    if potVal < 0.1:
    	setText("BBG In-Out\nWeather Station")
    	for c in range(0,255):
        	setRGB(c,255-c,0)
		time.sleep(0.02)
    elif potVal>0.1 and potVal <0.3:
    	tempDisplay = 'Outside :\n'+'T: ' + str(temp)+"C " + 'H: '+ str(humidity) +'%'
    	setRGB(0,255,0)
    	setText(tempDisplay)    
    	time.sleep(2)
    elif potVal >0.3 and potVal <0.5:
    	humidSensor, tempSensor = Adafruit_DHT.read_retry(sensor, sensorPin)
 	setRGB(100,200,0)
	if humidSensor is not None and tempSensor is not None:
        	print 'Temp={0:0.1f}*C  Humidity={1:0.1f}%'.format(tempSensor, humidSensor)
		insideCond = 'Inside :\n' +str('T={0:0.1f}C H={1:0.1f}%'.format(tempSensor, humidSensor))
        	setText(insideCond)
    	else :
        	print 'Failed to get reading. Try again!'
		setText("Inside: Failed\nto read sensor")
	time.sleep(2)
    elif potVal>0.5 and potVal<0.8:
	setRGB(0,0,255)
	setText("Uploading Data \nto dweet.io ..")
 	uploadDweet()
	time.sleep(0.2)
    else:
    	weatherDisplay = 'Weather :\n' + status
    	setRGB(100,200,0)
    	setText(weatherDisplay)
    	time.sleep(2)
    	
    print 'End of loop'
    runPOTloop()

if __name__=="__main__":

    ADC.setup()
    createChar(0,dot)
    runPOTloop()

openWeather.py

Python
Test program to get the weather info of your city from openweather.org
Note: Modify the APIkey to your key
#!/usr/bin/python
import pyowm
APIKey = 'XXXXXXXXXXXXXXXXXX'
placeName = 'Toronto,CA'
owm = pyowm.OWM(APIKey)
observation = owm.weather_at_place(placeName)
w = observation.get_weather()

temp = w.get_temperature(unit='celsius')['temp']
status = w.get_status()
windSpeed = w.get_wind()['speed']
humidity = w.get_humidity()
pressure = w.get_pressure()['press']

print ('Temperature : '+ str(temp) + ' C')
print ('Weather Condition : ' + status)
print ('Wind Speed : '+ str(windSpeed) + ' m/s')
print ('Humidity : ' + str(humidity) + ' %')
print ('Pressure : ' + str(pressure) + ' hpa')

analogRead.py

Python
Simple program to test the POT and to approximate the range of the POT for the markings
#!/usr/bin/python
import time
import Adafruit_BBIO.ADC as ADC

ADC.setup()
analogPinPOT = "P9_33"
while(1):
        potVal = ADC.read(analogPinPOT)
        print ("Pot Value : " + str(potVal))
        time.sleep(5)

Credits

CJA3D

CJA3D

10 projects • 80 followers
Tinkerer and 3D Printing enthusiast.

Comments