Table of Contents
Introduction
To simplify the viewing of changing data, we created this library of functions to simulate panel meters on your screen. It is based on pygame which is preinstalled on the Raspian OS so no additional software has to be installed.
What You'll Need
- A connection to your Raspberry Pi - either through a monitor and keyboard or remotely with VNC
- Optional - a TINKERplate connected to a programmed Raspberry Pi
Steps
Example 1 - Simple Meter
- Open the Thonny Python IDE under the Raspberry Icon:
- Enter the code as ahown below - you don't have to type all the stuff after the hashtags (#)
- If you have typed everything correctly, click on the green GO button should produce this window with changing data on your screen:
- Here's the code again if you prefer to simply paste it into your editor:
123456789101112import piplates.TINKERplate as TINK #import TIINKERplate moduleimport math #import math module - needed for sine and piimport time #import the time module - needed for sleepMag=10N=360TINK.openMETER() #create a panel meter with the default of a single linewhile(True): #Loop foreverfor i in range(N): #do this 360 timesval=Mag*math.sin(2*math.pi*i/360) #calculate the sine valueTINK.setMETER(val,'volts','Sine Data:') #send data to the metertime.sleep(0.05) #pause for 50msec- git clone https://github.com/pi-plates/TINKERplate-Projects.git
- cd TINKERplate-Projects
- python3 SimpleMeter.py
Example 2 - Four Meters
- Either modify your existing code or enter this new example from scratch
- Write and save the code as shown below and don't worry about all the comments (the stuff after the hashtags)
- Again if you have typed everything correctly, click on the green GO button should produce this new window with changing data on your screen:
Note that we have four lines of data now, bright yellow text, and a title for our window. - Here's the code again with more comments if you simply want to paste it into your program:
1234567891011121314151617181920import piplates.TINKERPlate as TINK #import TINKERplate moduleimport math #import math module - needed for sine and piimport time #import the time module - needed for sleepMag=10N=360mColor=(255,255,0) #this tuple represents the color yellowTINK.openMETER(4) #create a panel meter with the default of a single lineTINK.setCOLOR(mColor) #set meter colorTINK.setTITLE('Trigonometery Functions') #Set meter titlewhile(True): #Loop foreverfor i in range(N): #do this 360 timesTINK.setMETER(i,'degrees','Angle:',1) #write angle to line 1val=math.sin(2*math.pi*i/360) #calculate sine of angleTINK.setMETER(val,'','Sine:',2) #write sine value to line 2val=math.cos(2*math.pi*i/360) #calculate cosine of angleTINK.setMETER(val,'','Cosine:',3) #write cosine value to line 3val=math.tan(2*math.pi*i/360) #calculate tangent of angleTINK.setMETER(val,'','Tangent:',4) #write tangent value to line 4time.sleep(0.1)
The above code can be downloaded from github by typing the following instructions on the command line:
- git clone https://github.com/pi-plates/TINKERplate-Projects.git
- cd TINKERplate-Projects
- python3 FourMeters.py