本帖最后由 shadowba 于 2023-6-2 09:19 编辑
免责声明:没有基础切勿进行车辆改装,本帖仅是个人娱乐,所有因改装引发的各类损失、车辆事故、人员伤害等等与本人无关,责任自负!!!!!i2c读卡器工作不稳定,最后选择mini韦根读卡器安装在左后视镜里面,经过一个月使用,工作状态良好,推荐!
心血来潮,周末愉快,做个汽车中控积木,替换原来的8266esp32“中控”丐版福音,网上找了许久没发现CAN总线如何实现,也未找到相关教程,如有智者可以倾囊相授,深表感激一起玩耍
已实现功能:
1.车辆发动机状态显示
2.车门状态显示
3.灯光状态显示
4.充电插头状态显示
5.充电状态显示
6.远程启动或者关闭发动机
7.远程开锁或者关锁
8.远程打开后备箱或者本地车辆实体按钮打开
9.远程打开充电口或者本地车辆实体按钮打开
10.刹车灯、左转灯、右转灯、近光灯、示廓灯、鸣笛控制
11.车内温度检测
12、座椅加热坐垫控制
13.待实现空调配合温度传感器远程控制,冬天送孩子上学再也不会吵这车里冷了,夏天出门可以提前打开空调,凉凉啊。
14.自动大灯,用了两个光敏模块用来分别控制示廓灯和近光灯
15.后视镜折叠或者展开
16.蓄电池电压检测
17.手机或者手表刷卡开车门,NFC读卡器模块用I2C实现手机刷卡开锁,因电平不匹配,加了个电平转换模块
以上功能可以互相配合比如锁车后升窗加灯光提示、鸣笛提示,定时开启车辆后检测车内温度开启空调等等,玩法多多,貌似比遥控模型好玩,ENJOY!!
调试成功
NFC刷卡模块PN532安装在左侧后视镜内,线引进车内
锁车升窗需要根据车辆中控不同而定,我的玻璃升降中控在主驾驶控制上,拆开取里面的触点,把线印出来通过继电器闭合或者开路来实现锁车升窗
自制的控制模块
上车测试一切正常
16路继电器模块
合影,争取周日装到车上
那么多段子,索性买把钳子!
一不小心烧了一个mcp23017,没想到原来才十多块钱一个,现在价格早已翻了几翻,太贵了
太贵了,索性买直插的自己diy一个扩展
洞洞板真是个好东西
请原谅我那渣渣的手艺
充电状态、插头状态,和运行状态是通过PC817光耦串一个500欧左右的电阻接在仪表盘led灯上实现的,是不是很简单??
颗颗饱满,需要哪个状态灯就接哪个
注意LED正负极,接入光耦一定要串电阻,不然对应的表盘灯会不亮
esphome:
name: "esphome-web-c30ev"
esp32:
board: esp32dev
framework:
type: arduino
logger:
web_server:
port: 80
ota:
password: "XXXXXXXXXXXXXXXXX"
wifi:
networks:
- ssid: XXXXXXXXXXX
password: XXXXXXXXXXX
ap:
ssid: "XXXXXXXXXXXXXX"
password: "XXXXXXXXXXXXX"
captive_portal:
mqtt:
broker: XXXXXXXXXXXX
username: admin
password: XXXXXXXXXXXXXXX
i2c:
- id: bus_a
sda: 21
scl: 22
scan: true
frequency: 10kHz
- id: bus_b
sda: 19
scl: 18
scan: true
frequency: 10kHz
mcp23017:
- id: 'mcp23017_hub'
i2c_id: bus_a
address: 0x20
pn532_i2c:
i2c_id: bus_b
update_interval: 1s
dallas:
- pin: 5
update_interval: 120s
sensor:
- platform: dallas
address: 0xXXXXXXXXXXXXXX
name: "D5 Car-Temperature"
- platform: adc
pin: 36
name: "VP Car Battery Voltage"
icon: "mdi:car-battery"
filters:
- multiply: 20.7
update_interval: 300s
# - platform: wifi_signal
# name: "WiFi Signal C30ev"
# update_interval: 60s
binary_sensor:
- platform: pn532
uid: XX-XX-XX-XX
name: "D2122 Car-NFC"
icon: "mdi:nfc"
on_press:
then:
- if:
condition:
- binary_sensor.is_on: carlock #车辆如果已上锁
then:
- switch.turn_on: relay12 #打开开锁继电器
- if:
condition:
- binary_sensor.is_off: carlock #如果车辆已解锁
then:
- switch.turn_on: relay7 #打开上锁继电器
- platform: gpio #发动机状态检测传感器
pin:
number: GPIO39
mode:
input: true
name: "VN Car-engine"
device_class: running
icon: "mdi:engine"
id: engine
on_press:
then:
- if:
condition:
- binary_sensor.is_on: parking #如果示廓传感器被打开
then:
- switch.turn_on: relay5 #打开示廓灯继电器
- if:
condition:
and:
- binary_sensor.is_on: dimmed #如果近光灯传感器被打开
- binary_sensor.is_on: parking #如果示廓灯传感器被打开
then:
- switch.turn_on: relay10 #打开近光灯继电器
- delay: 5s
- switch.turn_on: relay11 # 玻璃升降控制
on_release:
then:
- switch.turn_off: relay10 #否则关闭近光灯继电器
- switch.turn_off: relay5 #关闭示廓灯控制继电器
- delay: 1s
- switch.turn_off: relay2 #关闭前左座椅加热继电器
- switch.turn_off: relay3 #关闭前右座椅加热继电器
- switch.turn_off: relay13 #关闭后排座椅加热继电器
- delay: 300s
- switch.turn_off: relay11 #关闭车窗升继电器
- platform: gpio #充电状态传感器
pin:
number: GPIO34
mode:
input: true
name: "D34 Car-charging"
device_class: battery_charging
icon: "mdi:ev-station"
id: charging
- platform: gpio #充电插头传感器
pin:
number: GPIO35
mode:
input: true
name: "D35 Car-power-plug"
device_class: plug
icon: "mdi:power-plug"
- platform: gpio #光照传感器示廓灯
# One of INPUT or INPUT_PULLUP
pin:
number: GPIO32
mode:
input: true
# inverted: true
name: "D32 Car-parking-lights"
icon: "mdi:car-parking-lights"
device_class: light
id: parking
filters:
- delayed_on: 1s
- delayed_off: 25s
on_press:
then:
- if:
condition:
- binary_sensor.is_on: engine #如果引擎传感器已打开
then:
- switch.turn_on: relay5 #打开示廓灯继电器
on_release:
then:
- switch.turn_off: relay5 #否则关闭示廓灯继电器
- platform: gpio #传感器近光灯控制
pin:
number: GPIO33
mode:
input: true
# inverted: true
name: "D33 Car-light-dimmed-light"
icon: "mdi:car-light-dimmed"
device_class: light
id: dimmed
filters:
- delayed_on: 1s
- delayed_off: 20s
on_press:
then:
- delay: 100ms
- if:
condition:
and:
- binary_sensor.is_on: engine #如果引擎传感器已打开
- binary_sensor.is_on: parking #如果近光灯传感器已打开
then:
- switch.turn_on: relay10 #打开近光灯继电器
on_release:
then:
- switch.turn_off: relay10 #否则关闭近光灯
- platform: gpio # 打开充电口
pin:
number: GPIO13
mode:
input: true
pullup: true
inverted: true
name: "D25 Car-plug-button"
icon: "mdi:ev-plug-type2"
on_press:
- switch.toggle: relay1 #充电口按钮开关
- platform: gpio # 行李箱解锁
pin:
number: GPIO16
mode:
input: true
pullup: true
inverted: true
name: "D26 Car-back-button"
icon: "mdi:car-back"
on_press:
- switch.toggle: relay14 #行李箱按钮开关
- platform: gpio # 自动大灯总控按钮开关
pin:
number: GPIO25
mode:
input: true
pullup: true
inverted: true
name: "D27 Car-light-auto-button"
icon: "mdi:lightbulb-auto"
on_press:
- switch.toggle: relay5 # 关闭自动示阔灯控制
- switch.toggle: relay10 # 关闭自动近光灯控制
- platform: gpio # 后排座椅加热总控按钮开关
pin:
number: GPIO14
mode:
input: true
pullup: true
inverted: true
name: "D14 Car-seat-heater-bl-button"
icon: "mdi:car-seat-heater"
on_press:
- switch.toggle: relay13 # 座椅加热后左
- platform: gpio # 座椅加热前左
pin:
number: GPIO26
mode:
input: true
pullup: true
inverted: true
name: "D16 Car-seat-heater-fl-button"
icon: "mdi:car-seat-heater"
on_press:
- switch.toggle: relay2 # 座椅加热前左继电器
- platform: gpio # 座椅加热前右按钮开关
pin:
number: GPIO17
mode:
input: true
pullup: true
inverted: true
name: "D13 Car-seat-heater-fr-button"
icon: "mdi:car-seat-heater"
on_press:
- switch.toggle: relay3 #座椅加热前右继电器
- platform: gpio #车辆上锁状态监测
pin:
number: GPIO27
mode:
input: true
pullup: true
inverted: false
name: "D23 Car-lock"
device_class: lock
icon: "mdi:car"
id: carlock
- platform: gpio #防盗门控制用来联动家里的防盗门锁
pin:
number: GPIO23
mode:
input: true
pullup: true
inverted: true
name: "D17 Door-key-button"
icon: "mdi:door-closed-lock"
- platform: gpio #空调状态
pin:
number: GPIO15
mode:
input: true
pullup: true
inverted: true
name: "D15 Car-A/C"
icon: "mdi:air-conditioner"
switch:
- platform: template #车锁开关
name: "Car key"
icon: "mdi:car-key"
lambda: |-
if (id(carlock).state) {
return true;
} else {
return false;
}
turn_on_action:
- switch.turn_on: relay12 #车门开锁
- switch.turn_on: relay4 #鸣笛控制
turn_off_action:
- switch.turn_on: relay7 #车门上锁
- switch.turn_on: relay4 #鸣笛控制
- delay: 500ms
- switch.turn_on: relay4 #鸣笛控制
- platform: template #一键启停
name: "Car-One key start"
icon: "mdi:refresh-auto"
lambda: |-
if (id(engine).state) {
return true;
} else {
return false;
}
turn_on_action:
- switch.turn_on: relay12 #车门开锁继电器
- delay: 4s
- switch.turn_on: relay8 #打开刹车灯继电器
- delay: 1s
- switch.turn_on: start #按引擎开关
- delay: 1s
- switch.turn_off: relay8 #打开刹车灯继电器
turn_off_action:
- switch.turn_on: relay8 #打开刹车灯继电器
- delay: 1s
- switch.turn_on: start #按引擎开关
- delay: 1s
- switch.turn_off: relay8 #关闭刹车灯继电器
- delay: 1s
- switch.turn_on: relay7 #车门上锁继电器
- platform: gpio #汽车引擎启动开关 在esp32 IO上
pin: 2
id: start
name: "D2 Engine start"
icon: "mdi:engine"
on_turn_on:
- delay: 1s
- switch.turn_off: start
- platform: gpio #关闭空调 在esp32 IO上
pin: 4
id: acoff
name: "D4 Car-A/C OFF"
icon: "mdi:air-conditioner"
on_turn_on:
- delay: 1s
- switch.turn_off: acoff
- platform: gpio #打开空调 在esp32 IO上
pin: 12
id: acon
name: "D12 Car-A/C ON"
icon: "mdi:air-conditioner"
on_turn_on:
- delay: 1s
- switch.turn_off: acon
- platform: restart #系统重启
name: "Car-sys-restart"
#mcp23017_hub
- platform: gpio
name: "Car-light-L" # 左转向灯继电器--正触发
pin:
mcp23xxx: mcp23017_hub
number: 0
mode:
output: true
inverted: false
icon: "mdi:arrow-left-bold"
id: relay
on_turn_on:
- delay: 400ms
- switch.turn_off: relay
- platform: gpio
name: "Car-ev-plug" # 充电口
pin:
mcp23xxx: mcp23017_hub
number: 1
mode:
output: true
inverted: false
icon: "mdi:ev-plug-type2"
id: relay1
on_turn_on:
- delay: 100ms
- switch.turn_off: relay1
- platform: gpio
name: "Car-seat-heater-fl" # 座椅加热前左
pin:
mcp23xxx: mcp23017_hub
number: 2
mode:
output: true
inverted: false
icon: "mdi:car-seat-heater"
id: relay2
on_turn_on:
- delay: 1800s
- switch.turn_off: relay2
- platform: gpio
name: "Car-seat-heater-fr" # 座椅加热前右
pin:
mcp23xxx: mcp23017_hub
number: 3
mode:
output: true
inverted: false
icon: "mdi:car-seat-heater"
id: relay3
on_turn_on:
- delay: 1800s
- switch.turn_off: relay3
- platform: gpio
name: "Car-whistle" # 鸣笛控制
pin:
mcp23xxx: mcp23017_hub
number: 4
mode:
output: true
inverted: false
icon: "mdi:bullhorn-variant"
id: relay4
on_turn_on:
- delay: 1ms
- switch.turn_off: relay4
- platform: gpio
name: "Car-little-light" # 示廓灯
pin:
mcp23xxx: mcp23017_hub
number: 5
mode:
output: true
inverted: false
icon: "mdi:car-parking-lights"
id: relay5
- platform: gpio
name: "Car-mirror-open" # 后视镜展开
pin:
mcp23xxx: mcp23017_hub
number: 6
mode:
output: true
inverted: false
icon: "mdi:mirror"
id: relay6
interlock: [relay9]
on_turn_on:
- delay: 3.5s
- switch.turn_off: relay6
- platform: gpio
name: "Car-door-lock" #车门上锁
pin:
mcp23xxx: mcp23017_hub
number: 7
mode:
output: true
inverted: false
icon: "mdi:car-door-lock"
id: relay7
interlock: [relay12]
on_turn_on:
- delay: 500ms
- switch.turn_off: relay7 #关闭车门上锁继电器
- switch.turn_on: relay9 #打开后视镜折叠继电器
- delay: 500ms
- switch.turn_on: relay #打开左转灯继电器
- switch.turn_on: relay15 #打开右转灯继电器
- delay: 500ms
- switch.turn_on: relay8 #打开刹车灯继电器
- delay: 1s
- switch.turn_off: relay8 #打开刹车灯继电器
- delay: 10s
- switch.turn_off: relay11 #关闭玻璃升降控制继电器
- platform: gpio #刹车信号灯控制继电器--正触发
name: "Car-break-light"
pin:
mcp23xxx: mcp23017_hub
number: 8
mode:
output: true
inverted: false
icon: "mdi:car-brake-hold"
id: relay8
on_turn_on:
- delay: 4s
- switch.turn_off: relay8 #关闭刹车信号灯控制继电器
- platform: gpio
name: "Car-mirror-close" #后视镜折叠控制继电器
pin:
mcp23xxx: mcp23017_hub
number: 9
mode:
output: true
inverted: false
icon: "mdi:mirror"
id: relay9
interlock: [relay6]
on_turn_on:
- delay: 3.5s
- switch.turn_off: relay9
- platform: gpio
name: "Car-light-dimmed" #近光灯控制继电器
pin:
mcp23xxx: mcp23017_hub
number: 10
mode:
output: true
inverted: false
icon: "mdi:car-light-dimmed"
id: relay10
- platform: gpio
name: "Car-windshield" #玻璃升降控制
pin:
mcp23xxx: mcp23017_hub
number: 11
mode:
output: true
inverted: false
icon: "mdi:car-windshield"
id: relay11
- platform: gpio
name: "Car-door-open" #车门开锁
pin:
mcp23xxx: mcp23017_hub
number: 12
mode:
output: true
inverted: false
icon: "mdi:car-door"
id: relay12
interlock: [relay7]
on_turn_on:
- delay: 500ms
- switch.turn_off: relay12 #关闭车门开锁继电器
- switch.turn_on: relay6 #打卡后视镜展开继电器
- delay: 500ms
- switch.turn_on: relay #打开左转灯继电器
- delay: 500ms
- switch.turn_on: relay15 #打开右转灯继电器
- delay: 500ms
- switch.turn_on: relay #打开左转灯继电器
- delay: 500ms
- switch.turn_on: relay15 #打开右转灯继电器
- platform: gpio
name: "Car-seat-heater-bl" #座椅加热后左
pin:
mcp23xxx: mcp23017_hub
number: 13
mode:
output: true
inverted: false
icon: "mdi:car-seat-heater"
id: relay13
on_turn_on:
- delay: 1800s
- switch.turn_off: relay13
- platform: gpio
name: "Car-back" #行李箱解锁继电器
pin:
mcp23xxx: mcp23017_hub
number: 14
mode:
output: true
inverted: false
icon: "mdi:car-back"
id: relay14
on_turn_on:
- delay: 500ms
- switch.turn_off: relay14 #关闭行李箱解锁继电器
- platform: gpio
name: "Car-light-R" #右转向灯继电器--正触发
pin:
mcp23xxx: mcp23017_hub
number: 15
mode:
output: true
inverted: false
icon: "mdi:arrow-right-bold"
id: relay15
on_turn_on:
- delay: 400ms
- switch.turn_off: relay15 #关闭右转向灯继电器
|