コード例 #1
0
    def pi_i2c_bus_number(self):
        return 1


## Weewx
WEEWX_ADDRESS = '127.0.0.1'
WEEWX_PORT = '8888'

## GPIO
WIND_GPIO = 21
RAIN_GPIO = 20

## ADC
GAIN = 1
ADC_WIND_DIRECTION_CHANNEL = 1
adc = Adafruit_ADS1x15.ADS1115(address=0x49)

## wind
KMH_PER_TICK_SECOND = 2.4
wind_lock = threading.Semaphore()

# rain
# MM_PER_TICK = 0.2794
MM_PER_TICK = -0.2794  # disable rain by making it negative
rain_lock = threading.Semaphore()

# pressure
INHG_PER_PA = 0.0002953
bmp = BMP280.BMP280()

# humidity
コード例 #2
0
ファイル: nat_gas_code_sept_20_2019.py プロジェクト: ATFL/GUI
    100, 75, 125, 175, 225, 275, 325, 375, 425, 475, 525, 575, 625, 675, 725,
    775, 825, 875, 925
]
ethaneConcList = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

if len(methaneConcList) != len(ethaneConcList):
    print("Error! Concentration lists are not the same length!")

numtests = len(methaneConcList)

#------------------------Variable Declarations------------------------#

sensor_input_channel = 3  # The physical terminal on DAQCplate the sensor number 1 signal is connected to
linear_actuator_position_channel = 2  # The physical terminal on DAQCplate the linear actuator position sensor signal is connected to

adc = ads.ADS1115(0x48)
gain = 2 / 3

# Following correction factors were provided by MKS (MFC Manufacturer) (Ph. 978-284-4000)
#methane_correction_factor = 0.72 # Manufacturer specified 10 SCCM Nitrogen is equivalent to 7.2 SCCM Methane through the MFC
methane_correction_factor = 0.72
#ethane_correction_factor = 1.01
ethane_correction_factor = 0.5  # Manufacturer specified 10 SCCM Nitrogen is equivalent to 5 SCCM Ethane through the MFC

methane_flow_rate = 10  # mL/min, this will be the arbitrary, constant setpoint of the MFC
ethane_flow_rate = 1
# methane_flow_rate = 1
# ethane_flow_rate = 0.1
diffusion_time = 0  # time allowed for injected gas to diffuse in sensing chamber before sensor exposure occurs
mfc_flow_stabilization_time = 10  # venting flow through MFC for 5 seconds while flow stabilizes. Stable flow is then switch into chamber
switching_time = 1  # time allowed for flow and pressure to stabilize within system while switching purge solenoids
コード例 #3
0
ファイル: adc_data.py プロジェクト: zine-robotics/Actroid
import RPi.GPIO as RPi
import Adafruit_ADS1x15
import time

adc_ob = Adafruit_ADS1x15.ADS1115()
ga = 1
adc = [0] * 4
hgt
while (1):
    for i in range(4):
        adc[i] = adc_ob.read_adc(i, gain=ga)
        print adc[i]
        time.sleep(0.2)
コード例 #4
0
#########

# initial setup
showIcon = True
batteryStatus = 0

if monitorType == "SERIAL":
    adsDivisor = 1023.0
    controlVoltage = 1
    try:
        ser = serial.Serial('/dev/ttyACM' + str(serialPort), 115200)
    except serial.SerialException:
        print('Serial Port ACM' + str(serialPort) + ' Not Found')
elif adsType == "1115":
    ads = Adafruit_ADS1x15.ADS1115()
    adsDivisor = 32767.0
else:
    ads = Adafruit_ADS1x15.ADS1015()
    adsDivisor = 2047.0

signal.signal(signal.SIGTERM, endProcess)
signal.signal(signal.SIGINT, endProcess)
system(pngView + " -b 0 -l 299999 -x " + str(xLocation) + " -y " +
       str(yLocation) + " " + iconFolder + "/blank.png &")

# read and/or create showIcon toggle file
try:
    with open(stateFile, 'r') as f:
        showIcon = (f.read() == "True")
except IOError:
コード例 #5
0
import signal, sys  # Required for interrupt handler
import RPi.GPIO as GPIO  # Required to control RaspberryPI GPIO pins
import pysnmp.hlapi as SNMP  # Required for owserver 1-wire temperature sensors

# Import Adafruit modules that drive the hardware
import Adafruit_ADS1x15  # Required for ADS1x15 Analog to Digital Converter
from Adafruit_LED_Backpack import AlphaNum4  # Required for 14 segment AlphaNumeric Display
from Adafruit_MotorHAT import Adafruit_MotorHAT  # Required for Stepper Motor Controller
from Adafruit_MotorHAT import Adafruit_StepperMotor  # Required for Stepper Motor Controller

####################################
# Initialize objects
####################################

# Create instance of an ADS1115 ADC (16-bit)
adc = Adafruit_ADS1x15.ADS1115(address=0x48, busnum=1)

# Create instances of displays with a specific I2C address and/or bus.
# Also create empty string in messagelist for each display
for d in range(len(displayaddr)):
    displaylist.append(AlphaNum4.AlphaNum4(address=displayaddr[d], busnum=1))
    messagelist.append("    ")

# Initialize the displays
for d in range(len(displaylist)):
    displaylist[d].begin()

# Set brightness of all displays
set_display_brightness(bright)

# Initialize MotorHat for Stepper Motor
コード例 #6
0
at a different topic ('RasPi1/1Hz',' RasPi1/10Hz', 'RasPi1/100Hz')
"""

from datetime import datetime
import Adafruit_ADS1x15
import paho.mqtt.client as mqtt
import pandas as pd
import numpy as np
import time
from multiprocessing import Process

# create four ADS115 instances with different addresses
# based on the connection of the ADR (address) pin
# Data Rate samples are chosen based on the frequency we want to pull data
# from it. data_rate indicates the time it will take in measuring the analog data
adc0 = Adafruit_ADS1x15.ADS1115(
    address=0x48)  # ADR to GRN | Will do 10Hz readings
adc1 = Adafruit_ADS1x15.ADS1115(
    address=0x49)  # ADR to VDD | Will do 10Hz readings
adc2 = Adafruit_ADS1x15.ADS1115(
    address=0x4A)  # ADR to SDA | Will do 1Hz readings
adc3 = Adafruit_ADS1x15.ADS1115(
    address=0x4B)  # ADR to SCL | Will do 100Hz readings


def connect_to_broker(client_id, host, port, keepalive, on_connect,
                      on_publish):
    # Params -> Client(client_id=””, clean_session=True, userdata=None, protocol=MQTTv311, transport=”tcp”)
    # We set clean_session False, so in case connection is lost, it'll reconnect with same ID
    client = mqtt.Client(client_id=client_id, clean_session=False)
    client.on_connect = on_connect
    client.on_publish = on_publish
コード例 #7
0
    return conversion_value


mult = 10
ser = serial.Serial("/dev/ttyS0")
writestring = "M 4\r\n"
ser.write(writestring.encode())
writestring = "K 2\r\n"
ser.write(writestring.encode())
ser.flushInput()

R = 10000
V0 = 5

# Create an ADS1115 ADC (16-bit) instance.
adc1 = Adafruit_ADS1x15.ADS1115(0x48)
adc2 = Adafruit_ADS1x15.ADS1115(0x49)

GAIN = 2 / 3

extended_state = 4.5  # voltage value achieved when linear actuator is extended to correct sensing depth
retracted_state = 0.9  # voltage value achieved when linear actuator is retracted to idle state
printing_time = 1
continueTest = True
sampling_time = 0.1  # time between samples taken, determines sampling frequency

sensing_delay_time = 9  # normall 9 time delay after beginning data acquisition till when the sensor is exposed to sample
sensing_retract_time = 20  # normally 130 time allowed before sensor is retracted, no longer exposed to sample
duration_of_signal = 20  # normally 300time allowed for data acquisition per test run

vacuum_pump = 4  # Broadcom pin 17 (P1 pin 11)
コード例 #8
0
def readSensor():
    # Simple demo of reading each analog input from the ADS1x15 and printing it to
    # the screen.
    # Author: Tony DiCola
    # License: Public Domain
    #import time

    # Import the ADS1x15 module.
    import Adafruit_ADS1x15

    # Create an ADS1115 ADC (16-bit) instance.
    adc = Adafruit_ADS1x15.ADS1115()

    # Or create an ADS1015 ADC (12-bit) instance.
    #adc = Adafruit_ADS1x15.ADS1015()

    # Note you can change the I2C address from its default (0x48), and/or the I2C
    # bus by passing in these optional parameters:
    #adc = Adafruit_ADS1x15.ADS1015(address=0x49, busnum=1)

    # Choose a gain of 1 for reading voltages from 0 to 4.09V.
    # Or pick a different gain to change the range of voltages that are read:
    #  - 2/3 = +/-6.144V
    #  -   1 = +/-4.096V
    #  -   2 = +/-2.048V
    #  -   4 = +/-1.024V
    #  -   8 = +/-0.512V
    #  -  16 = +/-0.256V
    # See table 3 in the ADS1015/ADS1115 datasheet for more info on gain.
    valAdcGain = 1

    #print('Reading ADS1x15 values, press Ctrl-C to quit...')
    # Print nice channel column headers.
    #print('| {0:>6} | {1:>6} | {2:>6} | {3:>6} |'.format(*range(4)))
    #print('| {ch2:>6} |')
    #print('-' * 9)
    # Main loop.
    #i = 0
    #while i < 20:
    # Read all the ADC channel values in a list.
    #values = [0]*4

    # Read the specified ADC channel using the previously set gain value.
    valAdc0 = [0] * 5
    valAdc1 = [0] * 5
    valAdc2 = [0] * 5

    i = 0
    while i < 5:
        valAdc0[i] = adc.read_adc(0, gain=valAdcGain)
        valAdc1[i] = adc.read_adc(1, gain=valAdcGain)
        valAdc2[i] = adc.read_adc(2, gain=valAdcGain)
        i += 1
        # Note you can also pass in an optional data_rate parameter that controls
        # the ADC conversion time (in samples/second). Each chip has a different
        # set of allowed data rate values, see datasheet Table 9 config register
        # DR bit values.
        #values[i] = adc.read_adc(i, gain=GAIN, data_rate=128)
        # Each value will be a 12 or 16 bit signed integer value depending on the
        # ADC (ADS1015 = 12-bit, ADS1115 = 16-bit).
        # Print the ADC values.
        #print('| {0:>6} | {1:>6} | {2:>6} | {3:>6} |'.format(*values))
        #print('| {0:>6} |'.format(RS_ValAdc))
        # Pause for half a second.
        #time.sleep(0.5)

    #average
    valAdc0Avg = sum(valAdc0) / len(valAdc0)
    valAdc1Avg = sum(valAdc1) / len(valAdc1)
    valAdc2Avg = sum(valAdc2) / len(valAdc2)

    adc.stop_adc()
    return valAdc0Avg, valAdc1Avg, valAdc2Avg
コード例 #9
0
ファイル: tcaTest.py プロジェクト: wgililland/HyperLynx2019
#initalize SMBus on i2c-1
i2c = smbus.SMBus(1)
#MUX address
MUX = 0x70
#close all MUX channels
i2c.write_byte(MUX, 0)
#initialize IR thermometer i2c addr 0x5B on channel 0
i2c.write_byte(MUX, (1 << 0))
IR = MLX90614(0x5B)
#initialize IMU i2c addr 0x28 on channel 2
i2c.write_byte(MUX, (1 << 2))
IMU = BNO055(0x28)
IMU.begin()
#initialize ADC i2c addr 0x48 on channel 7
i2c.write_byte(MUX, (1 << 7))
ADC = Adafruit_ADS1x15.ADS1115(address=0x48)
#conversion for ADC read
CONVERT = (6.144 / 32767)


def tempRead():
    #select channel 0
    i2c.write_byte(MUX, (1 << 0))
    data = IR.get_obj_temp_C()
    return data


def orientRead():
    #select channel 2
    i2c.write_byte(MUX, (1 << 2))
    data = IMU.read_euler()
コード例 #10
0
'''
树莓派代码,用于ADS1115模型通信树莓派,连续读取数字信号
读取心电信号并进行预处理
'''
import Adafruit_ADS1x15 as ada
import matplotlib.pyplot as plt
import numpy as np
import pywt
adc = ada.ADS1115()
adc.start_adc(3, 2 / 3, 475)
'''
3是通道数
2/3是信号增益
475是采样率
'''
data = []
while len(data) < 5000:
    data.append(adc.get_last_result())
data = np.array(data)
coeffs = pywt.wavedec(data=data, wavelet='db5', level=9)
cA9, cD9, cD8, cD7, cD6, cD5, cD4, cD3, cD2, cD1 = coeffs
threshold = (np.median(np.abs(cD1)) / 0.6745) * (np.sqrt(2 * np.log(len(cD1))))
cD1.fill(0)
cD2.fill(0)
cD3.fill(0)
for i in range(1, len(coeffs) - 3):
    coeffs[i] = pywt.threshold(coeffs[i], threshold)
rdata = pywt.waverec(coeffs=coeffs, wavelet='db5')
plt.figure(figsize=(20, 4))
plt.subplot(3, 1, 1)
plt.plot(data)
コード例 #11
0
from PyQt4 import QtCore, QtGui  # PyQt4
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
import pyqtgraph as pg  # Pyqtgraph
import time  # Import time
import Adafruit_ADS1x15  # Import the ADS1x15 module.
import argparse
# import the "form class" from your compiled UI
from template import Ui_CustomWidget

### SETUP

## ADC
adc = Adafruit_ADS1x15.ADS1115(
)  # Create an ADS1115 ADC (16-bit) instance. Connect TMP to A0 and RV to A1
# Gain for ADC
GAIN = 1
# Read all the ADC channel values in a list.
readValues = [0] * 4

## VARIABLES
samplingfrequency = 120  # Hz
samplingperiod = 1000 / samplingfrequency  # In milliseconds
zeroWindAdjustment = 0.2  # Negative numbers yield smaller wind speeds and vice versa.
# Initialise lists for subequent plotting
global TimeList, WSList
dtList = []
WSList = []
VolFlowList = []
VolList = []
コード例 #12
0
ファイル: main.py プロジェクト: dRoje/python-for-hardware
from multiprocessing import Process, Value
import time
import Adafruit_ADS1x15 as ADS
import RPi.GPIO as GPIO

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)

ledPin = 27
adcAddress = 0x48
adcBusNumber = 1
adcRange = 32767
frequency = 500

GPIO.setup(ledPin, GPIO.OUT)
adc = ADS.ADS1115(address=adcAddress, busnum=adcBusNumber)

f = FlaskThread()
f.start()

adcRead = Value('i', 0)


def dimmer():
    while True:
        dutyOn = adcRead.value / adcRange
        dutyOff = 1 - dutyOn
        GPIO.output(ledPin, 1)
        time.sleep(dutyOn / frequency)
        GPIO.output(ledPin, 0)
        time.sleep(dutyOff / frequency)
コード例 #13
0
 def get(self):
     hydration = Adafruit_ADS1x15.ADS1115().read_adc(0, gain=2 / 3)
     data = {'hydration': hydration}
     return jsonify(data)
コード例 #14
0
ファイル: adc.py プロジェクト: nubbysaurus/radish-pi
 def __init__(self, adc_address=0x48, i2c_bus=1):
     self.i2c_bus = i2c_bus  # default: 1 (0 on older pi's)
     self.adc_address = adc_address  # default: 0x48
     self.adc_i = Adafruit_ADS1x15.ADS1115(address=adc_address, busnum=1)
     print("Connected sensor: ADS1115 @ " + str(self.adc_address))
コード例 #15
0
ファイル: adc.py プロジェクト: MxToolbox/BalloonLaunch
# Choose a gain of 1 for reading voltages from 0 to 4.09V.
# Or pick a different gain to change the range of voltages that are read:
#  - 2/3 = +/-6.144V
#  -   1 = +/-4.096V
#  -   2 = +/-2.048V
#  -   4 = +/-1.024V
#  -   8 = +/-0.512V
#  -  16 = +/-0.256V
# See table 3 in the ADS1015/ADS1115 datasheet for more info on gain.

GAIN = 1
Vin = 5.0
REF_RESISTANCE = 1000

AdConverter1 = Adafruit_ADS1x15.ADS1115(
)  # Create an ADS1115 ADC (16-bit) instance.


def readVoltage(channel, factor=1):
    # factor is optional, use this if input is voltage divided (e.g. x5)
    try:
        raw = AdConverter1.read_adc(channel, gain=GAIN)
        Vout = round(((raw / 32768) * 4.096) * factor, 4)
        return Vout
    except:
        logging.error("readVoltage() Exception occurred", exc_info=True)


if __name__ == '__main__':  # Program start from here
    try:
        while True:
コード例 #16
0
 def __init__(self):
     """
     Here is where you can initialize any instance variables you might need!
     """
     self.adc = Adafruit_ADS1x15.ADS1115()
     self.GAIN = 1
コード例 #17
0
pg.setConfigOption('foreground', 'k')
import random
import sys
import time
import datetime
import Adafruit_ADS1x15 as ads
#import Adafruit_MAX31855.MAX31855 as MAX31855
#i2c 76
from Adafruit_BME280 import *
#i2c 77
from Adafruit_BME280_2 import *
import busio
import board
import digitalio

adc1 = ads.ADS1115(0x48)
adc2 = ads.ADS1115(0x49)
## --- Global Variable Initialization --- ##
global liveGraph
global bme1Box
global bme2Box
#global max31855Box
global emergencyStop
global app
global printing
global progress
global startB
global veryStartTime
global totalTime
totalTime = 250
global stopB
コード例 #18
0
def run_test():
    mult = 10
    ser = serial.Serial("/dev/ttyS0")
    writestring = "M 4\r\n"
    ser.write(writestring.encode())
    writestring = "K 2\r\n"
    ser.write(writestring.encode())
    ser.flushInput()

    R = 10000
    V0 = 5

    # Create an ADS1115 ADC (16-bit) instance.
    adc1 = Adafruit_ADS1x15.ADS1115(0x48)
    #adc2 = Adafruit_ADS1x15.ADS1115(0x49)

    GAIN = 2 / 3

    extended_state = 4.5  # voltage value achieved when linear actuator is extended to correct sensing depth
    retracted_state = 0.9  # voltage value achieved when linear actuator is retracted to idle state
    printing_time = 1
    continueTest = True
    sampling_time = 0.1  # time between samples taken, determines sampling frequency

    sensing_delay_time = 9  # time delay after beginning data acquisition till when the sensor is exposed to sample
    sensing_retract_time = 130  # time allowed before sensor is retracted, no longer exposed to sample
    duration_of_signal = 300  # time allowed for data acquisition per test run

    vacuum_pump = 4  # Broadcom pin 17 (P1 pin 11)
    solenoid = 17  # Broadcom pin 17 (P1 pin 11)
    linear_actuator_extend = 27  # Broadcom pin 5 (P1 pin 13)
    linear_actuator_unlock_retract = 22  # Broadcom pin 12 (P1 pin 15)

    GPIO.setmode(
        GPIO.BCM
    )  # There are two options for this, but just use the board one for now. Don't worry much about it, we can check the definitions when I get back
    GPIO.setup(vacuum_pump, GPIO.OUT)  # Specifies vacuum_pump pin as an output
    GPIO.setup(solenoid, GPIO.OUT)  # Specifies vacuum_pump pin as an output
    # GPIO.setup(linear_actuator_extend, GPIO.OUT) # Specifies linear_actuator_extend pin as an output
    # GPIO.setup(linear_actuator_unlock_retract, GPIO.OUT) # Specifies linear_actuator_unlock_retract pin as an output
    GPIO.setup(18, GPIO.OUT)

    # GPIO.output(linear_actuator_extend, GPIO.LOW)
    # GPIO.output(linear_actuator_unlock_retract, GPIO.LOW)
    GPIO.output(solenoid, GPIO.LOW)
    GPIO.output(vacuum_pump, GPIO.LOW)
    pwm = GPIO.PWM(18, 50)
    pwm.start(7)

    global stopCounter
    start_time = time.time(
    )  # capture the time at which the test began. All time values can use start_time as a reference
    dataVector1 = []  # data values to be returned from sensor 1
    dataVector2 = []  # data values to be returned from sensor 2
    dataVector3 = []  # data values to be returned from sensor 1
    dataVector4 = []  # data values to be returned from sensor 2
    timeVector = []  # time values associated with data values
    sampling_time_index = 1  # sampling_time_index is used to ensure that sampling takes place every interval of sampling_time, without drifting.

    print("Starting data capture")

    while (time.time() < (start_time + duration_of_signal)) and (
            continueTest
            == True):  # While time is less than duration of logged file
        if (
                time.time() >
            (start_time + (sampling_time * sampling_time_index))
                and (continueTest == True)
        ):  # if time since last sample is more than the sampling time, take another sample
            ##        print("get another sample")
            dataVector1.append(
                adc1.read_adc(0, gain=GAIN)
            )  # Perform analog to digital function, reading voltage from first sensor channel
            dataVector2.append(
                adc1.read_adc(1, gain=GAIN)
            )  # Perform analog to digital function, reading voltage from second sensor channel
            dataVector3.append(
                adc1.read_adc(2, gain=GAIN)
            )  # Perform analog to digital function, reading voltage from first sensor channel
            dataVector4.append(
                adc1.read_adc(3, gain=GAIN)
            )  # Perform analog to digital function, reading voltage from second sensor channel
            timeVector.append(time.time() - start_time)
            sampling_time_index += 1

    ##        writestring = "Z\r\n"
    ##        ser.write(writestring.encode())
    ##        resp = ser.read(10)
    ##        resp = resp[:8]
    ##        co2 = float(resp[2:])
    ##        print("CO2: " + co2 * mult)

    ##        print(ADC_linear_actuator())

    # increment sampling_time_index to set awaited time for next data sample
    ##    if ((sampling_time_index - 1) % 10 == 0):
    ##        print(int(time.time() - start_time))

    # If time is between 10-50 seconds and the Linear Actuator position sensor signal from the ADC indicates a retracted state, extend the sensor
        elif (time.time() >= (start_time + sensing_delay_time)
              and time.time() <= (sensing_retract_time + start_time)
              and (continueTest == True)):
            ##            print("extend actuator")
            # GPIO.output(linear_actuator_extend, GPIO.HIGH)  # Actuate linear actuator to extended position
            # GPIO.output(linear_actuator_unlock_retract, GPIO.LOW)  # Energizing both control wires causes linear actuator to extend
            pwm.ChangeDutyCycle(5)
        # If time is less than 10 seconds or greater than 50 seconds and linear actuator position sensor signal from the ADC indicates an extended state, retract the sensor
        elif (((time.time() < (sensing_delay_time + start_time)) or
               (time.time() > (sensing_retract_time + start_time)))
              and (continueTest == True)):
            ##            print("retract actuator")
            # GPIO.output(linear_actuator_unlock_retract,GPIO.HIGH)  # Retract linear actuator to initial position. Energizing only the linear_actuator_unlock_retract wire causes the linear actuator to retract
            # GPIO.output(linear_actuator_extend, GPIO.LOW)
            pwm.ChangeDutyCycle(5.8)
        # Otherwise, keep outputs off
        else:
            # GPIO.output(linear_actuator_unlock_retract, GPIO.LOW)
            # GPIO.output(linear_actuator_extend, GPIO.LOW)
            pwm.ChangeDutyCycle(6)
    combinedVector = np.column_stack(
        (timeVector, dataVector1, dataVector2, dataVector3, dataVector4))

    # This section of code is used for generating the output file name. The file name will contain date/time of test, as well as concentration values present during test
    current_time = datetime.datetime.now()
    year = current_time.year
    month = current_time.month
    day = current_time.day
    createFolders(year, month, day)
    hour = current_time.hour
    minute = current_time.minute
    fileName = str(year) + '-' + str(month) + '-' + str(day) + '_' + str(
        hour) + ':' + str(minute) + '_Isaac_neg_no_lid.csv'
    #fileName = str(year) + '-' + str(month) + '-' + str(day) + '_' + str(hour) + ':' + str(minute) + '_bl.csv'
    np.savetxt(r'/home/pi/Documents/Tests/' + str(year) + '/' + str(month) +
               '/' + str(day) + '/' + str(fileName),
               combinedVector,
               fmt='%.10f',
               delimiter=',')
コード例 #19
0
#!usr/bin/env python

"""hay que hacer andar el ads1115"""

import time

# import sensor de humedad
import Adafruit_DHT
 
# Import the ADS1x15 module.
import Adafruit_ADS1x15 

# Create an ADS1115 ADC (16-bit) instance.
adc = Adafruit_ADS1x15.ADS1115() #.ADS1015 para elegir el otro

# Note you can change the I2C address from its default (0x48), and/or the I2C
# bus by passing in these optional parameters:
#adc = Adafruit_ADS1x15.ADS1015(address=0x49, busnum=1)

# Choose a gain of 1 for reading voltages from 0 to 4.09V.
# Or pick a different gain to change the range of voltages that are read:
#  - 2/3 = +/-6.144V
#  -   1 = +/-4.096V
#  -   2 = +/-2.048V
#  -   4 = +/-1.024V
#  -   8 = +/-0.512V
#  -  16 = +/-0.256V
# See table 3 in the ADS1015/ADS1115 datasheet for more info on gain.
GAIN = 1

#ahora voy a configurar el DHT
コード例 #20
0
ファイル: Battery.py プロジェクト: JoGist/Technology-Team
 def __init__(self):
     self.adc = Adafruit_ADS1x15.ADS1115();
     self.voltage = 0;
     self.GAIN = 1;
コード例 #21
0
 def __init__(self):
     self.rotaryListener=[]
     self.adc = Adafruit_ADS1x15.ADS1115()
コード例 #22
0
ファイル: tempControl.py プロジェクト: BarrettJB/IOTFermentor
from math import log

#Takes value from ADC and returns temperature
def calculate_temperature(val):
    T0 = 298.15
    Tk = 273.15
    B = 3950
    R0 = 10000
    volt = num*(5.0/32768)
    Rt = (volt*10000)/(5-volt)
    T_inv = (1.0/T0) + (1.0/B)*log(Rt/10000)
    T = (1.0/T_inv)-Tk 
    #print('|  %2.2fC | %5.1f | %1.5f |' % (T,Rt,volt))
    return T;

adc = ads1x15.ADS1115()
GAIN = 1

#setup relay GPIO pin
GPIO.setmode(GPIO.BCM)
GPIO.setup(25, GPIO.OUT)
GPIO.output(25, GPIO.HIGH)

#timer for data points
start = time.clock()

#file to write data into
file = open('tempData.txt','w')

print('Starting temperature controlled relay')
print('Measured Temperature')
コード例 #23
0
ファイル: fsr_rpizero_ads1115.py プロジェクト: 0xf17/reride2
def map(x, min1, max1, min2, max2):
    steps = (x/(max1-min1))
    buf = steps*(max2-min2) + min2
    return buf
def average(data):
    sum = 0
    for i in data:
        sum +=i
    return round(sum/len(data),4)

SAMPLE = 10
INTERVAL = 0.005
GAINVOL = 4.096
CHANNELS_CONNECTED = 2
adc = Adafruit_ADS1x15.ADS1115(0x48,busnum=0)
CHANNELS_CONNECTED = 4
fsr = [0]*CHANNELS_CONNECTED
GAIN=16
value= [0]*CHANNELS_CONNECTED

for i in range(CHANNELS_CONNECTED):
    value[i] = adc.read_adc(i, gain=GAIN)
mean = (value[0]+value[1]+value[2]+value[3])/4
while True:
    values= []
    f1,f2,f3,f4 = [],[],[],[]
    for s in range(SAMPLE):
        for i in range(CHANNELS_CONNECTED):
            buf = adc.read_adc(i, gain=GAIN) - mean
            mv = round(map(buf,-32768,32767,0,8192),0)
コード例 #24
0
 def __init__(self,pin):
     self.adc = Adafruit_ADS1x15.ADS1115()
     self.GAIN = 1
     #read_values from A(pin)
     self.ana_input = pin
コード例 #25
0
import Adafruit_ADS1x15 as ADS
import serial
from pathlib import Path
#----> Machine learning Imports <----
# import pickle
# import sklearn

#################### Object Declaration ####################
GPIO.setmode(GPIO.BOARD)
# Linear Actuator
pinLA = 8
pinEnable = 10
linearActuator = LinearActuator(pinLA, pinEnable)
# Analog-Digital Converter
#Darius Edit adc = ADS.ADS1115(0x49)
adc2 = ADS.ADS1115(0x48)
# MOS Sensor

sensor1 = MOS(adc2, 0)  #
sensor2 = MOS(adc2, 1)
sensor3 = MOS(adc2, 2)
sensor4 = MOS(adc2, 3)

all_sensors = all_sensors(sensor1, sensor2, sensor3, sensor4)

# Temperature sensor
#Darius Edit Temp_adc_channel = 1
#Darius Edit temperatureSensor = TemperatureSensor(adc, Temp_adc_channel)
#Pressure Sensor
#Press_adc_channel = 0
#pressureSensor = PressureSensor(adc,Press_adc_channel)
コード例 #26
0
# Simple demo of reading each analog input from the ADS1x15 and printing it to
# the screen.
# Author: Tony DiCola
# License: Public Domain
import time

# Import the ADS1x15 module.
import Adafruit_ADS1x15

coeff = 76.29  # ADC 16 bits 76.29uv

# Create an ADS1115 ADC (16-bit) instance.

adc = Adafruit_ADS1x15.ADS1115(address=0x50, busnum=2)

# Choose a gain of 1 for reading voltages from 0 to 4.09V.
# Or pick a different gain to change the range of voltages that are read:
#  - 2/3 = +/-6.144V
#  -   1 = +/-4.096V
#  -   2 = +/-2.048V
#  -   4 = +/-1.024V
#  -   8 = +/-0.512V
#  -  16 = +/-0.256V
# See table 3 in the ADS1015/ADS1115 datasheet for more info on gain.
GAIN = 1

# Main loop.
while True:
    values = adc.read_adc(3, gain=GAIN)

    voltage = (values) * (
コード例 #27
0
CSV_FILE = "data/creek_data.csv"
LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

# RainSensor Setting
GPIO.setmode(GPIO.BCM)
GPIO.setup(15, GPIO.IN)
RAIN_REPE_NUM = 100
RAIN_REPE_TIME = 0.2

# TemperatureSensor Setting
SENSOR_ID = "28-01191ed4dcbc"
SENSOR_W1_SLAVE = "/sys/bus/w1/devices/" + SENSOR_ID + "/w1_slave"
ERR_VAL = 85000

# DO,pH Setting
ADC = Adafruit_ADS1x15.ADS1115()
GAIN = 1
DOPH_REPE_NUM = 150
DOPH_REPE_TIME = 0.2

PH_MID = 25200
PH_SLOPE_LOW = 1192
PH_INTERCEPT_LOW = 17177
PH_SLOPE_HIGH = 1626
PH_INTERCEPT_HIGH = 14257

DO_SLOPE = 474
DO_INTERCEPT = -1312


def ph_calc(value):
コード例 #28
0
    def run(self):
        #time
        a11 = 0
        acd = []
        m = 0
        h = 0

        def time_f(sec, minute, hour):

            sec += 1
            if (sec > 59):
                minute = minute + 1
                sec = 0
                if (minute > 59):
                    hour = hour + 1
                    minute = 0
            aaa = [sec, minute, hour]
            print(hour, " ", minute, " ", sec)
            return aaa

        book = openpyxl.load_workbook('appending.xlsx')
        sheet = book.active

        #define lux sensor
        i2c = busio.I2C(board.SCL, board.SDA)
        sensor = adafruit_tsl2591.TSL2591(i2c)

        adc_value = []
        c = []
        adc = Adafruit_ADS1x15.ADS1115()
        GAIN = 1

        def teraadc():
            global w
            global x
            global y
            GAIN = 1
            a = []

            temp = round(
                (adc.read_adc(0, gain=GAIN) - adc.read_adc(3, gain=GAIN)) *
                5.0 / (32767 * .0065), 4)
            print("Temp", temp)
            lcd.write_string('Temp: ' + str(temp))
            temperature.put(temp)
            w = list(temperature.queue)
            if (temperature.full()):
                temperature.get()
            time.sleep(1)
            lcd.clear()

            volt = round(adc.read_adc(1, gain=GAIN) * 4.8 * 72.2 / 32767, 4)
            print("Voltage", volt)
            lcd.write_string(u'Volt: ' + str(volt))
            voltage.put(volt)
            x = list(voltage.queue)
            if (voltage.full()):
                voltage.get()
            time.sleep(1)
            lcd.clear()

            curr = round(adc.read_adc(2, gain=GAIN) * 4.6 * 0.95 / 32767, 4)
            print("Current", curr)
            lcd.write_string(u'Current: ' + str(curr))
            current.put(curr)
            y = list(current.queue)
            if (current.full()):
                current.get()
            time.sleep(1)
            lcd.clear()

            a = [temp, volt, curr]
            return a

        def luxsensor():
            global z
            lux = round(sensor.lux * 2, 4)
            print("Lux", lux)
            lcd.write_string(u'Lux: ' + str(lux))
            luxxx.put(lux)
            if (luxxx.full()):
                luxxx.get()
            z = list(luxxx.queue)
            time.sleep(1)
            lcd.clear()
            return lux

        dim = sheet.dimensions
        c = list(dim)
        k = c[-1]
        t = int(k)

        while (True):
            print("\n")
            #time
            acd = time_f(a11, m, h)
            a11 = acd[0]
            m = acd[1]
            h = acd[2]

            adc_value = teraadc()
            adc_value.append(luxsensor())
            j = 1

            for i in adc_value:
                sheet.cell(row=t + 1, column=j).value = i
                j = j + 1
                if (j > 4):
                    t = t + 1
                    break
            book.save('appending.xlsx')
コード例 #29
0
import Adafruit_ADS1x15
import MySQLdb
import time
import datetime
import pymssql

# Create an ADS1115 ADC (16-bit) instance.
adc = Adafruit_ADS1x15.ADS1115()

# See table 3 in the ADS1015/ADS1115 datasheet for more info on gain.
GAIN = 1

time_sensor = time.time()
# Main loop.
sensor1 = [0]*4
sensor2 = [0]*4
sensor3 = [0]*4
sensor4 = [4]*4


for i in range(4):
    sensor1[i] = adc.start_adc(i, gain=GAIN)
    sensor2[i] = adc.start_adc(i, gain=GAIN)
    sensor3[i] = adc.start_adc(i, gain=GAIN)
    sensor4[i] = adc.start_adc(i, gain=GAIN)

connobj = pymssql.connect(server='192.168.0.240', user='******', password='******', database='tempdb', port='1433',autocommit=True)
cursor = connobj.cursor()
cursor.execute('SELECT * FROM temp_table')
コード例 #30
0
import Adafruit_ADS1x15 #adafruit object wordt aangemaakt
import time
import numpy as np
import matplotlib.pyplot as plt
import csv

adc = Adafruit_ADS1x15.ADS1115() #Een ADS1115 ADC object wordt aangemaakt
##adc = Adafruit_ADS1x15.ADS1015() #Een ADS1115 ADC object wordt aangemaakt
#uncomment bij het gebruik van ADS1015 bovenstaande 
ref_time = time.time() #tijd bij het opstarten van het programma

'settings ADS
'gain instellingen' 
#  - 2/3 = +/-6.144V
#  -   1 = +/-4.096V
#  -   2 = +/-2.048V
#  -   4 = +/-1.024V
#  -   8 = +/-0.512V
#  -  16 = +/-0.256V
GAIN = 1 #instellen amplifier
'Data rates instellingen' 
#data rate moet een van de volgende waarden hebben:
#8, 16, 32, 64, 128, 250, 475, 860 bij de ADS1115
#128, 250, 490, 920, 2400, 3300    bij de ADS1015
DATA_RATE=[ 128,250,490,920,1600,2400,3300]
###DATA_RATE=[8, 16, 32, 64, 128, 250, 475, 860]
DATA_RATE= [-1] #sample rate 


#uncomment deze sectie en commentariseer de andere sectie als je de waarden op het scherm wilt laten printen en wilt laten opslaan 
N=1000