This program is not finished, I am in the habit of compiling after every few steps to catch issues early.
//PID Libraries
#include <PID_v1.h>
#include <PID_AutoTune_v0.h>
//DS18B20 Libraries
#include <OneWire.h>
#include <DallasTemperature.h>
//BLynk Libraries
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
// So we can save and retrieve settings
#include <EEPROM.h>
// ************************************************
// Pin definitions
// ************************************************
// Output Relay
#define RelayPin 7
// One-Wire Temperature Sensor
// (Use GPIO pins for power/ground to simplify the wiring)
#define ONE_WIRE_BUS 2
#define ONE_WIRE_PWR 3
#define ONE_WIRE_GND 4
// ************************************************
// PID Variables and constants
// ************************************************
//Define Variables we'll be connecting to
double Setpoint;
double Input;
double Output;
volatile long onTime = 0;
// pid tuning parameters
double Kp;
double Ki;
double Kd;
// EEPROM addresses for persisted data
const int SpAddress = 0;
const int KpAddress = 8;
const int KiAddress = 16;
const int KdAddress = 24;
//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
// 10 second Time Proportional Output window
int WindowSize = 10000;
unsigned long windowStartTime;
// ************************************************
// States for state machine
// ************************************************
enum operatingState { OFF = 0, SETP, RUN, TUNE_P, TUNE_I, TUNE_D, AUTO};
operatingState opState = OFF;
// ************************************************
// Sensor Variables and constants
// ************************************************
// Data wire is plugged into port 2 on the Arduino
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// arrays to hold device address
DeviceAddress tempSensor;
void LoadParameters();
void DriveOutput();
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
// Initialize Relay Control:
pinMode(RelayPin, OUTPUT); // Output mode to drive relay
digitalWrite(RelayPin, LOW); // make sure it is off to start
// Set up Ground & Power for the sensor from GPIO pins
pinMode(ONE_WIRE_GND, OUTPUT);
digitalWrite(ONE_WIRE_GND, LOW);
pinMode(ONE_WIRE_PWR, OUTPUT);
digitalWrite(ONE_WIRE_PWR, HIGH);
// Start up the DS18B20 One Wire Temperature Sensor
sensors.begin();
if (!sensors.getAddress(tempSensor, 0))
sensors.setResolution(tempSensor, 12);
sensors.setWaitForConversion(false);
// Initialize the PID and related variables
LoadParameters();
myPID.SetTunings(Kp,Ki,Kd);
myPID.SetSampleTime(1000);
myPID.SetOutputLimits(0, WindowSize);
// Run timer2 interrupt every 15 ms
TCCR2A = 0;
TCCR2B = 1<<CS22 | 1<<CS21 | 1<<CS20;
//Timer2 Overflow Interrupt Enable
TIMSK2 |= 1<<TOIE2;
}
// ************************************************
// Timer Interrupt Handler
// ************************************************
SIGNAL(TIMER2_OVF_vect)
{
if (opState == OFF)
{
digitalWrite(RelayPin, LOW); // make sure relay is off
}
else
{
DriveOutput();
}
}
void loop() {
// put your main code here, to run repeatedly:
}
This is my current code. Earlier today, I did not have
void LoadParameters();
void DriveOutput();
This led to errors because loadparameters() and DriveOutput() were not defined.
after adding that code in above the void setup(), I am still getting these errors that I do not really understand.
In file included from C:\Users\-_-\Documents\Arduino\Projects\sketch_feb24a\sketch_feb24a.ino:3:0:
C:\Users\-_-\Documents\Arduino\libraries\PID_AutoTune_v0/PID_AutoTune_v0.h:3:0: warning: "LIBRARY_VERSION" redefined
#define LIBRARY_VERSION 0.0.1
^
In file included from C:\Users\-_-\Documents\Arduino\Projects\sketch_feb24a\sketch_feb24a.ino:2:0:
C:\Users\-_-\Documents\Arduino\libraries\PID/PID_v1.h:3:0: note: this is the location of the previous definition
#define LIBRARY_VERSION 1.1.1
^
C:\Users\-_-\AppData\Local\Temp\ccAgg2oe.ltrans0.ltrans.o: In function `setup':
C:\Users\-_-\Documents\Arduino\Projects\sketch_feb24a/sketch_feb24a.ino:112: undefined reference to `LoadParameters()'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino/Genuino Uno.