Changing Pins to seeed accommodate relay shield

Hi all this is my first time posting. I'm trying to get a arduino to control a heating element based off of inputs given by a thermocouple which will hopefully also be displayed on a little lcd screen. Currently I have a code from the adafruit_max31855.h breakout board which displays the temp like I would like however some of the pins (4, 5, 6, 7) are used to control the the relays on the seeed relay shield and the program uses (3,4,5) for the thermocouple and (7, 8, 9, 10, 11, 12) is used for the LCD display. How would I go about moving the thermocouple pins to (1, 2, 3) and move the lcd pin to (8, 9, 10, 11, 12, 13) . I've tried to simply shift the numbers to the range as described above however the temp isn't changing on the lcd display and it isn't reading the int. temp as it was before adding the shield. Allow me to say thanks in advance and I really appreciate any help in this matter.

Code as given by adafruit libary for max31855

#include <SPI.h>
#include "Adafruit_MAX31855.h"
#include <LiquidCrystal.h>

int thermoCLK = 3;
int thermoCS = 4;
int thermoDO = 5;

// Initialize the Thermocouple
Adafruit_MAX31855 thermocouple(thermoCLK, thermoCS, thermoDO);
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

  
void setup() {
  Serial.begin(9600);
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  
  lcd.print("MAX31855 test");
  // wait for MAX chip to stabilize
  delay(500);
}

void loop() {
  // basic readout test, just print the current temp
   lcd.setCursor(0, 0);
   lcd.print("Int. Temp = ");
   lcd.println(thermocouple.readInternal());
   lcd.print("  "); 
     
   double c = thermocouple.readCelsius();
   lcd.setCursor(0, 1);
   if (isnan(c)) 
   {
     lcd.print("T/C Problem");
   } 
   else 
   {
     lcd.print("C = "); 
     lcd.print(c);
     lcd.print("  "); 
   }
 
   delay(1000);
}

code with shifted pin location to accommodate relay board.

#include <SPI.h>
#include "Adafruit_MAX31855.h"
#include <LiquidCrystal.h>

int thermoCLK = 0;
int thermoCS = 1;
int thermoDO = 2;

// Initialize the Thermocouple
Adafruit_MAX31855 thermocouple(thermoCLK, thermoCS, thermoDO);
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);

I don't fully understand it but certain pins are reserved for special use. you are using spi.h which means that it needs access to some pins depending on the board. Also pins 0 and 1 are used by the usb connection.

you need to research which pins are being used and set them to the most important first. There no need to keep the lcd on sequenced pins (might even be able to use analog pins for some of the lcd pins)

with out knowing your board, lcd, shield, etc its all a guess. Google your board for a pin map

You earned yourself a karma point. :smiley:
You're the only first-time poster I've seen in a long time who actually posted his code between code tags. :slight_smile:

I thought that the thermocouple would need the standard SPI pins, but according to the Adafruit web page on that device:

SPI data output requires any 3 digital I/O pins.

So it looks like you can move it wherever you want. You might need to do some more reading on this to double-check requirements.
Reference: MAX31855 breakout board

Then if you can move the LCD from pin7 you should be in business with the relay board. (In theory, anyway.)

Thanks for the reply and the karma points ( I can use all the karma I can get). I read somewhere that it was possible to turn the analog pins into digital pins. Now I must admit that I'm not entirely sure of the difference but if that is the case and I can convert one of the analog pins to digital I can just move the 7 pin from the lcd like you were saying. So hopefully I can turn something up on the web. Thanks again for pointing me in the right direction.

quick edit:

apparently it's as easy as initating pin 14, which is analog pin 0

ZBay:
Thanks for the reply and the karma points ( I can use all the karma I can get). I read somewhere that it was possible to turn the analog pins into digital pins. Now I must admit that I'm not entirely sure of the difference but if that is the case and I can convert one of the analog pins to digital I can just move the 7 pin from the lcd like you were saying. So hopefully I can turn something up on the web. Thanks again for pointing me in the right direction.

quick edit:

apparently it's as easy as initating pin 14, which is analog pin 0

http://www.instructables.com/id/How-to-add-6-extra-pins-to-your-Arduino-with-no-ex/

Yep. You just use pinMode() to set it as digital input or output, as you would a normal digital IO pin.
ie "pinMode(A0, INPUT);" or "pinMode(A0,OUTPUT);"

Ok so I was able to move the pins around by modifying the code as shown below. What I would like to do is design a conditional statement which cycles a relay (pines 4,5,6,7) on and off depending the returned input from thermocouple, not exactly sure how this is done in c++. which line in the code is returning the temp to be displayed on the lcd? This is just the first step into implementing a more advanced PID controller which will hopefully do a better job and regulating the temperature. once again any help is greatly appreciated, I have some programming experience but my C++ working knowledge is still hovering around the 'hello world' stage.

Psudo - Code:

if temp(input) <= 31.0 degrees C
      cycle pin 7 on
else: 
      cycle pin 7 off

Current Code:

#include <SPI.h>
#include "Adafruit_MAX31855.h"
#include <LiquidCrystal.h>

int thermoCLK = (14);
int thermoCS  = (15);
int thermoDO  = (16);

// Initialize the Thermocouple
Adafruit_MAX31855 thermocouple(thermoCLK, thermoCS, thermoDO);
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(17, 8, 9, 10, 11, 12);

  
void setup() {
  Serial.begin(9600);
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  
  lcd.print("MAX31855 test");
  // wait for MAX chip to stabilize
  delay(500);
}

void loop() {
  // basic readout test, just print the current temp
   lcd.setCursor(0, 0);
   lcd.print("Int. Temp = ");
   lcd.println(thermocouple.readInternal());
   lcd.print("  "); 
     
   double c = thermocouple.readCelsius();
   lcd.setCursor(0, 1);
   if (isnan(c)) 
   {
     lcd.print("T/C Problem");
   } 
   else 
   {
     lcd.print("F = "); 
     lcd.print(c);
     lcd.print("  "); 
   }
 
   delay(1000);
}

Unless I'm missing something, this is too easy.
This line returns the temperature in Celsius:-

double c = thermocouple.readCelsius();

So all you need is:-

if(c<=31.0)
    digitalWrite(7,HIGH);
else
    digitalWrite(7,LOW);

It can go into the 'else' of the 'if else' statement:-

if (isnan(c))
   {
     lcd.print("T/C Problem");
   }
   else
   {
     lcd.print("F = ");
     lcd.print(c);
     lcd.print("  ");
     if(c<=31.0)
        digitalWrite(7,HIGH);
     else
        digitalWrite(7,LOW);
   }

Is this what you're after, or am I missing something?

About the only other thing I can think of is that you might want to add some hysteresis.

Edit: And you don't really need "31.0". If that's the trigger temp, "31" is fine.

I believe that is exactly what I'm after, I couldn't figure out which one was returning the variable in which was being printed out. I kind of figured it was the line you indicated but wasn't sure what the double keyword before it was. I'll try wiring in an led and see if that switches on and off given the indicated threshold.
Thanks again

No problem. And this is what a double is:-

Double precision floating point number. On the Uno and other ATMEGA based boards, this occupies 4 bytes. That is, the double implementation is exactly the same as the float, with no gain in precision.
On the Arduino Due, doubles have 8-byte (64 bit) precision.

Basically a 'float'. (A 32-bit value that can contain a decimal point.)

So the program works when I change it to pin 18 which is the analog 4 pin, I'm assuming that due to the fact that the seeed relay board uses pin 7 to control the relay it won't work on pin 7 unless I wired the led through the relay. however it's running on pin 18 so the proof of concept is there just have to wait for the heating element which I'm taking from a 12v RV hair dryer gets here. I've attached a picture as you can see the blue led is on and the temp is below 31 degrees c. Waiting on parts is always the fun part.

Looking good so far.
You might find that you need to add hysteresis to stop the LED / relay flickering at the trip point, but that's an easy addition to the code.
If that does prove to be a problem, yell out and I'll help with the code if you have trouble.