Added config file
This commit is contained in:
parent
53218b64aa
commit
5e05666a87
3 changed files with 30 additions and 8 deletions
|
@ -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
|
||||
|
||||
|
|
11
config.ini
Normal file
11
config.ini
Normal file
|
@ -0,0 +1,11 @@
|
|||
[adc]
|
||||
CLK = 11
|
||||
MISO = 9
|
||||
MOSI = 10
|
||||
CS = 8
|
||||
|
||||
[button]
|
||||
BUTTON = 5
|
||||
|
||||
[voltage_sensor]
|
||||
MODEL = grove
|
25
raspicar.py
25
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
|
||||
|
|
Loading…
Reference in a new issue