MT-07 CAN Bus Documentation 1.0
Comprehensive documentation for the MT-07 CAN Bus Interface library.
 
Loading...
Searching...
No Matches
main.ino File Reference

Main program for MT-07 CAN Bus Interface. More...

#include "MT07_CANBus.h"
Include dependency graph for main.ino:

Go to the source code of this file.

Functions

MT07_CANBus mt07 (CS_PIN)
 Instance of the MT07_CANBus class.
 
void setup ()
 Arduino setup function.
 
void loop ()
 Arduino loop function.
 

Variables

const int CS_PIN = 5
 Chip select pin for MCP2515.
 

Detailed Description

Main program for MT-07 CAN Bus Interface.

This program uses the MT07_CANBus library to interact with the CAN bus of a Yamaha MT-07 motorcycle (2014 model). It initializes the CAN bus, decodes incoming messages, and displays the following data in real-time:

  • Gear position
  • Throttle position sensor (TPS)
  • Motor and air temperature
  • Speed and RPM
Author
Andreas Panagiotakis
Date
2024-08-03 \license MIT License

\usage

  • Connect the MCP2515 module to the ESP32.
  • Wire the CAN bus to the motorcycle.
  • Compile and upload the program to the ESP32.
  • View the decoded data in the Serial Monitor at 115200 baud.

Definition in file main.ino.

Function Documentation

◆ loop()

void loop ( )

Arduino loop function.

Checks for incoming CAN messages, processes them, and displays the decoded data in the Serial Monitor.

Definition at line 52 of file main.ino.

52 {
53 unsigned long rxId;
54 byte rxBuf[8];
55 byte rxDlc;
56
57 // Check for incoming CAN messages
58 if (CAN_MSGAVAIL == mt07.CAN.checkReceive()) {
59 if (mt07.CAN.readMsgBuf(&rxId, &rxDlc, rxBuf) == CAN_OK) {
60 mt07.processMessage(rxId, rxBuf); // Decode the message
61
62 // Display decoded data
63 Serial.print("Gear Position: ");
64 Serial.println(mt07.getGearPosition());
65
66 Serial.print("TPS: ");
67 Serial.print(mt07.getTPS());
68 Serial.println("%");
69
70 Serial.print("Motor Temp: ");
71 Serial.println(mt07.getMotorTemp());
72
73 Serial.print("Air Temp: ");
74 Serial.println(mt07.getAirTemp());
75
76 Serial.print("Speed: ");
77 Serial.print(mt07.getSpeed());
78 Serial.println(" km/h");
79
80 Serial.print("RPM: ");
81 Serial.println(mt07.getRPM());
82 Serial.println("---------------------------");
83 } else {
84 Serial.println("Error reading CAN message.");
85 }
86 }
87}
MT07_CANBus mt07(CS_PIN)
Instance of the MT07_CANBus class.

References mt07().

Here is the call graph for this function:

◆ mt07()

MT07_CANBus mt07 ( CS_PIN )

Instance of the MT07_CANBus class.

References CS_PIN.

Referenced by loop(), and setup().

Here is the caller graph for this function:

◆ setup()

void setup ( )

Arduino setup function.

Initializes the Serial Monitor and CAN bus. If the CAN bus fails to initialize, the program halts.

Definition at line 36 of file main.ino.

36 {
37 Serial.begin(115200);
38
39 if (mt07.begin(CAN_500KBPS, MCP_8MHZ)) {
40 Serial.println("MT-07 CANBus initialized successfully.");
41 } else {
42 Serial.println("Failed to initialize MT-07 CANBus.");
43 while (1); // Halt the program if initialization fails
44 }
45}

References mt07().

Here is the call graph for this function:

Variable Documentation

◆ CS_PIN

const int CS_PIN = 5

Chip select pin for MCP2515.

Definition at line 26 of file main.ino.

Referenced by mt07().