本文整理汇总了Python中ABE_ADCPi.ADCPi类的典型用法代码示例。如果您正苦于以下问题:Python ADCPi类的具体用法?Python ADCPi怎么用?Python ADCPi使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ADCPi类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self):
self._a2d_chan_speed = a2d_chan_speed
self._a2d_chan_direction = a2d_chan_direction
self._a2d_chan_vcc = a2d_chan_vcc
self._file_report_period = file_report_period
self._i2c_helper = ABEHelpers()
self._bus = self._i2c_helper.get_smbus()
self._adc = ADCPi(self._bus, 0x68, 0x69, 12)
self._CtrlPort = 8200
self._IPAddr = self.get_local_ip()
self._samples = list()
self._samples_lock = threading.Lock()
self._display_lock = threading.Lock()
self._thread_sampling_obj = None
self._thread_reporting_obj = None
self._stop_requested = False
self._dirs_stream = list() #stream of directions searched for callibration samples
#calibrated directions
self._dirs = list()
self._dirs_volts = list()
self._dirs_names = ("NN", "NE", "EE", "SE", "SS", "SW", "WW", "NW")
self._dirs_file = "/home/pi/PyProj/dirs_calibration.txt"
self._calibration_restore()
self.files_to_compress = list()
self.display = False
示例2: __init__
def __init__(self, drive):
""" Standard Constructor """
logging.info("Three Point Turn constructor")
# set up ADC
self.i2c_helper = ABEHelpers()
self.bus = self.i2c_helper.get_smbus()
self.adc = ADCPi(self.bus, 0x6a, 0x6b, 12)
# define fixed values
# red is typically 3.5V
self.red_min = 3
self.red = 3.5
self.stopped = 0
self.full_forward = 0.5
self.half_forward = 0.25
self.slow_forward = 0.1
self.full_reverse = -0.5
self.half_reverse = -0.25
self.slow_reverse = -0.1
self.straight = 0
self.full_left = -1
self.slow_left = -0.5
self.rear_line_sensor = 2
# same sensor for now
self.front_line_sensor = 2
self.max_rate = 2
# Drivetrain is passed in
self.drive = drive
self.killed = False
示例3: __init__
def __init__(self, drive):
""" Standard Constructor """
logging.info("Proximity constructor")
# set up ADC
self.i2c_helper = ABEHelpers()
self.bus = self.i2c_helper.get_smbus()
self.adc = ADCPi(self.bus, 0x6a, 0x6b, 12)
# define fixed values
self.stopped = 0
self.full_forward = 0.4
self.slow_forward = 0.3
self.full_reverse = -0.5
self.slow_reverse = -0.25
self.left_steering = -0.25
self.right_steering = 0.25
self.straight = 0
self.distance_sensor = 1
# Voltage value we are aiming for (2 was close, 0.5 was further away)
self.distance_threshold = 50.0
self.distance_required = 17.0
# Drivetrain is passed in
self.drive = drive
self.killed = False
示例4: __init__
def __init__(self, drive):
""" Standard Constructor """
logging.info("Straight Line Speed constructor")
# set up ADC
self.i2c_helper = ABEHelpers()
self.bus = self.i2c_helper.get_smbus()
self.adc = ADCPi(self.bus, 0x6a, 0x6b, 12)
# define fixed values
self.stopped = 0
self.full_forward = 0.5
self.slow_forward = 0.1
self.full_reverse = -0.5
self.slow_reverse = -0.1
self.left_steering = -0.25
self.right_steering = 0.25
self.straight = 0
self.distance_sensor = 1
# Voltage value we are aiming for (2 was close, 0.5 was further away)
self.nominal_voltage = 0.5
self.min_dist_voltage = 2.0
self.max_dist_voltage = 0.4
# Drivetrain is passed in
self.drive = drive
self.killed = False
示例5: __init__
class dld_solar_window:
_channel = 0
_report_period = 5
_thread = None
_stop_requested = False
_srv_ip_addr = "1.2.2.201"
_srv_port = 8200
def __init__(self, channel=0, report_period=the_report_period):
self._channel = channel
self._report_period = report_period
self._i2c_helper = ABEHelpers()
self._bus = self._i2c_helper.get_smbus()
self._adc = ADCPi(self._bus, 0x68, 0x69, 12)
def Start(self):
self._stop_requested = False
self._thread = threading.Thread(target=self.SamplingThread)
self._thread.start()
print("sampling thread initialized")
def SamplingThread(self):
print("sampling thread started")
mc_socket = None
time_last_report = time.time()
connected = False
while self._stop_requested != True:
if connected == False:
try:
# time.sleep(5)
mc_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mc_socket.connect((self._srv_ip_addr, self._srv_port))
print("connected")
time.sleep(1)
except Exception as e:
connected = False
continue
time_now = time.time()
voltage = self._adc.read_voltage(self._channel)
try:
mc_socket.send("Vout:%02f\n" % (voltage))
print("Vout:%02f\n" % (voltage))
except Exception as e:
connected = False
time.sleep(5.0)
def Stop(self):
if self._thread == None:
return
self._stop_requested = True
if self._thread.isAlive():
self._thread.join()
self._thread = None
示例6: __init__
def __init__(self):
""" Standard Constructor """
logging.info("Three Point Turn constructor")
# set up ADC
self.i2c_helper = ABEHelpers()
self.bus = self.i2c_helper.get_smbus()
self.adc = ADCPi(self.bus, 0x6a, 0x6b, 12)
self.killed = False
示例7: __init__
def __init__ (self, ph7, ph4, ds):
self.ph7 = ph7
self.ph4 = ph4
self.ds = ds
i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
self.adc = ADCPi(bus, self.i2c1, self.i2c2, self.bitrate)
self.calcpHSlope()
示例8: __init__
def __init__(self, channel = 1, dir_channel = 2, wind_power_channel = 3, report_period = the_report_period):
self._channel = channel
self._dir_channel = dir_channel
self._wind_power_channel = wind_power_channel
self._temp_channel = 4
self._report_period = report_period
self._i2c_helper = ABEHelpers()
self._bus = self._i2c_helper.get_smbus()
self._adc = ADCPi(self._bus, 0x68, 0x69, 12)
self._IPAddr = self.GetLocalIP()
示例9: main
def main():
i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
adc = ADCPi(bus, 0x68, 0x69, 18)
if not os.path.isfile(db_name):
createdb()
while (True):
temp = 0
light = 0
moisture = 0
for x in range(0, 60):
# read from adc channels and write to the log file
temp = temp + (adc.read_voltage(1) - 0.5) * 100
light = light + adc.read_voltage(2)
moisture = moisture + adc.read_voltage(3)
time.sleep(0.4)
# Average temp
temp = temp / 60
# Correct temp
temp = temp - 1.2
# Average light
light = light / 60
# Average moisture
moisture = moisture / 60
print("temp,light,moisture")
print(temp)
print(light)
print(moisture)
writetodb("%02f" % temp, "%02f" % light, "%02f" % moisture)
示例10: __init__
def __init__(self):
self._a2d_chan_speed = a2d_chan_speed
self._a2d_chan_direction = a2d_chan_direction
self._a2d_chan_vcc = a2d_chan_vcc
self._file_report_period = file_report_period
self._i2c_helper = ABEHelpers()
self._bus = self._i2c_helper.get_smbus()
self._adc = ADCPi(self._bus, 0x68, 0x69, 12)
self._CtrlPort = 8200
self._IPAddr = self.get_local_ip()
self._samples = list()
self._samples_lock = threading.Lock()
self._thread_sampling = None
self._thread_reporting = None
self._stop_requested = False
示例11: ABEHelpers
# ADC
#---------------------------------------------------------------------------
from ABE_ADCPi import ADCPi
from ABE_helpers import ABEHelpers
import os
############################################################################################
#
# Paramétrage des composants I2Cs
#
############################################################################################
i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
adc = ADCPi(bus, 0x68, 0x69, 12)
############################################################################################
#
# Initialisation des GPIOs
#
############################################################################################
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(12, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)
示例12: ABEHelpers
#!/usr/bin/python
from ABE_ADCPi import ADCPi
from ABE_helpers import ABEHelpers
import os
import time
i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
adc = ADCPi(bus, 0x68, 0x69, 12)
v1 = adc.read_voltage(1)
v2 = adc.read_voltage(2)
def calcCurrent(inval):
return ((inval) - (v1 / 2)) / 0.066
#c1 = float(vdd / calcCurrent(v2))
while (True):
# clear the console
os.system('clear')
# read from adc channels and print to screen
print ("Channel 1 voltage V: %02f" % v1)
print ("Channel 1 current I: %02f" % calcCurrent(v2))
#print ("Channel 1 resistance R: %02f" % c1)
# wait 1 second before reading the pins again
示例13: ABEHelpers
#!/usr/bin/python
from ABE_ADCPi import ADCPi
from ABE_helpers import ABEHelpers
import os
import time
import RPi.GPIO as GPIO
i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
adc = ADCPi(bus, 0x68, 0x69, 12)
# Configure the GPIO pins
BUTTON_PIN = 24
GPIO.setmode(GPIO.BCM)
GPIO.setup(BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# voltage reading from channel 1
v1 = adc.read_voltage(1)
# voltage reading from channel 2, used for current calc i2
v2 = adc.read_voltage(2)
# calculates current from channel preceded by 'i' (eg. i2)
# i2 = current calculated from adc channel 2 defined globally
def calccurrent(inval):
global i
i = ((inval) - 2.5) / 0.066
# calculates resistance using two global variables
示例14: ABEHelpers
Requires python smbus to be installed
run with: python demo-read_voltage.py
================================================
Initialise the ADC device using the default addresses and sample rate,
change this value if you have changed the address selection jumpers
Sample rate can be 12,14, 16 or 18
"""
i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
adc = ADCPi(bus, 0x68, 0x69, 12)
while (True):
# clear the console
os.system('clear')
# read from adc channels and print to screen
print ("Channel 1: %02f" % adc.read_voltage(1))
print ("Channel 2: %02f" % adc.read_voltage(2))
print ("Channel 3: %02f" % adc.read_voltage(3))
print ("Channel 4: %02f" % adc.read_voltage(4))
print ("Channel 5: %02f" % adc.read_voltage(5))
print ("Channel 6: %02f" % adc.read_voltage(6))
print ("Channel 7: %02f" % adc.read_voltage(7))
print ("Channel 8: %02f" % adc.read_voltage(8))
示例15: ABEHelpers
#!/usr/bin/python
from ABE_ADCPi import ADCPi
from ABE_helpers import ABEHelpers
import os
import time
import RPi.GPIO as GPIO
i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
adc = ADCPi(bus, 0x68, 0x69, 12)
# Configure the GPIO pins
BUTTON_PIN = 24
EXIT_BUTTON = 23
GPIO.setmode(GPIO.BCM)
GPIO.setup(BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(EXIT_BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_UP)
button_press = GPIO.input(BUTTON_PIN)
# voltage reading from channel 1 (v_supply) / 2, used for calccurrent()
v_i = (adc.read_voltage(1)) /2
# voltage reading from channel 1 (v_supply), used for calccurrent()
v1 = (adc.read_voltage(1))
# calculates current from channel labelled 'v_i'
# i = current calculated from adc channel 1 defined globally
def calccurrent(inval):
global i
i = ((inval) - v_i) / 0.066