This skecth shows how to get the engine RPM using the standard OBD-II PIDs codes. This codes are used to request data from a vehicle, used as a diagnostic tool.
Required Materials
1 x Waspmote
1 x Battery
1 x CAN Bus
1 x OBD cable
Notes
- Waspmote must be powered with a battery
- CAN Bus was designed to work in automotive applications, but it can be used in other communication areas.
- The CAN Bus library integrates the most important PID functions, but it does not include all of them.
- This example can be executed in Waspmote v12 and Waspmote v15
Code
/* * ------ [CAN_Bus_02] CAN Bus Get Engine RPM -------- * * This sketch shows how to get the engine RPM using the standard OBD-II * PIDs codes. This codes are used to request data from a vehicle, used * as a diagnostic tool. * * Copyright (C) 2014 Libelium Comunicaciones Distribuidas S.L. * http://www.libelium.com * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Version: 0.1 * Implementation: Luis Antonio Martin & Ahmad Saad */// Include always these libraries before using the CAN Bus functions#include<WaspCAN.h>voidsetup(){ // Turn on the USB USB.ON();delay(100);// Print initial message USB.println("Initializing CAN Bus..."); // Configuring the BUS at 500 Kbit/sCAN.ON(500); USB.println("CAN Bus initialized at 500 KBits/s"); }voidloop(){ // Read the value of RPM if the engine int engineRpm =CAN.getEngineRPM(); // Print received data in the serial monitorUSB.print("RPM of engine: "); USB.println(engineRpm);delay(1000); }
Output
H#
Initializing CAN Bus...
CAN Bus initialized at 500 KBits/s
RPM of engine : 9375
RPM of engine : 9375
RPM of engine : 9375
RPM of engine : 9375
RPM of engine : 9375
RPM of engine : 8750
RPM of engine : 8437
RPM of engine : 7812
RPM of engine : 5937
RPM of engine : 3750
RPM of engine : 3750
RPM of engine : 3750
RPM of engine : 3437
RPM of engine : 3437