Python board.MOSI Examples

The following are 3 code examples of board.MOSI(). 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: soil.py    From aws-builders-fair-projects with Apache License 2.0 6 votes vote down vote up
def __init__(self):
        Sensor.__init__(self)

        self.moisture_min = float(self.config["soil"]["min"])
        self.moisture_max = float(self.config["soil"]["max"])

        # create SPI bus
        spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)

        # create the cs (chip select)
        cs = digitalio.DigitalInOut(board.D8)

        # create the mcp object
        mcp = MCP.MCP3008(spi, cs)
        
        # create an analog input channel
        self.pin = []
        self.pin.append(AnalogIn(mcp, MCP.P0))
        self.pin.append(AnalogIn(mcp, MCP.P1))
        self.pin.append(AnalogIn(mcp, MCP.P2))
        self.pin.append(AnalogIn(mcp, MCP.P3))
        self.pin.append(AnalogIn(mcp, MCP.P4))
        self.pin.append(AnalogIn(mcp, MCP.P5))
        self.pin.append(AnalogIn(mcp, MCP.P6))
        self.pin.append(AnalogIn(mcp, MCP.P7)) 
Example #2
Source File: adc_worker.py    From mudpi-core with MIT License 5 votes vote down vote up
def __init__(self, config: dict, main_thread_running, system_ready):
        self.config = config
        self.main_thread_running = main_thread_running
        self.system_ready = system_ready
        self.node_ready = False

        spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)
        cs = digitalio.DigitalInOut(ADCMCP3008Worker.PINS[config['pin']])

        self.mcp = MCP.MCP3008(spi, cs)

        self.sensors = []
        self.init_sensors()

        self.node_ready = True 
Example #3
Source File: apa102.py    From apa102-pi with GNU General Public License v2.0 4 votes vote down vote up
def __init__(self, num_led=8, global_brightness=31,
                 order='rgb', mosi=10, sclk=11, ce=None, bus_speed_hz=8000000):
        """Initializes the library

        :param num_led: Number of LEDs in the strip
        :param global_brightness: Overall brightness
        :param order: Order in which the colours are addressed (this differs from strip to strip)
        :param mosi: Master Out pin. Use 10 for SPI0, 20 for SPI1, any GPIO pin for bitbang.
        :param sclk: Clock, use 11 for SPI0, 21 for SPI1, any GPIO pin for bitbang.
        :param ce: GPIO to use for Chip select. Can be any free GPIO pin. Warning: This will slow down the bus
                   significantly. Note: The hardware CE0 and CE1 are not used
        :param bus_speed_hz: Speed of the hardware SPI bus. If glitches on the bus are visible, lower the value.
        """
        self.num_led = num_led
        order = order.lower()  # Just in case someone use CAPS here.
        self.rgb = RGB_MAP.get(order, RGB_MAP['rgb'])
        self.global_brightness = global_brightness
        self.use_bitbang = False  # Two raw SPI devices exist: Bitbang (software) and hardware SPI.
        self.use_ce = False  # If true, use the BusDevice abstraction layer on top of the raw SPI device

        self.leds = [self.LED_START, 0, 0, 0] * self.num_led  # Pixel buffer
        if ce is not None:
            # If a chip enable value is present, use the Adafruit CircuitPython BusDevice abstraction on top
            # of the raw SPI device (hardware or bitbang)
            # The next line is just here to prevent an "unused" warning from the IDE
            digitalio.DigitalInOut(board.D1)
            # Convert the chip enable pin number into an object (reflection à la Python)
            ce = eval("digitalio.DigitalInOut(board.D"+str(ce)+")")
            self.use_ce = True
        # Heuristic: Test for the hardware SPI pins. If found, use hardware SPI, otherwise bitbang SPI
        if mosi == 10:
            if sclk != 11:
                raise ValueError("Illegal MOSI / SCLK combination")
            self.spi = busio.SPI(clock=board.SCLK, MOSI=board.MOSI)
        elif mosi == 20:
            if sclk != 21:
                raise ValueError("Illegal MOSI / SCLK combination")
            self.spi = busio.SPI(clock=board.SCLK_1, MOSI=board.MOSI_1)
        else:
            # Use Adafruit CircuitPython BitBangIO, because the pins do not match one of the hardware SPI devices
            # Reflection à la Python to get at the digital IO pins
            self.spi = bitbangio.SPI(clock=eval("board.D"+str(sclk)), MOSI=eval("board.D"+str(mosi)))
            self.use_bitbang = True
        # Add the BusDevice on top of the raw SPI
        if self.use_ce:
            self.spibus = SPIDevice(spi=self.spi,  chip_select=ce, baudrate=bus_speed_hz)
        else:
            # If the BusDevice is not used, the bus speed is set here instead
            while not self.spi.try_lock():
                pass
            self.spi.configure(baudrate=bus_speed_hz)
            self.spi.unlock()
        # Debug
        if self.use_ce:
            print("Use software chip enable")
        if self.use_bitbang:
            print("Use bitbang SPI")
        else:
            print("Use hardware SPI")