def init(): signal.signal(signal.SIGINT, signal_handler) conf_analog = Conf_analog() SK_name.append(sen_temp_SK) SK_name.append(sen_humi_SK)
def init(): signal.signal(signal.SIGINT, signal_handler) conf_analog = Conf_analog() FIRMATA = 'FIRMATA_' #example to set arduino A2 as analog input -> config file "openplotter_analog.conf" #[FIRMATA_2] #sk_name = tanks.fuel.left.currentLevel #adjust_points = [[403.0,0.0],[522.0,25.0],[708.0,50.0],[913.0,100],[1024.0,100.01]] index = 0 for i in range(16): if conf_analog.has_section(FIRMATA + str(i)): channel.append(i) RawValue.append(0) adjust_point_active.append(0) adjust_point.append(0) channel_index.append(index) board.set_pin_mode(i, board.INPUT, board.ANALOG) if 0 == conf_analog.has_option(FIRMATA + str(i), 'sk_name'): conf_analog.set(FIRMATA + str(i), 'sk_name', '0') SK_name.append(conf_analog.get(FIRMATA + str(i), 'sk_name')) if 0 == conf_analog.has_option(FIRMATA + str(i), 'adjust_points'): adjust_point_active[index] = 0 else: line = conf_analog.get(FIRMATA + str(i), 'adjust_points') if line: adjust_point[index] = eval(line) adjust_point_active[index] = 1 else: adjust_point[index] = [] index += 1
# # You should have received a copy of the GNU General Public License # along with Openplotter. If not, see <http://www.gnu.org/licenses/>. import socket, time, math, csv, datetime, subprocess, sys, os op_folder = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..') sys.path.append(op_folder + '/classes') from ads1115 import Ads1115 from conf_analog import Conf_analog from ina219 import INA219 from ina219 import DeviceRangeError SHUNT_OHMS = 0.1 conf_analog = Conf_analog() home = conf_analog.home if len(sys.argv) > 1: if sys.argv[1] == 'settings': print home + '/.openplotter/openplotter_analog.conf' subprocess.Popen( ['leafpad', home + '/.openplotter/openplotter_analog.conf']) exit else: sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) poll_interval = 1 rate_analog = 1
# Openplotter is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Openplotter. If not, see <http://www.gnu.org/licenses/>. import socket, time, datetime, subprocess, sys, os op_folder = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../..') sys.path.append(op_folder + '/classes') from ads1115 import Ads1115 from conf_analog import Conf_analog conf_analog = Conf_analog() home = conf_analog.home if len(sys.argv) > 1: if sys.argv[1] == 'settings': print home + '/.openplotter/tools/openplotter_analog.conf' subprocess.Popen( ['leafpad', home + '/.openplotter/tools/openplotter_analog.conf']) exit else: ads1115 = Ads1115() a_index = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] a_value = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
def __init__(self): self.ADS1115_address = 0x48 # Select the gain # gain = 6144 # 0 +/- 6.144V # gain = 4096 # 1 +/- 4.096V # gain = 2048 # 2 +/- 2.048V # gain = 1024 # 3 +/- 1.024V # gain = 512 # 4 +/- 0.512V # gain = 256 # 5 +/- 0.256V self.gain_mV = [6144, 4096, 2048, 1024, 512, 256] # Select the sample rate # self.sps = 8 # 0 8 samples per second # self.sps = 16 # 1 16 samples per second # self.sps = 32 # 2 32 samples per second # self.sps = 64 # 3 64 samples per second # self.sps = 128 # 4 128 samples per second # self.sps = 250 # 5 250 samples per second # self.sps = 475 # 6 475 samples per second # self.sps = 860 # 7 860 samples per second self.samples_s = [8, 16, 32, 64, 128, 250, 475, 860] conf_analog = Conf_analog() self.bus = smbus.SMBus(1) a_index = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] self.active = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] self.gain = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] self.samples = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] self.ohmmeter = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] self.fixed_resistor = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] self.high_voltage = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] self.voltage_divider = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] self.upper_resistance = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] self.lower_resistance = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] self.adjust = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] self.adjust_point_b = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] self.adjust_point = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ADS1115 = 'ADS1115_' for i in a_index: #self.analog_active += 1 if 0 == conf_analog.has_section(ADS1115 + str(i)): conf_analog.add_section(ADS1115 + str(i)) if 0 == conf_analog.has_option(ADS1115 + str(i), 'active'): conf_analog.set(ADS1115 + str(i), 'active', '0') self.active[i] = conf_analog.get(ADS1115 + str(i), 'active') == '1' if 0 == conf_analog.has_option(ADS1115 + str(i), 'gain'): conf_analog.set(ADS1115 + str(i), 'gain', '0') if 0 == conf_analog.has_option(ADS1115 + str(i), 'samples'): conf_analog.set(ADS1115 + str(i), 'samples', '0') if 0 == conf_analog.has_option(ADS1115 + str(i), 'ohmmeter'): conf_analog.set(ADS1115 + str(i), 'ohmmeter', '0') if 0 == conf_analog.has_option(ADS1115 + str(i), 'fixed_resistor'): conf_analog.set(ADS1115 + str(i), 'fixed_resistor', '0') if 0 == conf_analog.has_option(ADS1115 + str(i), 'high_voltage'): conf_analog.set(ADS1115 + str(i), 'high_voltage', '3000') if 0 == conf_analog.has_option(ADS1115 + str(i), 'voltage_divider'): conf_analog.set(ADS1115 + str(i), 'voltage_divider', '0') if 0 == conf_analog.has_option(ADS1115 + str(i), 'upper_resistance'): conf_analog.set(ADS1115 + str(i), 'upper_resistance', '1000') if 0 == conf_analog.has_option(ADS1115 + str(i), 'lower_resistance'): conf_analog.set(ADS1115 + str(i), 'lower_resistance', '1000') if 0 == conf_analog.has_option(ADS1115 + str(i), 'adjust'): conf_analog.set(ADS1115 + str(i), 'adjust', '0') if 0 == conf_analog.has_option(ADS1115 + str(i), 'adjust_points'): self.adjust_point_b[i] = 0 else: line = conf_analog.get(ADS1115 + str(i), 'adjust_points') if line: self.adjust_point[i] = eval(line) self.adjust_point_b[i] = 1 else: self.adjust_point[i] = [] if self.active[i]: self.gain[i] = conf_analog.getint(ADS1115 + str(i), 'gain') if self.gain[i] > 5: self.gain[i] = 0 conf_analog.set(ADS1115 + str(i), 'gain', '0') self.samples[i] = conf_analog.getint(ADS1115 + str(i), 'samples') if self.samples[i] > 7: self.samples[i] = 0 conf_analog.set(ADS1115 + str(i), 'samples', '0') self.ohmmeter[i] = conf_analog.get(ADS1115 + str(i), 'ohmmeter') == '1' if self.ohmmeter[i]: self.fixed_resistor[i] = conf_analog.getfloat( ADS1115 + str(i), 'fixed_resistor') if self.fixed_resistor[i] < 100: self.fixed_resistor[i] = 100 conf_analog.set(ADS1115 + str(i), 'fixed_resistor', '100') self.high_voltage[i] = conf_analog.getfloat( ADS1115 + str(i), 'high_voltage') if self.high_voltage[i] < 3000: self.high_voltage[i] = 3000 conf_analog.set(ADS1115 + str(i), 'high_voltage', '3000') self.voltage_divider[i] = conf_analog.get( ADS1115 + str(i), 'voltage_divider') == '1' if self.voltage_divider[i]: self.upper_resistance[i] = conf_analog.getfloat( ADS1115 + str(i), 'upper_resistance') if self.upper_resistance[i] < 1000: self.upper_resistance[i] = 1000 conf_analog.set(ADS1115 + str(i), 'upper_resistance', '1000') self.lower_resistance[i] = conf_analog.getfloat( ADS1115 + str(i), 'lower_resistance') if self.lower_resistance[i] < 1000: self.lower_resistance[i] = 1000 conf_analog.set(ADS1115 + str(i), 'lower_resistance', '1000') self.adjust[i] = conf_analog.getfloat(ADS1115 + str(i), 'adjust')