PID, peltier, python logging
hi there,
i'm trying real-time log 2 peltier-temperatures in python. works ok except adc converting errors (see attached picture) every , then. i'm pretty sure it's not python code, here arduino code:
edit: actually, have question well: real-time monitoring lagging quite bit without delay(200) , i'm not quite sure why. adds dead time control loop why rid of it. it's not "real-time" be. it's still has noticeable latency...does have idea why (randomly chosen) 200ms work better or how determine better value?
i'm trying real-time log 2 peltier-temperatures in python. works ok except adc converting errors (see attached picture) every , then. i'm pretty sure it's not python code, here arduino code:
code: [select]
#include <math.h>
#include <pid_v1.h>
int peltier_cold = 2;
int peltier_hot = 3;
float b_value = 3947.7;
float res_25 = 83000;
float temp_25 = 298.15;
float vcc = 5.04;
double setpoint_cold, input_cold, output_cold;
double setpoint_hot, input_hot, output_hot;
//specify links , initial tuning parameters
double conskp_cold=14;
double conski_cold=5;
double conskd_cold=0.8;
pid mypid_cold(&input_cold, &output_cold, &setpoint_cold, conskp_cold, conski_cold, conskd_cold, direct);
double conskp_hot=1;
double conski_hot=3;
double conskd_hot=0.25;
pid mypid_hot(&input_hot, &output_hot, &setpoint_hot, conskp_hot, conski_hot, conskd_hot, direct);
void setup()
{
// initialize serial communication @ 9600 bits per second:
serial.begin(115200);
// initialize pid
input_cold = read_temperature_cold(); // a0
setpoint_cold = 18;
// turn pid on
mypid_cold.setmode(automatic);
mypid_cold.setcontrollerdirection(reverse);
input_hot = read_temperature_hot(); // a1
setpoint_hot = 28;
// turn pid on
mypid_hot.setmode(automatic);
mypid_hot.setcontrollerdirection(direct);
}
float convert_to_temperature(int sensor_value)
{
// convert analog reading (which goes 0 - 1023) voltage (0 - 5v):
float voltage_adc = sensor_value * (vcc / 1023.0);
// calculate resistance of ntc
float res_ntc = 100000 * ( vcc/voltage_adc - 1 );
// calculate temperature
double temperature_kelvin = 1 / ( ( (log(res_ntc/res_25))/b_value) + (1/temp_25) );
// convert celsius
double temperature = temperature_kelvin - 273.15;
return temperature;
}
float read_temperature_cold()
{
// read input on analog pin 0:
int sensor_value_cold = analogread(a0);
return convert_to_temperature(sensor_value_cold);
}
float read_temperature_hot()
{
int sensor_value_hot = analogread(a1);
return convert_to_temperature(sensor_value_hot);
}
void loop()
{
// --------------------- serial monitoring ---------------
input_cold = read_temperature_cold();
input_hot = read_temperature_hot();
// //serial.print("(c:");
serial.print(input_cold);
serial.print(" ");
serial.print(input_hot);
serial.print("\n");
// --------------------- pid_1 (cold) ---------------------------
mypid_cold.settunings(conskp_cold, conski_cold, conskd_cold);
mypid_cold.compute();
analogwrite(peltier_cold,output_cold);
// --------------------- pid_2 (hot) ----------------------------
mypid_hot.settunings(conskp_hot, conski_hot, conskd_hot);
mypid_hot.compute();
analogwrite(peltier_hot,output_hot);
delay(200);
}
edit: actually, have question well: real-time monitoring lagging quite bit without delay(200) , i'm not quite sure why. adds dead time control loop why rid of it. it's not "real-time" be. it's still has noticeable latency...does have idea why (randomly chosen) 200ms work better or how determine better value?
have tried looking @ serial port data using arduino ide serial port monitor? why using such high baud rate?
Arduino Forum > Using Arduino > Project Guidance > PID, peltier, python logging
arduino
Comments
Post a Comment