hey guys
im been tinkering with a display gauge for my car, and now im stuck
it connects to the CANbus no problem, the display is working correctly, but i just cannot get it to display data correctly (or at all really)
currently the Oil pressure digits and bar graph work correctly
but thr boot pressure, oil temp and max boost display nothing and the oil pressure history gauge only seems to come up halfway
as a note if you just use the code related to getting data from the canbus, i can get correct data in the serial monitor
as the full code i can only get the oil pressure data
#include <mcp_can.h>
#include <mcp_can_dfs.h>
#include <SPI.h>
#include <U8x8lib.h>
#include <U8g2lib.h>
//U8G2_SSD1322_NHD_256X64_F_8080 u8g2(U8G2_R0, 40, 41, 42, 43, 44, 45, 46, 47, 30, 31, 28, 29); //[full framebuffer, size = 2048 bytes]
U8G2_SSD1322_NHD_256X64_F_4W_HW_SPI u8g2(U8G2_R0, 46, 47, 44);
//U8G2_SSD1322_NHD_256X64_F_4W_SW_SPI u8g2(U8G2_R0, 52, 51, 46, 47, 44);
#define U8G2_16BIT
long unsigned int rxId;
unsigned char len = 0;
unsigned char rxBuf[8];
//boost press
int BoostPressure;
int BoostMax = 0;
int BoostBarMax = 30;
//oil press
int OilPressure;
//int OilMax = 0;
int OilMin = 0;
int OilBarMax = 150;
//oil temp
int OilTemp;
bool flashTracker = false;
unsigned long startMillis;
unsigned long currentMillis;
const unsigned long period = 25;
const int sensorHistoryLength = 128;
int sensorHistory[sensorHistoryLength];
int sensorHistoryPos = sensorHistoryLength - 1;
#define Stageas_width 124
#define Stageas_height 30
// 'Stageas', 124x30px
const unsigned char Stageas_bits [] PROGMEM = {
0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xc0, 0x3d, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x10, 0x62, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1e, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x63, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80, 0x31, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xc0, 0x08, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x60, 0x0c, 0x04, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x60, 0x06, 0x1e, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x10, 0x03, 0xfc, 0x83, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x18, 0x03, 0x0c, 0xcc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x18, 0x03, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xe0, 0x03, 0xe0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x80, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x8e, 0x0f, 0x0e, 0x00, 0xfe, 0xff, 0xff, 0xff, 0x7f, 0xfe, 0x7f, 0xff, 0x3f, 0xfe, 0x07,
0x00, 0x1e, 0x78, 0x1e, 0x00, 0x7e, 0x00, 0x3c, 0x78, 0x78, 0x0f, 0x80, 0x0f, 0x80, 0x07, 0x07,
0x00, 0x78, 0x80, 0x3f, 0x00, 0xfc, 0x07, 0x1e, 0xfc, 0xff, 0xc7, 0xff, 0xff, 0xcf, 0xff, 0x07,
0x00, 0xe0, 0x01, 0xf0, 0x01, 0x80, 0x1f, 0x0f, 0xff, 0xfb, 0x03, 0xdc, 0x03, 0xe0, 0xbf, 0x03,
0x80, 0x03, 0x03, 0x30, 0xe6, 0xff, 0x8f, 0x87, 0x07, 0xbc, 0xff, 0x8f, 0xff, 0x7f, 0x80, 0x03,
0x60, 0x7c, 0x06, 0x18, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x60, 0xf0, 0x0f, 0x18, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xc0, 0x00, 0x0e, 0x8c, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80, 0x01, 0x08, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x06, 0x00, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0c, 0x00, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x30, 0xc0, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xf8, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x8c, 0x98, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x80, 0x67, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
#define Stagea_width 256
#define Stagea_height 64
static const unsigned char Stagea_bits[] U8X8_PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x83, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xf0, 0xff, 0x31, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3e, 0x7e, 0x70, 0x80, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0f, 0x10, 0xf0, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xe0, 0x07, 0x00, 0xe0, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xf0, 0x07, 0x02, 0xc0, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3c, 0xc0, 0x00, 0x00, 0x2f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0e, 0x70, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x07, 0x3c, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x80, 0x07, 0x0f, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xe0, 0x87, 0x07, 0x00, 0x00, 0xe0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xf0, 0xc7, 0x03, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x78, 0xe0, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x38, 0xf0, 0x00, 0x60, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1c, 0x70, 0x00, 0xe0, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1c, 0x78, 0x00, 0xe0, 0x03, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3e, 0x3c, 0x00, 0xf0, 0x1f, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x3c, 0x00, 0xe0, 0x7f, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0x1e, 0x00, 0xe0, 0xfe, 0x3f, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80, 0x03, 0x1e, 0x00, 0xe0, 0xe1, 0xff, 0x80, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80, 0x03, 0x1e, 0x00, 0xc0, 0x03, 0xe0, 0xf7, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80, 0x01, 0x0f, 0x00, 0x80, 0x0f, 0x80, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xc0, 0x03, 0x0f, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xc0, 0x7f, 0x0f, 0x00, 0x00, 0xfc, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xfe, 0x0f, 0x00, 0x00, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xc0, 0xff, 0x00, 0x00, 0xe0, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xff, 0x0f, 0x00, 0x80, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xfe, 0xff, 0x01, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xfc, 0xff,
0xff, 0x9f, 0xff, 0xff, 0x03, 0xf8, 0xff, 0xff, 0x1f, 0xfc, 0xff, 0xff, 0x1f, 0xfc, 0xff, 0x3f,
0x00, 0x00, 0xfe, 0xf1, 0x1f, 0x00, 0xfc, 0x03, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xfe, 0xff,
0xff, 0xff, 0xff, 0xff, 0x07, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, 0xff, 0x1f, 0xfe, 0xff, 0x7f,
0x00, 0x00, 0xfc, 0x01, 0xfe, 0x03, 0xf0, 0x07, 0x00, 0x00, 0xe0, 0xff, 0xff, 0x7f, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xcf, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x7f,
0x00, 0x00, 0xf8, 0x03, 0xe0, 0x3f, 0xf0, 0x0f, 0x00, 0x00, 0xe0, 0x7f, 0x00, 0x00, 0x00, 0xfe,
0x01, 0xf8, 0x07, 0xf0, 0xe7, 0x3f, 0x00, 0x00, 0xe0, 0x7f, 0x00, 0x00, 0xc0, 0x3f, 0x80, 0x3f,
0x00, 0x00, 0xf0, 0x07, 0x00, 0xfe, 0xe7, 0x0f, 0x00, 0x00, 0xe0, 0xff, 0x07, 0x00, 0x00, 0xff,
0x00, 0xfc, 0x03, 0xf8, 0xf7, 0x0f, 0xfc, 0xff, 0xf7, 0xff, 0xff, 0xff, 0xe1, 0x1f, 0x80, 0x3f,
0x00, 0x00, 0xe0, 0x1f, 0x00, 0xc0, 0xff, 0x1f, 0x00, 0x00, 0xc0, 0xff, 0xff, 0x00, 0x80, 0x7f,
0x00, 0xff, 0xff, 0xfb, 0xf3, 0x07, 0xfe, 0xff, 0xf7, 0xff, 0xff, 0xff, 0xf1, 0xff, 0xbf, 0x3f,
0x00, 0x00, 0x80, 0x7f, 0x00, 0x00, 0xfc, 0x1f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x07, 0xc0, 0x3f,
0x80, 0xff, 0xff, 0xfb, 0xfb, 0x03, 0xfe, 0xff, 0xfb, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0x1f,
0x00, 0x00, 0x00, 0xfe, 0x01, 0x00, 0x80, 0xff, 0x01, 0x00, 0x00, 0xe0, 0xff, 0x0f, 0xe0, 0x1f,
0xc0, 0xff, 0xff, 0xf9, 0xfb, 0x03, 0x00, 0xfe, 0xf9, 0x07, 0x00, 0x00, 0xfe, 0xff, 0xdf, 0x1f,
0x00, 0x00, 0x00, 0xf8, 0x07, 0x00, 0x00, 0xfe, 0x3f, 0x00, 0x00, 0x00, 0xfc, 0x1f, 0xf0, 0x0f,
0xe0, 0xff, 0xff, 0xfc, 0xf9, 0x03, 0x00, 0xfe, 0xf8, 0x03, 0x00, 0x00, 0xff, 0xff, 0xc7, 0x1f,
0x00, 0x00, 0x00, 0xe0, 0x0f, 0x00, 0x00, 0x1e, 0x7f, 0x00, 0x00, 0x00, 0xf0, 0x1f, 0xf8, 0x07,
0xf8, 0x0f, 0x00, 0xfc, 0xf9, 0x07, 0x80, 0x7f, 0xf8, 0x07, 0x00, 0x80, 0x7f, 0x00, 0xc0, 0x1f,
0x00, 0x00, 0x07, 0x00, 0x3f, 0x00, 0x00, 0x1e, 0x70, 0xc0, 0xff, 0xff, 0xff, 0x0f, 0xfc, 0x03,
0xfc, 0x07, 0x00, 0xfc, 0xf1, 0xff, 0xff, 0x3f, 0xf0, 0xff, 0xff, 0xcf, 0x3f, 0x00, 0xe0, 0x0f,
0x00, 0xe0, 0x7f, 0x00, 0x7c, 0x00, 0x00, 0x1e, 0x70, 0xe0, 0xff, 0xff, 0xff, 0x07, 0xfc, 0x01,
0xfe, 0x01, 0x00, 0xfc, 0xe1, 0xff, 0xff, 0x1f, 0xe0, 0xff, 0xff, 0xf7, 0x1f, 0x00, 0xe0, 0x0f,
0x00, 0xf8, 0xf0, 0x01, 0xf8, 0x00, 0x00, 0x1e, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3c, 0xc0, 0xff, 0xe3, 0x00, 0x00, 0x0f, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1c, 0x00, 0xff, 0xff, 0x01, 0x00, 0x0f, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x38, 0x00, 0x80, 0xff, 0x01, 0x00, 0xc7, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xf0, 0x00, 0x00, 0xfc, 0x01, 0x80, 0x87, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xc0, 0x01, 0x00, 0xf0, 0x01, 0x80, 0x03, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x80, 0x07, 0x00, 0xc0, 0x01, 0xc0, 0x03, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0f, 0x00, 0x80, 0x00, 0xe0, 0x81, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0xf0, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x78, 0xfc, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xe0, 0x01, 0x00, 0x00, 0x3c, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x1e, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0x0f, 0x00, 0x00, 0x07, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1e, 0x00, 0xc0, 0x01, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0x3d, 0x00, 0x30, 0x88, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0xf7, 0x00, 0x00, 0xfc, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xe0, 0xe7, 0x01, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xf0, 0xc1, 0x01, 0x03, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x38, 0x80, 0xc1, 0xdf, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0c, 0x80, 0xfb, 0xfc, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x3f, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
MCP_CAN CAN0(10); // Set CS to pin
void setup(void) {
u8g2.begin();
u8g2.setFlipMode(1);
Serial.begin(115200);
if(CAN0.begin(MCP_STD, CAN_1000KBPS, MCP_16MHZ) == CAN_OK) Serial.print("MCP2515 Init Okay!!\r\n");
else Serial.print("MCP2515 Init Failed!!\r\n");
pinMode(2, INPUT); // Setting pin 2 for /INT input
CAN0.init_Mask(0,0,0x03FF0000); // Init first mask...
CAN0.init_Filt(0,0,0x03610000); // Init first filter...
CAN0.init_Filt(1,0,0xFFFFFFFF); // Init second filter...
CAN0.init_Mask(1,0,0x03FF0000); // Init second mask...
CAN0.init_Filt(2,0,0x03610000); // Init third filter...
CAN0.init_Filt(3,0,0x03E00000); // Init fourth filter...
CAN0.init_Filt(4,0,0x03600000); // Init fifth filter...
CAN0.init_Filt(5,0,0x03610000); // Init sixth filter...
Serial.println("MCP2515 Library Mask & Filter Example...");
CAN0.setMode(MCP_NORMAL); // Change to normal mode to allow messages to be transmitted
u8g2.clearBuffer();
u8g2.drawXBMP(0,0, Stagea_width, Stagea_height, Stagea_bits);
u8g2.sendBuffer();
delay(2000);
u8g2.clearBuffer();
u8g2.drawLine(0, 32, 256, 32);
u8g2.drawXBMP(132, 34, Stageas_width, Stageas_height, Stageas_bits);
u8g2.drawLine(128, 32, 128, 64);
u8g2.sendBuffer();
}
void loop(void) {
if(!digitalRead(2)) // If pin 2 is low, read receive buffer
{
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
}
if (rxId == 0x0360) //Boost Filter
{
int BoostRaw = rxBuf[2] * 256 + rxBuf[3];
for (int i = 0; i < len; i++) // print the data
Serial.println();
float absolutePressure = BoostRaw /10 ;
// Subtract 14.7 psi == pressure at sea level
BoostPressure = (absolutePressure / 6.895) - 14.7;
Serial.print(BoostPressure);
// Update max and min
if (BoostPressure > BoostMax) BoostMax = BoostPressure;
// Log the history
addSensorHistory(BoostPressure);
}
if (rxId == 0x0361) //Oil Pressure Filter
{
int OilPRaw = rxBuf[2] * 256 + rxBuf[3];
for (int i = 0; i < len; i++) // print the data
Serial.println();
float OilPressureK = OilPRaw /10 ;
OilPressure = (OilPressureK - 101.3) / 6.895;
Serial.print(OilPressure);
//if (OilPressure > OilMax) OilMax = OilPressure;
if (OilPressure < OilMin) OilMin = OilPressure;
// Log the history
addSensorHistory(OilPressure);
}
if (rxId == 0x03E0) //Oil Temp Filter
{
int OilTRaw = rxBuf[6] * 256 + rxBuf[7];
for (int i = 0; i < len; i++) // print the data
Serial.println();
float OilTempK = OilTRaw /10 ;
// Subtract 14.7 psi == pressure at sea level
OilTemp = OilTempK - 273.15;
Serial.print(OilTemp);
}
u8g2.clearBuffer();
// Draw current oilpressure
u8g2.setFont(u8g2_font_fub20_tf);
char cstr[6];
dtostrf((float)OilPressure, 1, 1, cstr);
u8g2.drawStr(0, 20, cstr);
// Draw current pressure
u8g2.setFont(u8g2_font_fub20_tf);
dtostrf((float)BoostPressure, 1, 2, cstr);
u8g2.drawStr(130, 22, cstr);
u8g2.drawLine(128, 0, 128, 32);
// Draw oil temp
u8g2.setFont(u8g2_font_fub11_tf);
dtostrf((float)OilTemp, 1, 2, cstr);
int yPos1 = u8g2.getStrWidth(cstr);
u8g2.drawStr(115 - yPos1, 11, cstr);
u8g2.setFont(u8g2_font_fub11_tf);
u8g2.setCursor(115, 11);
u8g2.print("c");
// Draw max pressure
u8g2.setFont(u8g2_font_fub11_tf);
dtostrf((float)BoostMax
/ 100, 1, 2, cstr);
int yPos = u8g2.getStrWidth(cstr);
u8g2.drawStr(256 - yPos, 11, cstr);
drawBarGraph(0, 22, 128, 8);
drawBarGraph1(128, 22, 256, 8);
u8g2.updateDisplayArea(0, 0, 32, 4);
drawGraph(0, 32, 128, 31);
u8g2.updateDisplayArea(0, 7, 16, 4);
}
void addSensorHistory(int val) {
sensorHistory[sensorHistoryPos] = val;
sensorHistoryPos--;
if (sensorHistoryPos < 0) sensorHistoryPos = sensorHistoryLength - 1;
}
int getSensorHistory(int index) {
index += sensorHistoryPos;
if (index >= sensorHistoryLength) index = index - sensorHistoryLength;
return sensorHistory[index];
}
// Display functions
void drawGraph(int x, int y, int len, int height) {
// Draw the lines
drawHorizontalDottedLine(x, y, len);
drawHorizontalDottedLine(x, y + height, len);
//var absMin = Math.abs;
int absMin = abs(OilMin);
int range = absMin + OilBarMax;
// Draw 0 line
int zeroYPos = mapValueToYPos(absMin, range, y, height);
drawHorizontalDottedLine(x, zeroYPos, len);
// Draw the graph line
for (int i = 0; i < 128; i++) {
// Scale the values so that the min is always 0
int valueY = getSensorHistory(i) + absMin;
// Calculate the coordinants
int yPos = mapValueToYPos(valueY, range, y, height);
int xPos = len - i;
if (yPos < zeroYPos) {
// Point is above zero line, fill in space under graph
u8g2.drawVLine(xPos, yPos, zeroYPos + 1 - yPos);
} else {
// Point is below zero line, draw graph line without filling in
u8g2.drawPixel(xPos, yPos);
}
}
}
void drawBarGraph(int x, int y, int len, int height) {
if (OilPressure > 0) {
// Draw the pressure bar behind the graph
int barLength = ((float)OilPressure / OilBarMax) * len;
u8g2.setDrawColor(2);
u8g2.drawBox(x, y, barLength, height);
u8g2.setDrawColor(1);
}
}
void drawBarGraph1(int x, int y, int len, int height) {
if (BoostPressure > 0) {
// Draw the pressure bar behind the graph
int barLength = ((float)BoostPressure / BoostBarMax) * len;
u8g2.setDrawColor(2);
u8g2.drawBox(x, y, barLength, height);
u8g2.setDrawColor(1);
}
}
// Maps a value to a y height
int mapValueToYPos(int val, int range, int y, int height) {
float valueY = ((float)val / range) * height;
return y + height - (int)valueY;
}
void drawHorizontalDottedLine(int x, int y, int len) {
for (int i = 0; i < len; i++) {
if (!(i % 4)) u8g2.drawPixel(x + i, y);
}
}