Libelium's API

It is mandatory to include the CAN Bus library when using this module. The following line must be introduced at the beginning of the code:
#include <WaspCAN.h>
Waspmote's API CAN Bus files:
  • WaspCAN.cpp
  • WaspCAN.h
APIs functions
- Private functions:
The following functions are executed inside the API functions. In normal conditions, the user must NOT manage or use them.
Private functions
void writeRegister( char direction, char data)
Writes a MCP2515 register
char readRegister(char direction);
Reads a MCP2515 register
void bitModify(char direction, char mask, char data);
Modifies a bit of the MCP2515 registers
char readStatus(char type);
Checks the status of the MCP2515 registers
bool checkFreeBuffer(void);
Checks if the buffers are empty
void reset(void);
Resets module
- Data structure
This is a structure created inside the CAN Bus library. The structure fits with the standard CAN Bus frame, so it is used to create the message to send, or to receive messages from other devices.
typedef struct{
unsigned int id;
struct {
char rtr: 1;
char length: 4;
uint8_t data[8];
messageCAN messageRx;
messageCAN messageTx;
-Public functions:
Public funtions
Empty constructor
bool ON(uint16_t speed);
Powers the CAN Bus module and opens the SPI
uint8_t messageAvailable(void);
Checks if there is any message
char getMessage(messageCAN *msje);
Takes the CAN message
char sendMessage(messageCAN *msje);
Sends the CAN message
void printMessage(messageCAN *msje);
Prints a CAN message in the serial monitor
void setMode(uint8_t mode);
Configures the MCP2515 work mode
- CAN in a Automation functions
The OBD-II standard sets some common PIDs for all cars, but it is not always respected. This is a list of useful functions for retreiving data from cars. Consult the specific PIDs in each car.
unsigned int getEngineLoad();
Calculated engine load value in %
unsigned int getEngineCoolantTemp();
Engine coolant temperature in ºC
unsigned int getFuelPressure();
Fuel pressure in KPa
unsigned int getIntakeMAPressure();
Intake manifold absolute pressure in KPa
unsigned int getEngineRPM();
Engine RPM
unsigned int getVehicleSpeed();
Vehicle speed in Km/h
unsigned int getTimingAdvance();
Timing advance (time in seconds from the car start)
unsigned int getIntankeAirTemp();
Intake air temperature in ºC
unsigned int getMAFairFlowRate();
MAF air flow rate in g/s
unsigned int getThrottlePosition();
Throttle position in %
unsigned int getFuelLevel();
Fuel level in %
unsigned int getBarometricPressure();
Barometric pressure in KPa
unsigned int getEngineFuelRate();
Engine fuel rate in litres/hour
void CiARequest(uint8_t PID);
General PID function. Request information through OBD.