def read_adda(port=2, nb_times=50, wait_for=1): import ads1256 # import this lib ads1256.start(str(1), "25") while True: value = ads1256.read_channel(port) volt = (value * 100 / 167.0) / 1000000.0 print(volt)
def init_board(gain=1, sps=25): global ADS1256_INITIALIZED if ADS1256_INITIALIZED: print "not double initing board..." return print "initing board..." ADS1256_INITIALIZED = True ads1256.start(str(gain), str(sps)) print "inited board..."
def ReadValues(): rate = 25 # Frequency in Hz ads1256.start("1", str(rate)) pub = rospy.Publisher('/sen_4/ResVal', Float32, tcp_nodelay=False, queue_size=1) rospy.init_node('Rheostat', anonymous=True) rate = rospy.Rate(10) while not rospy.is_shutdown(): absoluteValue = ads1256.read_channel(0) voltage = ((absoluteValue * 100) / 167.0) / 1000000.0 rospy.loginfo(voltage) pub.publish(voltage) rate.sleep() ads1256.stop()
def __init__(self): print("init") self.voltageAverage = 0 self.voltagePositiveAverage = 0 self.lastPublishedCurrent = -99999 self.nextPublishTime = 0 if ads1256.start("1", str(self.readFrequency)) != 0: print("Failed starting the ADC") return
def get_sensor_card_and_take_pic(rotation, gpio_pin, shutter, folder, verbose, width=720, height=480): import ads1256 # import this lib ads1256.start(str(1), "25") camera = "" try: camera = PiCamera() camera.resolution = (width, height) camera.rotation = rotation % 360 camera.shutter_speed = shutter print("launching script") except Exception, e: print("camera allready in use") exit(0)
def __init__(self): SensorDataEntry.__init__(self) self.voltageAverage = 0 self.voltagePositiveAverage = 0 #self.lastPublishedCurrent = -999999 self.nextPublishTime = 0 if ads1256.start(str(self.gain), str(self.readFrequency)) != 0: print "Failed starting ADC" return self.stopLoop = False threading.Thread(target=self.loop).start()
def PWM_Voltage_Measure(Measurement): gain = 1 # ADC's Gain parameter sps = 25 # ADC's SPS parameter ads1256.start(str(gain), str(sps)) if Measurement == 'DC_Link': ChannelValue = ads1256.read_channel(3) ChannelValueVolts = (( (ChannelValue * 100) / 167.0) / int(gain)) / 1000000.0 DCVolts = ChannelValueVolts elif Measuremnet == 'Solar': ChannelValue = ads1256.read_channel(3) ChannelValueVolts = (( (ChannelValue * 100) / 167.0) / int(gain)) / 1000000.0 DCVolts = ChannelValueVolts else: UPS_Error('Error_Voltage_Measurement') ads1256.stop() return DCVolts
#!/usr/bin/env python import socket import ads1256 import struct import datetime TCP_IP = '192.168.1.104' TCP_PORT = 5005 TCP_PACK_SIZE = 200 TCP_SAMPLE_SIZE = 8 #Start the ADC ads1256.start("1", "2d5") s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((TCP_IP, TCP_PORT)) s.listen(1) print "Wait for client..." #Wait for a connection conn, addr = s.accept() print 'Connection address:', addr while 1: outBin = "" for i in range(TCP_PACK_SIZE): t1 = datetime.datetime.now() data = ads1256.read_all_channels() t3 = datetime.datetime.now()
import ads1256 # import the ads1256 lib import time # import the time lib from datetime import datetime # import the datetime lib #Python example to use the ADS1256 as a Voltage Data Logger. gain = 1 # ADC's Gain parameter. Possible values: 1, 2, 4, 8, 16, 32, 64 sps = "25" # ADC's SPS parameter. Possible values: 2d5, 5, 10, 15, 25, 30, 50, 60, 100, 500, 1000, 2000, 3750, 7500, 15000, 30000 chv = [0, 0, 0, 0, 0, 0, 0, 0] # Create the first list. It will receive ADC's absolute values ch = [ 0, 0, 0, 0, 0, 0, 0, 0 ] # Create the second list. It will received absolute values converted to Volts ads1256.start(str(gain), str(sps)) # Initialize the ADC using the parameters # Define the CSV filename based on the date and time timest = str(datetime.now()) timest = timest.replace(":", "_") timest = timest.replace(" ", "-") timest = timest.replace(".", "-") timest = timest[:-7] filename = "ads1256-log-" + str(timest) + ".csv" header = [] header.extend([ "Row_id", "Channel 0", "Channel 1", "Channel 2", "Channel 3", "Channel 4", "Channel 5", "Channel 6", "Channel 7", "Timestamp" ]) # Define a CSV header
import SetFrequency import multiprocessing status_connected = False while status_connected == False: try: url = 'https://www.google.com' urllib.urlopen(url) status_connected = True except: status_connected = False gain = 1 # ADC's Gain parameter sps = 25 # ADC's SPS parameter AllChannelValuesVolts = [0, 0, 0, 0, 0, 0, 0, 0] AllChannelValues = [0, 0, 0, 0, 0, 0, 0, 0] ads1256.start(str(gain), str(sps)) frec = 0 fi = 0 fp = 0 ff = 0 tiempo_incial = 0 parar = 0 v_value = [0] v_tiempo = [0] v_amp = [0] v_bat = [0] v_fase = [0] vo_1 = [0] vo_2 = [0]
from __future__ import print_function, division import ads1256 import time, random import numpy as np import matplotlib import matplotlib.pyplot as plt # Initializes the ADC using py-ads1256 library function # First argument: GAIN. The second: SPS # Possible settings: # GAIN values: 1, 2, 4, 8, 16, 32, 64 # SPS values: 2d5, 5, 10, 15, 25, 30, 50, 60, 100, # SPS values: 500, 1000, 2000, 3750, 7500, 15000, 30000 ads1256.start("1", "30000") time.sleep(0.1) channel = 0 n_samples = 5000 # Performs the reading of ADC channel 0 time_prev = time.time() first_time = time_prev values = [] times = [] time_diffs = [] for i in range(n_samples):
import numpy as np from time import sleep import datetime as dt import signal import sys def signal_handler(signal, frame): global interupted interupted = True def readADC_volts(channel = 5): # Read voltage from ADS1256 reading = float(adc.read_channel(channel)) voltage = reading/8388607 * 5 return voltage adc.start("1", "2d5") signal.signal(signal.SIGINT, signal_handler) interupted = False dataLog = open("dcf_datalog.txt", "w") dataLog.write("%5s %5s"%("Time", "Volts\n")) print "DCF Survival Test" print "Start time: ", dt.datetime.now().strftime('%Y-%m-%d - %H:%M:%S') print "Press CTRL-C to exit safely" count = 0 while True: dataLine = (dt.datetime.now().strftime('%Y-%m-%d - %H:%M:%S'), readADC_volts(channel = 7))
import ads1256 from time import sleep import numpy as np def volts2turb(volts): """ from manufacturer callibration curve """ turbidity = -1120.4*(volts**2) + 5742.3*volts - 4352.9 return turbidity ads1256.start("1", "10") data = [] mean = [] count = 0 for i in range(7500*60*10): reading = float(ads1256.read_channel(7)) #print reading voltageOut = reading/8388607 * 5 #print voltageOut,"Volts \r", sleep(0.1) mean.append(voltageOut) if i % 1 == 0: avgVolts = float(sum(mean))/len(mean) data.append(avgVolts) mean = []
import time import math import rospy from std_msgs.msg import Float32 # configuration # adcChannel = 2 publishInterval = 1 readFrequency = 30000 # ADC's SPS parameter. Possible values: 2d5, 5, 10, 15, 25, 30, 50, 60, 100, 500, 1000, 2000, 3750, 7500, 15000, 30000 smoothingFactor = 0.01 ################# voltageAverage = 0 voltagePositiveAverage = 0 nextPublishTime = 0 ads1256.start("1", str(readFrequency)) pub = rospy.Publisher('/sen_4/ac_sensor', Float32, tcp_nodelay=False, queue_size=1) rospy.init_node('ac_sensor', anonymous=True) rate = rospy.Rate(readFrequency / 2) def Loop(channelValue): global voltageAverage, voltagePositiveAverage, nextPublishTime voltage = ((channelValue * 100) / 167.0) / 1000000.0 if (voltageAverage == 0): voltageAverage = voltage voltagePositiveAverage = voltage else: