bmw e60 dan e46 ya canbus kod cevirici gösterge çalıştırmak için



C++:
// ECUHARD CANBUS SHIELD V2 ILE YAPILDI ARDUINO UNO KULLANILDI
// https://wiki.seeedstudio.com/CAN-BUS_Shield_V2.0/


#include <SPI.h>

#define CAN_2515

const int SPI_CS_PIN = 9;
const int CAN_INT_PIN = 2;

#include "mcp2515_can.h"
mcp2515_can CAN(SPI_CS_PIN);

int motorDeviri = 0;
int sogutmaSicakligi = 0;
int yakitTuketimi = 0;
int gazPedaliYuzdesi = 0;
  unsigned char uzunluk = 0;
  unsigned char tampon[8];


int say = 0;
bool blink = false;
int gear = 0;

void setup()
{
  while (CAN_OK != CAN.begin(CAN_500KBPS)) {
  delay(10);
  }
}

unsigned char RPM_BYTE[8] = {0};
unsigned char CLT_BYTE[8] = {0};
unsigned char GEAR_BYTE[8] = {0};
unsigned char OTHER_BYTE[8] = {0};
unsigned char TRACTION_BYTE[8] = {0};

void loop()
{
  // RPM Gerçek Zamanlı
  int rMSB = motorDeviri / 40;
  int rLSB = (motorDeviri - (rMSB * 40)) * 6.4;
  RPM_BYTE[0] = 0xB0;
  RPM_BYTE[1] = 0x0;
  RPM_BYTE[2] = rLSB;
  RPM_BYTE[3] = rMSB;
  CAN.sendMsgBuf(0x316, 0, 8, RPM_BYTE);

  static unsigned long lastUpdate = 0;
  if (millis() - lastUpdate >= 10) {
    lastUpdate = millis();

    // Blink kontrolü
    blink = (say < 10);
    if (++say > 20) say = 0;

    // CLT
    int CLT_HAM = sogutmaSicakligi * 2 + 20;
    CLT_HAM = min(CLT_HAM, 254);
    CLT_BYTE[0] = 0xD9;
    CLT_BYTE[1] = CLT_HAM;
    CLT_BYTE[5] = (gazPedaliYuzdesi * 390) / 1000;
    CAN.sendMsgBuf(0x329, 0, 8, CLT_BYTE);

    // OTHER
    int mMSB = (gazPedaliYuzdesi) & 0xFF;
    int mLSB = ((gazPedaliYuzdesi) >> 8) & 0xFF;
    OTHER_BYTE[0] = (motorDeviri > 4000 && blink) ? 0x02 : 0x81;
    OTHER_BYTE[2] = mLSB;
    OTHER_BYTE[1] = mMSB;
    OTHER_BYTE[3] = (sogutmaSicakligi > 100 && blink) ? 0xFF : 0x00;
    CAN.sendMsgBuf(0x545, 0, 8, OTHER_BYTE);

    // TRACTION
    memset(TRACTION_BYTE, 0, sizeof(TRACTION_BYTE));
    CAN.sendMsgBuf(0x153, 0, 8, TRACTION_BYTE);
  }
  comm();
}

void comm() {

  if (CAN.checkReceive()) {
    CAN.readMsgBuf(&uzunluk, tampon);
    switch (CAN.getCanId()) {
      case 0x1D0:
        if (uzunluk == 8) {
          sogutmaSicakligi = tampon[0] - 48;
        }
        break;

      case 0xAA:
        if (uzunluk == 8) {
          motorDeviri = ((tampon[5] << 8) + tampon[4]) / 4;
          yakitTuketimi = tampon[7];
          gazPedaliYuzdesi = (tampon[3] & 0x0F) * 39 / 100;
        }
        break;

      default:
        break;
    }
  }
}
 
Son düzenleme:
Geri
Üst