top of page
  • Writer's pictureThe Arithmancer

Plasma Ball Control - Remote GPIO

Updated: Oct 21, 2019

The Effect:


Touch a plasma ball and the Magic Mirror says "Who dares disturb my slumber"



What You Will Learn:


1. How to use the i2c Current Detector

2. Remote GPIO



What You Will Need:


1. Magic Mirror built by following my previous tutorials

5. Plasma Ball

6. LED & Resistor



How Does it Work?





The idea is to monitor the power being drawn by the plasma ball because when someone touches the ball, you provide an easier route to ground. As a result, there is a power surge that we can monitor using the INA 219. So that I have a visual confirmation, I have added an LED to one of the GPIO pins. From the magic mirror, I then remotely test the LED to see whether it is on using the pigpio library which allows me to control the GPIO pins of a remote pi as long as it is on the same wifi network.


The first question I get asked is why a second raspberry pi? Why not use the same Pi as the one for the mirror? That is indeed the simpler solution but the effect is a lot more dramatic if you have no wire connecting the Plasma Ball and the back of the mirror! Using a second pi allows you to take advantage of remote GPIO to detect the power via Wifi!



The Circuit


I did this bit with my dad. I'd recommend doing this bit with an adult as it requires some basic soldering and stripping the wire of the plasma ball itself.





The Code


To control the INA219 current detector from your python code, the best library I found is the one by Chris that can be found here. To install it, type:


$  sudo pip3 install pi-ina219

To Check i2c is working

$  sudo i2cdetect -y 1




Python Import Functions at Top of Code:

 from ina219 import INA219  
 from ina219 import DeviceRangeError 


Monitoring the Power:

I've included commented out code for how to monitor voltage or current using the INA for completeness. However, it is the power that we are using for this project.

from ina219 import INA219, DeviceRangeError
from time import sleep

SHUNT_OHMS = 0.1
MAX_EXPECTED_AMPS = 2.0
ina = INA219(SHUNT_OHMS, MAX_EXPECTED_AMPS)
ina.configure(ina.RANGE_16V)

def read_ina219():
    try:
        #print('Bus Voltage: {0:0.2f}V'.format(ina.voltage()))
        #print('Bus Current: {0:0.2f}mA'.format(ina.current()))  
        #print('Shunt Voltage: {0:0.2f}mV\n'.format(ina.shunt_voltage()))     
        average = 0
        for i in range(5): 
            average = average+ina.power() 
            sleep(0.005) 
        average=average/5  
        print ("Power Reading: " + average)
        if average>8500: 
            ###### TURN ON LED on PIN 26 ##### 
            print("Plasma ball is being touched")  
        else: 
            ###### Turn off LED
     except DeviceRangeError as e:
        # Current out of device range with specified shunt resister
        print(e)

while 1:
    read_ina219()
    sleep(1)
SHUNT_OHMS = 0.1
def read():
   ina = INA219(SHUNT_OHMS)
   ina.configure()
   print "Bus Voltage: %.3f V" % ina.voltage()
   try:
       print "Bus Current: %.3f mA" % ina.current()
       print "Power: %.3f mW" % ina.power()
       print "Shunt voltage: %.3f mV" % ina.shunt_voltage()
   except DeviceRangeError as e:
       # Current out of device range with specified shunt resister
       print e
if __name__ == "__main__":
   read()

This will print out a graph that roughly looks like the below: (I touched the plasma ball at random intervals)



Tutorial coming soon

pi1 = pigpio.pi()       # pi1 accesses the local Pi's GPIO
pi2 = pigpio.pi('tom')  # pi2 accesses tom's GPIO
pi3 = pigpio.pi('dick') # pi3 accesses dick's GPIO

pi1.write(4, 0) # set local Pi's GPIO 4 low
pi2.write(4, 1) # set tom's GPIO 4 to high
pi3.read(4)     # get level of dick's GPIO 4
 sudo apt-get install pigpio python-pigpio python3-pigpio 
 import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.OUT)
print "LED on"
GPIO.output(18,GPIO.HIGH)
time.sleep(1)
print "LED off"
GPIO.output(18,GPIO.LOW) 
136 views0 comments

Recent Posts

See All

Comments


bottom of page