我有一个项目,我必须在物联网的帮助下开发一个应用程序,该应用程序获取油箱液位值和里程表值的数据,因为这些值在市场上可用的普通 OBD 中不可用。我发现 ELM327 使用 WLAN 协议和串行通信通过 WIFI 进行通信。但我不知道如何与 Arduino esp32 模块建立这种通信。对此的任何想法都会有很大帮助。
问问题
4598 次
1 回答
0
您可以通过正确的步骤轻松完成:
- 确保使用“BluetoothSerial.h”设置经典蓝牙
- 调用 .begin() 时,确保包含第二个参数 (bool true)
- 调用 .connect("OBDII") 连接到您的 ELM327
- 确保在向 ELM327 发送命令/查询时只发送回车(没有换行符!)
这是一个简单的示例程序(今天在我自己的 ELM327 上测试):
#include "BluetoothSerial.h"
BluetoothSerial SerialBT;
#define DEBUG_PORT Serial
#define ELM_PORT SerialBT
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
DEBUG_PORT.begin(115200);
ELM_PORT.begin("ESP32test", true);
DEBUG_PORT.println("Attempting to connect to ELM327...");
if (!ELM_PORT.connect("OBDII"))
{
DEBUG_PORT.println("Couldn't connect to OBD scanner");
while(1);
}
DEBUG_PORT.println("Connected to ELM327");
DEBUG_PORT.println("Ensure your serial monitor line ending is set to 'Carriage Return'");
DEBUG_PORT.println("Type and send commands/queries to your ELM327 through the serial monitor");
DEBUG_PORT.println();
}
void loop()
{
if(DEBUG_PORT.available())
{
char c = DEBUG_PORT.read();
DEBUG_PORT.write(c);
ELM_PORT.write(c);
}
if(ELM_PORT.available())
{
char c = ELM_PORT.read();
if(c == '>')
DEBUG_PORT.println();
DEBUG_PORT.write(c);
}
}
此外,ELMduino现在支持 ESP32 板卡,方便连接和车辆数据查询!
于 2020-02-07T01:01:49.603 回答