Go Down

Topic: Controlling automotive NOx sensor with CAN bus (Read 108 times) previous topic - next topic

HarMoe

I am working on a project that aims to proof that a wood gasifier powered car has lower emissions than a gasoline powered one. We have a small group of gasifier enthusiasts here in Finland, who are trying to make it legal to convert newer cars to run on wood. We have built a gasifier system into a newer car that is in Euro III emission gategory, and now we need to measure its emissions to proof that it acually runs cleaner than before. We did emission tests on a professional testing laboratory and found out that the NOx-emissions were higher than allowed. Now we are trying to find the cause of this, and find a way to lower the NOx-emissions.

Because the laboratory testing is expensive and difficult, I am trying to build a handheld device that can be used to measure NOx-emissions with automotive NOx-sensor that connects to arduino nano with CAN bus. For Can bus interface I am using MCP2515 module. I am able to send and receive data between two arduinos using the CAN bus connection. However I am not able to communicate or get any data out from the NOx-sensor.

If I read the datasheet correctly, by sending byte {0, 0, 0, 0, 0, 0, 0, 0} into the sensor address 65247, it would go into standby/preheat mode. And with byte {0, 0, 0, 0, 0, 1, 0, 0} it would heat up and start sending data back. However the sensor doesn't seem to react to any sent messages. I haven't used CAN bus messaging before, and I think the problem is probably just a wrong addressing or a wrong data byte.
I really hope someone could help me get this sensor to work, it would have a big impact to our little hobby.


Library I am using for MCP2515:
MCP2515 Library V1.5


Code: [Select]
#include <mcp_can.h>
#include <SPI.h>

long unsigned int rxId;
unsigned char len = 0;
unsigned char rxBuf[8];

MCP_CAN CAN0(10);                               // Set CS to pin 10

unsigned char msg1[8] = {0, 0, 0, 0, 0, 0, 0, 0};  //Devpoint not reached
unsigned char msg2[8] = {0, 0, 0, 0, 0, 1, 0, 0};  //Devpoint reached heat-up started


void setup()
{
  Serial.begin(115200);
  CAN0.begin(CAN_250KBPS,MCP_16MHz);            // init can bus : baudrate = 250k
  pinMode(2, INPUT);                            // Setting pin 2 for /INT input
  delay(100);
  
}

void loop()
{
    if(!digitalRead(2))                          // If pin 2 is low, read receive buffer
    {
      CAN0.readMsgBuf(&len, rxBuf);              // Read data: len = data length, buf = data byte(s)
      rxId = CAN0.getCanId();                    // Get message ID
      Serial.print("ID: ");
      Serial.print(rxId, HEX);
      Serial.print("  Data: ");
      for(int i = 0; i<len; i++)                 // Print each byte of the data
      {
        if(rxBuf[i] < 0x10)                      // If data byte is less than 0x10, add a leading zero
        {
          Serial.print("0");
        }
        Serial.print(rxBuf[i], HEX);
        Serial.print(" ");
      }
      Serial.println();
    }

   // send data:  id = 65247, standrad flame, data len = 8, stmp: data buf
  if(millis() < 1000)
    CAN0.sendMsgBuf(65247, 8, 8, msg1);
  if(millis() > 1000)
    CAN0.sendMsgBuf(65247, 8, 8, msg2);
    
  delay(100);                       // send data per 100ms
}

Go Up