Hey all... Hope you're all having a great day. I have a few questions for those who understand CPP with ease.
First let me explain the project. Last year I was toying with a arduino PID controlled heater and had that working pretty decently with the sample PID code from http://www.arduino.cc/playground/Code/PIDLibrary.
Now I have added: a sparkfun SerLCD screen as well as 2 pushbuttons.
Ideally...one button will be to increase the "Setpoint" by 1 degree and the other will lower it by 1 degree. I am trying to accomplish having the LCD(16x2 lines) readout the "Setpoint" on the first line and on the second line I am trying to get it to display the current temp or PV i believe..
Here is what I have so far:
/********************************************************
- PID Simple Example
- Reading analog input 0 to control analog PWM output 10
********************************************************/
#include <PID_Beta6.h>
//Define Variables we'll be connecting to
double Setpoint, Input, Output;
//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint, 2,5,1);
const int lcdPin = 1 // Serial com. to LCD
const int heatPin = 10; // PWM signal for the heater
const int onPin = 2; // choose the input pin to trigger heater via pushbutton
const int upPin = 6; // choose the input pin to increase temp
const int downPin = 7; // choose the input pin to decrease temp
int buttonState = 0; // variable for reading the pin status
unsigned long lastTime;
void setup()
{
Serial.begin( 19200 );
//initialize the variables we're linked to
Input = analogRead(0);
Setpoint = 200;
// Declare inputs
pinMode(onPin, INPUT); // declare pushbutton as input(heater trigger button)
pinMode(upPin, INPUT); // declare pushbutton as input (increase temp by 1)
pinMode(downPin, INPUT); // declare pushbutton as input(decrease temp by 1)
pinMode(heatPin, OUTPUT); // declare pushbutton as output (signal to power heater)
pinmode(lcdPin, OUTPUT); // declare serial LCD output
//turn the PID on
myPID.SetMode(MANUAL);
Output=0;
myPID.SetSampleTime(250);
myPID.SetTunings(2,3,1);
myPID.SetOutputLimits(0, 220);
lastTime = millis();
}
void loop()
{
buttonState = digitalRead(onPin);
if (buttonState == HIGH) {
// turn LED/HEATER on:
digitalWrite(heatPin, HIGH);
myPID.SetMode(AUTO);
}
else {
// turn LED/HEATER off:
digitalWrite(heatPin, LOW);
myPID.SetMode(MANUAL);
Output=0;
}
unsigned long lastTime;
if(digitalRead(upPin)==HIGH)
{
if (millis()-lastTime >= 250) {
Setpoint+=1;
lastTime=millis();
}
}
if(digitalRead(downPin)==HIGH)
{
if (millis()-lastTime >= 250) {
Setpoint-=1;
lastTime=millis();
}
}
Input = analogRead(0);
myPID.Compute();
analogWrite(10,Output);
}
Now.... a couple things... I am running the PID @ 19200 baud rate. I know that the SerLCD has a default of 9600. So... Is the following code sort of correct to adjust the baud rate of the LCD to 19200? AND... where should I put this code?
Serial.print(0x7C, BYTE); //character 124 wich tells the lcd it's about to get configed
Serial.print( 0x09, BYTE); // splash screen reset - when you have the usb and tx and vc plugged in you get a conflict that is why you need this code
delay(500);
Serial.print(0x0F, BYTE); //19200 bps baud rate config command?
So I am stuck on how to send the setpoint to the first line and the PV to the second line.
Lastly... The new arduino software seems to not be liking the sample PID scripts... When I just load the sample script unmodified like it is when you download it and try and have the program compile or "test" it I get the following error:
"
PIDSample.cpp:6:23: error: PID_Beta6.h: No such file or directory
PIDSample:11: error: 'PID' does not name a type
PIDSample.cpp: In function 'void setup()':
PIDSample:20: error: 'myPID' was not declared in this scope
PIDSample:20: error: 'AUTO' was not declared in this scope
PIDSample.cpp: In function 'void loop()':
PIDSample:26: error: 'myPID' was not declared in this scope
"
I never used to get that with the old software... version 15 i believe... now I have 21..
Any ideas? Thank you so much!