Pi-SPi Temperature Sensor HVAC KIT

  • $64.95
  • Save $19


The Pi-SPi-8AI Temperature Sensor Kit is everything you need for a simple HVAC controller, just add your Raspberry Pi! The Pi-SPi-8AI is pre-configured for 2 x Thermistor Inputs, 2 x analog 4-20mA inputs and 4 x 0 to 6.6 VDC inputs. The kit includes:

  • Qty 1 Pi-SPi-8AI Interface with thermistor inputs (fully assembled and tested)
  • Qty 1 Pi-SPi-8KO Relay Output Interface
  • Qty 1 40 Pin to 26 Pin Interface Cable for the RPi
  • Qty 1 26 Pin to 26 Pin Interface Cable to connect the Pi-SPi's
  • Qty 2 10K Thermistor Temperature Sensor with 36" wire leads
  • Qty 1 Wall Mount Adapter 24 VDC Power Supply

If purchased separately, this package would cost $84.65! You save over 23%!

Port Pins Used:

SPI-MOSI  (GPIO10)
SPI-MISO  (GPIO9)
SPI-SCK   (GPIO11)
CS_8AI     (GPIO7)
CS_8KO   (GPIO8)

Complete list of features:

  • Identical foot print to the RPi 3
  • Each module has its own 3.3VDC LDO regulator operating from the RPi 5VDC bus
  • No loading on the RPi 3.3VDC bus
  • Terminal Blocks for Thermistor Inputs and Relay Contact Outputs
  • LED indicators for power
  • Dual GPIO connectors (left and right)
  • MCP3208 A/D Converter with 12 bit resolution
  • Each analog signal buffered (1/4 LM324 Op Amp)
  • Analog Inputs 1 thru 2 are configured for Thermistor Inputs
  • Modules are powered from the Raspberry Pi
  • Separate 24 VDC input for Relay Module

Sample Code

/*
 * pispi_2ai_2K0_thermostat.c
 *
 * Copyright 2016  <pi@raspberrypi>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 *  
 */

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <math.h>
#include <wiringPi.h>     
#include <wiringPiSPI.h>

// Define Pins as used by Pi-SPi modules
#define CS_2AO        4
#define CS_8DI        17
#define CS_SPARE2    27
#define CS_SPARE1    22
#define CS_LEDS        18
#define CS_LCD1        23
#define CS_LCD2        24
#define CS_8KO        8
#define CS_8AI        7
#define DIR_RS485    25

// Steinhar-Hart Equation Defines for 10K Thermistor Beta 3380 Temp Sensor
#define R_LOAD             10000.0
#define R_ROOM_TEMP        10000.0 // for 25 Deg C
#define T_BETA            3380
#define T_AD_COUNTS        4095    // MCP3208 is 12 bit ADC
#define ROOM_TEMP_NOM     25.0
    
// Thermostat Project Defines
#define HEAT_SETPOINT    30.0        // Heat turns on when T1 < HEAT_SETPOINT
#define COOL_SETPOINT    30.0        // AC turns on when T1 > COOL_SETPOINT
#define HEAT_DEADBAND     2.0
#define COOL_DEADBAND    2.0
#define HVAC_OFF        0
#define HVAC_HEAT        0x01
#define HVAC_COOL        0x02
#define Relay_HEAT        0x01
#define Relay_COOL        0x02

        
// Prototypes    
void Initialize_Pi_Hardware(void);
void Update_Analog(unsigned char channel);
void Update_Temperatures(unsigned char channel);
void Update_Relays(unsigned char status);
int Update_HVAC(int status);
    
// Variables
unsigned AN_AD[8];
float AN_Temp[8];
unsigned char Relay_Status;
int    Heat_Cool;

// main
int main(void) {

    unsigned char i;
    
    wiringPiSetupGpio();           
      Initialize_Pi_Hardware();      
     digitalWrite(CS_8AI, HIGH);
    Relay_Status = 0;                                
              
    while(1)
    {    
        Heat_Cool = HVAC_COOL;  // Set to HVAC_HEAT or HVAC_COOL
                    
        for(i = 0; i < 2; i++) {            
            Update_Temperatures(i);
        }
        
        Relay_Status = Update_HVAC(Heat_Cool);
        Update_Relays(Relay_Status);                

        switch(Heat_Cool) {
            case HVAC_OFF:    {printf("HVAC CONTROL = OFF \n");                            
                            break;}                            
            case HVAC_HEAT:    {printf("HVAC CONTROL = HEAT \n");                          
                            break;}                           
            case HVAC_COOL:    {printf("HVAC CONTROL = COOL \n");                        
                            break;}
        }
        printf("Indoor Temperature  = %0.1f C \n", AN_Temp[0]);    
        printf("Outdoor Temperature = %0.1f C \n", AN_Temp[1]);           
        printf("Relay Status = %02x \n\n", Relay_Status);    
        delay(1000);
    }

    return 0;
}

int Update_HVAC(int status) {

    if(status == HVAC_OFF) {
        return 0;    
    }
    
    if(status == HVAC_HEAT) {
        if(AN_Temp[0] <= HEAT_SETPOINT) {
            Relay_Status = Relay_HEAT;
        }
        else {
            if(AN_Temp[0] > (HEAT_SETPOINT + HEAT_DEADBAND)) {
                Relay_Status = 0;
            }
        }
        
        return Relay_Status;
    }    

    if(status == HVAC_COOL) {
        if(AN_Temp[0] >= COOL_SETPOINT) {
            Relay_Status = Relay_COOL;
        }
        else {
            if(AN_Temp[0] < (COOL_SETPOINT - HEAT_DEADBAND)) {
                Relay_Status = 0;
            }
        }
        
        return Relay_Status;
    }    
    
    return 0 ;
}


void Update_Analog(unsigned char channel) {

    unsigned int  adc, input;
    unsigned char buf[3];
    wiringPiSPISetup(1, 100000);
    input = 0x0600 | (channel << 6);
    
    buf[0] = (input >> 8) & 0xff;
    buf[1] = input & 0xff;
    buf[2] = 0;
    
    digitalWrite(CS_8AI, LOW);    
    wiringPiSPIDataRW(1,buf,3);
    adc = ((buf[1] & 0x0f ) << 8) | buf[2];
    digitalWrite(CS_8AI, HIGH);
            
    AN_AD[channel] = adc;   
}

void Update_Temperatures(unsigned char channel) {
    float sample;
    unsigned int average;
    int i;
    
    // Calculate Temperature for Cold Water Line
    average = 0;
    
    for(i=0; i<5; i++) {            // take 5 reading and average
        Update_Analog(channel);            // to smooth out the reading    
        average += AN_AD[channel];
    }
    
    average = average / 5;          
    sample = ((float)T_AD_COUNTS / average) - 1;
    sample = (float)R_LOAD / sample;
    sample = sample / (float)R_ROOM_TEMP;
    sample = log(sample);
    sample /= (float)T_BETA;
    sample += 1.0 / ((float)ROOM_TEMP_NOM +275.15);
    sample = 1.0 / sample;
    sample -= 273.15; 
    AN_Temp[channel] = sample;   
}

void Update_Relays(unsigned char status) {
    unsigned char buf[2];
    buf[0] = status;
    wiringPiSPISetup(0, 100000);
    wiringPiSPIDataRW(0,buf,1);   
    digitalWrite(CS_8KO, LOW);
    delay(1);
    digitalWrite(CS_8KO, HIGH);   
}


void Initialize_Pi_Hardware(void) {   
    // SPI CS Enable Lines
    pinMode(CS_2AO, OUTPUT);
    pinMode(CS_8DI, OUTPUT);
    pinMode(CS_SPARE2, OUTPUT);
    pinMode(CS_SPARE1, OUTPUT);
    pinMode(CS_LEDS, OUTPUT);
    pinMode(CS_LCD1, OUTPUT);
    pinMode(CS_LCD2, OUTPUT);
    pinMode(CS_8KO, OUTPUT);
    pinMode(CS_8AI, OUTPUT);
    pinMode(DIR_RS485, OUTPUT);
}

 

SaveSaveSaveSaveSave