Modifiche a sketch esistente controllo pid temperatura

Salve a tutti,
questo sarebbe uno sketch trovato in rete che fa al caso mio solo che la misurazione della temperatura viene fatta con un modulo maxim digitale mentre io vorrei che venisse fatto con modulo MAX6675, qualcuno potrebbe aiutarmi? Con il software sono un neofita…
Grazie
Luca

questo è il codice:

#include <PID_v1.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Servo.h> 

// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

//Define Variables we'll be connecting to
double Setpoint, Input, Output;
Servo myservo;
float tempUpper;
float tempLower;
float avgTemp1;
//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint,2,5,1, DIRECT); //these tuning parameters NEED to be updated for 5gal brew
DeviceAddress upperThermometer = { 0x28, 0x4C, 0xB6, 0x9A, 0x04, 0x00, 0x00, 0xA1 };
DeviceAddress lowerThermometer = { 0x28, 0x3F, 0xF2, 0x9A, 0x04, 0x00, 0x00, 0x96 };



void setup  ()
{
  //Input = avgTemp1(0);
  Setpoint = 160; //temperature to set to in degrees F 
  myPID.SetMode(AUTOMATIC);
  //myPID.SetOutputLimits(10, 95);//10 and 95 are the max and min servo angle positions
  myPID.SetOutputLimits(650, 1520);//650 and 1520 are the write microseconds limits
  myPID.SetSampleTime(2000);
  Serial.begin(9600);
  myservo.attach(8);  //the pin for the servo control 
    myservo.write(60); //set initial servo position if desired
  //Serial.println("PID to servo control angle"); // so I can keep track of what is loaded
  Serial.println("Time, Set Point, Upper Temp, Lower Temp, Avg Temp, Output Angle"); //headers for CSV table output

   sensors.begin();
  // set the resolution to 10 bit (good enough?), going to 12 for greater precision
    sensors.setResolution(upperThermometer, 12);
    sensors.setResolution(lowerThermometer, 12);

}


void loop (void)
{
  delay(2000);
 // Serial.print("Time is: "); comment out if using excel
  Serial.print(millis());Serial.print(", ");
  //Serial.print("Setpoint: ");
  Serial.print(Setpoint); Serial.print(", ");
      //Serial.println("Getting temperatures...");
       //Temperature sensor section
     sensors.requestTemperatures();
      tempUpper = sensors.getTempF(upperThermometer); //Use sensors.getTempC if you prefer your systems metric
      tempLower = sensors.getTempF(lowerThermometer); 
      avgTemp1 = (tempUpper+tempLower)/2;
  //Serial.print("upper temperature is: ");
  Serial.print(tempUpper);Serial.print(", ");
 // Serial.print("lower temperature is: ");
  Serial.print(tempLower);Serial.print(", ");
 // Serial.print("avg pot temperature is: ");
  Serial.print(avgTemp1); Serial.print(", ");   
  
  //PID section  
  Input =  avgTemp1;
  myPID.Compute();
  //Servo section
  //int invOutput = map(Output, 10, 95, 95, 10); //need to map 10 to 95 to reverse the output from the PID
 // Since 10 is max value on the gas and 95 is min
  int invOutput = map(Output, 650, 1520, 1520, 650);
  //Serial.print("writing angle: "); 
  Serial.println(Output);
  //myservo.write(invOutput);
  myservo.writeMicroseconds(invOutput);
  
  
}

Cercando su internet trovi sia le lib che gli schemi. Come software ad esempio questi: http://code.google.com/p/max6675-arduino-library/ https://github.com/adafruit/MAX6675-library

Ciao,
ho installato le librerie del MAX6675 e testato fisicamente la termocoppia: tutto ok
Però quando sostituisco nello sketch i riferimenti del onewire con il max6675ricevo questo errore:

no matching function for call ?DallasTemperature::DallasTemperature(MAX6675*)’

In file included from PID_temperature_to_servo_control_angle.ino:4:
C:\Users\Luca\Documents\arduino-1.5.2-windows\arduino-1.5.2\libraries\DallasTemperature/DallasTemperature.h:64: error: expected `)’ before ‘’ token
C:\Users\Luca\Documents\arduino-1.5.2-windows\arduino-1.5.2\libraries\DallasTemperature/DallasTemperature.h:222: error: ISO C++ forbids declaration of ‘OneWire’ with no type
C:\Users\Luca\Documents\arduino-1.5.2-windows\arduino-1.5.2\libraries\DallasTemperature/DallasTemperature.h:222: error: expected ‘;’ before '
’ token
PID_temperature_to_servo_control_angle:16: error: no matching function for call to ‘DallasTemperature::DallasTemperature(MAX6675*)’
C:\Users\Luca\Documents\arduino-1.5.2-windows\arduino-1.5.2\libraries\DallasTemperature/DallasTemperature.h:61: note: candidates are: DallasTemperature::DallasTemperature()
C:\Users\Luca\Documents\arduino-1.5.2-windows\arduino-1.5.2\libraries\DallasTemperature/DallasTemperature.h:61: note: DallasTemperature::DallasTemperature(const DallasTemperature&)

Mi pare di capire che non è proprio un copia / incolla =(

ho modificato il codice così:

#include <PID_v1.h>
#include <Servo.h> 
#include <MAX6675.h>
#include <DallasTemperature.h>

//Pins for the Olimexino-328
int thermoDO = 12;
int thermoCS = 7;
int thermoCLK = 11;

// Initialize the MAX6675 Library for our chip

MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);



//Define Variables we'll be connecting to
double Setpoint, Input, Output;
Servo myservo;
float tempUpper;
float tempLower;
float avgTemp1;
//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint,2,5,1, DIRECT); //these tuning parameters NEED to be updated for 5gal brew
DeviceAddress upperThermometer = { 0x28, 0x4C, 0xB6, 0x9A, 0x04, 0x00, 0x00, 0xA1 };
DeviceAddress lowerThermometer = { 0x28, 0x3F, 0xF2, 0x9A, 0x04, 0x00, 0x00, 0x96 };



void setup  ()
{
  //Input = avgTemp1(0);
  Setpoint = 160; //temperature to set to in degrees F 
  myPID.SetMode(AUTOMATIC);
  //myPID.SetOutputLimits(10, 95);//10 and 95 are the max and min servo angle positions
  myPID.SetOutputLimits(650, 1520);//650 and 1520 are the write microseconds limits
  myPID.SetSampleTime(2000);
  Serial.begin(9600);
  myservo.attach(8);  //the pin for the servo control 
    myservo.write(60); //set initial servo position if desired
  //Serial.println("PID to servo control angle"); // so I can keep track of what is loaded
  Serial.println("Time, Set Point, Upper Temp, Lower Temp, Avg Temp, Output Angle"); //headers for CSV table output

   sensors.begin();
  // set the resolution to 10 bit (good enough?), going to 12 for greater precision
    sensors.setResolution(upperThermometer, 12);
    sensors.setResolution(lowerThermometer, 12);

}


void loop (void)
{
  delay(2000);
 // Serial.print("Time is: "); comment out if using excel
  Serial.print(millis());Serial.print(", ");
  //Serial.print("Setpoint: ");
  Serial.print(Setpoint); Serial.print(", ");
      //Serial.println("Getting temperatures...");
       //Temperature sensor section
     sensors.requestTemperatures();
      tempUpper = sensors.getTempF(upperThermometer); //Use sensors.getTempC if you prefer your systems metric
      tempLower = sensors.getTempF(lowerThermometer); 
      avgTemp1 = (tempUpper+tempLower)/2;
  //Serial.print("upper temperature is: ");
  Serial.print(tempUpper);Serial.print(", ");
 // Serial.print("lower temperature is: ");
  Serial.print(tempLower);Serial.print(", ");
 // Serial.print("avg pot temperature is: ");
  Serial.print(avgTemp1); Serial.print(", ");   
  
  //PID section  
  Input =  avgTemp1;
  myPID.Compute();
  //Servo section
  //int invOutput = map(Output, 10, 95, 95, 10); //need to map 10 to 95 to reverse the output from the PID
 // Since 10 is max value on the gas and 95 is min
  int invOutput = map(Output, 650, 1520, 1520, 650);
  //Serial.print("writing angle: "); 
  Serial.println(Output);
  //myservo.write(invOutput);
  myservo.writeMicroseconds(invOutput);
  
  
}

Grazie a chi mi aiuta!

Con la 1.0.4 e le librerie aggiornate, compila per la UNO. :grin: --> https://github.com/br3ttb/Arduino-PID-Library --> http://www.pjrc.com/teensy/td_libs_OneWire.html --> https://github.com/milesburton/Arduino-Temperature-Control-Library

EDIT: Compila anche con la 1.5.2 sia per la UNO che per la DUE (programming port)

EDIT2: scusa... ho compilato lo sketch senza il MAX :-(

La Dallas si aspetta un parametro di tipo OneWire, non gli puoi passare la classe MAX6657.

In pratica la libreria dallas non si interfaccia con il max6675 quindi in poche parole sono fritto?

Quale sarebbe l'alternativa della libreria dallas? (che lavora con il max6675?)

leo72: Cercando su internet trovi sia le lib che gli schemi. Come software ad esempio questi: http://code.google.com/p/max6675-arduino-library/

Scusa, ma questa lib l'hai provata?

Si questa mi fa casino con l’argomento SCk perchè duplica una già presente in una libreria di arduino…
Quella che funziona è questa:

// this example is public domain.
// www.ladyada.net/learn/sensors/thermocouple

#include "MAX6675.h"

//Pins for the Olimexino-328
int thermoDO = 12;
int thermoCS = 7;
int thermoCLK = 11;

MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);

void setup() {
  Serial.begin(9600);

  
  Serial.println("MAX6675 test");
  // wait for MAX chip to stabilize
  delay(500);
}

void loop() {
  // basic readout test, just print the current temp
  
   Serial.print("C = "); 
   Serial.println(thermocouple.readCelsius());
   Serial.print("F = ");
   Serial.println(thermocouple.readFarenheit());
 
   delay(1000);
}

Ma non so come collegarla alla libreria pid

  1. quale Arduino hai?
  2. come hai collegato il Max6675?

Ciao Uwe

Ciao, ho un arduino nano 2.2 ed ho collegato il modulo Max6675 come da istruzioni, infatti con lo sketch di prova funziona perfettamente.
Ho smanettato un po e sono riuscito a non avere più errori, questo è l’ultimo codice (che però ancora non funziona):

#include <PID_v1.h>
#include <Servo.h> 
#include <MAX6675.h>

//Pins for the Olimexino-328
int thermoDO = 12;
int thermoCS = 7;
int thermoCLK = 11;

// Initialize the MAX6675 Library for our chip

MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);

//Define Variables we'll be connecting to
double Setpoint, Input, Output;
Servo myservo;
float tempUpper;
float tempLower;
float avgTemp1;
//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint,2,5,1, DIRECT); //these tuning parameters NEED to be updated for 5gal brew
//DeviceAddress upperThermometer = { 0x28, 0x4C, 0xB6, 0x9A, 0x04, 0x00, 0x00, 0xA1 };
//DeviceAddress lowerThermometer = { 0x28, 0x3F, 0xF2, 0x9A, 0x04, 0x00, 0x00, 0x96 };

void setup  ()
{
  Input = thermocouple.readCelsius();
  Setpoint = 50; //temperature to set to in degrees F 
  myPID.SetMode(AUTOMATIC);
  myPID.SetOutputLimits(10, 95);//10 and 95 are the max and min servo angle positions
  myPID.SetOutputLimits(650, 1520);//650 and 1520 are the write microseconds limits
  myPID.SetSampleTime(2000);
  Serial.begin(9600);
  myservo.attach(8);  //the pin for the servo control 
    myservo.write(40); //set initial servo position if desired
  Serial.println("PID to servo control angle"); // so I can keep track of what is loaded
  Serial.println("Time, Set Point, Upper Temp, Lower Temp, Avg Temp, Output Angle"); //headers for CSV table output

}


void loop(void) {
 
  
  //PID section  
  Input =  avgTemp1;
  myPID.Compute();
  //Servo section
  //int invOutput = map(Output, 10, 95, 95, 10); //need to map 10 to 95 to reverse the output from the PID
 // Since 10 is max value on the gas and 95 is min
  int invOutput = map(Output, 650, 1520, 1520, 650);
  //Serial.print("writing angle: "); 
  Serial.println(Output);
  //myservo.write(invOutput);
  myservo.writeMicroseconds(invOutput);
  
  
}

allego le foto dell’hardware.

Grazie

Luca

uwefed:

  1. quale Arduino hai?
  2. come hai collegato il Max6675?

Ciao Uwe

Ce l'ho fatta! funziona!

http://www.youtube.com/watch?v=FU2UD_73NNs

Solo che il servo lavora solo per 90 gradi, non capisco perchè se cambio l'impostazione dei gradi di lavoro del servo non cambia nulla...