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)
|
- Raspberry Pi Zero or other Raspberry Pi version (3 or 4)
|
||||||
- [Optional] UBEC DC/DC Step-Down (Buck) Converter - 5V @ 3A output
|
- [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)
|
- Voltage sensor (tested with Grove - Voltage Divider and ARCELI DC0-25V)
|
||||||
|
- Temperature sensor (TMP36)
|
||||||
- MCP3008 - 8-Channel 10-Bit ADC With SPI Interface
|
- MCP3008 - 8-Channel 10-Bit ADC With SPI Interface
|
||||||
- Momentary switch button
|
- Momentary switch button
|
||||||
|
|
||||||
|
|
44
config.ini
44
config.ini
|
@ -8,17 +8,37 @@ CS = 8
|
||||||
# GPIO Pin
|
# GPIO Pin
|
||||||
BUTTON = 5
|
BUTTON = 5
|
||||||
|
|
||||||
[voltage_sensor]
|
[display]
|
||||||
# grove or arceli
|
# Model: 7x4, 14x4
|
||||||
MODEL = grove
|
MODEL = 7x4
|
||||||
|
BRIGHTNESS = 0.5
|
||||||
|
BLINK_RATE = 0
|
||||||
|
|
||||||
[sensors]
|
[sensors]
|
||||||
# voltage, temperature or pressure
|
# Type: voltage, temperature, pressure
|
||||||
SENSOR_0 = voltage
|
# Voltage model: grove, arceli
|
||||||
SENSOR_1 = temperature
|
# Temperature model: tmp36
|
||||||
SENSOR_2 = temperature
|
# Pressure model: default
|
||||||
SENSOR_3 = temperature
|
SENSOR_0_TYPE = voltage
|
||||||
SENSOR_4 = temperature
|
SENSOR_0_MODEL = grove
|
||||||
SENSOR_5 = temperature
|
|
||||||
SENSOR_6 = temperature
|
SENSOR_1_TYPE = temperature
|
||||||
SENSOR_7 = pressure
|
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
|
import board
|
||||||
from adafruit_ht16k33.segments import Seg7x4
|
from adafruit_ht16k33.segments import Seg7x4
|
||||||
|
from adafruit_ht16k33.segments import Seg14x4
|
||||||
|
|
||||||
|
|
||||||
class Display:
|
class Display:
|
||||||
"""Class for communicate with display"""
|
"""Class for communicate with display"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, config):
|
||||||
i2c = board.I2C()
|
i2c = board.I2C()
|
||||||
self.display = Seg7x4(i2c)
|
model = config.get('display', 'MODEL')
|
||||||
|
|
||||||
self.display.brightness = 1
|
self.display = None
|
||||||
self.display.blink_rate = 0
|
|
||||||
|
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):
|
def clear(self):
|
||||||
self.display.fill(0)
|
self.display.fill(0)
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import time
|
import time
|
||||||
import atexit
|
import atexit
|
||||||
import board
|
|
||||||
import configparser
|
import configparser
|
||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
|
|
||||||
|
@ -10,7 +9,7 @@ from display import Display
|
||||||
config = configparser.RawConfigParser()
|
config = configparser.RawConfigParser()
|
||||||
config.read(r'./config.ini')
|
config.read(r'./config.ini')
|
||||||
|
|
||||||
display = Display()
|
display = Display(config)
|
||||||
sensor = Sensors(config)
|
sensor = Sensors(config)
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,7 +53,7 @@ def main():
|
||||||
display.print(sensor.getValue())
|
display.print(sensor.getValue())
|
||||||
|
|
||||||
# Wait before next loop
|
# Wait before next loop
|
||||||
time.sleep(10)
|
time.sleep(2)
|
||||||
|
|
||||||
atexit.register(handleExit)
|
atexit.register(handleExit)
|
||||||
|
|
||||||
|
|
14
sensors.py
14
sensors.py
|
@ -10,7 +10,6 @@ class Sensors:
|
||||||
self.miso = int(config.get('adc', 'MISO'))
|
self.miso = int(config.get('adc', 'MISO'))
|
||||||
self.clk = int(config.get('adc', 'CLK'))
|
self.clk = int(config.get('adc', 'CLK'))
|
||||||
self.cs = int(config.get('adc', 'CS'))
|
self.cs = int(config.get('adc', 'CS'))
|
||||||
self.voltage_sensor_model = config.get('voltage_sensor', 'MODEL')
|
|
||||||
self.channel = 0
|
self.channel = 0
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
|
@ -60,7 +59,7 @@ class Sensors:
|
||||||
# Convert value to volt
|
# Convert value to volt
|
||||||
def convertToVoltage(self, value):
|
def convertToVoltage(self, value):
|
||||||
correction = 1
|
correction = 1
|
||||||
if (self.voltage_sensor_model == "arceli"):
|
if (self.getChannelModel() == "arceli"):
|
||||||
correction = 2
|
correction = 2
|
||||||
|
|
||||||
return value * (3.3 / 1024) * 5 / correction
|
return value * (3.3 / 1024) * 5 / correction
|
||||||
|
@ -76,7 +75,16 @@ class Sensors:
|
||||||
return self.convertToCelcius(value)
|
return self.convertToCelcius(value)
|
||||||
|
|
||||||
def getChannelType(self):
|
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):
|
def getChannel(self):
|
||||||
return self.channel
|
return self.channel
|
||||||
|
|
Loading…
Reference in a new issue