Things used in this project

Hardware components:
Raspberry pi zero
Raspberry Pi Zero
×1
PiBow Zero 1.3
×1
Geeky Glasses
×1
Enviro pHAT
×1
Adafruit industries ada258 image 75px
Li-Ion Battery 1000mAh
×1
Adafruit PowerBoost 500
×1
Adafruit OLED Screen
×1
Google Cardboard Lens
×1
SD Card
×1
Extended Header
×1
E switch eg1218 image 75px
Slide Switch
×1
Adafruit industries ada592 image 75px
USB-A to Micro-USB Cable
×1
Sugru
×1
Tie Wraps
×1
Blu Tak
×1
Openbuilds nylon spacer
OpenBuilds Nylon Spacer
×1
Nylon Standoffs
×1
F/F Jumper Wires
×1
Hand tools and fabrication machines:
09507 01
Soldering iron (generic)

Code

Code snippet #1Plain text
#imports for the envirophat
from envirophat import light
from envirophat import leds
from envirophat import weather
from envirophat import motion

#general imports
import os
import math
import time
import decimal

#OLED screen imports
import Adafruit_GPIO.SPI as SPI
import Adafruit_SSD1351

#stuff for drawing
import Image
import ImageFont
import ImageDraw

#the setup section for the screen
RST = 24
DC = 23
SPI_PORT = 0
SPI_DEVICE = 0


disp = Adafruit_SSD1351.SSD1351_128_96(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000))

disp.begin()

width = disp.width
height = disp.height

#determining the direction of north for the heading sensor
north = 294

#main loop
while True:
	#setting up the image for the display as well as clearing anything currently on screen
	disp.clear()

	image = Image.new('1', (width, height))

	font = ImageFont.load_default()

	draw = ImageDraw.Draw(image)

	disp.clear()

	#here the sensors data is assigned to variables
	light_level = light.light()

	r, g, b = light.rgb()

	temp = weather.temperature()

	pressure = weather.pressure()

	x, y, z = motion.accelerometer()
	
	#calculating degrees to north
	corr_heading = (motion.heading() - north) % 360
	
	#if the light sensor is covered it will wait 5 seconds, if its still covered after this point, it will shutdown the raspberry pi
	if light_level == 0:
		time.sleep(5)
		light_level = light.light()
		if light_level == 0:
			os.system("sudo shutdown -h now")
		else:
			pass

	#here i assign headers to the data from the hat, into labelled strings
	text_light = ('Light: ' + str(light_level))

	text_rgb = ('R: ' + str(r) + ' G: ' + str(g) + ' B: ' + str(b))

	text_temp = ('Temp: ' + str(temp))

	text_pressure = ('Pressure: ' + str(pressure))

	text_motion_1 = ('Motion')

	text_motion_2 = ('X: ' + str(x))

	text_motion_3 = ('Y: ' + str(y))

	text_motion_4 = ('Z: ' + str(z))
	
	text_heading = ('Deg to North : ' + str(corr_heading))
	
	#finally the strings are written to the display
	draw.text((0, 0), text_light, font=font, fill=255)

	draw.text((0, 10), text_rgb, font=font, fill=255)

	draw.text((0, 20), text_temp, font=font, fill=255)

	draw.text((0, 30), text_pressure, font=font, fill=255)

	draw.text((0, 40), text_motion_1, font=font, fill=255)

	draw.text((0, 50), text_motion_2, font=font, fill=255)

	draw.text((0, 60), text_motion_3, font=font, fill=255)

	draw.text((0, 70), text_motion_4, font=font, fill=255)
	
	draw.text((0, 80), text_heading, font=font, fill=255)
	
	disp.roughimage(image)

	time.sleep(1)
Code snippet #2Plain text
#imports for the envirophat
from envirophat import light
from envirophat import leds
from envirophat import weather
from envirophat import motion

#general imports
import os
import math
import time
import decimal

#OLED screen imports
import Adafruit_GPIO.SPI as SPI
import Adafruit_SSD1351

#stuff for drawing
import Image
import ImageFont
import ImageDraw

#the setup section for the screen
RST = 24
DC = 23
SPI_PORT = 0
SPI_DEVICE = 0


disp = Adafruit_SSD1351.SSD1351_128_96(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000))

disp.begin()

width = disp.width
height = disp.height

#determining the direction of north for the heading sensor
north = 294

#main loop
while True:
	#setting up the image for the display as well as clearing anything currently on screen
	disp.clear()

	image = Image.new('1', (width, height))

	font = ImageFont.load_default()

	draw = ImageDraw.Draw(image)

	disp.clear()

	#here the sensors data is assigned to variables
	light_level = light.light()

	r, g, b = light.rgb()

	temp = weather.temperature()

	pressure = weather.pressure()

	x, y, z = motion.accelerometer()
	
	#calculating degrees to north
	corr_heading = (motion.heading() - north) % 360
	
	#if the light sensor is covered it will wait 5 seconds, if its still covered after this point, it will shutdown the raspberry pi
	if light_level == 0:
		time.sleep(5)
		light_level = light.light()
		if light_level == 0:
			os.system("sudo shutdown -h now")
		else:
			pass

	#here i assign headers to the data from the hat, into labelled strings
	text_light = ('Light: ' + str(light_level))

	text_rgb = ('R: ' + str(r) + ' G: ' + str(g) + ' B: ' + str(b))

	text_temp = ('Temp: ' + str(temp))

	text_pressure = ('Pressure: ' + str(pressure))

	text_motion_1 = ('Motion')

	text_motion_2 = ('X: ' + str(x))

	text_motion_3 = ('Y: ' + str(y))

	text_motion_4 = ('Z: ' + str(z))
	
	text_heading = ('Deg to North : ' + str(corr_heading))
	
	#finally the strings are written to the display
	draw.text((0, 0), text_light, font=font, fill=255)

	draw.text((0, 10), text_rgb, font=font, fill=255)

	draw.text((0, 20), text_temp, font=font, fill=255)

	draw.text((0, 30), text_pressure, font=font, fill=255)

	draw.text((0, 40), text_motion_1, font=font, fill=255)

	draw.text((0, 50), text_motion_2, font=font, fill=255)

	draw.text((0, 60), text_motion_3, font=font, fill=255)

	draw.text((0, 70), text_motion_4, font=font, fill=255)
	
	draw.text((0, 80), text_heading, font=font, fill=255)
	
	disp.roughimage(image)

	time.sleep(1)

Credits

3ce53562f165e662b479f874c207ce79
Michael Darby

I like to keep fit, explore and of course make projects. https://314reactor.com/

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

PiMiniMint
Intermediate
  • 371
  • 7

Full instructions

Build your very own Linux terminal inside a mint tin!

Stepper Motor Control
Intermediate
  • 103
  • 3

Full instructions

A full featured Stepper control involving speed and line interpolation for 2 axis motion.

Solar Smart Greenhouse Using Vertical Aquaponic Towers
Intermediate
  • 3,229
  • 44

Work in progress

Feed your family with 22 sqm greenhousing by combining permaculture, aquaponic vertical towers and IoT.

SORT4U
Intermediate
  • 74
  • 2

Full instructions

It's the sorting machine that you've been waiting for. Just throw all your junk in it and let it sort for you.

SORT4U

Team The Avengers

Drop of Life
Intermediate
  • 677
  • 17

Full instructions

A display to remind me when I can donate blood and save lives, powered by the Red Cross API and Particle.

FM Radio
Intermediate
  • 8,766
  • 38

Full instructions

Build a great sounding FM radio with a cool display using an Arduino Nano and the Sparkfun Si4703 FM tuner breakout.

ProjectsCommunitiesContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login
Respect project
Feedback