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/

Contact

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

Android Things A.I. Candy Dispenser
Intermediate
  • 153
  • 4

Full instructions

A Candy Dispenser running Android Things that exchanges photos for candies. It uses computer vision to classify the image.

Pulse Train Hat for Raspberry Pi Mecanum Bot Example
Intermediate
  • 937
  • 15

Full instructions

With this example, we show how to use the PTHAT and wireless Xbox controller to control a Mecanum Bot.

WiFi Messenger
Intermediate
  • 588
  • 10

Protip

Calling my son from his room using 2 ESP8266 modules, instead of shouting.

Smart Garden
Intermediate
  • 1,382
  • 13

Smart Garden is plant environmental monitoring system.

Pool Buddy
Intermediate
  • 721
  • 7

Work in progress

Monitor and log water quality (pH & ORP) and temperature from everywhere.

Intel Curie TinyTILE Dress: Accelerometer + Optical Fibers
Intermediate
  • 346
  • 10

Full instructions

A dress using Intel Curie accelerometer on TinyTILE and its small form factor to control colors of the optical fibers with arm movements.

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login
Feedback