Advertisement
ioannisIGI

Stirling_engine_tests

Jul 5th, 2022
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <UTFTGLUE.h>              //use GLUE class and constructor
  2. UTFTGLUE myGLCD(0, A2, A1, A3, A4, A0); //all dummy args
  3.  
  4. float rev; // Revolution Count
  5. float measureTime = 0;
  6. int ThermistorPin1 = 15;
  7. int ThermistorPin2 = 14;
  8. int Vo;
  9. float R1 = 10000;
  10. float logR2, R2, T1, T2, Tc1, Tf1, Tc2, Tf2;
  11. float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
  12. float rpm = 0;
  13.  
  14.  
  15. void setup() {
  16.   Serial.begin(115200);
  17.   pinMode(2, INPUT); // Interrupt 0
  18.   Serial.print("***TACHOMETER***");
  19.   delay(500);
  20.   // Setup the LCD
  21.   myGLCD.InitLCD(3);
  22.   myGLCD.clrScr();
  23.   myGLCD.setColor(255, 255, 255);
  24.   myGLCD.setBackColor(0, 0, 0);
  25.   print_lcd_startup();
  26.   attachInterrupt(2, addRevolution, FALLING);
  27. }
  28. void addRevolution() {
  29.   rev++;
  30. }
  31.  
  32. void loop() {
  33.   delay(1000);
  34.   //noInterrupts();
  35.   if (millis() - measureTime > 1000){
  36.     rpm = (rev / 12) * 60;
  37.     rev = 0;
  38.     measureTime = millis();
  39.   }
  40.   //rpm = rev * 7500 / (millis() - measureTime);
  41.   //rev = 0;
  42.   //measureTime = millis();
  43.   read_temp();
  44.   print_lcd();
  45.   Serial.println(rpm);
  46.   //interrupts();
  47. }
  48.  
  49. void read_temp() {
  50.   Vo = analogRead(ThermistorPin1);
  51.   R2 = R1 * (1023.0 / (float)Vo - 1.0);
  52.   logR2 = log(R2);
  53.   T1 = (1.0 / (c1 + c2 * logR2 + c3 * logR2 * logR2 * logR2));
  54.   Tc1 = T1 - 273.15;
  55.   Tf1 = (Tc1 * 9.0) / 5.0 + 32.0;
  56.   Vo = analogRead(ThermistorPin2);
  57.   R2 = R1 * (1023.0 / (float)Vo - 1.0);
  58.   logR2 = log(R2);
  59.   T2 = (1.0 / (c1 + c2 * logR2 + c3 * logR2 * logR2 * logR2));
  60.   Tc2 = T2 - 273.15;
  61.   Tf2 = (Tc2 * 9.0) / 5.0 + 32.0;
  62.  
  63.   Serial.print("Temperature: ");
  64.   Serial.print(Tf1);
  65.   Serial.print(" F; ");
  66.   Serial.print(Tc1);
  67.   Serial.println(" C");
  68. }
  69.  
  70. void print_lcd() {
  71.   myGLCD.setFont(BigFont);
  72.   if (Tc1 < 25) {
  73.     myGLCD.setColor(0, 255, 255);
  74.     myGLCD.print("      ", 30, 160);
  75.     myGLCD.printNumI(Tc1, 30, 160);
  76.     myGLCD.print("C", 90, 160);
  77.   } else if (Tc1 > 24 && Tc1 < 100) {
  78.     myGLCD.setColor(255, 255, 0);
  79.     myGLCD.print("      ", 30, 160);
  80.     myGLCD.printNumI(Tc1, 30, 160);
  81.     myGLCD.print("C", 90, 160);
  82.   } else if (Tc1 > 99) {
  83.     myGLCD.setColor(255, 0, 0);
  84.     myGLCD.print("      ", 30, 160);
  85.     myGLCD.printNumI(Tc1, 30, 160);
  86.     myGLCD.print("C", 90, 160);
  87.   }
  88.  
  89.   myGLCD.setColor(255, 255, 255);
  90.   myGLCD.print("        ", 210, 50);
  91.   myGLCD.printNumI(rpm, 210, 50);
  92.   myGLCD.print("        ", 220, 160);
  93.   myGLCD.printNumI(Tc2, 220, 160);
  94.   myGLCD.print("C", 280, 160);
  95. }
  96.  
  97. void print_lcd_startup() {
  98.   myGLCD.setFont(BigFont);
  99.   myGLCD.setColor(0, 128, 0);
  100.   myGLCD.print("Stirling Engine", 40, 0);
  101.   myGLCD.print("Experiments", 70, 20);
  102.   myGLCD.setColor(255, 255, 255);
  103.   myGLCD.print("RPM: ", 80, 50);
  104.   myGLCD.print("Temperatures", 60, 100);
  105.   myGLCD.print(" Engine     Ambient", 0, 130);
  106. }
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement