How to use the gpiozero.MCP3008 function in gpiozero

To help you get started, we’ve selected a few gpiozero examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github theyosh / TerrariumPI / terrariumAnalogSensor.py View on Github external
def load_data(self):
    data = None

    if self.get_address() is not None and len(self.get_address().split(',')) >= 1:
      address = self.get_address().split(',')
      data_pin = address[0]
      device = 0 if len(address[0]) == 1 else address[1]

      sensor = MCP3008(channel=int(data_pin), device=int(device))
      values = []
      for counter in range(5):
        value = sensor.value
        if terrariumUtils.is_float(value):
          values.append(float(value))
        sleep(0.2)

      sensor = None
      # sort values from low to high
      values.sort()
      # Calculate average. Exclude the min and max value. And therefore devide by 3
      data = round((sum(values[1:-1]) / (len(values)-2)),5)

    return data
github simonmonk / raspberrypi_cookbook_ed3 / python / ch_13_adc_tmp36.py View on Github external
from gpiozero import MCP3008
import time

analog_input = MCP3008(channel=0)

while True:
    reading = analog_input.value
    voltage = reading * 3.3 
    temp_c = voltage * 100 - 50
    temp_f = temp_c * 9.0 / 5.0 + 32
    print("Temp C={:.2f}\tTemp F={:.2f}".format(temp_c, temp_f))
    time.sleep(1)
github gpiozero / gpiozero / docs / examples / robot_pots_2.py View on Github external
from gpiozero import Robot, MCP3008
from gpiozero.tools import scaled
from signal import pause

robot = Robot(left=(4, 14), right=(17, 18))

left_pot = MCP3008(0)
right_pot = MCP3008(1)

robot.source = zip(scaled(left_pot, -1, 1), scaled(right_pot, -1, 1))

pause()
github gpiozero / gpiozero / docs / examples / robot_pots_1.py View on Github external
from gpiozero import Robot, MCP3008
from gpiozero.tools import zip_values
from signal import pause

robot = Robot(left=(4, 14), right=(17, 18))

left_pot = MCP3008(0)
right_pot = MCP3008(1)

robot.source = zip_values(left_pot, right_pot)

pause()
github gpiozero / gpiozero / docs / examples / robot_pots_2.py View on Github external
from gpiozero import Robot, MCP3008
from gpiozero.tools import scaled
from signal import pause

robot = Robot(left=(4, 14), right=(17, 18))

left_pot = MCP3008(0)
right_pot = MCP3008(1)

robot.source = zip(scaled(left_pot, -1, 1), scaled(right_pot, -1, 1))

pause()
github raspitv / analogzero / adc_voltmeter_16x2.py View on Github external
lcd = lcddriver.lcd()    # create object for lcd control
lcd.lcd_clear()          # clear LCD ready for start

def update():
    lcd.lcd_display_string('{:^16}'.format(row_one), 1)
    lcd.lcd_display_string('{:^16}'.format(row_two), 2)

# display an intro message
row_one = "Hi 16x2 RasPiO"
row_two = "Analog Zero"
update()
sleep(2)

while True:
    for x in range(3):
        adc = MCP3008(channel=x)
        readings = 0.0
        repetitions = 200            # how many times we sample
        for y in range(repetitions):
            readings += adc.value
        average = readings / repetitions
        volts = '{:6.3f}'.format(vref * average * conversion_factors[x])
        print("channel " + str(x) + ":", volts,"Volts")
        adc_list[x] = volts
        if x == 2:
            row_one   = str("10V:"+adc_list[0])+"V"
            row_two   = str("15V:"+adc_list[1])+"V"
            row_three = str("20V:"+adc_list[2])+"V"
            row_four  = str("RasPiO Voltmeter")
            if counter % 7 == 0:       # change to tweak alternation
                if toggle == 0:
                    toggle = 1
github azogue / hass_config / custom_components / sensor / raspioanalog.py View on Github external
def __init__(self, name, analog_channel, unit=None, device_class=None, negate=False):
        """Initialize the analog sensor."""
        from gpiozero import MCP3008

        self._analog_sensor = MCP3008(channel=analog_channel)
        self._channel = analog_channel
        self._name = name
        self._device_class = device_class
        self._unit = unit
        self._negate_value = negate
        self._value = self._get_analog_value_as_percentage()
github gpiozero / gpiozero / docs / examples / rgbled_pot_2.py View on Github external
from gpiozero import RGBLED, MCP3008
from gpiozero.tools import zip_values
from signal import pause

led = RGBLED(2, 3, 4)
red_pot = MCP3008(0)
green_pot = MCP3008(1)
blue_pot = MCP3008(2)

led.source = zip_values(red_pot, green_pot, blue_pot)

pause()
github gpiozero / gpiozero / docs / examples / rgbled_pot_2.py View on Github external
from gpiozero import RGBLED, MCP3008
from gpiozero.tools import zip_values
from signal import pause

led = RGBLED(2, 3, 4)
red_pot = MCP3008(0)
green_pot = MCP3008(1)
blue_pot = MCP3008(2)

led.source = zip_values(red_pot, green_pot, blue_pot)

pause()
github gpiozero / gpiozero / docs / examples / pot_2.py View on Github external
from gpiozero import LEDBarGraph, MCP3008
from signal import pause

graph = LEDBarGraph(5, 6, 13, 19, 26, pwm=True)
pot = MCP3008(channel=0)

graph.source = pot

pause()