def poll_temp(self):
     while self.RUNNING:
         value = ads1256.read_channel(self.pin)
         temp = self.m*value + self.b
         print "pin:%d val:%f Celcius:%fc" % (self.pin, value, temp)
         self.add_value(temp)
         time.sleep(self.sleep)
    def on_timer(self, event):
        """Add some data at the end of each signal (real-time signals)."""
        k = 1

        y[:, :-k] = y[:, k:]
        data_chunk = ads1256.read_channel(channel)
        print(data_chunk)
        # Scale data to -1 to 1 range
        data_chunk = data_chunk / (DATA_MAX / 2.0) - 1

        data_min = np.amin(y)
        data_max = np.amax(y)

        y[:, -k:] = data_chunk

        if self.autoscale and (not self.hold_plot) and (
            (data_max - data_min) > 0.005):

            self.program['a_position'] = y - (data_max + data_min) / 2.0

            scale_x, scale_y = self.program['u_scale']
            scale_x_new, scale_y_new = (scale_x,
                                        (2.0 / (np.amax(y) - np.amin(y))))
            self.program['u_scale'] = (max(1,
                                           scale_x_new), max(1, scale_y_new))

            self.update()
        elif (not self.hold_plot or ((data_max - data_min) < 0.005)):
            scale_x, scale_y = self.program['u_scale']
            scale_x_new, scale_y_new = (scale_x, 1)
            self.program['u_scale'] = (max(1,
                                           scale_x_new), max(1, scale_y_new))

            self.program['a_position'].set_data(y.ravel().astype(np.float32))
            self.update()
Beispiel #3
0
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 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
Beispiel #5
0
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()
Beispiel #6
0
# SPS values:   2d5,  5,  10,  15,  25,  30,  50,  60,  100,  
# SPS values:   500, 1000,  2000,  3750,  7500,  15000,  30000
ads1256.start("1","2d5")
 

# Calculates and displays how much time has elapsed from the start of the program 
# to the end of executing the initialization function
print(str(int((time.time()-d0)*1000))+"mS in initializing ADC\n")


# Performs 5 readings of all ADC channels.
print("\nReading all channels with the function ads1256.read_all_channels():")
for i in range(1):
    d0 =time.time()
    valorTodosCanais = ads1256.read_all_channels()
    for x in valorTodosCanais:
        print(x)
    print("\n" + str(int((time.time()-d0)*1000))+"mS elapsed in reading 8 channels (" + str(int((time.time()-d0)*1000)/8) + " mS in each one)\n")


# Performs the reading of ADC channel 0
print("\nReading only the channel 0 with ads1256.read_channel():")
d0 =time.time()
valorCanal = ads1256.read_channel(0)
print(valorCanal)
        
print("\n" + str(int((time.time()-d0)*1000))+"mS in reading only channel 0\n")
 

ads1256.stop()
Beispiel #7
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):

    # For some reason 8 values are repeated, so take only one

    # Read the channel
    value = ads1256.read_channel(channel)

    time_ms = ((time.time() - time_prev) * 1000)
    time_prev = time.time()
    time_diffs.append(time_ms)

    # Add the value read from the ADC
    values.append(value)

    # Add the UNIX timestamp
    times.append(time.time())

#print(zip(times, values))
print("SPS:", n_samples / (time.time() - first_time))

plt.plot(np.array(times) - first_time, values, marker='+')
Beispiel #8
0
import ads1256  # import this lib

gain = 1  # ADC's Gain parameter
sps = 25  # ADC's SPS parameter

# Initialize the ADC using the parameters
ads1256.start(str(gain), str(sps))

# Fill the first list with all the ADC's absolute channel values
ChannelValue = ads1256.read_channel(0)

# Fill the second list  with the voltage values
ChannelValueVolts = (((ChannelValue * 100) / 167.0) / int(gain)) / 1000000.0
ChannelValueVolts2 = (((ChannelValue) / int(gain)) * 3.3) / 16777216

print ChannelValue

print ChannelValueVolts

print ChannelValueVolts2

# Print a new line
print("\n")

# Stop the use of the ADC
ads1256.stop()
Beispiel #9
0
def readADC_volts(channel = 5):
    # Read voltage from ADS1256
    reading = float(adc.read_channel(channel))
    voltage = reading/8388607 * 5
    return voltage
Beispiel #10
0
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 = []
		count += 1
		print count, avgVolts, " Volts", reading
		#print volts2turb(avgVolts), "NTU \r",

np.savetxt("Settling Data.txt", np.array(data))
Beispiel #11
0
                                 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)
    while True:
        ret = ads1256.read_channel(gpio_pin)
        if int(ret) > 4000000:
            take_picture(lsr, folder, camera, verbose)


def get_sound(base_folder, duration, fs, verbose):
    try:
        import sounddevice as sd
        from scipy.io.wavfile import write
    except Exception, e:
        print("lib not installed")
        exit(1)
    while True:
        myrecording = sd.rec(int(duration * fs), samplerate=fs, channels=1)
        sd.wait()
        now = datetime.now()
Beispiel #12
0
def ReadValues():
    while not rospy.is_shutdown():
        Loop(ads1256.read_channel(adcChannel))
        rate.sleep()
    ads1256.stop()
Beispiel #13
0
def ReadValues():
    while True:
        Loop(ads1256.read_channel(adcChannel))
        time.sleep(1 / readFrequency / 2)
    ads1256.stop()