diff --git a/README.md b/README.md index 57207d8..0e107d3 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ 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 -- 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 - Momentary switch button diff --git a/config.ini b/config.ini new file mode 100644 index 0000000..81fb4be --- /dev/null +++ b/config.ini @@ -0,0 +1,11 @@ +[adc] +CLK = 11 +MISO = 9 +MOSI = 10 +CS = 8 + +[button] +BUTTON = 5 + +[voltage_sensor] +MODEL = grove diff --git a/raspicar.py b/raspicar.py index dc3abfe..b826278 100644 --- a/raspicar.py +++ b/raspicar.py @@ -1,16 +1,23 @@ import time import atexit import board +import configparser import RPi.GPIO as GPIO from datetime import datetime 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 -CLK = 11 -MISO = 9 -MOSI = 10 -CS = 8 +CLK = int(config.get('adc', 'CLK')) +MISO = int(config.get('adc', 'MISO')) +MOSI = int(config.get('adc', 'MOSI')) +CS = int(config.get('adc', 'CS')) CHANNEL = 0 # By default read sensor 0 # Display configuration @@ -18,7 +25,7 @@ i2c = board.I2C() display = Seg7x4(i2c) # Button -BUTTON = 5 # GPIO5 +BUTTON = int(config.get('button', 'BUTTON')) # Function called on push button (change sensor) def handlePushButton(button): @@ -34,7 +41,7 @@ def handlePushButton(button): def handleExit(): print("GoodBye!") display.print("--:--") - sleep(2) + time.sleep(2) display.fill(0) @@ -61,7 +68,11 @@ def init(): # Convert value to volt 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