change autodection so only SW SPI needs pins listed in config.py
This commit is contained in:
parent
9fb5ec940f
commit
8c9d3881dc
17
config.py
17
config.py
@ -38,14 +38,16 @@ currency_type = "$" # Currency Symbol to show when calculating cost to run j
|
|||||||
#
|
#
|
||||||
# - faster
|
# - faster
|
||||||
# - requires 3 specific GPIO pins be used on rpis
|
# - requires 3 specific GPIO pins be used on rpis
|
||||||
|
# - no pins are listed in this config file
|
||||||
#
|
#
|
||||||
# Software SPI
|
# Software SPI
|
||||||
#
|
#
|
||||||
# - slower (which will not matter for reading a thermocouple
|
# - slower (which will not matter for reading a thermocouple
|
||||||
# - can use any GPIO pins
|
# - can use any GPIO pins
|
||||||
|
# - pins must be specified in this config file
|
||||||
|
|
||||||
#######################################
|
#######################################
|
||||||
# SPI pins if you choose hardware spi #
|
# SPI pins if you choose Hardware SPI #
|
||||||
#######################################
|
#######################################
|
||||||
# On the raspberry pi, you MUST use predefined
|
# On the raspberry pi, you MUST use predefined
|
||||||
# pins for HW SPI. In the case of the adafruit-31855, only 3 pins are used:
|
# pins for HW SPI. In the case of the adafruit-31855, only 3 pins are used:
|
||||||
@ -58,6 +60,8 @@ currency_type = "$" # Currency Symbol to show when calculating cost to run j
|
|||||||
# I chose gpio pin 5:
|
# I chose gpio pin 5:
|
||||||
#
|
#
|
||||||
# GPIO5 = BCM pin 5 = CS on the adafruit-31855
|
# GPIO5 = BCM pin 5 = CS on the adafruit-31855
|
||||||
|
#
|
||||||
|
# Note that NO pins are configured in this file for hardware spi
|
||||||
|
|
||||||
#######################################
|
#######################################
|
||||||
# SPI pins if you choose software spi #
|
# SPI pins if you choose software spi #
|
||||||
@ -66,12 +70,11 @@ currency_type = "$" # Currency Symbol to show when calculating cost to run j
|
|||||||
# You must connect clock, mosi, miso and cs each to a GPIO pin
|
# You must connect clock, mosi, miso and cs each to a GPIO pin
|
||||||
# and configure them below based on your connections.
|
# and configure them below based on your connections.
|
||||||
|
|
||||||
|
|
||||||
#######################################
|
#######################################
|
||||||
# SPI is Autoconfigured !!!
|
# SPI is Autoconfigured !!!
|
||||||
#######################################
|
#######################################
|
||||||
# whether you choose HW or SW spi, it is autodetected. If you use the hw pins
|
# whether you choose HW or SW spi, it is autodetected. If you list the PINs
|
||||||
# HW spi is assumed.
|
# below, software spi is assumed.
|
||||||
|
|
||||||
#######################################
|
#######################################
|
||||||
# Output to control the relay
|
# Output to control the relay
|
||||||
@ -81,10 +84,10 @@ currency_type = "$" # Currency Symbol to show when calculating cost to run j
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
import board
|
import board
|
||||||
spi_sclk = board.D11 #spi clock
|
spi_sclk = board.D17 #spi clock
|
||||||
|
spi_miso = board.D27 #spi Microcomputer In Serial Out
|
||||||
|
spi_cs = board.D22 #spi Chip Select
|
||||||
spi_mosi = board.D10 #spi Microcomputer Out Serial In (not connected)
|
spi_mosi = board.D10 #spi Microcomputer Out Serial In (not connected)
|
||||||
spi_miso = board.D9 #spi Microcomputer In Serial Out
|
|
||||||
spi_cs = board.D5 #spi Chip Select
|
|
||||||
gpio_heat = board.D23 #output that controls relay
|
gpio_heat = board.D23 #output that controls relay
|
||||||
except (NotImplementedError,AttributeError):
|
except (NotImplementedError,AttributeError):
|
||||||
print("not running on blinka recognized board, probably a simulation")
|
print("not running on blinka recognized board, probably a simulation")
|
||||||
|
|||||||
19
lib/oven.py
19
lib/oven.py
@ -121,26 +121,17 @@ class TempSensorReal(TempSensor):
|
|||||||
self.spi_setup()
|
self.spi_setup()
|
||||||
self.cs = digitalio.DigitalInOut(config.spi_cs)
|
self.cs = digitalio.DigitalInOut(config.spi_cs)
|
||||||
|
|
||||||
def hw_spi(self):
|
|
||||||
import board
|
|
||||||
if(hasattr(board,'SCLK') and
|
|
||||||
hasattr(board,'MOSI') and
|
|
||||||
hasattr(board,'MISO')):
|
|
||||||
if(board.SCLK == config.spi_sclk and
|
|
||||||
board.MOSI == config.spi_mosi and
|
|
||||||
board.MISO == config.spi_miso):
|
|
||||||
return board.SPI();
|
|
||||||
return None
|
|
||||||
|
|
||||||
def spi_setup(self):
|
def spi_setup(self):
|
||||||
self.spi = self.hw_spi()
|
if(hasattr(config,'spi_sclk') and
|
||||||
if self.spi is None:
|
hasattr(config,'spi_mosi') and
|
||||||
|
hasattr(config,'spi_miso')):
|
||||||
self.spi = bitbangio.SPI(config.spi_sclk, config.spi_mosi, config.spi_miso)
|
self.spi = bitbangio.SPI(config.spi_sclk, config.spi_mosi, config.spi_miso)
|
||||||
log.info("Software SPI selected for reading thermocouple")
|
log.info("Software SPI selected for reading thermocouple")
|
||||||
else:
|
else:
|
||||||
|
import board
|
||||||
|
self.spi = board.SPI();
|
||||||
log.info("Hardware SPI selected for reading thermocouple")
|
log.info("Hardware SPI selected for reading thermocouple")
|
||||||
|
|
||||||
|
|
||||||
def get_temperature(self):
|
def get_temperature(self):
|
||||||
'''read temp from tc and convert if needed'''
|
'''read temp from tc and convert if needed'''
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -30,18 +30,19 @@ except NotImplementedError:
|
|||||||
########################################################################
|
########################################################################
|
||||||
|
|
||||||
spi = None
|
spi = None
|
||||||
if(hasattr(board,'SCLK') and
|
if(hasattr(config,'spi_sclk') and
|
||||||
hasattr(board,'MOSI') and
|
hasattr(config,'spi_mosi') and
|
||||||
hasattr(board,'MISO')):
|
hasattr(config,'spi_miso')):
|
||||||
if(board.SCLK == config.spi_sclk and
|
|
||||||
board.MOSI == config.spi_mosi and
|
|
||||||
board.MISO == config.spi_miso):
|
|
||||||
spi = board.SPI();
|
|
||||||
print("Hardware SPI selected for reading thermocouple")
|
|
||||||
|
|
||||||
if spi is None:
|
|
||||||
spi = bitbangio.SPI(config.spi_sclk, config.spi_mosi, config.spi_miso)
|
spi = bitbangio.SPI(config.spi_sclk, config.spi_mosi, config.spi_miso)
|
||||||
print("Software SPI selected for reading thermocouple")
|
print("Software SPI selected for reading thermocouple")
|
||||||
|
print("SPI configured as:\n")
|
||||||
|
print(" config.spi_sclk = %s BCM pin" % (config.spi_sclk))
|
||||||
|
print(" config.spi_mosi = %s BCM pin" % (config.spi_mosi))
|
||||||
|
print(" config.spi_miso = %s BCM pin" % (config.spi_miso))
|
||||||
|
print(" config.spi_cs = %s BCM pin\n" % (config.spi_cs))
|
||||||
|
else:
|
||||||
|
spi = board.SPI();
|
||||||
|
print("Hardware SPI selected for reading thermocouple")
|
||||||
|
|
||||||
cs = DigitalInOut(config.spi_cs)
|
cs = DigitalInOut(config.spi_cs)
|
||||||
cs.switch_to_output(value=True)
|
cs.switch_to_output(value=True)
|
||||||
@ -57,11 +58,6 @@ if(config.max31856):
|
|||||||
print("thermocouple: adafruit max31856")
|
print("thermocouple: adafruit max31856")
|
||||||
sensor = adafruit_max31856.MAX31856(spi, cs)
|
sensor = adafruit_max31856.MAX31856(spi, cs)
|
||||||
|
|
||||||
print("SPI configured as:\n")
|
|
||||||
print(" config.spi_sclk = %s BCM pin" % (config.spi_sclk))
|
|
||||||
print(" config.spi_mosi = %s BCM pin" % (config.spi_mosi))
|
|
||||||
print(" config.spi_miso = %s BCM pin" % (config.spi_miso))
|
|
||||||
print(" config.spi_cs = %s BCM pin\n" % (config.spi_cs))
|
|
||||||
print("Degrees displayed in %s\n" % (config.temp_scale))
|
print("Degrees displayed in %s\n" % (config.temp_scale))
|
||||||
|
|
||||||
temp = 0
|
temp = 0
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user