Odpověď na: Max6675
Úvodní stránka › Fórum › Vaše projekty › Arduino › Max6675 › Odpověď na: Max6675
12.2.2017 v 22:17
#10456
rehot79
Účastník
Netuším v čom to je ale asi že mám po dlhej dobe volný víkend , prikladám code už aj s PID reguláciou a nastavením Set-point pomocou potenciometru .
////Vsetky kniznice nacitane cez ArduinoIDE spravca kniznic.
#include <PID_v1.h>
#include "max6675.h"
#include <Servo.h>
Servo myservo;
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
//Definicia pin
int thermoSO = 6;
int thermoCS = 5;
int thermoSCK = 4;
MAX6675 thermocouple(thermoSCK, thermoCS, thermoSO);
int vccPin = 3; //Napajanie + pre max6675 modul z digitalneho pinu
int gndPin = 2; //Napajanie - pre max6675 modul z digitalneho pinu
int val;
int poloha;
const int pot = A0;
//Define Variables we'll be connecting to
//Define Variables we'll be connecting to
double Setpoint, Input, Output;
//Define the aggressive and conservative Tuning Parameters
double aggKp=5, aggKi=0.7, aggKd=1;
double consKp=1, consKi=0.1, consKd=0.5;
//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint, consKp, consKi, consKd, DIRECT);
void setup()
{
// definicia napajacich pinou
pinMode(vccPin, OUTPUT); digitalWrite(vccPin, HIGH);
pinMode(gndPin, OUTPUT); digitalWrite(gndPin, LOW);
////definicia servo pinu
myservo.attach(9);
//initialize the variables we're linked to
Input = thermocouple.readCelsius();
Setpoint = map(analogRead(pot), 0, 1024, 0, 500);
//turn the PID on
myPID.SetMode(AUTOMATIC);
//////////////////////Oled////////////
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)
// init done
// Vycisti logo
display.clearDisplay();
//uvod email
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(10,0);
display.println("M.Jakab29@Gmail.com");
display.display();
delay(5000);
display.clearDisplay();
}
void loop()
{
Setpoint = map(analogRead(pot), 0, 1024, 0, 500); ;
Input = thermocouple.readCelsius();
double gap = abs(Setpoint-Input); //distance away from setpoint
if(gap<20)
{ //we're close to setpoint, use conservative tuning parameters
myPID.SetTunings(consKp, consKi, consKd);
}
else
{
//we're far from setpoint, use aggressive tuning parameters
myPID.SetTunings(aggKp, aggKi, aggKd);
}
myPID.Compute();
Output = map(Output, 0, 255, 0, 170);
myservo.write(Output);
poloha = myservo.read();
poloha= map(poloha, 0, 180, 0, 100);
val = Input;
// text display text
display.drawLine(0, 13, 0, display.height()-1, WHITE);
display.drawLine(300, 32, 0, display.height()-1, WHITE);
display.drawLine(300, 13, 0, display.height()-20, WHITE);
display.drawLine(127, 13, 127, display.height() -1, WHITE);
display.drawLine(42, 13, 42, display.height() -1, WHITE);
display.drawLine(84, 13, 84, display.height() -1, WHITE);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(6,2);
display.println("Tep. Poz.% Set.");
display.setTextSize(2);
display.setCursor(4,16);
display.println(val);
display.setTextSize(2);
display.setCursor(47,16);
display.println(poloha);
display.setTextSize(2);
display.setCursor(89,16);
display.println(Setpoint);
display.display();
display.clearDisplay();
delay(5000);
}