diff --git a/README.md b/README.md index 0e107d3..7af75d2 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,9 @@ Get and Display car sensors - Raspberry Pi Zero or other Raspberry Pi version (3 or 4) - [Optional] UBEC DC/DC Step-Down (Buck) Converter - 5V @ 3A output -- Adafruit 0.56" 4-Digit 7-Segment Display w/I2C Backpack +- Adafruit 0.56" 4-Digit 7-Segment Display w/I2C Backpack (or Adafruit Quad Alphanumeric Display - 0.54" Digits w/ I2C Backpack) - Voltage sensor (tested with Grove - Voltage Divider and ARCELI DC0-25V) +- Temperature sensor (TMP36) - MCP3008 - 8-Channel 10-Bit ADC With SPI Interface - Momentary switch button diff --git a/config.ini b/config.ini index 3f1e005..9f4f7bc 100644 --- a/config.ini +++ b/config.ini @@ -8,17 +8,37 @@ CS = 8 # GPIO Pin BUTTON = 5 -[voltage_sensor] -# grove or arceli -MODEL = grove +[display] +# Model: 7x4, 14x4 +MODEL = 7x4 +BRIGHTNESS = 0.5 +BLINK_RATE = 0 [sensors] -# voltage, temperature or pressure -SENSOR_0 = voltage -SENSOR_1 = temperature -SENSOR_2 = temperature -SENSOR_3 = temperature -SENSOR_4 = temperature -SENSOR_5 = temperature -SENSOR_6 = temperature -SENSOR_7 = pressure +# Type: voltage, temperature, pressure +# Voltage model: grove, arceli +# Temperature model: tmp36 +# Pressure model: default +SENSOR_0_TYPE = voltage +SENSOR_0_MODEL = grove + +SENSOR_1_TYPE = temperature +SENSOR_1_MODEL = tmp36 + +SENSOR_2_TYPE = temperature +SENSOR_2_MODEL = tmp36 + +SENSOR_3_TYPE = temperature +SENSOR_3_MODEL = tmp36 + +SENSOR_4_TYPE = temperature +SENSOR_4_MODEL = tmp36 + +SENSOR_5_TYPE = temperature +SENSOR_5_MODEL = tmp36 + +SENSOR_6_TYPE = temperature +SENSOR_6_MODEL = tmp36 + +SENSOR_7_TYPE = pressure +SENSOR_7_MODEL = default diff --git a/display.py b/display.py index 9ee2f28..dee0beb 100644 --- a/display.py +++ b/display.py @@ -1,16 +1,27 @@ import board from adafruit_ht16k33.segments import Seg7x4 +from adafruit_ht16k33.segments import Seg14x4 class Display: """Class for communicate with display""" - def __init__(self): + def __init__(self, config): i2c = board.I2C() - self.display = Seg7x4(i2c) + model = config.get('display', 'MODEL') - self.display.brightness = 1 - self.display.blink_rate = 0 + self.display = None + + if (model == '7x4'): + self.display = Seg7x4(i2c) + elif (model == '14x4'): + self.display = Seg14x4(i2c) + else: + print('==== ERROR: Unknown display model ====') + return -1 + + self.display.brightness = float(config.get('display', 'BRIGHTNESS')) + self.display.blink_rate = int(config.get('display', 'BLINK_RATE')) def clear(self): self.display.fill(0) diff --git a/raspicar.py b/raspicar.py index c908a2d..0e5a1e6 100644 --- a/raspicar.py +++ b/raspicar.py @@ -1,6 +1,5 @@ import time import atexit -import board import configparser import RPi.GPIO as GPIO @@ -10,7 +9,7 @@ from display import Display config = configparser.RawConfigParser() config.read(r'./config.ini') -display = Display() +display = Display(config) sensor = Sensors(config) @@ -54,7 +53,7 @@ def main(): display.print(sensor.getValue()) # Wait before next loop - time.sleep(10) + time.sleep(2) atexit.register(handleExit) diff --git a/sensors.py b/sensors.py index 899cf7a..ee05bae 100644 --- a/sensors.py +++ b/sensors.py @@ -10,7 +10,6 @@ class Sensors: self.miso = int(config.get('adc', 'MISO')) self.clk = int(config.get('adc', 'CLK')) self.cs = int(config.get('adc', 'CS')) - self.voltage_sensor_model = config.get('voltage_sensor', 'MODEL') self.channel = 0 self.config = config @@ -60,7 +59,7 @@ class Sensors: # Convert value to volt def convertToVoltage(self, value): correction = 1 - if (self.voltage_sensor_model == "arceli"): + if (self.getChannelModel() == "arceli"): correction = 2 return value * (3.3 / 1024) * 5 / correction @@ -76,7 +75,16 @@ class Sensors: return self.convertToCelcius(value) def getChannelType(self): - return self.config.get('sensors', 'SENSOR_' + str(self.channel)) + return self.config.get( + 'sensors', + 'SENSOR_' + str(self.channel) + '_TYPE' + ) + + def getChannelModel(self): + return self.config.get( + 'sensors', + 'SENSOR_' + str(self.channel) + '_MODEL' + ) def getChannel(self): return self.channel