该项目可用于监控油温和压力、水温、电压、燃油液位。通过Nextion显示器或诺基亚LCD显示,以让你更直观的了解自己爱车的各项数值。
这次的项目中我们使用了一辆旧车,一辆ToyotaMR21990。
由于没有OBD端口,并且需要测量油温和压力并报警异常值,因此我们决定使用Arduinouno和诺基亚显示器从安装在汽车上的电阻传感器获取数据。
接下来是Arduino输入板:OP=油压;OT=油温;WT水温;V=伏特
再是用于LCD显示的程序:
#include "U8glib.h"
#define backlight_pin 9
int piezoPin = 8; //8 digital pin the piezo buzzer is attached for alarm.
const int oiltemppin = A1; //analog pin
const int oilpressurepin = A2; //oil spacer temp and pressure
const int watertemppin = A3; // fitted in water hose after thermostat
const int voltpin = A4; // from acc
const int fuelpin = A5; //from dash fuel gauge
;
int TA = 130; //OilTmp alarm level over 130
float OA = 1.5; //OilPres alarm level under 1.5
int WA = 100; //WaterTmp alarm level over 100
float VA = 12.0; //Volts alarm under 12.0v
float FA = 5; //Fuel alarm under 10
U8GLIB_PCD8544 u8g(13,11, 7, 5, 6); // CLK=13, DIN=11, CE=7, DC=5, RST=6
void draw(void) {
float oiltempres = analogRead(oiltemppin);//resistance value (432.667-Resistance)/1.75
double oiltemp = (432.667 - oiltempres) /1.80;// 50c=347ohm 60=324 70=312 80c= 95c= 110= 120=
float watertempres = analogRead(watertemppin);//resistance value (350.124-Resistance)/1.25
double watertemp = (350.124 - watertempres) /1.25;// 40c=297ohm 50=287 60=276 70=263 80=250 90=233 fan on
float oilpresres = analogRead(oilpressurepin);// 1= 2= 2.5=170 3=195 4=227 5=258 6=280 12.1v
float oilpressure = (98.5 - oilpresres) / -31.098; //
if (oilpressure < 0) {oilpressure = 0;}
float volts = analogRead(voltpin) / 65.0; //65
float fuel = analogRead(fuelpin) / 2.0;
analogWrite(backlight_pin,20); /* Set the Backlight intensity */
u8g.setFont(u8g_font_profont11); // select font
u8g.drawStr(0, 8, "OilTmp: "); // put string of display at position X, Y
u8g.drawStr(0, 17, "OilPres: ");
u8g.drawStr(0, 26, "WtrTmp: ");
u8g.drawStr(0, 35, "Volts: ");
u8g.drawStr(0, 44, "Fuel: ");
u8g.setPrintPos(55, 8); // set position
u8g.print(oiltemp, 0);
u8g.drawStr(80, 8, "c ");
if (oiltemp > TA) {u8g.drawStr(50, 8, "# ");tone(piezoPin, 500,3000);analogWrite(backlight_pin,250);} //tone(pin,freq,duration)
u8g.setPrintPos(55, 17);
u8g.print(oilpressure, 1);
u8g.drawStr(80, 17, "% ");
if ((oilpressure < OA)&(volts > 13.0)) {u8g.drawStr(50, 17, "# ");tone(piezoPin, 1000,3000);analogWrite(backlight_pin,250);}
u8g.setPrintPos(55, 26);
u8g.print(watertemp, 0);
u8g.drawStr(80, 26, "c ");
if (watertemp > WA) {u8g.drawStr(50, 26, "# ");tone(piezoPin, 1500,3000);analogWrite(backlight_pin,250);}
u8g.setPrintPos(55, 35);
u8g.print(volts, 1);
u8g.drawStr(80, 35, "v ");
if (volts < VA) {u8g.drawStr(50, 35, "# ");tone(piezoPin, 2500,3000);analogWrite(backlight_pin,250);}
u8g.setPrintPos(55, 44);
u8g.print(fuel, 0);
u8g.drawStr(80, 44, "l ");
if ((fuel < FA)& (oilpressure > 1)) {u8g.drawStr(50, 44, "# ");tone(piezoPin, 3000,1000);analogWrite(backlight_pin,250);}
//used for testing only
//u8g.setPrintPos(60, 44);
//u8g.print(fuel, 0);
//u8g.setPrintPos(30, 44);
//u8g.print(oilpresres, 1);
//u8g.setPrintPos(5, 44);
// u8g.print(watertempres, 0);
}
void setup(void) {
analogWrite(backlight_pin,20); /* Set the Backlight intensity */
}
void loop(void) {
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );
delay(1000); // update every 1000 = 1 sec
}
由于诺基亚显示屏变亮(灰色阴影)的问题,导致显示屏连接不良。最终我决定升级到Nextion显示器,结果看起来也更好。
由于Uno只有一个HardwareSerial端口(引脚0/1),并且它与USB-SerialUART共享,因此使用Nextion显示器调试项目很痛苦,所以我们转到链接中的页面并按照说明进行操作,然后我们串行连接在引脚10,11上。
我的NextionHID的硬件连接:
+5V(红色):来自arduino板的5V
TX(蓝色):引脚10(SoftwareSerialRX)
RX(黄色):引脚11(软件串行TX)
GND(黑色):Uno的GND。
颜色是显示器附带的颜色,它带有一个微型分线板上的微型USB连接器。
Nextion显示屏图片
-
显示器
+关注
关注
21文章
4918浏览量
139719
发布评论请先 登录
相关推荐
评论