So why a gauge? Why not a 7 segment display or an LCD?
Well, I'm a scraped knuckles, oily fingernails kind of engineer normally. I deal with enormous bits of machinery, so I get a bit excited by old engineering tools and bits of old plant. It probably helps that I have a mild Steampunk obsession too.
As a consequence, I have weird bits of engineering paraphernalia in my flat as decoration. Part of that, is a collection of fairly antique gauges.
So 7 seg displays - boring. Antique volt meter steampunk style - Pretty Freaking Awesome!
I have a working project that is similar using a 150 uA moving coil ammeter.
I have used the Adafruit MPC4725 DAC...
https://learn.adafruit.com/mcp4725-12-bit-dac-with-raspberry-pi
I have a 5K shunt resistor across the coil and the DAC outputs to the coil through a 10K trimpot.
The DAC is controlled by the Adafruit Python Library.
I use Feedparser to read a RSS feed.
https://pythonhosted.org/feedparser/
I write out the current comment count on a blog that has a Disqus comment system to a text file.
This script is called by cron every 5 minutes...
#!/usr/bin/python
from Adafruit_MCP4725 import MCP4725
import time
import feedparser
import os
#SineLookup Table
SineLookup = \
[ 178, 350, 512, 658, 784, 887,
962, 1008, 1024, 1008, 962, 887, 784, 658,
512, 350, 178, 0, -178, -350, -512, -658,
-784, -887, -962, -1008, -1024, -1008, -962, -887,
-784, -658, -512, -350, -178, 0 ]
# Initialise the DAC using the default address
dac = MCP4725(0x62)
#dac.setVoltage(0)
#get latest comment count
blog = 'tonyortega.org'
d = feedparser.parse('http://' + blog +'/feed/')
comments = int(d['entries'][0]['slash_comments'])
#scale value to meter - full scale = 1000
meter = int(float(4.095 * comments))
# Read previous comment count
with open("/home/pi/count.txt", "rt") as in_file:
text = in_file.read()
#get comment delta
sweep = (comments - int(text))
#play sound if new post.
if sweep < 0:
os.system("mpc -q play 1")
#sine sweep needle once for each new comment
while (sweep > 0):
for val in SineLookup:
dac.setVoltage (meter+(int(val)))
time.sleep(0.03)
sweep = sweep - 1
# Write latest comment count to file
dac.setVoltage(meter)
with open("/home/pi/count.txt", "wt") as out_file:
out_file.write (str(comments))
The above works quite reliably and the DAC holds it value between runs.