#!/bin/bash #values in kiloohms to get rid of zeroes VREF=3.3 #VREF=1.2 if [ "$1" == "-r" ]; then VREF=$2; shift;shift; fi if [ "$1" == "-3" ]; then VREF=3.3; shift; fi if [ "$1" == "-1" ]; then VREF=1.2; shift; fi R1=$1 R2=$2 # if no second value, use insanely high, 100 megaohms if [ "$R2" == "" ]; then R2=100000; fi #3.3*33/(1/(1/100+1/100)) # # 3.3v rest # R2 R1 # OUT---*---/\/\/\---*---/\/\/\---GND # | | # ---/\/\/\---* # Rtherm | # | # REF---------------- # calcv() { echo -n "$1'c/${2}kOhm: " # requires qalc (apt-get install qalc) RES=`qalc -t "$VREF*(1/(1/$2+1/$R2)+$R1)/(1/(1/$2+1/$R2))"` # compare with input voltage, truncate if higher if [ "`echo $RES|cut -d '.' -f 1`" -gt 11 ]; then echo "12 ($RES)"; else echo $RES; fi } #uses tabulated data for the 100k thermistor echo -n "Output voltages for Vref=${VREF}V, 100k thermistor, and R1=${R1}k" if [ "$R2" != "100000" ]; then echo -n ", R2=${R2}k"; fi echo calcv 25 100 calcv 35 63 calcv 50 33 calcv 65 19 calcv 75 13 calcv 85 9