Professional Documents
Culture Documents
Pid Arduino Uno
Pid Arduino Uno
Pid Arduino Uno
Project name:
HowTo Control devices with PIDLibrary?? #arduSerie 23
Flavour 0 - Dark Tube Experiment - Use
Hex File: _23_arduSerie_DarkTube.ino
Use this pair code in Processing:
_23_arduSerie_DarkTube_Processing.pde
Revision History:
20161226:
Description:
this is the goal: we have to control the speed of an exhaust fan by
the pid method. We will use the Arduino PID Library by Brett Beauregard
and Front-End v03 using Processing.org version 3.1.
MCU: Arduino 1.6.12 - @16MHz http://www.arduino.cc/
74HC14 IC Chip - SChmitt Trigger
https://en.wikipedia.org/wiki/Schmitt_trigger
Connections:
See Officil you.tube channel vid:
Based on: Code by Brett Beauregard
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License v3 as published by
the Free Software Foundation
*/
/******************************************************************
* PID Simple Example (Augmented with Processing.org Communication)
* Version 0.3
* by Brett Beauregard
* License: Creative-Commons Attribution Share-Alike
* April 2011
******************************************************************/
#include <PID_v1.h>
//Define Variables we'll be connecting to
double Setpoint, Input, Output;
int inputPin=0, outputPin=3;
//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint,0.01,0.2,0.00, DIRECT);
unsigned long serialTime; //this will help us know when to talk with processing
void setup()
{
//initialize the serial link with processing
Serial.begin(9600);
}
/********************************************
* Serial Communication functions / helpers
********************************************/
union { // This Data structure lets
byte asBytes[24]; // us take the byte array
float asFloat[6]; // sent from processing and
} // easily convert it to a
foo; // float array
// getting float values from processing into the arduino
// was no small task. the way this program does it is
// as follows:
// * a float takes up 4 bytes. in processing, convert
// the array of floats we want to send, into an array
// of bytes.
// * send the bytes to the arduino
// * use a data structure known as a union to convert
// the array of bytes back into an array of floats
// the bytes coming from the arduino follow the following
// format:
// 0: 0=Manual, 1=Auto, else = ? error ?
// 1: 0=Direct, 1=Reverse, else = ? error ?
// 2-5: float setpoint
// 6-9: float input
// 10-13: float output
// 14-17: float P_Param
// 18-21: float I_Param
// 22-245: float D_Param
void SerialReceive()
{
// read the bytes sent from Processing
int index=0;
byte Auto_Man = -1;
byte Direct_Reverse = -1;
while(Serial.available()&&index<26)
{
if(index==0) Auto_Man = Serial.read();
else if(index==1) Direct_Reverse = Serial.read();
else foo.asBytes[index-2] = Serial.read();
index++;
}