Added config file

This commit is contained in:
dbroqua 2021-01-23 19:00:02 +01:00
parent 53218b64aa
commit 5e05666a87
3 changed files with 30 additions and 8 deletions

View file

@ -9,7 +9,7 @@ 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
- Voltage sensor (tested with Grove - Voltage Divider) - Voltage sensor (tested with Grove - Voltage Divider and ARCELI DC0-25V)
- MCP3008 - 8-Channel 10-Bit ADC With SPI Interface - MCP3008 - 8-Channel 10-Bit ADC With SPI Interface
- Momentary switch button - Momentary switch button

11
config.ini Normal file
View file

@ -0,0 +1,11 @@
[adc]
CLK = 11
MISO = 9
MOSI = 10
CS = 8
[button]
BUTTON = 5
[voltage_sensor]
MODEL = grove

View file

@ -1,16 +1,23 @@
import time import time
import atexit import atexit
import board import board
import configparser
import RPi.GPIO as GPIO import RPi.GPIO as GPIO
from datetime import datetime from datetime import datetime
from adafruit_ht16k33.segments import Seg7x4 from adafruit_ht16k33.segments import Seg7x4
config = configparser.RawConfigParser()
config.read(r'./config.ini')
# Voltage Sersor
VOLTAGE_SENSOR_MODEL = config.get('voltage_sensor', 'MODEL')
# ADC configuration # ADC configuration
CLK = 11 CLK = int(config.get('adc', 'CLK'))
MISO = 9 MISO = int(config.get('adc', 'MISO'))
MOSI = 10 MOSI = int(config.get('adc', 'MOSI'))
CS = 8 CS = int(config.get('adc', 'CS'))
CHANNEL = 0 # By default read sensor 0 CHANNEL = 0 # By default read sensor 0
# Display configuration # Display configuration
@ -18,7 +25,7 @@ i2c = board.I2C()
display = Seg7x4(i2c) display = Seg7x4(i2c)
# Button # Button
BUTTON = 5 # GPIO5 BUTTON = int(config.get('button', 'BUTTON'))
# Function called on push button (change sensor) # Function called on push button (change sensor)
def handlePushButton(button): def handlePushButton(button):
@ -34,7 +41,7 @@ def handlePushButton(button):
def handleExit(): def handleExit():
print("GoodBye!") print("GoodBye!")
display.print("--:--") display.print("--:--")
sleep(2) time.sleep(2)
display.fill(0) display.fill(0)
@ -61,7 +68,11 @@ def init():
# Convert value to volt # Convert value to volt
def convertToVoltage(value): def convertToVoltage(value):
return value * ( 3.3 / 1024 ) * 5 correction = 1
if ( VOLTAGE_SENSOR_MODEL == "arceli" ):
correction = 2
return value * ( 3.3 / 1024 ) * 5 / correction
# Convert volt to celcius value # Convert volt to celcius value