Some corrections/improvement
This commit is contained in:
parent
cdfbd29426
commit
df1041ac14
5 changed files with 62 additions and 23 deletions
|
@ -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
|
||||
|
||||
|
|
44
config.ini
44
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
|
||||
|
|
19
display.py
19
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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
14
sensors.py
14
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
|
||||
|
|
Loading…
Reference in a new issue