Python board.SDA Examples

The following are 22 code examples of board.SDA(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module board , or try the search function .
Example #1
Source File: character_lcd.py    From Adafruit_CircuitPython_CharLCD with MIT License 6 votes vote down vote up
def cursor(self):
        """True if cursor is visible. False to stop displaying the cursor.

        The following example shows the cursor after a displayed message:

        .. code-block:: python

            import time
            import board
            import busio
            import adafruit_character_lcd.character_lcd_i2c as character_lcd

            i2c = busio.I2C(board.SCL, board.SDA)
            lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2)

            lcd.cursor = True
            lcd.message = "Cursor! "
            time.sleep(5)

        """
        return self.displaycontrol & _LCD_CURSORON == _LCD_CURSORON 
Example #2
Source File: log_si7021.py    From Pigrow with GNU General Public License v3.0 6 votes vote down vote up
def read_sensor(sensor):
    try:
        i2c = busio.I2C(board.SCL, board.SDA)
        sensor = adafruit_si7021.SI7021(i2c)
        temperature = sensor.temperature
        humidity = sensor.relative_humidity
        if humidity == None or temperature == None or humidity > 101:
            print("--problem reading sensor on GPIO:"+sensor_gpio+"--")
            return '-1','-1','-1'
        else:
            humidity = round(humidity,2)
            temperature = round(temperature, 2)
            logtime = datetime.datetime.now()
            return humidity, temperature, logtime
    except:
        print("--problem reading si7021")
        return '-1','-1','-1' 
Example #3
Source File: i2c.py    From Adafruit_Blinka with MIT License 6 votes vote down vote up
def test_read_value(self):
        """
        Access all sensor values as per
        https://github.com/adafruit/Adafruit_CircuitPython_BNO055/blob/bdf6ada21e7552c242bc470d4d2619b480b4c574/examples/values.py
        Note I have not successfully run this test. Possibly a hardware issue with module I have.
        See https://forums.adafruit.com/viewtopic.php?f=60&t=131665
        """
        import board

        gc.collect()
        import adafruit_bno055

        gc.collect()
        i2c = I2C(board.SCL, board.SDA)
        sensor = adafruit_bno055.BNO055(i2c)

        self.assertTrue(9 <= sensor.gravity <= 11)
        self.assertTrue(sensor.temperature != 0)
        self.assertTrue(sensor.acceleration != (0, 0, 0))
        self.assertTrue(sensor.magnetometer != (0, 0, 0))
        self.assertTrue(sensor.gyroscope != (0, 0, 0))
        self.assertTrue(sensor.quaternion != (0, 0, 0, 0))
        sensor.euler
        sensor.linear_acceleration 
Example #4
Source File: character_lcd_rgb_i2c.py    From Adafruit_CircuitPython_CharLCD with MIT License 6 votes vote down vote up
def select_button(self):
        """The select button on the RGB Character LCD I2C Shield or Pi plate.

        The following example prints "Select!" to the LCD when the select button is pressed:

        .. code-block:: python

            import board
            import busio
            from adafruit_character_lcd.character_lcd_rgb_i2c import Character_LCD_RGB_I2C

            i2c = busio.I2C(board.SCL, board.SDA)
            lcd = Character_LCD_RGB_I2C(i2c, 16, 2)

            while True:
                if lcd.select_button:
                    lcd.message = "Select!"

        """
        return not self._select_button.value 
Example #5
Source File: character_lcd_rgb_i2c.py    From Adafruit_CircuitPython_CharLCD with MIT License 6 votes vote down vote up
def right_button(self):
        """The right button on the RGB Character LCD I2C Shield or Pi plate.

        The following example prints "Right!" to the LCD when the right button is pressed:

        .. code-block:: python

            import board
            import busio
            from adafruit_character_lcd.character_lcd_rgb_i2c import Character_LCD_RGB_I2C

            i2c = busio.I2C(board.SCL, board.SDA)
            lcd = Character_LCD_RGB_I2C(i2c, 16, 2)

            while True:
                if lcd.right_button:
                    lcd.message = "Right!"

        """
        return not self._right_button.value 
Example #6
Source File: character_lcd_rgb_i2c.py    From Adafruit_CircuitPython_CharLCD with MIT License 6 votes vote down vote up
def down_button(self):
        """The down button on the RGB Character LCD I2C Shield or Pi plate.

        The following example prints "Down!" to the LCD when the down button is pressed:

        .. code-block:: python

            import board
            import busio
            from adafruit_character_lcd.character_lcd_rgb_i2c import Character_LCD_RGB_I2C

            i2c = busio.I2C(board.SCL, board.SDA)
            lcd = Character_LCD_RGB_I2C(i2c, 16, 2)

            while True:
                if lcd.down_button:
                    lcd.message = "Down!"

        """
        return not self._down_button.value 
Example #7
Source File: character_lcd_rgb_i2c.py    From Adafruit_CircuitPython_CharLCD with MIT License 6 votes vote down vote up
def left_button(self):
        """The left button on the RGB Character LCD I2C Shield or Pi plate.

        The following example prints "Left!" to the LCD when the left button is pressed:

        .. code-block:: python

            import board
            import busio
            from adafruit_character_lcd.character_lcd_rgb_i2c import Character_LCD_RGB_I2C

            i2c = busio.I2C(board.SCL, board.SDA)
            lcd = Character_LCD_RGB_I2C(i2c, 16, 2)

            while True:
                if lcd.left_button:
                    lcd.message = "Left!"

        """
        return not self._left_button.value 
Example #8
Source File: character_lcd.py    From Adafruit_CircuitPython_CharLCD with MIT License 6 votes vote down vote up
def text_direction(self):
        """The direction the text is displayed. To display the text left to right beginning on the
        left side of the LCD, set ``text_direction = LEFT_TO_RIGHT``. To display the text right
        to left beginning on the right size of the LCD, set ``text_direction = RIGHT_TO_LEFT``.
        Text defaults to displaying from left to right.

        The following example displays "Hello, world!" from right to left.

        .. code-block:: python

            import time
            import board
            import busio
            import adafruit_character_lcd.character_lcd_i2c as character_lcd

            i2c = busio.I2C(board.SCL, board.SDA)
            lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2)

            lcd.text_direction = lcd.RIGHT_TO_LEFT
            lcd.message = "Hello, world!"
            time.sleep(5)
        """
        return self._direction 
Example #9
Source File: character_lcd.py    From Adafruit_CircuitPython_CharLCD with MIT License 6 votes vote down vote up
def move_right(self):
        """Moves displayed text right one column.

        The following example scrolls a message to the right off the screen.

        .. code-block:: python

            import time
            import board
            import busio
            import adafruit_character_lcd.character_lcd_i2c as character_lcd

            i2c = busio.I2C(board.SCL, board.SDA)
            lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2)

            scroll_message = "Scroll -->"
            lcd.message = scroll_message
            time.sleep(2)
            for i in range(len(scroll_message) + 16):
                lcd.move_right()
                time.sleep(0.5)
        """
        self._write8(_LCD_CURSORSHIFT | _LCD_DISPLAYMOVE | _LCD_MOVERIGHT) 
Example #10
Source File: character_lcd.py    From Adafruit_CircuitPython_CharLCD with MIT License 6 votes vote down vote up
def message(self):
        """Display a string of text on the character LCD.
        Start position is (0,0) if cursor_position is not set.
        If cursor_position is set, message starts at the set
        position from the left for left to right text and from
        the right for right to left text. Resets cursor column
        and row to (0,0) after displaying the message.

        The following example displays, "Hello, world!" on the LCD.

        .. code-block:: python

            import time
            import board
            import busio
            import adafruit_character_lcd.character_lcd_i2c as character_lcd

            i2c = busio.I2C(board.SCL, board.SDA)
            lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2)

            lcd.message = "Hello, world!"
            time.sleep(5)
        """
        return self._message 
Example #11
Source File: character_lcd.py    From Adafruit_CircuitPython_CharLCD with MIT License 6 votes vote down vote up
def display(self):
        """
        Enable or disable the display. True to enable the display. False to disable the display.

        The following example displays, "Hello, world!" on the LCD and then turns the display off.

        .. code-block:: python

            import time
            import board
            import busio
            import adafruit_character_lcd.character_lcd_i2c as character_lcd

            i2c = busio.I2C(board.SCL, board.SDA)
            lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2)

            lcd.message = "Hello, world!"
            time.sleep(5)
            lcd.display = False
        """
        return self.displaycontrol & _LCD_DISPLAYON == _LCD_DISPLAYON 
Example #12
Source File: character_lcd.py    From Adafruit_CircuitPython_CharLCD with MIT License 6 votes vote down vote up
def blink(self):
        """
        Blink the cursor. True to blink the cursor. False to stop blinking.

        The following example shows a message followed by a blinking cursor for five seconds.

        .. code-block:: python

            import time
            import board
            import busio
            import adafruit_character_lcd.character_lcd_i2c as character_lcd

            i2c = busio.I2C(board.SCL, board.SDA)
            lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2)

            lcd.blink = True
            lcd.message = "Blinky cursor!"
            time.sleep(5)
            lcd.blink = False
        """
        return self.displaycontrol & _LCD_BLINKON == _LCD_BLINKON 
Example #13
Source File: character_lcd.py    From Adafruit_CircuitPython_CharLCD with MIT License 6 votes vote down vote up
def clear(self):
        """Clears everything displayed on the LCD.

        The following example displays, "Hello, world!", then clears the LCD.

        .. code-block:: python

            import time
            import board
            import busio
            import adafruit_character_lcd.character_lcd_i2c as character_lcd

            i2c = busio.I2C(board.SCL, board.SDA)
            lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2)

            lcd.message = "Hello, world!"
            time.sleep(5)
            lcd.clear()
        """
        self._write8(_LCD_CLEARDISPLAY)
        time.sleep(0.003) 
Example #14
Source File: character_lcd.py    From Adafruit_CircuitPython_CharLCD with MIT License 5 votes vote down vote up
def backlight(self):
        """Enable or disable backlight. True if backlight is on. False if backlight is off.

        The following example turns the backlight off, then displays, "Hello, world?", then turns
        the backlight on and displays, "Hello, world!"

        .. code-block:: python

            import time
            import board
            import busio
            import adafruit_character_lcd.character_lcd_i2c as character_lcd

            i2c = busio.I2C(board.SCL, board.SDA)

            lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2)

            lcd.backlight = False
            lcd.message = "Hello, world?"
            time.sleep(5)
            lcd.backlight = True
            lcd.message = "Hello, world!"
            time.sleep(5)

        """
        return self._enable 
Example #15
Source File: character_lcd.py    From Adafruit_CircuitPython_CharLCD with MIT License 5 votes vote down vote up
def color(self):
        """
        The color of the display. Provide a list of three integers ranging 0 - 100, ``[R, G, B]``.
        ``0`` is no color, or "off". ``100`` is maximum color. For example, the brightest red would
        be ``[100, 0, 0]``, and a half-bright purple would be, ``[50, 0, 50]``.

        If PWM is unavailable, ``0`` is off, and non-zero is on. For example, ``[1, 0, 0]`` would
        be red.

        The following example turns the LCD red and displays, "Hello, world!".

        .. code-block:: python

            import time
            import board
            import busio
            import adafruit_character_lcd.character_lcd_rgb_i2c as character_lcd

            i2c = busio.I2C(board.SCL, board.SDA)

            lcd = character_lcd.Character_LCD_RGB_I2C(i2c, 16, 2)

            lcd.color = [100, 0, 0]
            lcd.message = "Hello, world!"
            time.sleep(5)
        """
        return self._color 
Example #16
Source File: i2c.py    From Adafruit_Blinka with MIT License 5 votes vote down vote up
def test_read_value(self):

        import board

        gc.collect()
        import adafruit_bme280

        gc.collect()

        if not (
            yes_no("Is BME280 wired to SCL {} SDA {}".format(board.SCL, board.SDA))
        ):
            return  # test trivially passed

        i2c = I2C(board.SCL, board.SDA)
        bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)
        temperature = bme280.temperature
        humidity = bme280.humidity
        pressure = bme280.pressure
        altitude = bme280.altitude
        self.assertTrue(type(temperature) is float)
        self.assertTrue(type(humidity) is float)
        self.assertTrue(type(pressure) is float)
        self.assertTrue(type(altitude) is float)

        self.assertTrue(-50 <= temperature <= 50)
        self.assertTrue(0 <= humidity <= 100)
        self.assertTrue(900 <= pressure <= 1100)
        self.assertTrue(-1000 <= altitude <= 9, 848) 
Example #17
Source File: i2c.py    From Adafruit_Blinka with MIT License 5 votes vote down vote up
def test_read_value(self):
        import math

        gc.collect()
        import board

        gc.collect()

        if not (
            yes_no(
                "Is MMA8451 wired to SCL {} SDA {} and held still".format(
                    board.SCL, board.SDA
                )
            )
        ):
            return  # test trivially passed
        # from https://github.com/adafruit/Adafruit_CircuitPython_MMA8451/blob/29e31a0bb836367bc73763b83513105252b7b264/examples/simpletest.py
        import adafruit_mma8451

        i2c = I2C(board.SCL, board.SDA)
        sensor = adafruit_mma8451.MMA8451(i2c)

        x, y, z = sensor.acceleration
        absolute = math.sqrt(x ** 2 + y ** 2 + z ** 2)
        self.assertTrue(9 <= absolute <= 11, "Not earth gravity")

        orientation = sensor.orientation
        self.assertTrue(
            orientation
            in (
                adafruit_mma8451.PL_PUF,
                adafruit_mma8451.PL_PUB,
                adafruit_mma8451.PL_PDF,
                adafruit_mma8451.PL_PDB,
                adafruit_mma8451.PL_LRF,
                adafruit_mma8451.PL_LRB,
                adafruit_mma8451.PL_LLF,
                adafruit_mma8451.PL_LLB,
            )
        ) 
Example #18
Source File: uv.py    From aws-builders-fair-projects with Apache License 2.0 5 votes vote down vote up
def __init__(self):
        Sensor.__init__(self)

        self.uv_min = float(self.config["uv"]["min"])
        self.uv_max = float(self.config["uv"]["max"])

        # initialize I2C
        i2c = busio.I2C(board.SCL, board.SDA)

        # create the VEML6075 object
        self.veml = adafruit_veml6075.VEML6075(
            i2c,
            integration_time=int(self.config["uv"]["integration_time"])
        ) 
Example #19
Source File: snake_eyes_bonnet.py    From Pi_Eyes with MIT License 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        """SnakeEyesBonnet constructor."""
        super(SnakeEyesBonnet, self).__init__(*args, **kwargs) # Thread
        self.i2c = busio.I2C(board.SCL, board.SDA)
        self.ads = ADS.ADS1015(self.i2c)
        self.ads.gain = 1
        self.period = 1.0 / 60.0  # Polling inverval = 1/60 sec default
        self.print_values = False # Don't print values by default
        self.channel = []
        for index in range(4):
            self.channel.append(AdcChannel(
                                AnalogIn(self.ads, self.channel_dict[index]))) 
Example #20
Source File: sensor_rgbtcs34725.py    From Pigrow with GNU General Public License v3.0 5 votes vote down vote up
def read_sensor(location="", extra="", *args):
    # Try importing the modules then give-up and report to user if it fails
    import datetime
    import time
    try:
        import board
        import busio
        import adafruit_tcs34725
    except:
        print("adafruit_tcs34725 module not installed, install using the command;")
        print("   sudo pip3 install adafruit-circuitpython-tcs34725   ")
        return None


    # set up and read the sensor
    read_attempt = 1
    i2c = busio.I2C(board.SCL, board.SDA)
    sensor = adafruit_tcs34725.TCS34725(i2c)
    gain = 1
    sensor.gain = gain  # 1, 4, 16, 60
    sensor.integration_time = 50  # The integration time of the sensor in milliseconds.  Must be a value between 2.4 and 614.4.
    while read_attempt < 5:
        try:
            color_temp = sensor.color_temperature
            lux = sensor.lux
            rgb = sensor.color_rgb_bytes
            #
            if lux == None:
                print("--problem reading tcs34725, try " + str(read_attempt))
                time.sleep(2)
                read_attempt = read_attempt + 1
            else:
                logtime = datetime.datetime.now()
                return [['time',logtime], ['lux', str(lux / gain)], ['color_temp', color_temp], ['r', rgb[0]], ['g', rgb[1]], ['b', rgb[2]]]
        except Exception as e:
            print("--exception while reading tcs34725, try " + str(read_attempt))
            print(" -- " + str(e))
            time.sleep(2)
            read_attempt = read_attempt + 1
    return None 
Example #21
Source File: sensor_si7021.py    From Pigrow with GNU General Public License v3.0 5 votes vote down vote up
def read_sensor(location="", extra="", *args):
    # Try importing the modules then give-up and report to user if it fails
    import datetime
    try:
        import board
        import busio
        import adafruit_si7021
    except:
        print("adafruit_si7021 module not installed, install using the command;")
        print("     sudo pip3 install adafruit-circuitpython-si7021")
        return None

    # set up and read the sensor
    try:
        i2c = busio.I2C(board.SCL, board.SDA)
        sensor = adafruit_si7021.SI7021(i2c)
        temperature = sensor.temperature
        humidity = sensor.relative_humidity
        if humidity == None or temperature == None or humidity > 101:
            print("--problem reading si7021")
            return None
        else:
            humidity = round(humidity,2)
            temperature = round(temperature, 2)
            logtime = datetime.datetime.now()
            return [['time',logtime], ['humid', humidity], ['temperature', temperature]]
    except:
        print("--problem reading si7021")
        return None 
Example #22
Source File: sensor_bme280.py    From Pigrow with GNU General Public License v3.0 4 votes vote down vote up
def read_sensor(location="", extra="", *args):
    # Try importing the modules then give-up and report to user if it fails
    import datetime
    import time
    try:
        import board
        import busio
        import adafruit_bme280
    except:
        print("bme280 module not installed, install using the command;")
        print("   sudo pip3 install adafruit-circuitpython-bme280   ")
        return None


    # set up and read the sensor
    read_attempt = 1
    i2c = busio.I2C(board.SCL, board.SDA)
    i2c_address = location
    if location == "0x76":
        bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, 0x76)
    elif location == "0x77":
        bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, 0x77)

    while read_attempt < 5:
        try:
            temperature = bme280.temperature
            humidity = bme280.humidity
            pressure = bme280.pressure
            #
            if humidity == None or temperature == None or humidity > 101:
                print("--problem reading bme280, try " + str(read_attempt))
                time.sleep(2)
                read_attempt = read_attempt + 1
            else:
                humidity = round(humidity,2)
                temperature = round(temperature, 2)
                pressure = round(pressure, 2)
                logtime = datetime.datetime.now()
                return [['time',logtime], ['humid', humidity], ['temperature', temperature], ['pressure', pressure]]
        except Exception as e:
            print("--exception while reading bcm280, try " + str(read_attempt))
            print(" -- " + str(e))
            time.sleep(2)
            read_attempt = read_attempt + 1
    return None