MikrofonSensor und TemperaturSenor die zwei Python programme funktionieren. mit den jeweiligen 2 json Datein. Beim TemperaturSensor wird im Terminal keine Wertre ausgegeben aber in der json Datei kann man die Temp und Hum sehen.
This commit is contained in:
parent
4c654ec969
commit
1751076592
2614 changed files with 349009 additions and 0 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,58 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""FT2232H pin names"""
|
||||
|
||||
from adafruit_blinka.microcontroller.ftdi_mpsse.mpsse.pin import Pin
|
||||
|
||||
# See https://eblot.github.io/pyftdi/pinout.html for detailed FTDI device pinout information
|
||||
|
||||
# MPSSE Port A
|
||||
AD4 = Pin(4, interface_id=0)
|
||||
AD5 = Pin(5, interface_id=0)
|
||||
AD6 = Pin(6, interface_id=0)
|
||||
AD7 = Pin(7, interface_id=0)
|
||||
AC0 = Pin(8, interface_id=0)
|
||||
AC1 = Pin(9, interface_id=0)
|
||||
AC2 = Pin(10, interface_id=0)
|
||||
AC3 = Pin(11, interface_id=0)
|
||||
AC4 = Pin(12, interface_id=0)
|
||||
AC5 = Pin(13, interface_id=0)
|
||||
AC6 = Pin(14, interface_id=0)
|
||||
AC7 = Pin(15, interface_id=0)
|
||||
|
||||
SCL0 = Pin(interface_id=0)
|
||||
SDA0 = Pin(interface_id=0)
|
||||
SCK0 = SCLK0 = Pin(interface_id=0)
|
||||
MOSI0 = Pin(interface_id=0)
|
||||
MISO0 = Pin(interface_id=0)
|
||||
|
||||
# MPSSE Port B
|
||||
BD4 = Pin(4, interface_id=1)
|
||||
BD5 = Pin(5, interface_id=1)
|
||||
BD6 = Pin(6, interface_id=1)
|
||||
BD7 = Pin(7, interface_id=1)
|
||||
BC0 = Pin(8, interface_id=1)
|
||||
BC1 = Pin(9, interface_id=1)
|
||||
BC2 = Pin(10, interface_id=1)
|
||||
BC3 = Pin(11, interface_id=1)
|
||||
BC4 = Pin(12, interface_id=1)
|
||||
BC5 = Pin(13, interface_id=1)
|
||||
BC6 = Pin(14, interface_id=1)
|
||||
BC7 = Pin(15, interface_id=1)
|
||||
|
||||
SCL1 = Pin(interface_id=1)
|
||||
SDA1 = Pin(interface_id=1)
|
||||
SCK1 = SCLK1 = Pin(interface_id=1)
|
||||
MOSI1 = Pin(interface_id=1)
|
||||
MISO1 = Pin(interface_id=1)
|
||||
|
||||
i2cPorts = (
|
||||
(0, SCL0, SDA0),
|
||||
(1, SCL1, SDA1),
|
||||
)
|
||||
|
||||
spiPorts = (
|
||||
(0, SCLK0, MOSI0, MISO0),
|
||||
(1, SCLK1, MOSI1, MISO1),
|
||||
)
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,28 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""FT232H pin names"""
|
||||
|
||||
from adafruit_blinka.microcontroller.ftdi_mpsse.mpsse.pin import Pin
|
||||
|
||||
# See https://eblot.github.io/pyftdi/pinout.html for detailed FTDI device pinout information
|
||||
|
||||
# MPSSE Port A
|
||||
D4 = Pin(4)
|
||||
D5 = Pin(5)
|
||||
D6 = Pin(6)
|
||||
D7 = Pin(7)
|
||||
C0 = Pin(8)
|
||||
C1 = Pin(9)
|
||||
C2 = Pin(10)
|
||||
C3 = Pin(11)
|
||||
C4 = Pin(12)
|
||||
C5 = Pin(13)
|
||||
C6 = Pin(14)
|
||||
C7 = Pin(15)
|
||||
|
||||
SCL = Pin()
|
||||
SDA = Pin()
|
||||
SCK = SCLK = Pin()
|
||||
MOSI = Pin()
|
||||
MISO = Pin()
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,42 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""FT4232H pin names"""
|
||||
|
||||
from adafruit_blinka.microcontroller.ftdi_mpsse.mpsse.pin import Pin
|
||||
|
||||
# See https://eblot.github.io/pyftdi/pinout.html for detailed FTDI device pinout information
|
||||
|
||||
# MPSSE Port A
|
||||
AD4 = Pin(4, interface_id=0)
|
||||
AD5 = Pin(5, interface_id=0)
|
||||
AD6 = Pin(6, interface_id=0)
|
||||
AD7 = Pin(7, interface_id=0)
|
||||
|
||||
SCL0 = Pin(interface_id=0)
|
||||
SDA0 = Pin(interface_id=0)
|
||||
SCK0 = SCLK0 = Pin(interface_id=0)
|
||||
MOSI0 = Pin(interface_id=0)
|
||||
MISO0 = Pin(interface_id=0)
|
||||
|
||||
# MPSSE Port B
|
||||
BD4 = Pin(4, interface_id=1)
|
||||
BD5 = Pin(5, interface_id=1)
|
||||
BD6 = Pin(6, interface_id=1)
|
||||
BD7 = Pin(7, interface_id=1)
|
||||
|
||||
SCL1 = Pin(interface_id=1)
|
||||
SDA1 = Pin(interface_id=1)
|
||||
SCK1 = SCLK1 = Pin(interface_id=1)
|
||||
MOSI1 = Pin(interface_id=1)
|
||||
MISO1 = Pin(interface_id=1)
|
||||
|
||||
i2cPorts = (
|
||||
(0, SCL0, SDA0),
|
||||
(1, SCL1, SDA1),
|
||||
)
|
||||
|
||||
spiPorts = (
|
||||
(0, SCLK0, MOSI0, MISO0),
|
||||
(1, SCLK1, MOSI1, MISO1),
|
||||
)
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,81 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""I2C Class for FTDI MPSSE"""
|
||||
from adafruit_blinka.microcontroller.ftdi_mpsse.mpsse.pin import Pin
|
||||
from adafruit_blinka.microcontroller.ftdi_mpsse.mpsse.url import (
|
||||
get_ft232h_url,
|
||||
get_ftx232h_url,
|
||||
)
|
||||
|
||||
|
||||
class I2C:
|
||||
"""Custom I2C Class for FTDI MPSSE"""
|
||||
|
||||
MASTER = 0
|
||||
SLAVE = 1
|
||||
_mode = None
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def __init__(self, i2c_id=None, mode=MASTER, baudrate=None, frequency=400000):
|
||||
if mode != self.MASTER:
|
||||
raise NotImplementedError("Only I2C Master supported!")
|
||||
_mode = self.MASTER
|
||||
|
||||
# change GPIO controller to I2C
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from pyftdi.i2c import I2cController
|
||||
|
||||
# pylint: enable=import-outside-toplevel
|
||||
|
||||
self._i2c = I2cController()
|
||||
if i2c_id is None:
|
||||
self._i2c.configure(get_ft232h_url(), frequency=frequency)
|
||||
else:
|
||||
self._i2c.configure(get_ftx232h_url(i2c_id), frequency=frequency)
|
||||
Pin.mpsse_gpio = self._i2c.get_gpio()
|
||||
|
||||
def scan(self):
|
||||
"""Perform an I2C Device Scan"""
|
||||
return [addr for addr in range(0x79) if self._i2c.poll(addr)]
|
||||
|
||||
def writeto(self, address, buffer, *, start=0, end=None, stop=True):
|
||||
"""Write data from the buffer to an address"""
|
||||
end = end if end else len(buffer)
|
||||
port = self._i2c.get_port(address)
|
||||
port.write(buffer[start:end], relax=stop)
|
||||
|
||||
def readfrom_into(self, address, buffer, *, start=0, end=None, stop=True):
|
||||
"""Read data from an address and into the buffer"""
|
||||
end = end if end else len(buffer)
|
||||
port = self._i2c.get_port(address)
|
||||
result = port.read(len(buffer[start:end]), relax=stop)
|
||||
for i, b in enumerate(result):
|
||||
buffer[start + i] = b
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def writeto_then_readfrom(
|
||||
self,
|
||||
address,
|
||||
buffer_out,
|
||||
buffer_in,
|
||||
*,
|
||||
out_start=0,
|
||||
out_end=None,
|
||||
in_start=0,
|
||||
in_end=None,
|
||||
stop=False,
|
||||
):
|
||||
"""Write data from buffer_out to an address and then
|
||||
read data from an address and into buffer_in
|
||||
"""
|
||||
out_end = out_end if out_end else len(buffer_out)
|
||||
in_end = in_end if in_end else len(buffer_in)
|
||||
port = self._i2c.get_port(address)
|
||||
result = port.exchange(
|
||||
buffer_out[out_start:out_end], in_end - in_start, relax=True
|
||||
)
|
||||
for i, b in enumerate(result):
|
||||
buffer_in[in_start + i] = b
|
||||
|
||||
# pylint: enable=unused-argument
|
|
@ -0,0 +1,80 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""MPSSE pin names"""
|
||||
|
||||
from adafruit_blinka.microcontroller.ftdi_mpsse.mpsse.url import (
|
||||
get_ft232h_url,
|
||||
get_ftx232h_url,
|
||||
)
|
||||
|
||||
|
||||
class Pin:
|
||||
"""A basic Pin class for use with FTDI MPSSEs."""
|
||||
|
||||
IN = 0
|
||||
OUT = 1
|
||||
LOW = 0
|
||||
HIGH = 1
|
||||
PULL_NONE = 0
|
||||
PULL_UP = 1
|
||||
PULL_DOWN = 2
|
||||
|
||||
mpsse_gpio = None
|
||||
|
||||
def __init__(self, pin_id=None, interface_id=None):
|
||||
# setup GPIO controller if not done yet
|
||||
# use one provided by I2C as default
|
||||
if not Pin.mpsse_gpio:
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from pyftdi.i2c import I2cController
|
||||
|
||||
# pylint: enable=import-outside-toplevel
|
||||
|
||||
i2c = I2cController()
|
||||
if interface_id is None:
|
||||
i2c.configure(get_ft232h_url())
|
||||
else:
|
||||
i2c.configure(get_ftx232h_url(interface_id))
|
||||
Pin.mpsse_gpio = i2c.get_gpio()
|
||||
# check if pin is valid
|
||||
if pin_id:
|
||||
if Pin.mpsse_gpio.all_pins & 1 << pin_id == 0:
|
||||
raise ValueError("Can not use pin {} as GPIO.".format(pin_id))
|
||||
# ID is just bit position
|
||||
self.id = pin_id
|
||||
|
||||
def init(self, mode=IN, pull=None):
|
||||
"""Initialize the Pin"""
|
||||
if not self.id:
|
||||
raise RuntimeError("Can not init a None type pin.")
|
||||
# MPSSE does't have configurable internal pulls?
|
||||
if pull:
|
||||
raise NotImplementedError("Internal pull up/down not currently supported.")
|
||||
pin_mask = Pin.mpsse_gpio.pins | 1 << self.id
|
||||
current = Pin.mpsse_gpio.direction
|
||||
if mode == self.OUT:
|
||||
current |= 1 << self.id
|
||||
else:
|
||||
current &= ~(1 << self.id)
|
||||
Pin.mpsse_gpio.set_direction(pin_mask, current)
|
||||
|
||||
def value(self, val=None):
|
||||
"""Set or return the Pin Value"""
|
||||
if not self.id:
|
||||
raise RuntimeError("Can not access a None type pin.")
|
||||
current = Pin.mpsse_gpio.read(with_output=True)
|
||||
# read
|
||||
if val is None:
|
||||
return 1 if current & 1 << self.id != 0 else 0
|
||||
# write
|
||||
if val in (self.LOW, self.HIGH):
|
||||
if val == self.HIGH:
|
||||
current |= 1 << self.id
|
||||
else:
|
||||
current &= ~(1 << self.id)
|
||||
# must mask out any input pins
|
||||
Pin.mpsse_gpio.write(current & Pin.mpsse_gpio.direction)
|
||||
return None
|
||||
# release the kraken
|
||||
raise RuntimeError("Invalid value for pin")
|
|
@ -0,0 +1,103 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""SPI Class for FTDI MPSSE"""
|
||||
from adafruit_blinka.microcontroller.ftdi_mpsse.mpsse.pin import Pin
|
||||
from adafruit_blinka.microcontroller.ftdi_mpsse.mpsse.url import (
|
||||
get_ft232h_url,
|
||||
get_ftx232h_url,
|
||||
)
|
||||
|
||||
|
||||
# pylint: disable=protected-access
|
||||
class SPI:
|
||||
"""Custom SPI Class for FTDI MPSSE"""
|
||||
|
||||
MSB = 0
|
||||
|
||||
def __init__(self, spi_id=None):
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from pyftdi.spi import SpiController
|
||||
|
||||
# pylint: enable=import-outside-toplevel
|
||||
|
||||
self._spi = SpiController(cs_count=1)
|
||||
if spi_id is None:
|
||||
self._spi.configure(get_ft232h_url())
|
||||
else:
|
||||
self._spi.configure(get_ftx232h_url(spi_id + 1))
|
||||
self._port = self._spi.get_port(0)
|
||||
self._port.set_frequency(100000)
|
||||
self._port._cpol = 0
|
||||
self._port._cpha = 0
|
||||
# Change GPIO controller to SPI
|
||||
Pin.mpsse_gpio = self._spi.get_gpio()
|
||||
|
||||
# pylint: disable=too-many-arguments,unused-argument
|
||||
def init(
|
||||
self,
|
||||
baudrate=100000,
|
||||
polarity=0,
|
||||
phase=0,
|
||||
bits=8,
|
||||
firstbit=MSB,
|
||||
sck=None,
|
||||
mosi=None,
|
||||
miso=None,
|
||||
):
|
||||
"""Initialize the Port"""
|
||||
self._port.set_frequency(baudrate)
|
||||
# FTDI device can only support mode 0 and mode 2
|
||||
# due to the limitation of MPSSE engine.
|
||||
# This means CPHA must = 0
|
||||
self._port._cpol = polarity
|
||||
if phase != 0:
|
||||
raise ValueError("Only SPI phase 0 is supported by FT232H.")
|
||||
self._port._cpha = phase
|
||||
|
||||
# pylint: enable=too-many-arguments
|
||||
|
||||
@property
|
||||
def frequency(self):
|
||||
"""Return the current frequency"""
|
||||
return self._port.frequency
|
||||
|
||||
def write(self, buf, start=0, end=None):
|
||||
"""Write data from the buffer to SPI"""
|
||||
end = end if end else len(buf)
|
||||
chunks, rest = divmod(end - start, self._spi.PAYLOAD_MAX_LENGTH)
|
||||
for i in range(chunks):
|
||||
chunk_start = start + i * self._spi.PAYLOAD_MAX_LENGTH
|
||||
chunk_end = chunk_start + self._spi.PAYLOAD_MAX_LENGTH
|
||||
self._port.write(buf[chunk_start:chunk_end])
|
||||
if rest:
|
||||
rest_start = start + chunks * self._spi.PAYLOAD_MAX_LENGTH
|
||||
self._port.write(buf[rest_start:end])
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def readinto(self, buf, start=0, end=None, write_value=0):
|
||||
"""Read data from SPI and into the buffer"""
|
||||
end = end if end else len(buf)
|
||||
buffer_out = [write_value] * (end - start)
|
||||
result = self._port.exchange(buffer_out, end - start, duplex=True)
|
||||
for i, b in enumerate(result):
|
||||
buf[start + i] = b
|
||||
|
||||
# pylint: enable=unused-argument
|
||||
|
||||
# pylint: disable=too-many-arguments
|
||||
def write_readinto(
|
||||
self, buffer_out, buffer_in, out_start=0, out_end=None, in_start=0, in_end=None
|
||||
):
|
||||
"""Perform a half-duplex write from buffer_out and then
|
||||
read data into buffer_in
|
||||
"""
|
||||
out_end = out_end if out_end else len(buffer_out)
|
||||
in_end = in_end if in_end else len(buffer_in)
|
||||
result = self._port.exchange(
|
||||
buffer_out[out_start:out_end], in_end - in_start, duplex=True
|
||||
)
|
||||
for i, b in enumerate(result):
|
||||
buffer_in[in_start + i] = b
|
||||
|
||||
# pylint: enable=too-many-arguments
|
|
@ -0,0 +1,39 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""
|
||||
Support for getting the URL from the BLINKA_FT232H
|
||||
and BLINKA_FTX232H_{} environment variables.
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
|
||||
def get_ft232h_url():
|
||||
"""
|
||||
Return the FTDI url to use. If BLINKA_FT232H starts with ftdi:, returns
|
||||
that. Otherwise, returns a default value.
|
||||
"""
|
||||
|
||||
url = os.environ.get("BLINKA_FT232H", "1")
|
||||
|
||||
if url.startswith("ftdi:"):
|
||||
return url
|
||||
|
||||
return "ftdi://ftdi:ft232h/1"
|
||||
|
||||
|
||||
def get_ftx232h_url(interface_id):
|
||||
"""
|
||||
Return the FTDI url to use. If BLINKA_FTX232H_{} starts with ftdi:, returns
|
||||
that. Otherwise, returns a default value.
|
||||
"""
|
||||
|
||||
url = os.environ.get("BLINKA_FTX232H_{}".format(interface_id), "1")
|
||||
|
||||
if url.startswith("ftdi:"):
|
||||
return url
|
||||
|
||||
if os.environ.get("BLINKA_FT2232H", None):
|
||||
return "ftdi://ftdi:ft2232h/{}".format(interface_id + 1)
|
||||
return "ftdi://ftdi:ft4232h/{}".format(interface_id + 1)
|
Loading…
Add table
Add a link
Reference in a new issue