CAN Bus 04: Dash Board

This sketch shows how to get the most important parameters from a vehicle 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_04] CAN Bus Dash Board -------- 
 *  
 *  This sketch shows how to get the most important parameters from 
 *  a vehicle 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 .  
 */

// Include always these libraries before using the CAN Bus functions
#include <WaspCAN.h>


void setup() {
  // Turn on the USB 
  USB.ON();
  delay(100);

  // Print initial message 
  USB.println("Initializing CAN Bus...");	

  // Configuring the Bus at 500 Kbit/s
  CAN.ON(500);   

  USB.println("CAN Bus initialized at 500 KBits/s");  
  USB.println();
}


void loop() {

  // Read the value of the Vehicle Speed 
  int vehicleSpeed = CAN.getVehicleSpeed(); 

  // Read the value of RPM of the engine
  int engineRPM = CAN.getEngineRPM(); 

  // Read the engine fuel rate
  int engineFuelRate = CAN.getEngineFuelRate();

  // Get the fuel level
  int fuelLevel = CAN.getFuelLevel();

  // Get the throttle position
  int throttlePosition = CAN.getThrottlePosition();

  //Get the fuel pressure value 
  int fuelPressure = CAN.getFuelPressure(); 


  USB.println(F("<============================================>"));
  USB.print(F("\tVehicle Speed =>  ")); 
  USB.print(vehicleSpeed);
  USB.println("  Km / h");

  USB.print(F("\tEngine RPM =>  ")); 
  USB.print(engineRPM);
  USB.println("  RPM");

  USB.print(F("\tEngine Fuel Rate =>  ")); 
  USB.print(engineFuelRate);
  USB.println("  L/h");

  USB.print(F("\tFuel Level =>  ")); 
  USB.print(fuelLevel);
  USB.println("  %");

  USB.print(F("\tThrottle Position =>  ")); 
  USB.print(throttlePosition);
  USB.println(" % ");

  USB.print(F("\tFuel Pressure =>  ")); 
  USB.print(fuelPressure);
  USB.println("  KPa");

  USB.println(F("<============================================>"));

  USB.println();

  delay(1000); 
}

Output

H#
Initializing CAN Bus...
CAN Bus initialized at 500 KBits/s

<============================================>
Vehicle Speed => 215 Km / h
Engine RPM => 3437 RPM
Engine Fuel Rate => 3071 L/h
Fuel Level :=> 12 %
Throttle Position => 43 %
Fuel Pressure => 381 KPa
<============================================>

<============================================>
Vehicle Speed => 215 Km / h
Engine RPM => 3437 RPM
Engine Fuel Rate => 3071 L/h
Fuel Level :=> 12 %
Throttle Position => 43 %
Fuel Pressure => 381 KPa
<============================================>

Last updated