(Uni) DT021/TU821 Electric Car Week 10, Onwards

Electric Car Tractive System


TUDAUTHOR NAME: Jerico M.                        STUDENT NUMBER: C15580367                COURSE: DT021A/TU821      


Week 8, 9 & 10 Objectives

  1. Data logging sensor measurements on an SD card via the Arduino
  2. Implement watchdog timer with Arduino: To prevent infinite loops in system
  3. Implement an efficient method for a signal-check code between two Arduinos that can be used for the LVCSS Arduino to constantly check if Lowry’s Arduino is still running:
    • Inter-Integrated Circuit (I2C) Signal Check
    • Serial Peripheral Interface (SPI) Signal Check
    • Digital Pin Signal Check
  4. Implement CAN bus for the following sensors:
    • BMS Temperature Sensors
    • Speed Sensors (Lowry’s code)
    • Motor/Drive Current
    • Motor/Drive Voltage
    • Motor/Drive Power

EV Tractive System & LVCSS Progress

asgsagdsagdsagadsgdsagsadgdsagasgsadgdsagsadgasadgasgdsagsadgadsgasgas

SD Card Data Logging

The first part needed for this task is to know the components needed to log data on to an SD card and the required libraries to implement this on the Arduino. Due to the small selection of components at hand before the closure of the campus, the components I obtained for this task were:

Components

x1 Arduino Uno Rev3

x1 Arduino Ethernet Shield 2

x1 SD Card

The reason the Ethernet Shield 2 is used for this task is because it has an onboard SD card, which can simply be utilized as an SD card reader for the Arduino, carrying out the same tasks any any other SD card module, but for future references, since the Ethernet Shield 2 fits directly on the Arduino Uno, if another microcontroller model is used in this project, an external SD card module can be used instead. The next part of this task is to identify the libraries needed, the general method with using the SD card with Arduino is using the libraries, note that all of these libraries are preset libraries then come with the Arduino software when installed, so there is no need for additional libraries to be downloaded.

Libraries

SPI.h

SD.h

SPI is simply the communication protocol that is used between the microcontroller and the SD card, which on both the Uno and Nano, takes place on digital pins 11, 12 and 13 with digital pin 10 as the default Slave Select (SS) pin for SPI, see Arduino SD Library for more information. The Ethernet Shield 2 can simply be mounted on the Uno as shown in Figure 1, with the SD card installed on the shield. By having the shield mounted on the Uno, no additional connections are needed since all pins of the shield and Uno are connected, thus all that is needed is a program to log the data on the SD card.

Week 10 SD Card Connections.PNG

Figure 1: Ethernet Shield and SD Card with Arduino Uno

The next step was to implement the program to log multiple data on the SD card, using the libraries mentioned above. Using the DS18B20 one-wire temperature sensors specified in the Week 7, 8 & 9 Blog, the following variables measured for the EV were programmed to be logged on to the SD card. Due to the lack of components at hand, only live data from the temperature sensors were implemented, while the rest of the variables were dummied using simple increment code, then each variable was logged on the SD card using the program below:

EV Variables

BMS Temperature (Multiple sensors) – Live data

BMS Voltage – Dummy data

BMS Current – Dummy data

Motor Voltage (Front left) – Dummy data

Motor Current (Front left) – Dummy data

Motor Voltage (Front right) – Dummy data

Motor Current (Front right) – Dummy data

Total Tractive System Power – Dummy data

From the program below, the most important thing to initially note is the use of the SD library to create the file then log the data. The first step is with a chosen file name using the functions “File myFile;” followed by the file name you want “char filename[] = “EV_Data.CSV”;”. Although the default SS pin for SPI is pin 10, another digital pin can be used for SS for SPI communication with the SD card i.e. Digital pin 4 using the function”const int chipSelect = 4;”. In the setup section, the SD library can then be set up using the function “!SD.begin(chipSelect)”.

After this, an important feature that I implemented was to ensure that no other versions of the file named EV_Data.CSV is on the SD card, to make sure that the SD card is empty and that a completely new file is at the start of each driving session, thus the functions “SD.exists(“EV_Data.CSV”)” and “SD.remove(“EV_Data.CSV”)” was used to carry this out. To start logging data on the file the function “SD.open(“EV_Data.CSV”, FILE_WRITE);” can be used to open up the file and the function “myFile.close();” is use to stop and close the file. The last most important thing to note with the SD library is that the function “myFile.print();” is simply used to log any variable into the SD card, where the variable name is placed within the brackets of the function, where “myFile.print(“,”);” can also be used to make the Arduino print on the next column of the spreadsheet.

/********************************************************************
– EV SD Card Data Logging Programme (4x Temperature and Dummy Variables)
(Version Includes: All variables)
– Version 1.1
– Modified by Jerico M.
– Last Edited on 05/04/22
********************************************************************/
/*
* Four DS18B20 sensors are used to measure temperature
* The wiring for each sensor are connected as followed:
– Pin 1 (GND) of DS18B20 sensors are connected to common ground
– Pin 2 (DQ) of DS18B20 sensors can be connected to any digital pin of Arduino
– Pin 3 (Vdd) of DS18B20 sensors can be connected to the 5V pin of the Arduino
– 4.7k pull-up resistor connected between DQ and Vdd of DS18B20 sensors
* Arduino Uno mounted with an Ethernet Shield 2 for the SD card (SPI):
– Pin D4 of Arduino as CS of SD card
– Pin D11 of Arduino for SPI SI pin
– Pin D12 of Arduino for SPI SO pin
– Pin D13 of Arduino for SPI SCK pin
– GND pin of Arduino to common ground
********************************************************************/
/***** Import the needed libraries for the sensors and SD card *****/
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <SD.h>

/* Create Excel file called “EV_Data.CSV” on the SD Card */
File myFile;
char filename[] = “EV_Data.CSV”;

/* Data wire from all sensors are plugged into pin 2 of the Arduino */
#define ONE_WIRE_BUS_PIN 2

/* Set up a oneWire instance to communicate with any OneWire device */
OneWire oneWire(ONE_WIRE_BUS_PIN);

/*** Allow Dallas Temperature Library to utilize oneWire Library ***/
DallasTemperature sensors(&oneWire);

/*** Chip Select Signal Pin is pin 4 ***/
const int chipSelect = 4;

/*** Variables stored into the SD card ***/
float tempC, Temp01, Temp02, Temp03, Temp04; // BMS Individual Sensor Variables
float BMSTempAVG, BMSVoltage, BMSCurrent; // BMS Temp., BMS Current and BMS Voltage Variables
float MotorVoltageFL, MotorCurrentFL; // Front Left Current Transducer Current, Voltage
float MotorVoltageFR, MotorCurrentFR; // Front Right Current Transducer Current, Voltage
float TSPower; // Tractive System Total Power
float Speed; //Average Speed of the EV (From Sensors)

/* Giving each sensor a name by assigning the serial numbers obtained
from previous code (e.g. Sensor Name = { Serial Number of Sensor}; */
DeviceAddress Sensor01 = { 0x28, 0x50, 0x87, 0x3B, 0x0A, 0x00, 0x00, 0x1C };
DeviceAddress Sensor02 = { 0x28, 0x6E, 0x75, 0x3B, 0x0A, 0x00, 0x00, 0xC7 };
DeviceAddress Sensor03 = { 0x28, 0x22, 0x70, 0x3B, 0x0A, 0x00, 0x00, 0x1D };
DeviceAddress Sensor04 = { 0x28, 0xF7, 0x87, 0x3B, 0x0A, 0x00, 0x00, 0xC5 };
/* void setup allows to run once */
void setup()
{
/* Start serial port to display results on screen */
Serial.begin(9600);
Serial.println(“Starting up EV Data Logging System”);
Serial.println(“————————————-“);

/* Always make pin 10 an output even when not using */
//pinMode(10, OUTPUT);

/* SD card configuration using SPI CS on pin 4 */
if (!SD.begin(chipSelect))
{
delay (1000);
return;
}
/* Ensure that the SD card is empty */
if (SD.exists(“EV_Data.CSV”))
{
SD.remove(“EV_Data.CSV”);
}

/* Setup the file by filling out the first row of the Excel spreadsheet and filling out column titles accordingly – Starts from left to right */
myFile = SD.open(“EV_Data.CSV”, FILE_WRITE);
myFile.println(“Sensor01(degC),Sensor02(degC),Sensor03(degC),Sensor04(degC),BMS Temperature(degC),BMS Voltage(V),BMS Current(A),FL Motor Voltage(V),FL Motor Current(A),FR Motor Voltage(V),FR Motor Current(A),TS Power(kW)”);
myFile.close();

/* DS18B20 sensor configuration and library startup */
// 9 bit resolution, 93.75 ms conversion time
// 10 bit resolution, 187.5 ms conversion time
// 11 bit resolution, 375 ms conversion time
// 12 bit resolution, 750 ms conversion time
sensors.begin();
sensors.setResolution(Sensor01, 10);
sensors.setResolution(Sensor02, 10);
sensors.setResolution(Sensor03, 10);
sensors.setResolution(Sensor04, 10);
}
/* End setup */
/* void loop allows to run continuously */
void loop()
{
/********************* BMS Temperature Data Log *********************/
sensors.requestTemperatures(); // Call for sensor measurements
myFile = SD.open(“EV_Data.CSV”, FILE_WRITE);
delay(500); // 0.5 second delay
/* Sensor01 temperature data logging */
Temp01 = sensors.getTempC(Sensor01);
myFile.print(Temp01);
myFile.print(“,”);
/* Sensor02 temperature data logging */
Temp02 = sensors.getTempC(Sensor02);
myFile.print(Temp02);
myFile.print(“,”);
/* Sensor03 temperature data logging */
Temp03 = sensors.getTempC(Sensor03);
myFile.print(Temp03);
myFile.print(“,”);
/* Sensor04 temperature data logging */
Temp04 = sensors.getTempC(Sensor04);
myFile.print(Temp04);
myFile.print(“,”);
/* BMS average temperature data logging */
BMSTempAVG = (Temp01 + Temp02 + Temp03 + Temp04)/4;
myFile.print(BMSTempAVG);
myFile.print(“,”);

/*********************** BMS Voltage Data Log ***********************/
/* BMS voltage dummy variable data logging */
BMSVoltage++; // BMS voltage dummy variable increment
delay (100); // 0.1 second delay
if (BMSVoltage>100) // If BMS voltage reaches max range of 100V, reset back to 0V
{
BMSVoltage = 0;
}
myFile.print(BMSVoltage);
myFile.print(“,”);

/*********************** BMS Current Data Log ***********************/
/* BMS current dummy variable data logging */
BMSCurrent++; // BMS current dummy variable increment
delay (100); // 0.1 second delay
if (BMSCurrent>650) // If BMS current reaches max range of 650A, reset back to 0A
{
BMSCurrent = 0;
}
myFile.print(BMSCurrent);
myFile.print(“,”);

/***************** Front Left Motor Voltage Data Log *****************/
MotorVoltageFL++; // Front left motor voltage dummy variable increment
delay (100); // 0.1 second delay
if (MotorVoltageFL>140) // If front left motor voltage reaches max range of 140V, reset back to 0V
{
MotorVoltageFL = 0;
}
myFile.print(MotorVoltageFL);
myFile.print(“,”);

/***************** Front Left Motor Current Data Log *****************/
MotorCurrentFL++; // Front left motor current dummy variable increment
delay (100); // 0.1 second delay
if (MotorCurrentFL>300) // If front left motor current reaches max range of 300A, reset back to 0A
{
MotorCurrentFL = 0;
}
myFile.print(MotorCurrentFL);
myFile.print(“,”);

/***************** Front Right Motor Voltage Data Log *****************/
MotorVoltageFR++; // Front right motor voltage dummy variable increment
delay (100); // 0.1 second delay
if (MotorVoltageFR>140) // If front right motor voltage reaches max range of 140V, reset back to 0V
{
MotorVoltageFR = 0;
}
myFile.print(MotorVoltageFR);
myFile.print(“,”);

/***************** Front Right Motor Current Data Log *****************/
MotorCurrentFR++; // Front right motor current dummy variable increment
delay (100); // 0.1 second delay
if (MotorCurrentFR>300) // If front right motor current reaches max range of 300A, reset back to 0A
{
MotorCurrentFR = 0;
}
myFile.print(MotorCurrentFR);
myFile.print(“,”);

/***************** Tractive System Power Data Log ******************/
TSPower++; // Tractive system power dummy variable increment
delay (100); // 0.1 second delay
if (MotorCurrentFR>80) // If tractive system power reaches max range of 80kW, reset back to 0kW
{
TSPower = 0;
}
myFile.print(TSPower);
myFile.print(“,”);

/********************* Average Speed Data Log *********************/
Speed++; // EV speed dummy variable increment
delay (100); // 0.1 second delay
if (Speed>600) // If speed reaches max range of 600RPM, reset back to 0RPM
{
Speed = 0;
}
myFile.print(Speed);
myFile.print(“,”);
myFile.println();
myFile.close(); // Close the file after all measurements have been logged
Serial.println(” Data Logged “); // Let user know that data has been logged
}
/* End main loop */
/* DS18B20 sensor configuration for sensor measurements */
void printTemperature(DeviceAddress deviceAddress)
{
/* If sensors read -127degC it means the wiring or code is wrong */
/* Print if there’s an error, otherwise allow sensors to read temperature */
tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00)
{
Serial.print(“Error getting temperature “);
}
else
{
Serial.print(tempC);
Serial.print(” (degC)”);
}
}
/*******************************************************************/

After successfully running the code, I let the Arduino run with the SD card for around 20 seconds before removing it. Using an SD card reader, I was able to check the SD card and was able to identify that an Excel file with the filename “EV_DATA.CSV” was successfully created as shown in Figure 2. This file was then checked and it successfully logged the data on to the SD card with results showing in Table 1 below. The first four columns show the individual temperature sensors where live measurements were logged on to the SD card, with an average BMS temperature calculation in the 5th column. The next 7 columns were then simply filled with dummy increments for the other variables, which can be filled out with real code to log live data from other sensors of the Arduino for the EV.

Week 10 SD Card File.PNG

Figure 2: SD Card File “EV_DATA.CSV” Created

Table 1: SD Card “EV_DATA.CSV” Data Logged

Week 10 SD Card Data Log Excel Results.PNG

For the rest of April and May the rest of the time is spent on focusing on finalizing the project, designs and thesis from dates 03/04/2020 to 25/05/2020.


Week 8, 9 & 10 Objectives Checklist

asgsagdsagdsagadsgdsagsadgdsagasgsadgdsagsadgasadgasgdsagsadgadsgasgasRed = Incomplete               Green = Complete

  1. Data logging sensor measurements on an SD card via the Arduino
  2. Implement watchdog timer with Arduino: To prevent infinite loops in within the Arduino program, can be applied to any Arduino in the EV 
  3. Implement an efficient method for a signal-check code between two Arduinos that can be used for the LVCSS Arduino to constantly check if Lowry’s Arduino is still running:
    • Inter-Integrated Circuit (I2C) Signal Check
    • Serial Peripheral Interface (SPI) Signal Check
    • Digital pin signal check
  4. Implement CAN bus for the following sensors:
    • BMS Temperature Sensors
    • Speed Sensors (Lowry’s code)
    • Motor/Drive Current
    • Motor/Drive Voltage
    • Motor/Drive Power

Leave a comment