Arduino PID Frontend Library

For my current project – an Arduino Sous-vide cooker – I needed a PID-Controller for Arduino.  Brett Beauregard wrote two really nice libraries that are really helpful for this task:

PID Library

PID Front-End using Processing.org

The PID Library worked nearly out of the box for me, but for the Front-End a short tutorial would have been helpful. Since I didn’t find one, I managed to figure out how to get it working myself, but here is a reminder on how to do it for my future me, and everyone else who is new to Arduino and/or processing.

The Components

  • The PID Library: This part will run on the arduino and will have the actual PID logic
  • The PID Font-End: This is a tool using the processing.org framework, which will connect to your arduino, get the PID-values from there and display it nicely. You can also update the PID-variables like setpoint or Kp, Ki and Kd. It uses serial connection to communicate with the arduino. The package consists of two parts: A demo code for arduino, and the Front-End code itself.
  • Processing.org is a framework that lets you write and run small software packages with GUIs in an easy way. The PID Front-End is written using processing.org, so we need to install it as well
  • ControlP5 is a library for processing.org that is needed by the Front-End. I don’t actually know what it does 😉

Installation process

    • Download 32-bit version Processing.org (On windows, you need the 32-bit version, because serial communication will not work with 64-bit version, I don’t know if the same restriction applies to linux.)
    • Install it by unzipping the content to a place where you’ll be able to find it again
    • Start processing.org by executing the processing.exe and exiting again (this is necessary to make processing create the folders for the ControlP5 library)
    • Download ControlP5 and install it by unzipping it to the processing library folder (on windows this is ~/Documents/Own Documents/Processing/libraries
    • Download the PID Front-End using Processing.org and unzip it somewhere.
    • Open processing again, and open the Front-End Sketch in “PID_Frontend_v03/PID_Frontend_v03.pde”.
    • Use the sample in ArduinoSampleCode to update your arduino code. It basically needs to be able to receive and send the pid-variables via serial.
    • Connect your arduino and run your arduino code
    • Start the Front-End sketch in processing. You will get an output listing all the available COM-ports:
      =========================================
      Native lib Version = RXTX-2.1-7
      Java lib Version   = RXTX-2.1-7
      [0] "COM3"
      [1] "COM4"
      [2] "COM5"
      [3] "COM6"
      [4] "COM11"
      ControlP5 2.0.4 infos, comments, questions at http://www.sojamo.de/libraries/controlP5

      On my machine my arduino is connected to COM11, not on COM3, but the Front-End tries to connect to the first available comport. Thus I had to change line 93 in the Front-End sketch from:

myPort = new Serial(this, Serial.list()[0], 9600);   //   Communication with

to

myPort = new Serial(this, Serial.list()[4], 9600);   //   Communication with
  • Now you’re set up to watch your PID at work, and change the parameters from your PC. The red line is the Input Value, green is the Setpoint and blue is the PID Output. The spikes are due to some problems with my temperature-sensor, that I might address in a later post.

    Example of PID Front-End

    Example of PID Front-End

Have fun using the PID libraries. Since this is my first blogpost ever, feedback would be nice 🙂

This entry was posted in Arduino and tagged , , , , . Bookmark the permalink.

3 Responses to Arduino PID Frontend Library

  1. Excalibur says:

    Thanks for the tutorial for installing. It saved me a lot of time!

  2. Hello, Neat post. There is an issue with your web site in internet explorer, may
    test this? IE still is the market leader and a good portion of
    folks will miss your excellent writing because of this problem.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s