0% found this document useful (0 votes)
64 views4 pages

Can Communication: Data Acquisition & Electronics

This document describes using CAN communication to simplify wiring in a formula racing car. Sensors are connected to a microcontroller which transmits the data as CAN messages. An Arduino code samples sensors like temperature probes and analog inputs. A Lua script in the data logger receives the CAN messages, reconstructs the original sensor values, and logs the readings to channels.

Uploaded by

Karthi keyan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views4 pages

Can Communication: Data Acquisition & Electronics

This document describes using CAN communication to simplify wiring in a formula racing car. Sensors are connected to a microcontroller which transmits the data as CAN messages. An Arduino code samples sensors like temperature probes and analog inputs. A Lua script in the data logger receives the CAN messages, reconstructs the original sensor values, and logs the readings to channels.

Uploaded by

Karthi keyan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

RAFTAR FORMULA RACING

CAN COMMUNICATION
DATA ACQUISITION & ELECTRONICS

AIM:
● To make the sensor harness in the car less complicated and easy to troubleshoot.

ADVANTAGES:
● This would reduce the number of microcontrollers used in the car by a great amount as
multiple sensors can be connected to a single microcontroller which can then be used to
transmit all the data as a CAN message.
● Makes the mounting and dismounting of the data logger much easier as only a lan cabe
goes inside it for data transfer.

COMPONENTS NEEDED:
● Microcontroller
● MCP 2515 module
● LAN Cable

SETUP:

● The SPI pins of the MCP module are connected to the corresponding pins of the arduino
i.e., MISO – pin 11
MOSI – pin 12
SCK – pin 13
● CAN high and CAN low of the MCP module are connected to the corresponding CAN
high and CAN low of one of the data logger's two CAN channels.

ARDUINO CODE:

The following code makes the microcontroller extract data from the sensors and convert it to
CAN messages with the help of the MCP module.

//START OF CODE

#include <SPI.h>
#include <mcp_can.h>
#include<Wire.h>
#include<Adafruit_MLX90614.h>

// INITIALIZING THE MLX90614 SENSORS


Adafruit_MLX90614 mlx = Adafruit_MLX90614(0x5A);
Adafruit_MLX90614 mlx1 = Adafruit_MLX90614(0x5B);
Adafruit_MLX90614 mlx2 = Adafruit_MLX90614(0x5C);
Adafruit_MLX90614 mlx3 = Adafruit_MLX90614(0x5D);
const int spiCSPin = 10;
float b1,b2,b3,b4;

MCP_CAN CAN(spiCSPin);

void setup()
{
Serial.begin(115200);

while (CAN_OK != CAN.begin(CAN_1000KBPS))


{
Serial.println("CAN BUS init Failed");
delay(100);
}
Serial.println("CAN BUS Shield Init OK!");
mlx.begin();
pinMode( A3 , OUTPUT); //Steering rack potentiometer
pinMode( A6, OUTPUT); //Linpot
pinMode( A7, OUTPUT); //Brake Pressure Sensor
}

void loop()
{
b1 = mlx.readObjectTempC();
b2 = mlx1.readObjectTempC();
b3 = mlx2.readObjectTempC();
b4 = mlx3.readObjectTempC();

//Separating the decimal values and the integer value to transfer


data byte by byte in CAN
int temp1 = b1 * 100;
int t1 = temp1/100;
int t1_d = temp1 - (t1*100);

int temp2 = b2 * 100;


int t2 = temp2/100;
int t2_d = temp2 - (t2*100);

int temp3 = b3 * 100;


int t3 = temp3/100;
int t3_d = temp3 - (t3*100);

int temp4 = b4 * 100;


int t4 = temp4/100;
int t4_d = temp4 - (t4*100);

float str = analogRead(A3);


int s = str * 100;
int s_i = s/100;
int s_d = s - (s_i * 100);

float lin = analogRead(A6);


int l = lin * 100;
int l_i = l/100;
int l_d = l - (l_i * 100);

float bps = analogRead(A7);


int b = bps * 100;
int b_i = b/100;
int b_d = b - (b_i * 100);

unsigned char p1[8] = {t1, t1_d,t2, t2_d,t3, t3_d,t4, t4_d};


Serial.println("In loop");
CAN.sendMsgBuf(0x43, 0, 8, p1); // Sending tire temperature data
delay(2);
unsigned char p2[6] = {s_i, s_d, l_i, l_d, b_i, b_d};
Serial.println("In loop");
CAN.sendMsgBuf(0x44, 0, 8, p2); // Sending Linpot, Steering and
brake pressure data
delay(3);

//END OF CODE

LUA SCRIPTING:

The following script in the data logger reveives the CAN messages and does necessary
operations on the data received to finally give out readable and usable data that can be logged.

--START OF CODE
startLogging()
count = 0
setTickRate(100)
function onTick()

-- Receive a CAN message on CAN1


local id, ext, data = rxCAN(0)

if (id == nil) then


println('No CAN message received!')
else if (id == 0x43)
ch_id1 = addChannel( "TTS1", 10, 2)
ch_id2 = addChannel( "TTS2", 10, 2)
ch_id3 = addChannel( "TTS3", 10, 2)
ch_id4 = addChannel( "TTS4", 10, 2)

–-combining the decimal values with the integer values to get final
sensor data

temp1 = data[1] + ( 0.01*data[2] )


temp2 = data[3] + ( 0.01*data[4] )
temp3 = data[5] + ( 0.01*data[6] )
temp4 = data[7] + ( 0.01*data[8] )
setChannel(ch_id1 , temp1)
setChannel(ch_id2 , temp2)
setChannel(ch_id3 , temp3)
setChannel(ch_id4 , temp4)
println('Temperatures are: ' ..temp1 ..', ' ..temp2 ..', ' ..temp3
..', ' ..temp4)
else if (id == 0x44)
ch_id4 = addChannel( "STR", 10, 2)
ch_id5 = addChannel( "LIN", 10, 2)
ch_id6 = addChannel( "BPS", 10, 2)
str = data[1] + ( 0.01*data[2] )
lin = data[3] + ( 0.01*data[4] )
bps = data[5] + ( 0.01*data[6] )
setChannel(ch_id4 , str)
setChannel(ch_id5 , lin)
setChannel(ch_id6 , bps)
println('Readings are STR: ' ..str ..', LIN: ' ..lin ..',
BPS: ' ..bps )
else
println('Got CAN message ID: ' ..id ..' data: ' ..data[1])
println('Got CAN message ID: ' ..id ..' data: ' ..data[2])
end
end

--END OF CODE

You might also like