Go Down

### Topic: GAS TURBINE ECU help please! CLEVER CODERS ENTER! (Read 8804 times)previous topic - next topic

#### Stimps

#15
##### Oct 26, 2011, 07:36 pm

I have so far a MEGA and a prototype on top (for my sensor and power supply components, etc)
and a TFTLCD shield on top of that.

Ive come across a hurdle...Ive got my LCD code stripped down to just displaying a box, and ive got the AD595 hooked up to a free pin.
Now, I can load the lcd code no worries, and then load the thermocouple code instead ok
but when i merge the two i get compliation errors, namely, "printFloat" was not declared in this scope
code structure stresses me lol

This thermocouple reading code was courtesy of an experimenter from Instructables.

// Define which analog input pin we have connected to the temperature sensor
#define TEMP_SENSOR_PIN 0

// if you tie the Arduino's vRef to the 3.3 volt supply, change this to 3.3
#define ANALOG_VOTLAGE_REFERENCE 5

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

void loop() {
// prints the currrent temperature with 1 place after the decimal point
printFloat(getTemperature(), 1);
// print a carriage return
Serial.println();
// rest 100 milliseconds
delay(100);
}

float CtoF(float c) {
// optionally convert from Celsius to Farenheit if you are into that sorta thing
return c * 9.0 / 5.0 + 32.0;
}

// divide by 1023, the maximum possible input value, that scales the input between 0 - 1
// then multiply by the reference voltage, which scales 0-1 to 0-vREF (default is 5V)
// lastly, multiply by 100 to scale it to 10s of millivolts or degrees
return inputValue / 1023.0 * ANALOG_VOTLAGE_REFERENCE * 100.0;
}
float getTemperature() {
}

// ---- This last function, printFloat isn't necessary to understand unless you want to
// ---- feel free to ignore it for now, and treat it as a built-in utility,
// ---- it prints out floating point point values

// printFloat prints out the float 'value' rounded to 'places' places after the decimal point
void printFloat(float value, int places) {
// this is used to cast digits
int digit;
float tens = 0.1;
int tenscount = 0;
int i;
float tempfloat = value;

// make sure we round properly. this could use pow from <math.h>, but doesn't seem worth the import
// if this rounding step isn't here, the value 54.321 prints as 54.3209

// calculate rounding term d: 0.5/pow(10,places)
float d = 0.5;
if (value < 0)
d *= -1.0;
// divide by ten for each decimal place
for (i = 0; i < places; i++)
d/= 10.0;
// this small addition, combined with truncation will round our values properly
tempfloat += d;

// first get value tens to be the large power of ten less than value
// tenscount isn't necessary but it would be useful if you wanted to know after this how many chars the number will take

if (value < 0)
tempfloat *= -1.0;
while ((tens * 10.0) <= tempfloat) {
tens *= 10.0;
tenscount += 1;
}

// write out the negative if needed
if (value < 0)
Serial.print('-');

if (tenscount == 0)
Serial.print(0, DEC);

for (i=0; i< tenscount; i++) {
digit = (int) (tempfloat/tens);
Serial.print(digit, DEC);
tempfloat = tempfloat - ((float)digit * tens);
tens /= 10.0;
}

// if no places after decimal, stop now and return
if (places <= 0)
return;

// otherwise, write the point and continue on
Serial.print('.');

// now write out each decimal place by shifting digits one by one into the ones place and writing the truncated value
for (i = 0; i < places; i++) {
tempfloat *= 10.0;
digit = (int) tempfloat;
Serial.print(digit,DEC);
// once written, subtract off that digit
tempfloat = tempfloat - (float) digit;
}

#### AWOL

#16
##### Oct 26, 2011, 07:52 pmLast Edit: Oct 26, 2011, 07:54 pm by AWOL Reason: 1
No, I can't see printFloat either.
Please use a code box using the # icon when you post code
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### Stimps

#17
##### Oct 26, 2011, 07:58 pm
so how come it works on its own???
strange....

#### Stimps

#18
##### Oct 26, 2011, 08:09 pm
Ignore that, found someone elses very simple quick and working code, put it in, worked straight away.

WOOT!!!
its dumping huge data to the screen thats ok tho:)

#### AWOL

#19
##### Oct 26, 2011, 08:46 pmLast Edit: Oct 26, 2011, 08:49 pm by AWOL Reason: 1
If you go back to your post with the code in it, you can highlight the code, then click on the # icon on the toolbar. This will post it in a code box, and avoid spurious formatting.
Also, before posting code, it is best to auto format you code using ctrl-t in the IDE.

It is good that you have found a partial solution to your problem, it would be great if you shared it.
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### Stimps

#20
##### Oct 27, 2011, 03:25 pm
oops yes sorry, here it is.
Its still got a bit of left over stuff in it about graphics, just a few boxes and stuff on the screen, and a bit of touchscreen info i will get back to later.
Next is the RPM code, to get an accurate reading of the speed of the turbine.
Can anyone show me how to make the serial print only send data to the serial every say, 500ms?
I have also soldered in the second AD595 chip and entered it into the code to give me two temperatures.

cheers and thanks for your help guys:) Its very neat:)

Code: [Select]
`//gas turbine ecu code start#include "TFTLCD.h"#include "TouchScreen.h"#if not defined USE_ADAFRUIT_SHIELD_PINOUT #error "For use with the shield, make sure to #define USE_ADAFRUIT_SHIELD_PINOUT in the TFTLCD.h library file"#endif// These are the pins for the shield!#define YP A1  // must be an analog pin, use "An" notation!#define XM A2  // must be an analog pin, use "An" notation!#define YM 7   // can be a digital pin#define XP 6   // can be a digital pin#define TEMP_SENSOR_PIN 4#define TEMP_SENSOR_PIN 5#define ANALOG_VOTLAGE_REFERENCE 5#define TS_MINX 150#define TS_MINY 120#define TS_MAXX 920#define TS_MAXY 940// For better pressure precision, we need to know the resistance// between X+ and X- Use any multimeter to read it// For the one we're using, its 300 ohms across the X plateTouchScreen ts = TouchScreen(XP, YP, XM, YM, 100);#define LCD_CS A3#define LCD_CD A2#define LCD_WR A1#define LCD_RD A0 // Color definitions#define BLACK           0x0000#define BLUE            0x001F#define RED             0xF800#define GREEN           0x07E0#define CYAN            0x07FF#define MAGENTA         0xF81F#define YELLOW          0xFFE0 #define WHITE           0xFFFFTFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, 0);#define BOXSIZE 200#define smallbox 30int oldcolor, currentcolor;void setup(void) {  Serial.begin(9600);  Serial.println("GAS TURBINE ECU...hopefully one day...");    tft.reset();  tft.initDisplay();   tft.fillScreen(BLACK);  //fills screen with black    tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED); //draws small red box filled in  tft.drawRect(23, 56, BOXSIZE, BOXSIZE, WHITE); //draws white rectangle  tft.drawRect(45, 33, smallbox, smallbox, WHITE); //draws small box  currentcolor = RED;  pinMode(13, OUTPUT);}#define MINPRESSURE 5#define MAXPRESSURE 500void loop(){  digitalWrite(13, HIGH);  Point p = ts.getPoint();  digitalWrite(13, LOW);  int raw1 = analogRead(4);  int TurbineInletTemp = ( 5.0 * raw1 * 100.0) / 1024.0;  Serial.print("TurbineInletTemp degrees C: ");  Serial.println(TurbineInletTemp);  int raw2 = analogRead(5);  int TurbineOutletTemp = ( 5.0 * raw2 * 100.0) / 1024.0;  Serial.print("TurbineOutletTemp degrees C: ");  Serial.println(TurbineOutletTemp);  // if you're sharing pins, you'll need to fix the directions of the touchscreen pins!  //pinMode(XP, OUTPUT);  pinMode(XM, OUTPUT);  pinMode(YP, OUTPUT);  //pinMode(YM, OUTPUT);  // we have some minimum pressure we consider 'valid'  // pressure of 0 means no pressing!  if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {    Serial.print("X = ");     Serial.print(p.x); //prints out press position X    delay(10);    Serial.print("\tY = ");     Serial.print(p.y);        delay(100);    Serial.print("\tPressure = ");     Serial.println(p.z);    //prints out screen press pressure    // turn from 0->1023 to tft.width    p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0);    p.y = map(p.y, TS_MINY, TS_MAXY, tft.height(), 0);         }    }`

#### Stimps

#21
##### Oct 31, 2011, 04:58 am
Can someone point me to the method for sending the temperature values to the display, and showing them in landscape? Currently it shows it in portrait. The example code shows how to rotate it, but i only want it to rotate once to get landscape.

#### Stimps

#22
##### Nov 07, 2011, 01:13 am
Ok I will sort out the display stuff later.
Currently I have nice pair of AD595's on the board, talking to MEga, display Temp to Serial. in ice, it reads 0. (NICE!)
in my armpit, it reads 37deg (very nice!)
in a blue gas flame it goes up to 999 and stops? I couldnt work this out, then i realised, I needed to take up the multiplier to 3 from 2.

I have a voltage divider set up so it gives 5 volts into the analog pin input when the AD595 gives out 15 volts. (1000deg C) using a quality trimpot.
when i get the sensor red hot, the chip output is 10.95 volts (1095deg C)

This post started out as a question, answered my own problem...now i guess im just posting for others to see what works.
Now it reads up to 1100degs C . Acurately!!
Note. I didnt then put it back into my hairy armpit to check 37deg c.

Code: [Select]
`//gas turbine ecu code start#include "TFTLCD.h"#include "TouchScreen.h"#if not defined USE_ADAFRUIT_SHIELD_PINOUT #error "For use with the shield, make sure to #define USE_ADAFRUIT_SHIELD_PINOUT in the TFTLCD.h library file"#endif// These are the pins for the shield!#define YP A1  // must be an analog pin, use "An" notation!#define XM A2  // must be an analog pin, use "An" notation!#define YM 7   // can be a digital pin#define XP 6   // can be a digital pin#define TEMP_SENSOR_PIN 4#define TEMP_SENSOR_PIN 5#define ANALOG_VOTLAGE_REFERENCE 5#define TS_MINX 150#define TS_MINY 120#define TS_MAXX 920#define TS_MAXY 940// For better pressure precision, we need to know the resistance// between X+ and X- Use any multimeter to read it// For the one we're using, its 300 ohms across the X plateTouchScreen ts = TouchScreen(XP, YP, XM, YM, 100);#define LCD_CS A3#define LCD_CD A2#define LCD_WR A1#define LCD_RD A0 // Color definitions#define BLACK           0x0000#define BLUE            0x001F#define RED             0xF800#define GREEN           0x07E0#define CYAN            0x07FF#define MAGENTA         0xF81F#define YELLOW          0xFFE0 #define WHITE           0xFFFFTFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, 0);#define BOXSIZE 40#define smallbox 30int oldcolor, currentcolor;int waittime = 0;void setup(void) {  Serial.begin(9600);  Serial.println("GAS TURBINE ECU...hopefully one day...");    tft.reset();  tft.initDisplay();   tft.fillScreen(BLACK);  //fills screen with black    tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED); //draws small red box filled in  tft.drawRect(23, 56, BOXSIZE, BOXSIZE, WHITE); //draws white rectangle  tft.drawRect(45,33, smallbox, smallbox, WHITE); //draws small box  tft.drawRect(140,128, smallbox, smallbox, RED);  currentcolor = RED;  pinMode(13, OUTPUT);}#define MINPRESSURE 5#define MAXPRESSURE 500void loop(){  digitalWrite(13, HIGH);  Point p = ts.getPoint();  digitalWrite(13, LOW);  waittime = waittime++;  if (waittime > 1000)  {    int raw1 = analogRead(4);    int TurbineInletTemp = 3 * ( 5.0 * raw1 * 100.0) / 1024.0;  //3 is temp multiplier so we can read up to 15 volts (with 5 volt max input pin)    Serial.print("TurbineInletTemp degrees C: ");    Serial.println(TurbineInletTemp);   int raw2 = analogRead(5);   int TurbineOutletTemp = 3 * ( 5.0 * raw2 * 100.0) / 1024.0;   Serial.print("TurbineOutletTemp degrees C: ");   Serial.println(TurbineOutletTemp);    waittime = 0;      }    // if you're sharing pins, you'll need to fix the directions of the touchscreen pins!  //pinMode(XP, OUTPUT);  pinMode(XM, OUTPUT);  pinMode(YP, OUTPUT);  //pinMode(YM, OUTPUT);  // we have some minimum pressure we consider 'valid'  // pressure of 0 means no pressing!  if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {    Serial.print("X = ");     Serial.print(p.x); //prints out press position X    delay(100);    Serial.print("\tY = ");     Serial.print(p.y);        delay(100);    Serial.print("\tPressure = ");     Serial.println(p.z);    //prints out screen press pressure    // turn from 0->1023 to tft.width    p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0);    p.y = map(p.y, TS_MINY, TS_MAXY, tft.height(), 0);         }    }`

#### electricflux91

#23
##### Feb 06, 2013, 04:48 am
Hi im working on a similar project for fun. Could you possibly list the sensors you used and what lcd display you chose. Also if you put in any emergency control type features such as warnings or emergency shut of based on a sense of high temperatures, high RPM or loss of pressure in to your code how did you do it. The difficulty im having is with the ignition. Did you use a glow plug or spark ignition? how did you set that up?  It would be great if you could post your final code for programming the turbo engine. Thanks!

#24