changing theremistor's without effecting reading ??

Hey Guys,

im using an arduino to update my dash on my bike, my old one had analogue signals straight to the dash but the new one has sensors going to the ECU then a data line to the dash, so i wanted to use an arduino to be the ECU in the middle, some other brilliant person has already mimicked this signal so i have an almost complete working dash except the temperature signal. i can get the dash going through the temperature range by connecting a pot and going through the range (the arduino see’s 20 degrees C = 2.89v and 140 degrees C = 200mV) but i was wondering if theres a way to use my original sender resistance ranges to make it work, i haven’t plotted my temp sender range curve yet but wanted to know if it could be done first or if i have to search for a thermistor with the correct curve?
i hope i’ve explained it well enough, i will include the code im using i had to modify Software serial to include 7800 Baud.

#include <SoftwareSerial.h>

#define RX 9
#define TX 10
#define ECU_SPEED 7800
#define BLINK_LED 13
#define BLINK_MS 500

#define GEAR_N_VAL 0 // - 4,95V
#define GEAR_1_VAL 450 // 369 - 1,79V
#define GEAR_2_VAL 570 // 462 - 2,25V
#define GEAR_3_VAL 700 // 615 - 3,00V
#define GEAR_4_VAL 790 // 746 - 3,65V
#define GEAR_5_VAL 952 // 888 - 4,36V
#define GEAR_6_VAL 999 // 952 - 4,69V

#define GEAR_N 0 // - 4,95V
#define GEAR_1 1 // 369 - 1,79V
#define GEAR_2 2 // 462 - 2,25V
#define GEAR_3 3 // 615 - 3,00V
#define GEAR_4 4 // 746 - 3,65V
#define GEAR_5 5 // 888 - 4,36V
#define GEAR_6 6 // 952 - 4,69V

uint8_t uiGear = GEAR_N; // gear variable

int sbytes[8]; // 7 bytes for serial data
int sensor = A1; // Motorcycle Thermistor
int Gearsen = A0;
int new_temp;
const int fuela = A2; // fuel low
const int fuelb = A3; // fuel empty

int FUELA = 0; // variable for reading the pushbutton status
int FUELB = 0; // variable for reading the pushbutton status

SoftwareSerial ecu(RX, TX);

void
clear_buf()
{
int j;
for (j = 0; j < 7; j++) {
sbytes[j] = 0;
}
}

void setup() {
Serial.begin(115200);
Serial.print(“Starting\n”);

pinMode(fuela, INPUT);
pinMode(fuelb, INPUT);

pinMode(6, OUTPUT);
pinMode(2, OUTPUT);

digitalWrite (6,HIGH);
digitalWrite (2,HIGH);

ecu.begin(ECU_SPEED);
clear_buf();
calc_csum();
}

/*

  • calculates the checksum of sbytes
    */
    void
    calc_csum() {
    byte check_sum = 0;

// Calculate check sum byte
for (int x = 0; x <= 6; x++) {
check_sum = check_sum + sbytes;
}

sbytes[7] = 256 - check_sum;
}

// printf to the HW serial port
void
serial_printf(char *fmt, … ) {
char tmp[128]; // resulting string limited to 128 chars
va_list args;
va_start (args, fmt );
vsnprintf(tmp, 128, fmt, args);
va_end (args);
Serial.print(tmp);
}

// Read temperature from thermistor
unsigned int
change_temp()
{
unsigned int temp = 0;

temp = sbytes[0] << 2;
temp += (sbytes[1] & 0xc0) >> 6;
temp = analogRead(sensor);
sbytes[0] = temp >> 2;
sbytes[1] = temp << 6;

unsigned int gear= 0;

gear = sbytes[5];
int uiADC = analogRead (Gearsen); // get the analog voltage from pin 0

if (uiADC < GEAR_1_VAL) // 1st gear
{
uiGear = GEAR_1;
}
else if (uiADC < GEAR_2_VAL) // 2nd gear
{
uiGear = GEAR_2;
}
else if (uiADC < GEAR_3_VAL) // 3rd gear
{
uiGear = GEAR_3;
}
else if (uiADC < GEAR_4_VAL) // 4th gear
{
uiGear = GEAR_4;
}
else if (uiADC < GEAR_5_VAL) // 5th gear
{
uiGear = GEAR_5;
}
else if (uiADC < GEAR_6_VAL) // 6th gear
{
uiGear = GEAR_6;
}
else // Neutral
{
uiGear = GEAR_N;
}

gear = uiGear;

sbytes[5] = gear >> 0;
sbytes[5] = gear << 5;

serial_printf(“temp = %04u\n”, temp);
serial_printf(“gear = %04u\n”, gear);
calc_csum();
new_temp = temp;
return temp;
return gear;
}

void
print_temp(unsigned int temp)
{
int i = 0;
byte val;
byte led_digits[4] = {
0xc0, 0xc2, 0xc4, 0xc6 };
}

void loop()
{
int x;
unsigned int temp;
unsigned int gear;
// Write data bytes to serial
for (x = 0; x <= 6; x++) {
ecu.write(sbytes);
delay(10);
}
ecu.write(sbytes[7]);

// Intermessage delay
delay(60);

temp = change_temp();
print_temp(temp);
serial_printf("%02x %02x %02x %02x %02x %02x %02x %02x\n",
sbytes[0], sbytes[1], sbytes[2], sbytes[3],
sbytes[4], sbytes[5], sbytes[6], sbytes[7]);

FUELA =digitalRead(fuela);
FUELB =digitalRead(fuelb);

if (FUELA == LOW) // we are on reserve (4.5 ltrs)
{
digitalWrite(6, LOW); // flash the fuel light

if (FUELB == LOW) // oops, we need to get fuel now (2.5 ltrs)
{
digitalWrite(2, LOW); // switch fuel light solid ON
}
else // enough fuel
{
digitalWrite(2, HIGH); // switch fuel light OFF
}
}
else // enough fuel
{
digitalWrite(6, HIGH); // stop fuel light flashing
}
}

quiky12: i was wondering if theres a way to use my original sender resistance ranges to make it work

This function will do what you want. It maps between two piecewise curves. You could use it to map the new analogRead() value to the old value. http://playground.arduino.cc/Main/MultiMap

Use the pot to determine what analogRead() values represent what readings on your new dashboard. Use a thermometer and heat source to see what those same temperatures read as on your new thermistor. Then map the two ranges.

I will map the existing sender over the weekend and have a play around, thanks for the link