Hi, I am building a multiplexed thermocouple for a reprap. I am using an uno to prototype it.
I have the following set up:
2 x MC14051 mux
1 x AD595 amplifier
On a separate circuit I have a MCP23017 connected to an LCD (the problem is not here).
At the moment I have the thermocouple inputs split between two 4051 mux chips. I can switch between channels by specifying the pin addresses in the code. However, when I try to switch channels during the main loop. The readings on the first channel change from a real temperature to something like "0.49" which indicates to me a loss of input into the AD595. However, the second channel is displaying a real temperature to my LCD reads "0.49" first line, "25.00" second line.
Here is the code below:
#include <Wire.h>
#include <AD595.h>
#include <LiquidTWI2.h>
// Connect via i2c, default address (0)
LiquidTWI2 lcd (0);
AD595 thermocouple;
void setup () {
//set up thermocouple
//set up digital pins
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
//set up serial feed
Serial.begin(9600);
// Set the kind of integrated use
// (Remove the quotes from the one used)
//lcd.setMCPType(LTI_TYPE_MCP23008);
lcd.setMCPType (LTI_TYPE_MCP23017);
// Sets the type of LCD (columns, rows)
lcd.begin (16, 2);
// Write a message on the LCD.
//lcd.print ("Palaeopi.org.uk");
//lcd.print (".gb");
delay(500);
}
void loop () {
//set up channel 0 on both 4051s
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
delay(5000);
thermocouple.init(3);
delay(500);
lcd.setCursor (0,0);
float temp1 = thermocouple.measure(TEMPC);
Serial.print("T1: ");
Serial.println(temp1);
lcd.print(temp1);
//set up channel 0 on both 4051s
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
delay(5000);
thermocouple.init(3);
delay(500);
lcd.setCursor (0,1);
float temp2 = thermocouple.measure(TEMPC);
Serial.print("T2: ");
Serial.println(temp2);
lcd.print(temp2);
}
Any clue what is going on here? Why if I deactivate the second channel by commenting out does the first channel begin reading real temperatures again?
Here is the fritzing layout: