Stuck with Sketch Temps+Pressures+uLCD = Headache

Hi All,
I have been slugging away at some Arduino coding for the last couple of days/week and I have to admit I am a bit lost.This would the most advanced sketch I have drawn up so far and I am open for any help or suggestions as I am self teaching my way though at present.One aspect that I would like to include is that the Arduino is only updating the current gauge not all 8 at once, how can I code for example-
if Form1 is active on uLCD update cool_gauge1If Form2 is active on uLCD update cool_gauge2 etc...

Outline

  • Arduino Uno
  • 4D Arduino Shield V2
  • uLCD-28PTU
  • 4 x Temps via Quad MAX31855 5V
  • 4 x Pressures running a 150 PSI transducer 1.2Mpa
  • Sensor Shield 5.0, 4D

Below is my attempted Sketch V1.1

#include <genieArduino.h>
#include <MAX31855.h>

   // define pins for Quad MAX31855 thermocouple breakout board 5V  
#define MISO 0
#define SCK  1
#define CS0  2
#define CS1  3
#define CS2  4
#define CS3  5

   // define input and output pins
int sensor1Pin = A0; // Press 1 in
int sensor2Pin = A1; // Press 2 in
int sensor3Pin = A2; // Press 3 in
int sensor4Pin = A3; // Press 4 in

   // for averaging Pressure readings
const int numReadings1 = 5;
int readings3[numReadings3];
int index3 = 0;
int total3 = 0;
int SensorRaw1 = 0;

const int numReadings2 = 5;
int readings4[numReadings4];
int index4 = 0;
int total4 = 0;
int SensorRaw2 = 0;

const int numReadings3 = 5;
int readings4[numReadings4];
int index4 = 0;
int total4 = 0;
int SensorRaw3 = 0;

const int numReadings4 = 5;
int readings4[numReadings4];
int index4 = 0;
int total4 = 0;
int SensorRaw4 = 0;

   // Create MAX31855 thermocouple objects
MAX31855 temp1(MISO, CS0, SCK);
MAX31855 temp2(MISO, CS1, SCK);
MAX31855 temp3(MISO, CS2, SCK);
MAX31855 temp4(MISO, CS3, SCK);


void setup()
{
 Serial.begin(200000);
 genie.Begin(Serial);
 genie.AttachEventHandler(myGenieEventHandler);
 sensors.begin();
 sensors.setWaitForConversion(false);

 // Reset Display
 digitalWrite(4, 1);
 delay(100);
 digitalWrite(4, 0);
 delay (3500);
 genie.WriteContrast(15);

}

void loop ()
{     // call readings from the MAX31855
 Temp1 = temp1.readThermocouple(CELSIUS);
 Temp2 = temp2.readThermocouple(CELSIUS);
 Temp3 = temp3.readThermocouple(CELSIUS);
 Temp4 = temp4.readThermocouple(CELSIUS);
}
 static long waitPeriod = millis();

 if (millis() >= waitPeriod)
 {   
     // call readings from 150 PSI Transducers 1.2Mpa 1508
     
     // Read Press 1
     total3 = total3 - readings3[index3];
     (void) analogRead(sensor1Pin);
     (void) analogRead(sensor1Pin);
     readings3[index3] = analogRead(sensor1Pin);
     total3 = total3 + readings3[index3];
     index3 = index3 + 1;
     if (index3 >= numReadings3)
       index3 = 0;
     SensorRaw1 = total3 / numReadings3;

     // Read Press 2
     total4 = total4 - readings4[index4];
     (void) analogRead(sensor2Pin);
     (void) analogRead(sensor2Pin);
     readings4[index4] = analogRead(sensor2Pin);
     total4 = total4 + readings4[index4];
     index4 = index4 + 1;
     if (index4 >= numReadings4)
       index4 = 0;
     SensorRaw2 = total4 / numReadings4;
     
     // Read Press 3
     total4 = total4 - readings4[index4];
     (void) analogRead(sensor2Pin);
     (void) analogRead(sensor2Pin);
     readings4[index4] = analogRead(sensor2Pin);
     total4 = total4 + readings4[index4];
     index4 = index4 + 1;
     if (index4 >= numReadings4)
       index4 = 0;
     SensorRaw2 = total4 / numReadings4;
     
     // Read Press 4
     total4 = total4 - readings4[index4];
     (void) analogRead(sensor2Pin);
     (void) analogRead(sensor2Pin);
     readings4[index4] = analogRead(sensor2Pin);
     total4 = total4 + readings4[index4];
     index4 = index4 + 1;
     if (index4 >= numReadings4)
       index4 = 0;
     SensorRaw2 = total4 / numReadings4;
    
     {
 genie.DoEvents();        //Genie events are received and queued here.

     // Map readings for use in gauges
     Press1      = map(SensorRaw1, 93, 930, 0, 150);
     Press2      = map(SensorRaw2, 95, 850, 0, 150);
     Press3      = map(SensorRaw3, 97, 850, 0, 150);
     Press4      = map(SensorRaw4, 99, 850, 0, 150);
     temp1Gauge  = map(Temp1, 50, 1800, 0 , 100);
     temp2Gauge  = map(Temp2, 50, 1800, 0 , 100);
     temp3Gauge  = map(Temp3, 50, 1800, 0 , 100);
     temp4Gauge  = map(Temp4, 50, 1800, 0 , 100);

     // Update gauges

     genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 0, Temp1);    // Coolgauge0 (Coolgauge0-Temp1)   
     genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 1, Press1);   // Coolgauge1 (Coolgauge1_Press1)
     genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 2, Temp2);    // Coolgauge2 (Coolgauge2_Temp2)
     genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 3, Press2);   // Coolgauge3 (Coolgauge3_Press2)
     genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 4, Temp3);    // Coolgauge4 (Coolgauge4_Temp3)  
     genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 5, Press3);   // Coolgauge5 (Coolgauge5_Press3)
     genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 6, Temp4);    // Coolgauge6 (Coolgauge6_Temp4)
     genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 7, Press4);   // Coolgauge7 (Coolgauge7_Press4)

   // Write to Gauges
   else if (flag == 0) {

     genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 0, 0);
     genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 1, 0);
     genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 2, 0);
     genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 3, 0);
     genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 4, 0);
     genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 5, 0);
     genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 6, 0);
     genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 7, 0);
   }
   
   waitPeriod = millis() + 20;
 }
}
[code]

Hi,

You need to post your code in code tags to make it easier to read.
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Have you tried each part of your sketch separately to see if they work as you want them.

Tom..... :slight_smile:

I have tried to compile the sketch...
Do I have the structure correct?
I am a beginner and tips and hint are welcome

w1r3d:
I have tried to compile the sketch...

...and what happened?

You have couple of syntax errors and typos in your code.
It would be easier if you correct those first that we can check the code logic.
Posting code is nice , but if you are using non-core API's it is little time consuming bypassing such code to even check syntax.