Cloud Chamber Code

Python Code

These are the Python Codes we used to control the LED Lighting, Heating, and High-Voltage Source with Raspberry Pi.

Special Thanks to Wesley Cooke for programing and technical assistance.

1) System Check

#System Check
import time
import RPi.GPIO as GPIO 

# Define the relay pin
relay_pinvs = 4
relay_pinli = 22
relay_pinhr = 27
relay_pinex = 23

# Set the mode to use the Broad Com layout 
GPIO.setmode(GPIO.BCM)

# Tell the pi this is an output pin. Same as pinMode in arduino
GPIO.setup(relay_pinvs, GPIO.OUT)
GPIO.setup(relay_pinli, GPIO.OUT)
GPIO.setup(relay_pinhr, GPIO.OUT)
GPIO.setup(relay_pinex, GPIO.OUT)

try:
	# Infinite Loop
	while True:
		GPIO.output(relay_pinvs, True)
		print("Voltage Source Power On!")
		time.sleep(.5)
		GPIO.output(relay_pinvs, False)
		print("Voltage Source Power Off!")
		time.sleep(.5)
		GPIO.output(relay_pinli, True)
		print("Light Power On!")
		time.sleep(.5)
		GPIO.output(relay_pinli, False)
		print("Light Power Off!")
		time.sleep(.5)
		GPIO.output(relay_pinhr, True)
		print("Heater Power On!")
		time.sleep(.5)
		GPIO.output(relay_pinhr, False)
		print("Heater Power Off!")
		time.sleep(.5)
		GPIO.output(relay_pinex, True)
		print("Aux Power On!")
		time.sleep(.5)
		GPIO.output(relay_pinex, False)
		print("Aux Power Off!")
		time.sleep(.5)
		print("System Check Complete")
		time.sleep(2)
		GPIO.cleanup()
		
		
# Catch any exceptions like a keyboard interrupt
except:
	# Tell the pi we are done with the pins defined
		GPIO.output(relay_pinvs, False)
		print("Off!")
		#time.sleep(2)
		GPIO.cleanup()
import time
import RPi.GPIO as GPIO 
relay_pinli = 22

try:
	# Infinite Loop
	while True:
		GPIO.output(relay_pinli, True)
		print("On!")
		time.sleep(2)
		

		
# Catch any exceptions like a keyboard interrupt
except:
	# Tell the pi we are done with the pins defined
		GPIO.output(relay_pinli, False)
		print("Off!")
		#time.sleep(2)
		GPIO.cleanup()
import time
import RPi.GPIO as GPIO 
relay_pinex = 23
try:
	# Infinite Loop
	while True:
		GPIO.output(relay_pinex, True)
		print("On!")
		time.sleep(2)
		

		
# Catch any exceptions like a keyboard interrupt
except:
	# Tell the pi we are done with the pins defined
		GPIO.output(relay_pinex, False)
		print("Off!")
		#time.sleep(2)
		GPIO.cleanup()

import time
import RPi.GPIO as GPIO 
relay_pinhr = 27
try:
	# Infinite Loop
	while True:
		GPIO.output(relay_pinhr, True)
		print("On!")
		time.sleep(2)
		

		
# Catch any exceptions like a keyboard interrupt
except:
	# Tell the pi we are done with the pins defined
		GPIO.output(relay_pinhr, False)
		print("Off!")
		#time.sleep(2)
		GPIO.cleanup()

2) Light Power Relay

#Light Power Relay
import time
import RPi.GPIO as GPIO 

# Define the relay pin
#relay_pin = 4
relay_pin = 22
#relay_pin = 27

# Set the mode to use the Broad Com layout 
GPIO.setmode(GPIO.BCM)

# Tell the pi this is an output pin. Same as pinMode in arduino
GPIO.setup(relay_pin, GPIO.OUT)

try:
	# Infinite Loop
	while True:
		GPIO.output(relay_pin, True)
		print("On!")
		time.sleep(2)
		
	
		
# Catch any exceptions like a keyboard interrupt
except:
	# Tell the pi we are done with the pins defined
	GPIO.output(relay_pin, False)
	print("Off!")
	#time.sleep(2)
	GPIO.cleanup()

3) Light Control Code

#include all necessary packages to get LEDs to work with Raspberry Pi
import time
import board
import neopixel
import RPi.GPIO as GPIO 

#Initialize a strips variable, provide the GPIO Data Pin
#utilized and the amount of LED Nodes on strip and brightness (0 to 1 value)
pixels1 = neopixel.NeoPixel(board.D12, 18, brightness=.5)

#Also create an arbitrary count variable
x=0

#Focusing on a particular strip, use the command Fill to make it all a single color
#based on decimal code R, G, B. Number can be anything from 255 - 0. Use a RGB color
#Code Chart Website to quickly identify a desired fill color.

pixels1.fill((150, 150, 150))

#Below demonstrates how to individual address a color to a LED Node, in this case
#LED Node 10 and color Blue was selected
# pixels1[7] = (0, 20, 255)

#Sleep for three seconds, You should now have all LEDs showing light with the first node
#Showing a different color
try: 
    time.sleep(300)
#while x<17:

 
 #   pixels1[x] = (0, 0, 0)
  #  x=x+1
   # time.sleep(0.25)
    #pixels1[x-1] = (220,225,225)


#Little Light slider script, it will produce a nice loading bar effect all the way up
#and then all the way back
#This was created using a While Loop taking advantage of that arbitrary variable to determine
#which LED Node we will target/index with a different color

#Below will loop until variable x has value 35
# while x<35:
    
#     pixels1[x] = (255, 0, 0)
#     pixels1[x-5] = (255, 0, 100)
#     pixels1[x-10] = (0, 0, 255)
    #Add 1 to the counter
#     x=x+1
    #Add a small time pause which will translate to 'smoothly' changing colour
#     time.sleep(0.05)

#below section is the same process as above loop just in reverse
#while x>-15:
#     pixels1[x] = (255, 0, 0)
#     pixels1[x+5] = (255, 0, 100)
#     pixels1[x+10] = (0, 255, 0)
#     x=x-1
#     time.sleep(0.05)

#Add a brief time delay to appreciate what has happened    
#time.sleep(4)

#Complete the script by returning all the LED to off
    
# Tell the pi we are done with the pins defined
except:
    pixels1.fill((0, 0, 0))
    GPIO.cleanup()

4) Heater Power

# Testing a relay hooked up to a raspberry pi
import time
import RPi.GPIO as GPIO 

# Define the relay pin
relay_pin = 27

# Set the mode to use the Broad Com layout 
GPIO.setmode(GPIO.BCM)

# Tell the pi this is an output pin. Same as pinMode in arduino
GPIO.setup(relay_pin, GPIO.OUT)

try:
	# Infinite Loop
	while True:
		GPIO.output(relay_pin, True)
		print("Ht Pwr On!")
		time.sleep(2)
		

		
# Catch any exceptions like a keyboard interrupt
except:
	# Tell the pi we are done with the pins defined
		GPIO.output(relay_pin, False)
		print("Off!")
		#time.sleep(2)
		GPIO.cleanup()

5) Voltage Source Test Cycle

import RPi.GPIO as GPIO 

# Define the relay pin
relay_pin = 4

# Set the mode to use the Broad Com layout 
GPIO.setmode(GPIO.BCM)

# Tell the pi this is an output pin. Same as pinMode in arduino
GPIO.setup(relay_pin, GPIO.OUT)

try:
	# Infinite Loop
	while True:
		GPIO.output(relay_pin, True)
		print("Vlt Src On!")
		time.sleep(.5)
		GPIO.output(relay_pin, False)
		print("Vlt Src Off!")
		time.sleep(.5)
		
		
# Catch any exceptions like a keyboard interrupt
except:
	# Tell the pi we are done with the pins defined
	GPIO.output(relay_pin, False)
	print("Off!")
	GPIO.cleanup()

6) Voltage Source Work Cycle

# Testing a relay hooked up to a raspberry pi


import time
import RPi.GPIO as GPIO 

# Define the relay pin`
relay_pin = 4
#relay_pin = 22
#relay_pin = 27

# Set the mode to use the Broad Com layout 
GPIO.setmode(GPIO.BCM)

# Tell the pi this is an output pin. Same as pinMode in arduino
GPIO.setup(relay_pin, GPIO.OUT)

try:
	# Infinite Loop
	while True:
		GPIO.output(relay_pin, True)
		print("Vlt Src On!")
		time.sleep(10)
		GPIO.output(relay_pin, False)
		print("Off!")
		time.sleep(.1)
		
		
# Catch any exceptions like a keyboard interrupt
except:
	# Tell the pi we are done with the pins defined
	GPIO.output(relay_pin, False)
	print("Vlt Src Off!")
	GPIO.cleanup()

7) Switch All Off

# Testing a relay hooked up to a raspberry pi
import time
import RPi.GPIO as GPIO 

# Define the relay pin
relay_pinvs = 4
relay_pinli = 22
relay_pinhr = 27
relay_pinex = 23

# Set the mode to use the Broad Com layout 
GPIO.setmode(GPIO.BCM)

# Tell the pi this is an output pin. Same as pinMode in arduino
GPIO.setup(relay_pinvs, GPIO.OUT)
GPIO.setup(relay_pinli, GPIO.OUT)
GPIO.setup(relay_pinhr, GPIO.OUT)
GPIO.setup(relay_pinex, GPIO.OUT)

try:
	# Infinite Loop
	while True:
		GPIO.output(relay_pinvs, False)
		print("Voltage Source Power Off!")
		time.sleep(.5)
		GPIO.output(relay_pinli, False)
		print("Light Power Off!")
		time.sleep(.5)
		GPIO.output(relay_pinhr, False)
		print("Heater Power Off!")
		time.sleep(.5)
		GPIO.output(relay_pinex, False)
		print("Aux Power Off!")
		time.sleep(.5)
		print("System Shutdown Complete")
		time.sleep(2)
		GPIO.cleanup()
		
		
		
		
# Catch any exceptions like a keyboard interrupt
except:
	# Tell the pi we are done with the pins defined
		GPIO.output(relay_pinvs, False)
		print("Off!")
		#time.sleep(2)
		GPIO.cleanup()
import time
import RPi.GPIO as GPIO 
relay_pinli = 22

try:
	# Infinite Loop
	while True:
		GPIO.output(relay_pinli, True)
		print("On!")
		time.sleep(2)
	
		
# Catch any exceptions like a keyboard interrupt
except:
	# Tell the pi we are done with the pins defined
		GPIO.output(relay_pinli, False)
		print("Off!")
		#time.sleep(2)
		GPIO.cleanup()
import time
import RPi.GPIO as GPIO 
relay_pinex = 23
try:
	# Infinite Loop
	while True:
		GPIO.output(relay_pinex, True)
		print("On!")
		time.sleep(2)
	

		
# Catch any exceptions like a keyboard interrupt
except:
	# Tell the pi we are done with the pins defined
		GPIO.output(relay_pinex, False)
		print("Off!")
		#time.sleep(2)
		GPIO.cleanup()

import time
import RPi.GPIO as GPIO 
relay_pinhr = 27
try:
	# Infinite Loop
	while True:
		GPIO.output(relay_pinhr, True)
		print("On!")
		time.sleep(2)
		

		
# Catch any exceptions like a keyboard interrupt
except:
	# Tell the pi we are done with the pins defined
		GPIO.output(relay_pinhr, False)
		print("Off!")
		#time.sleep(2)
		GPIO.cleanup()