class GroveLoudnessSensor(object): ''' Grove Loudness Sensor class Args: pin(int): number of analog pin/channel the sensor connected. ''' def __init__(self, channel): self.channel = channel self.adc = ADC() @property def value(self): ''' Get the loudness strength value, maximum value is 100.0% Returns: (int): ratio, 0(0.0%) - 1000(100.0%) ''' return self.adc.read(self.channel)
class GroveRoundForceSensor(ADC): ''' Class for Grove - Round Force Sensor Args: pin(int): number of analog pin/channel the sensor connected. ''' def __init__(self, channel): self.channel = channel self.adc = ADC() @property def value(self): ''' Get the force strength value, the strengest value is 100.0%. Returns: (int): ratio, 0(0.0%) - 1000(100.0%) ''' return self.adc.read(self.channel)
class GroveRotaryAngleSensor(ADC): ''' Grove Rotary Angle Sensor class Args: pin(int): number of analog pin/channel the sensor connected. ''' def __init__(self, channel): self.channel = channel self.adc = ADC() @property def value(self): ''' Get the rotary angle value, max angle is 100.0% Returns: (int): ratio, 0(0.0%) - 1000(100.0%) ''' return self.adc.read(self.channel)
class GroveAirQualitySensor(object): ''' Grove Air Quality Sensor class Args: pin(int): number of analog pin/channel the sensor connected. ''' def __init__(self, channel): self.channel = channel self.adc = ADC() @property def value(self): ''' Get the air quality strength value, badest value is 100.0%. Returns: (int): ratio, 0(0.0%) - 1000(100.0%) ''' return self.adc.read(self.channel)
class GroveCapMoistureSensor: def __init__(self, channel, dry_voltage, wet_voltage): self.channel = channel self.adc = ADC() self.dry_voltage = dry_voltage self.wet_voltage = wet_voltage @property def moisture_percent(self): v = self.voltage normalised_value = abs(self.dry_voltage-v) dif = float(abs(self.dry_voltage - self.wet_voltage)) percent = (normalised_value/dif)*100 return percent @property def voltage(self): value = self.adc.read_voltage(self.channel) return value
class GroveSoundSensor(object): ''' Grove Sound Sensor class Args: pin(int): number of analog pin/channel the sensor connected. ''' def __init__(self, channel): self.channel = channel self.adc = ADC() @property def sound(self): ''' Get the sound strength value Returns: (int): ratio, 0(0.0%) - 1000(100.0%) ''' value = self.adc.read(self.channel) return value
class GroveMoistureSensor: ''' Grove Moisture Sensor class Args: pin(int): number of analog pin/channel the sensor connected. ''' def __init__(self, channel): self.channel = channel self.adc = ADC() @property def moisture(self): ''' Get the moisture strength value/voltage Returns: (int): voltage, in mV ''' value = self.adc.read_voltage(self.channel) return value
def __init__(self, channel, sensor_type): self._channel = channel self._sensor_type = sensor_type # Analog to Digital Converter (ADC) - external chip unit on grove pi hat self.adc = ADC()
# do something with it if args.verbose: print("Servo:", last_received_midi) # print("MIDI:", midi_event) if args.servo: # Only send to servo if args suggest it. # Only act on most recent message. command_servo(last_received_midi) # define SERVOMIN 5 # define SERVOMAX 175 # MIDI: (10, 0, 0, 253, (0, 0), (129, 1), (128, 0), (0, 0, 0, 0, 0, 48)) # Setup ADC and Servo grove_adc = ADC() if args.servo: grove_servo = GroveServo(SERVO_CHANNEL) print("starting up.") if args.verbose: print("verbose mode on.") if args.screen: display = grove_display.setup_display() display.set_cursor(0, 0) display.puts('EMPI Ready.') # Run loop try: print("interface started.") while True: interaction_loop()
import sys import time from grove.factory import Factory from grove.grove_relay import GroveRelay from grove.adc import ADC from statistics import mean PIN = 22 # relay PIN relay = GroveRelay(PIN) adc = ADC() print("name: {0:20}, version: {1:4}".format(adc.name, adc.version)) # LCD 16x2 Characters # lcd = Factory.getDisplay("JHD1802") lcd = Factory.getLcd("JHD1802") rows, cols = lcd.size() print("LCD model: {}".format(lcd.name)) print("LCD type : {} x {}".format(cols, rows)) lcd.setCursor(0, 0) # ph = (voltage - b)/a a = (2.5 - 3.0) / (7.0 - 4.01) b = 2.5 - a * 7.0 offset = 0.0283 n = 1000 # ds18b20 sensor id _serialnum = "28-00000b702a1d" try:
def __init__(self): self.channel = 2 self.adc = ADC()
import sys import time import smbus2 from RPLCD.i2c import CharLCD from grove.adc import ADC sys.path.insert(0, "grove.py") print(sys.path) sys.modules['smbus'] = smbus2 lcd = CharLCD('PCF8574', address=0x27, port=1, backlight_enabled=True) adc = ADC() Offset = -2.2 print("name: {0:20}, version: {1:4}".format(adc.name, adc.version)) try: print('按下 Ctrl-C 可停止程式') lcd.clear() while True: lcd.cursor_pos = (0, 0) lcd.write_string("Date: {}".format(time.strftime("%Y/%m/%d"))) lcd.cursor_pos = (1, 0) lcd.write_string("Time: {}".format(time.strftime("%H:%M:%S"))) #voltage = adc.read_voltage(0)/1000 raw = adc.read_raw(0) voltage = adc.read_voltage(0) percent = adc.read(0) print("raw:{0:>6}, voltage:{1:>6}, percent(%):{2:>6} ".format( raw, voltage, percent)) # phValue = 7.0 + (voltage - 3.2) * (-5.5)
def __init__(self, channelX, channelY): self.channelX = channelX self.channelY = channelY self.adc = ADC()
def __init__(self, channel): self.__channel = channel self.__adc = ADC() self.__sum = 0 self.__count = 0 self.__max = 0
def __init__(self, channel, dry_voltage, wet_voltage): self.channel = channel self.adc = ADC() self.dry_voltage = dry_voltage self.wet_voltage = wet_voltage
def __init__(self): self.channel = int(os.environ.get("analogue_channel_light")) self.adc = ADC()
import time from grove.adc import ADC channel = 4 # pin A4 adc = ADC() while True: print(adc.read_voltage(channel)) time.sleep(0.5)
def __init__(self, channel): self.channelX = channel self.channelY = channel + 1 self.adc = ADC()
def __init__(self, channel): self.channel = channel self.adc = ADC() self._resolution = 1.5 # Celsius
def __init__(self, pin): #Analog Port self.pin = pin self.adc = ADC()
return amplitude_current # calculates the effective current we're interested in def getEffectiveCurrent(analog_port): current_amplitude = getAmplitude(analog_port) effective_current = current_amplitude / math.sqrt(2) print("The amplitude of the current = {} mA".format(current_amplitude)) return effective_current analog_port = 2 # connected to analog port A2 adc = ADC() try: with open('report.csv', mode='w') as file: fieldnames = ['Timestamp', 'Value'] writer = csv.DictWriter(file, fieldnames=fieldnames) writer.writeheader() while True: #minimum_current = 1 / 1024 * grove_vcc / 800 * 2000000 / 1.414 = 5.696(mA) # Only for sinusoidal alternating current now = datetime.now() effective_current = getEffectiveCurrent(analog_port) writer.writerow({ 'Timestamp': now.strftime("%Y-%m-%d %H:%M:%S"), 'Value': effective_current })
def __init__(self, channel): self.channel = channel self.adc = ADC()
def __init__(self, pin): self.pin = pin self.adc = ADC()