Community project

Diesel Engine CAN Telemetry

Photo of Diesel Engine CAN Telemetry
Generated with AI

Михаил БРОС

Published December 6, 2026

This project captures real-time telemetry from a diesel engine using an ESP32 microcontroller connected to multiple sensors via analog inputs and CAN bus. The system reads pressure, temperature, and RPM data from the engine and transmits it over CAN for logging or display on external monitoring equipment.

The guide provides a complete wiring diagram, parts list, and step-by-step assembly instructions for connecting the pressure sensor, thermocouples, thermistor, ADC module, CAN transceiver, and tachometer input to the ESP32. Firmware is included to handle sensor acquisition, CAN message formatting, and data storage on the microcontroller.

Wiring diagram

Wiring diagram for Diesel Engine CAN Telemetry
Loading diagram…

Gather all the parts

QtyComponent
1

Regulated bench supply 5 V

Regulated bench supply 5 V

1

ADS1115 16-Bit ADC Module

16-bit four-channel I2C analog-to-digital converter with programmable gain amplifier. Common ADS1115 breakouts expose MCU-facing SDA/SCL pins and four analog inputs for single-ended or differential measurements.

1

Bosch T-MAP 0 281 002 437

Bosch T-MAP 0 281 002 437

1

200 PSI 0.5–4.5 V pressure sensor

200 PSI 0.5–4.5 V pressure sensor

1

Two-pin NTC thermistor

Two-pin NTC thermistor

1

SN65HVD230 CAN module without onboard termination

SN65HVD230 CAN module without onboard termination

1

DS18B20

Digital temperature sensor using OneWire protocol

1

MAX6675 3.3 V module

MAX6675 3.3 V module

1

Ungrounded K-type thermocouple

Ungrounded K-type thermocouple

1

Resistor

10 kΩ

Through-hole resistor (current-limiting in series with an LED)

1

Resistor

18 kΩ

Through-hole resistor (current-limiting in series with an LED)

1

BAT54S dual Schottky clamp

BAT54S dual Schottky clamp

1

Resistor

10 kΩ

Through-hole resistor (current-limiting in series with an LED)

1

Resistor

18 kΩ

Through-hole resistor (current-limiting in series with an LED)

1

BAT54S dual Schottky clamp

BAT54S dual Schottky clamp

1

Ceramic Capacitor

100 nF

Through-hole ceramic capacitor bought by value, such as 22 pF, 10 nF or 100 nF (0.1 µF). It is non-polarised, so either lead can go to either net. Its most common job is decoupling: a 100 nF capacitor between an IC's supply pin and ground, placed as close to the chip as possible.

1

Ceramic Capacitor

100 nF

Through-hole ceramic capacitor bought by value, such as 22 pF, 10 nF or 100 nF (0.1 µF). It is non-polarised, so either lead can go to either net. Its most common job is decoupling: a 100 nF capacitor between an IC's supply pin and ground, placed as close to the chip as possible.

1

Ceramic Capacitor

100 nF

Through-hole ceramic capacitor bought by value, such as 22 pF, 10 nF or 100 nF (0.1 µF). It is non-polarised, so either lead can go to either net. Its most common job is decoupling: a 100 nF capacitor between an IC's supply pin and ground, placed as close to the chip as possible.

1

Ceramic Capacitor

100 nF

Through-hole ceramic capacitor bought by value, such as 22 pF, 10 nF or 100 nF (0.1 µF). It is non-polarised, so either lead can go to either net. Its most common job is decoupling: a 100 nF capacitor between an IC's supply pin and ground, placed as close to the chip as possible.

1

Resistor

2.2 kΩ

Through-hole resistor (current-limiting in series with an LED)

1

Resistor

2.2 kΩ

Through-hole resistor (current-limiting in series with an LED)

1

Resistor

4.7 kΩ

Through-hole resistor (current-limiting in series with an LED)

1

Resistor

4.7 kΩ

Through-hole resistor (current-limiting in series with an LED)

1

Resistor

4.7 kΩ

Through-hole resistor (current-limiting in series with an LED)

1

Resistor

120 Ω

Through-hole resistor (current-limiting in series with an LED)

1

Resistor

47 kΩ

Through-hole resistor (current-limiting in series with an LED)

1

Resistor

10 kΩ

Through-hole resistor (current-limiting in series with an LED)

1

3.3 V bench pulse generator

Open drain or 0–3.3 V output, 4 pulses per revolution

Assemble it in 3 steps

1. Подключите стендовое питание

Соедините стабилизированные 5 В с контактом 5V XIAO и датчиками давления. Соедините земли. Не подключайте внешний источник одновременно с USB. Бортсеть 12 В не подключать.

2. Соберите аналоговые входы

ADS1115 питается от 3V3, ADDR на землю. На каждом входе давления 10 кОм со стороны датчика и 18 кОм на землю. У BAT54S вывод 1 на землю, 2 на 3V3 и 3 на вход АЦП. Bosch: 1 — GND, 2 — IAT, 3 — 5V, 4 — OUT. Сверяйте номера на корпусе, не по цветам.

3. Подключите цифровые датчики и CAN

Питайте модули и DS18B20 от 3V3. На таховход подавайте только 0–3,3 В или открытый сток с общей землёй. Соедините CANH с CANH и CANL с CANL второго активного узла. На каждом конце линии должен быть ровно один резистор 120 Ом.

Review all connections

1. Connections between "ps" and "ESP32"

FunctionpsESP32
powerPLUS5V
groundMINUSGND

2. Connections between "adc" and "ESP32"

FunctionadcESP32
powerVDD3V3
groundGNDGND
i2cSDAGPIO 2
i2cSCLGPIO 18
groundADDRGND

3. Connections between "map" and "ESP32"

FunctionmapESP32
groundGNDGND
analogIAT → ADS1115 16-Bit ADC Module AIN3EXT
powerVCC5V

4. Connections between "oil" and "ESP32"

FunctionoilESP32
powerVCC5V
groundGNDGND

5. Connections between "cool" and "ESP32"

FunctioncoolESP32
analogSIG → ADS1115 16-Bit ADC Module AIN2EXT
groundGNDGND

6. Connections between "can" and "ESP32"

FunctioncanESP32
digitalTXDGPIO 22
digitalRXDGPIO 23
powerVCC3V3
groundGNDGND
dataCANH → Peer CANHEXT
dataCANL → Peer CANLEXT
groundGND → Peer CAN groundEXT

7. Connections between "air" and "ESP32"

FunctionairESP32
powerVCC3V3
groundGNDGND
dataDATAGPIO 16

8. Connections between "egt" and "ESP32"

FunctionegtESP32
powerVCC3V3
groundGNDGND
spiSCKGPIO 17
spiSOGPIO 19
spiCSGPIO 20

9. Connections between "probe" and "ESP32"

FunctionprobeESP32
analogPLUS → MAX6675 3.3 V module TPLUSEXT
analogMINUS → MAX6675 3.3 V module TMINUSEXT

10. Connections between "upper0" and "ESP32"

Functionupper0ESP32
digitalP1 → Bosch T-MAP 0 281 002 437 OUTEXT
digitalP2 → ADS1115 16-Bit ADC Module AIN0EXT

11. Connections between "lower0" and "ESP32"

Functionlower0ESP32
digitalP1 → ADS1115 16-Bit ADC Module AIN0EXT
groundP2GND

12. Connections between "clamp0" and "ESP32"

Functionclamp0ESP32
ground1GND
power23V3
analog3 → ADS1115 16-Bit ADC Module AIN0EXT

13. Connections between "upper1" and "ESP32"

Functionupper1ESP32
digitalP1 → 200 PSI 0.5–4.5 V pressure sensor OUTEXT
digitalP2 → ADS1115 16-Bit ADC Module AIN1EXT

14. Connections between "lower1" and "ESP32"

Functionlower1ESP32
digitalP1 → ADS1115 16-Bit ADC Module AIN1EXT
groundP2GND

15. Connections between "clamp1" and "ESP32"

Functionclamp1ESP32
ground1GND
power23V3
analog3 → ADS1115 16-Bit ADC Module AIN1EXT

16. Connections between "filter0" and "ESP32"

Functionfilter0ESP32
digital1 → ADS1115 16-Bit ADC Module AIN0EXT
ground2GND

17. Connections between "filter1" and "ESP32"

Functionfilter1ESP32
digital1 → ADS1115 16-Bit ADC Module AIN1EXT
ground2GND

18. Connections between "filter2" and "ESP32"

Functionfilter2ESP32
digital1 → ADS1115 16-Bit ADC Module AIN2EXT
ground2GND

19. Connections between "filter3" and "ESP32"

Functionfilter3ESP32
digital1 → ADS1115 16-Bit ADC Module AIN3EXT
ground2GND

20. Connections between "pull0" and "ESP32"

Functionpull0ESP32
powerP13V3
digitalP2 → ADS1115 16-Bit ADC Module AIN2EXT

21. Connections between "pull1" and "ESP32"

Functionpull1ESP32
powerP13V3
digitalP2 → ADS1115 16-Bit ADC Module AIN3EXT

22. Connections between "pull2" and "ESP32"

Functionpull2ESP32
powerP13V3
digitalP2 → ADS1115 16-Bit ADC Module SDAEXT

23. Connections between "pull3" and "ESP32"

Functionpull3ESP32
powerP13V3
digitalP2 → ADS1115 16-Bit ADC Module SCLEXT

24. Connections between "pull4" and "ESP32"

Functionpull4ESP32
powerP13V3
digitalP2 → DS18B20 DATAEXT

25. Connections between "term" and "ESP32"

FunctiontermESP32
digitalP1 → SN65HVD230 CAN module without onboard termination CANHEXT
digitalP2 → SN65HVD230 CAN module without onboard termination CANLEXT

26. Connections between "sopull" and "ESP32"

FunctionsopullESP32
digitalP1 → MAX6675 3.3 V module SOEXT
powerP23V3

27. Connections between "cspull" and "ESP32"

FunctioncspullESP32
digitalP1 → MAX6675 3.3 V module CSEXT
powerP23V3

28. Connections between "tach" and "ESP32"

FunctiontachESP32
digitalOUTGPIO 21
groundGNDGND

Deploy the firmware

#include <Arduino.h>
#include <Wire.h>
#include <Preferences.h>
#include <driver/twai.h>
#include <esp_task_wdt.h>
#include <math.h>

constexpr int TACH=21, CLOCK=17, SO=19, CS=20;
constexpr uint8_t ADC=0x48;
class BenchOneWire {
  static constexpr int pin=16;
  portMUX_TYPE mux=portMUX_INITIALIZER_UNLOCKED;
  void low(){digitalWrite(pin,LOW);pinMode(pin,OUTPUT_OPEN_DRAIN);}
  void release(){pinMode(pin,INPUT);}
public:
  bool reset(){low();delayMicroseconds(480);portENTER_CRITICAL(&mux);release();delayMicroseconds(70);bool present=!digitalRead(pin);portEXIT_CRITICAL(&mux);delayMicroseconds(410);return present && digitalRead(pin);}
  void write(uint8_t v){for(int i=0;i<8;i++,v>>=1){bool bit=v&1;portENTER_CRITICAL(&mux);low();delayMicroseconds(bit?6:60);release();portEXIT_CRITICAL(&mux);delayMicroseconds(bit?64:10);}}
  uint8_t read(){uint8_t v=0;for(int i=0;i<8;i++){portENTER_CRITICAL(&mux);low();delayMicroseconds(2);release();delayMicroseconds(8);v|=digitalRead(pin)<<i;portEXIT_CRITICAL(&mux);delayMicroseconds(55);}return v;}
  void skip(){write(0xCC);}
  static uint8_t crc8(const uint8_t *p,size_t n){uint8_t c=0;while(n--){c^=*p++;for(int i=0;i<8;i++)c=(c>>1)^((c&1)?0x8C:0);}return c;}
};
BenchOneWire ow;
Preferences nvs;
bool storage, watchdog, canReady;
volatile uint32_t pulses;
portMUX_TYPE tachLock=portMUX_INITIALIZER_UNLOCKED;
void IRAM_ATTR tachEdge(){portENTER_CRITICAL_ISR(&tachLock); ++pulses; portEXIT_CRITICAL_ISR(&tachLock);}
float volts[4]={NAN,NAN,NAN,NAN}, outside=NAN, zero=NAN, zeroSum=0;
float oilTrim=0;
uint8_t zeroCount=0, channel=0, alive=0;
uint32_t adcStart, adcTry, egtTime, owTime, fastTime, slowTime, bootTime;
bool adcBusy, converting, tachSeen;
int16_t egt=-1;

bool regRead(uint8_t reg,uint16_t &out){
  Wire.beginTransmission(ADC); Wire.write(reg);
  if(Wire.endTransmission(false)!=0 || Wire.requestFrom(ADC,uint8_t(2))!=2) return false;
  out=uint16_t(Wire.read())<<8; out|=Wire.read(); return true;
}
void pollAdc(uint32_t now){
  if(adcBusy){
    if(now-adcStart<9) return;
    uint16_t status, raw;
    bool ready=regRead(1,status);
    if(ready && !(status&0x8000) && now-adcStart<25) return;
    volts[channel]=(ready && (status&0x8000) && regRead(0,raw)) ? int16_t(raw)*0.000125f : NAN;
    if(channel==0 && isnan(zero)){
      float v=volts[0]*28/18;
      if(v>=0.38f && v<=4.68f){zeroSum+=v;if(++zeroCount==16) zero=zeroSum/16;}
    }
    channel=(channel+1)%4; adcBusy=false;
  }
  if(now-adcTry<10) return;
  adcTry=now;
  uint16_t config=0xC383 | (uint16_t(channel)<<12); // single-ended, ±4.096 V, 128 SPS, single shot
  Wire.beginTransmission(ADC); Wire.write(1); Wire.write(config>>8); Wire.write(config&255);
  adcStart=now; adcBusy=Wire.endTransmission()==0;
  if(!adcBusy){volts[channel]=NAN;channel=(channel+1)%4;}
}
void pollOutside(uint32_t now){
  if(now-owTime<(converting?750u:250u)) return;
  owTime=now;
  if(!ow.reset()){outside=NAN;converting=false;return;}
  ow.skip(); // exactly one externally powered DS18B20
  if(!converting){ow.write(0x44);converting=true;return;}
  ow.write(0xBE); uint8_t b[9]; for(auto &v:b)v=ow.read(); converting=false;
  float t=int16_t((uint16_t(b[1])<<8)|b[0])/16.0f;
  outside=(BenchOneWire::crc8(b,8)==b[8] && t>=-55 && t<=125 && b[5]==0xFF)?t:NAN;
}
void pollEgt(uint32_t now){
  if(now-egtTime<250) return;
  egtTime=now; uint16_t word=0; uint32_t start=micros(); bool timeout=false;
  digitalWrite(CS,LOW); delayMicroseconds(2);
  for(int i=0;i<16;i++){
    if(micros()-start>250){timeout=true;break;}
    word=(word<<1)|digitalRead(SO); digitalWrite(CLOCK,HIGH); delayMicroseconds(1);
    digitalWrite(CLOCK,LOW); delayMicroseconds(1);
  }
  digitalWrite(CS,HIGH);
  egt=(timeout || micros()-start>250 || (word&0x8006))?-1:((word>>3)&4095)/4;
}
float ntc(float v,float r25,float beta){
  if(!(v>0.02f && v<3.27f))return NAN;
  return 1/(1/298.15f+logf((2200*v/(3.3f-v))/r25)/beta)-273.15f;
}
void put16(uint8_t *p,uint16_t v){p[0]=v;p[1]=v>>8;}
int16_t temp10(float v){return isnan(v)?INT16_MIN:lroundf(v*10);}
void sendFrame(uint32_t id,const uint8_t *data){
  if(!canReady)return;
  twai_message_t m={};m.identifier=id;m.data_length_code=8;memcpy(m.data,data,8);twai_transmit(&m,0);
}
void pollCan(){
  if(!canReady)return;
  twai_status_info_t s;
  if(twai_get_status_info(&s)==ESP_OK){
    if(s.state==TWAI_STATE_BUS_OFF)twai_initiate_recovery();
    else if(s.state==TWAI_STATE_STOPPED)twai_start();
  }
  twai_message_t m;
  for(int i=0;i<4 && twai_receive(&m,0)==ESP_OK;i++){
    if(m.extd||m.rtr||m.identifier!=0x201)continue;
    if(m.data_length_code==1 && m.data[0]==3)ESP.restart();
    if(!storage)continue;
    if(m.data_length_code==1 && m.data[0]==1){
      float v=volts[0]*28/18;
      if(v>=0.38f && v<=4.68f && nvs.putFloat("boostZero",v)==4)zero=v;
    }
    if(m.data_length_code==3 && m.data[0]==2){
      int16_t trim=uint16_t(m.data[1])|(uint16_t(m.data[2])<<8);
      if(trim>=-200 && trim<=200 && nvs.putShort("oilTrim",trim)==2)oilTrim=trim;
    }
  }
}
void setup(){
  Serial.begin(115200);
  esp_task_wdt_config_t cfg={};cfg.timeout_ms=2000;cfg.idle_core_mask=1;cfg.trigger_panic=true;
  esp_err_t s=esp_task_wdt_init(&cfg);if(s==ESP_ERR_INVALID_STATE)s=esp_task_wdt_reconfigure(&cfg);
  watchdog=s==ESP_OK && (esp_task_wdt_status(nullptr)==ESP_OK || esp_task_wdt_add(nullptr)==ESP_OK);
  if(!watchdog) Serial.println("Watchdog setup failed");
  storage=nvs.begin("telemetry",false);if(storage)oilTrim=nvs.getShort("oilTrim",0);
  Wire.begin(2,18,100000);Wire.setTimeOut(3);
  pinMode(TACH,INPUT_PULLUP);attachInterrupt(TACH,tachEdge,FALLING);
  digitalWrite(CS,HIGH);pinMode(CS,OUTPUT);pinMode(CLOCK,OUTPUT);digitalWrite(CLOCK,LOW);pinMode(SO,INPUT);
  twai_general_config_t g=TWAI_GENERAL_CONFIG_DEFAULT(GPIO_NUM_22,GPIO_NUM_23,TWAI_MODE_NORMAL);
  twai_timing_config_t t=TWAI_TIMING_CONFIG_250KBITS();twai_filter_config_t f=TWAI_FILTER_CONFIG_ACCEPT_ALL();
  canReady=twai_driver_install(&g,&t,&f)==ESP_OK && twai_start()==ESP_OK;
  if(!canReady)Serial.println("TWAI setup failed");
  bootTime=fastTime=slowTime=egtTime=millis();
}
void loop(){
  uint32_t now=millis();pollAdc(now);pollOutside(now);pollEgt(now);pollCan();
  float bv=volts[0]*28/18, ov=volts[1]*28/18;
  bool boostOK=bv>=0.38f && bv<=4.68f, oilOK=ov>=0.45f && ov<=4.55f;
  if(isnan(zero)&&now-bootTime>=2500 && storage){float saved=nvs.getFloat("boostZero",NAN);if(saved>=0.38f && saved<=4.68f)zero=saved;}
  float coolant=ntc(volts[2],10000,3950),iat=ntc(volts[3],2500,3950); // provisional bench curves
  uint32_t elapsed=now-fastTime;
  static uint16_t rpm=0;
  if(elapsed>=100){
    portENTER_CRITICAL(&tachLock);uint32_t p=pulses;pulses=0;portEXIT_CRITICAL(&tachLock);
    tachSeen|=p!=0;uint64_t speed=uint64_t(p)*15000/elapsed;rpm=speed>65535?65535:speed;
  }
  bool demo=now-bootTime>=2000 && !tachSeen && !boostOK && !oilOK && isnan(coolant) && isnan(iat) && isnan(outside) && egt<0;
  if(elapsed>=100){
    fastTime=now;bool boostValid=boostOK&&!isnan(zero);
    uint8_t err=(!boostValid?1:0)|(egt<0?2:0)|(isnan(coolant)?4:0)|((!oilOK||isnan(iat)||isnan(outside))?8:0);
    uint8_t b[8]={};put16(b,demo?1500:rpm);put16(b+2,demo?35:boostValid?lroundf((bv-zero)*280/4.25f):INT16_MIN);
    put16(b+4,demo?350:egt);b[6]=demo?82:isnan(coolant)?128:uint8_t(int8_t(constrain(lroundf(coolant),-127L,127L)));
    b[7]=(alive++&15)<<4|err;sendFrame(0x101,b);
  }
  if(now-slowTime>=500){
    slowTime=now;uint8_t b[8]={};put16(b,demo?320:temp10(iat));put16(b+2,demo?210:temp10(outside));
    put16(b+6,demo?310:oilOK?constrain(lroundf((ov-0.5f)*1379/4+oilTrim),0L,1379L):65535);sendFrame(0x102,b);
  }
  if(watchdog)esp_task_wdt_reset();
  delay(1);
}

Remix this project

Make it yours in one click

Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.

Open in Schematik