Skip to content

Commit

Permalink
add a digital multimeter thermocouple
Browse files Browse the repository at this point in the history
Extend the available temperature sensor with VA18b / PeakTech 3415 DMM.
Based on the code from https://alexkaltsas.wordpress.com/2013/04/19/python-script-to-read-data-from-va18b-multimeter/
  • Loading branch information
frankalicious committed Mar 9, 2016
1 parent af3a27b commit 40d840f
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 2 deletions.
5 changes: 4 additions & 1 deletion config.py.EXAMPLE
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,18 @@ gpio_air = 9 # Switches 0-phase det. solid-state-relay
### Inputs
gpio_door = 18

### Thermocouple Adapter selection (MAX31855 or MAX6675)
### Thermocouple Adapter selection (MAX31855 or MAX6675 or VA18B)
max31855 = 1
max6675 = 0
va18b = 0

### Thermocouple I2C Connection
gpio_sensor_cs = 27
gpio_sensor_clock = 22
gpio_sensor_data = 17

# serial dmm device
device = '/dev/ttyUSB0'

########################################################################
#
Expand Down
8 changes: 7 additions & 1 deletion lib/oven.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
log = logging.getLogger(__name__)

try:
if (config.max31855 == config.max6675):
if (config.max31855 == config.max6675 == config.va18b):
log.error("choose (only) one converter IC")
exit()
if config.max31855:
Expand All @@ -19,6 +19,9 @@
if config.max6675:
from max6675 import MAX6675, MAX6675Error
log.info("import MAX6675")
if config.va18b:
from va18b import VA18B
log.info("import VA18B")
sensor_available = True
except ImportError:
log.warning("Could not initialize temperature sensor, using dummy values!")
Expand Down Expand Up @@ -216,6 +219,9 @@ def __init__(self, time_step):
config.gpio_sensor_clock,
config.gpio_sensor_data,
"c")
if config.va18b:
log.info("init DMM VA18B")
self.thermocouple = VA18B(config.device)

def run(self):
while True:
Expand Down
148 changes: 148 additions & 0 deletions lib/va18b.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
#!/usr/bin/python2.7

#
# Just a quick n' dirty script to read the Data from a VA18B multimeter.
# This DMM uses the low nibble of 14 bytes to send the lcd segments.
#
# License: GPL v3. http://www.gnu.org/licenses/gpl-3.0-standalone.html
#

# based on https://alexkaltsas.wordpress.com/2013/04/19/python-script-to-read-data-from-va18b-multimeter/

import signal
import sys
import time
import serial
import io
import getopt

class VA18B(object):
def __init__(self, device = '/dev/ttyUSB0'):
self.device = device

try:
self.port=serial.Serial(port=self.device,
baudrate=2400,
bytesize=serial.EIGHTBITS,
stopbits=serial.STOPBITS_ONE,
parity=serial.PARITY_NONE,
timeout=None)

if not self.port.isOpen():
self.port.open()

except IOError,err:
print '\nError:' + str(err) + '\n'
sys.exit(1)

# Every packet is 14 bytes long.
def get_bytes(self):
i=0
substr=''
while i<=13:
byte=self.port.read(1)
# converting every byte to binary format keeping the low nibble.
substr += '{0:08b}'.format(ord(byte))[4:]
i += 1
return substr


def stream_decode(self, substr):

ac = int(substr[0:1])
dc = int(substr[1:2])
auto = int(substr[2:3])
pclink = substr[3:4]
minus = int(substr[4:5])

digit1 = substr[5:12]
dot1 = int(substr[12:13])
digit2 = substr[13:20]
dot2 = int(substr[20:21])
digit3 = substr[21:28]
dot3 = int(substr[28:29])
digit4 = substr[29:36]

micro = int(substr[36:37])
nano = int(substr[37:38])
kilo = int(substr[38:39])
diotst = int(substr[39:40])
mili = int(substr[40:41])
percent = int(substr[41:42])
mega = int(substr[42:43])
contst = int(substr[43:44])
cap = int(substr[44:45])
ohm = int(substr[45:46])
rel = int(substr[46:47])
hold = int(substr[47:48])
amp = int(substr[48:49])
volts = int(substr[49:50])
hertz = int(substr[50:51])
lowbat = int(substr[51:52])
minm = int(substr[52:53])
fahrenh = substr[53:54]
celcius = int(substr[54:55])
maxm = int(substr[55:56])

digit = {"1111101":"0",
"0000101":"1",
"1011011":"2",
"0011111":"3",
"0100111":"4",
"0111110":"5",
"1111110":"6",
"0010101":"7",
"1111111":"8",
"0111111":"9",
"0000000":"",
"1101000":"L"}

value = ("-" if minus else " ") +\
digit.get(digit1,"") + ("." if dot1 else "") +\
digit.get(digit2,"") + ("." if dot2 else "") +\
digit.get(digit3,"") + ("." if dot3 else "") +\
digit.get(digit4,"")

flags = " ".join(["AC" if ac else "",
"DC" if dc else "",
"Auto" if auto else "",
"Diode test" if diotst else "",
"Conti test" if contst else "",
"Capacity" if cap else "",
"Rel" if rel else "",
"Hold" if hold else "",
"Min" if minm else "",
"Max" if maxm else "",
"LowBat" if lowbat else ""])

units = ("n" if nano else "") +\
("u" if micro else "") +\
("k" if kilo else "") +\
("m" if mili else "") +\
("M" if mega else "") +\
("%" if percent else "") +\
("Ohm" if ohm else "") +\
("Amp" if amp else "") +\
("Volt" if volts else "") +\
("Hz" if hertz else "") +\
("C" if celcius else "")

# print value + " " + flags + " " + units
# 020.6 Auto C
return float(value)

def get(self):
self.read()
return self.data

def read(self):
substr = self.get_bytes()
self.data = self.stream_decode(substr)
# print self.data
# self.port.flushInput()

class VA18BError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)

0 comments on commit 40d840f

Please sign in to comment.