Project - Arduino DataLogger

Icehax

Member
Country flag
Hi everybody, i'm currently working on a simple datalogger for my bike (to adjust fuelling and ignition) and thought i'd just share this in case someone else wants to try in the future.

I'm interested in logging 3 data points at the moment (more can be added later if need be): RPM, AFR and TPS. Currently i plan to get the first through the ignition coil low voltage signal, the second through a AEM uego x series afr gauge and the third by connecting it directly to the arduino's analog pins. i've already drafted some code (untested yet) and i plan to put everything together in the next couple of weeks. i will post here updates and pictures of the process. Hope you like it!
 

Icehax

Member
Country flag
first let me list some of the material i am using:

1x Arduino UNO Board
1x Variable voltage buck converter (to lower to 5v and stabilize the ignition coil signal)
1x Voltage divider (you can build one, it's very easy maths, to lower the analog TPS signal voltage so we dont destroy the arduino)

then we have various tools and other stuff like wires, connectors, soldering iron etc etc
 

Icehax

Member
Country flag
this is the first version of the software that will be running on the arduino, it's untested and i am posting this just so you get an idea of what the code might look like, i will definitely fix a lot of stuff in the coming weeks. the TPS readings will also need calibration but that's for another time.


C:
#include <SPI.h>
#include <SD.h>
#include <stdio.h>

#define TPS_S1 1
#define TPS_S2 2
#define AFR 0
#define IGN 12
#define TPS_MIN 0
#define TPS_MAX 1023


File myFile;
int last_clk = 0;
int rpm = 0;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("Initializing SD card...");

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    while (1);
  }
  Serial.println("initialization done.");
  Serial.println("opening file stream.");

  // open the file.
  myFile = SD.open("log.csv", FILE_WRITE);

  // if the file opened okay
  if (myFile) {
    Serial.println("file stream open.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening log.csv");
  }
  Serial.println("Setting up pins...");
  pinMode(TPS_S1, INPUT);
  pinMode(TPS_S2, INPUT);
  pinMode(AFR, INPUT);
  pinMode(IGN, INPUT);
 
  attachInterrupt(digitalPinToInterrupt(IGN), isr, RISING);
}

String generateCSV (int ms, int rpm, int afr, int tps) {
  return String(ms) + ", " + String(rpm) + ", " + String(afr)+ ", " + String(tps);
}

void isr(){
  int cur_clk = millis();
  float rpm = ((2.0f)/(float)(last_clk - cur_clk))*60000.0f; //2 revolutions per spark, rpm = 60000*rpms
  myFile.println(generateCSV(cur_clk, rpm, analogRead(AFR), (analogRead(TPS_S1) + analogRead(TPS_S2))/2)); //avg the two TPS sensors!

  last_clk = cur_clk;
}

void loop() {
  //everything is done through interrupts.
}
 

Icehax

Member
Country flag
Interesting project! What's the update on this?
I scrapped the idea of using an arduino as it was gonna be too clumsy with all the spliced cables and such... I am now using a raspberry pi to interface directly with my powertronic ECU. I wrote a program that communicates with powertronic ecus via USB and saves the data i need in csv format. I'm slowly improving it to get all the data i need, for now it can save TPS and RPM values. You can take a look here for the code, it runs on both windows and linux.
 
Top