Scrolling Graph in Processing

I want to create a graph where the old data scrolls off the left side of the window while the newest data is plotted on the right side of the window. Eventually, I’m going to use this for a display to plot the readings of a temperature probe. But for now, I just want to see if I can make it work using Processing. So instead of trying to read from the serial port, I’m just going to plot a bunch of random points.

Here’s the code I used.

// Set the width and height of the window to make
int windowWidth = 400;
int windowHeight = 300;
float maxTemp = 500; //Maximum temperature expect to read
float[] readings = new float[windowWidth]; // initialized to zeroes

void setup()
  size(windowWidth, windowHeight);  // Set up the window
  stroke(255,0,0);  // stroke will be red on dots plotted
  fill(255,0,0);  // fill will be red on dots plotted

void draw()
  background(255);  // Sets the background to white and clears screen each time through loop
  readings[windowWidth - 1] = random(maxTemp); // Put a random number in the last value of the array
  // Map the element so it fits in our graph
  readings[windowWidth - 1] = map(readings[windowWidth - 1], 0, maxTemp, 0, height);
  // Plot all the points
  for (int i = 0; i < windowWidth - 1; i++)
    if (readings[i] != 0) // Don't plot anything at zero, as that's the default value in the array
      ellipse(i, height - readings[i], 3, 3);
    readings[i] = readings[i + 1]; // Shift the readings to the left so can put the newest reading in

Click here to see the script running

A couple of things I’ve learned.

Processing is NOT java. If you try to use something from java (I had tried to use some array stuff, import java.util.Arrays;), the script will not work when you put it on a webpage. So only use things in Processing itself.

When you create an array in Processing (think this is true in java as well) it automatically puts a zero in every element. For the eventual temperature plot I’ll be making, this isn’t a problem because we’re not working with cold temps. That’s why I added the line of not plotting any values of zero. However, if zero would be an accepted value, I’d have to change something.

Arduino and Processing

I’m getting started with collecting data using an Arduino board, but displaying it using Processing. Eventually, I want do collect the data from a Raspberry PI board, but I’m starting with an Arduino because I think it will be easier.

The first step is to hook up a temperature probe to the Arduino and start collecting data. I’m using a MAX31855 breakout board from Adafruit. I hooked it up as suggested in the tutorials:

MAX31855 DO to Arduino digital 3
MAX31855 CS to Arduino digital 4
MAX31855 CLK to Arduino digital 5

And then ran wires for ground and 3V.

Next I needed to download the Adafruit MAX31855 library. I unzipped the file and put it in my ~/Arduino/libraries directory. One thing I needed to do was rename their directory. It had underscores in it, which the Arduino IDE complained about. So I renamed the directory AdafruitMAX31855 and it worked fine.

Here is the code I loaded on the Arduino, which I basically copied from the Adafruit website, but took out all the comments to make it shorter.

#include "Adafruit_MAX31855.h"

int thermoDO = 3;
int thermoCS = 4;
int thermoCLK = 5;

Adafruit_MAX31855 thermocouple(thermoCLK, thermoCS, thermoDO);
void setup() {
  delay(500);  // wait for MAX chip to stabilize

void loop() {

After I loaded this, I could open up the serial port monitor and watch the temperatures get printed. So that was done. Now on to Processing. Eventually, I’d like to generate a graph of the data. But first, I just want to see if I can simply read the data from the serial port and print it out in the Processing console.

Here is the code for Processing:

import processing.serial.*;

Serial thePort;
String theString = null;
char endChar = '\n';

void setup()
  thePort = new Serial(this, Serial.list()[2], 9600);
  theString = thePort.readStringUntil(endChar);
  println(Serial.list());  // only need this to get the list of ports so you know which one to use

void draw()
  // everything happens in the serialEvent()  

void serialEvent(Serial thePort)
  theString = thePort.readStringUntil(endChar);
  if (theString != null)
    theString = trim(theString);

A few interesting things to note. You have to find out which port you’re using. On my mac, in the Arduino IDE, I have choices like this:

Screen Shot 2014-06-25 at 12.33.31 PM

In Processing, this command will give a list of all the available ports.


The output of that command will look like this:

/dev/cu.Bluetooth-Incoming-Port /dev/cu.Bluetooth-Modem /dev/cu.usbmodem1411 /dev/tty.Bluetooth-Incoming-Port /dev/tty.Bluetooth-Modem /dev/tty.usbmodem1411

I know from the Arduino IDE that I used /dev/cu.usbmodem1411 as the port. In the above array, that port is at position 2. So to open a connection to that port in Processing, I should use the command:

thePort = new Serial(this, Serial.list()[2], 9600);

This all works ok. I’m not that familiar with Processing, so I need to read up on it a bit more so I fully understand everything I did. And then the next step will be to move on to creating a graph.

Cabinets In

Spent a couple of hours finishing my cabinet installation last week. The last ones went in on Sunday morning. The Ikea directions were a bit of a pain, but once I got the hang of it, it was easy. My biggest problem was the blister that I got on my hand from using the screwdriver so much.


Now I just need to measure for the countertop and pick out the color. Hopefully, I won’t have a hard time making a decision.

Testing PyROOT is Working

If you’ve compiled ROOT to use python, you need to find out if it’s working correctly. The following code will do that:

root [0] gSystem->Load("libPyROOT")
root [1] TPython::Exec("print 1+1")

Then to check that you can load ROOT into python, try:

[ ~]$ python
Python 2.7.7 (default, Jun 23 2014, 13:28:36) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>> import BAD_LIBRARY
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named BAD_LIBRARY

We didn’t get any errors when loading ROOT, that’s what we wanted.

Another Cabinet Down

I went to Home Depot with Julie today. She wanted to buy paint, I needed to get an assortment of wood screws and a board to put behind the sink cabinet. With that board, I was able to install the cabinet. I also put the fronts on and it looks ok.


I also started leveling the other two cabinets to get them ready to install next. Would have done more work, but today was the first day when I could stay in and watch all the World Cup games and I wanted to do that. And I’m also still a little bit worried about whether the dishwasher door is going to hit the handles on the drawers of the cabinet next to it. I think I have enough room, but I’m thinking that I should buy the dishwasher before I install any handles.

My one problem today was that one of the undercabinet lights I installed fell out. This is why I wanted to buy some more wood screws. I got a fewer longer ones and those seem to work better. At least the light hasn’t fallen out in the few hours since I put it in. We’ll see if it stays up.

A Mistake

Last weekend, I wanted to install the new track lighting I bought to go over the sink. When I went to attach the bit that gets hooked up to the electrical box, I realized that I used a regular box in the ceiling when I should have used a ceiling box. This just seems dumb to me and I remember installing the box and not thinking much about it. I basically just bought a bunch of deep, square boxes and put one wherever I wanted outlets or switches. But the part of the light that attaches to the ceiling is designed to go onto a smaller box. When I discovered this, I just assumed that I’d be able to get an adapter of some type to allow me to hook things up. I looked at both Ace and Home Depot and couldn’t find anything like this. So then I tried to come up with something else that would work. The problem was, anything I came up with required me to remove the drywall ring (I don’t know what it’s really called) that was already installed. This meant that I also screwed up the drywall around the box, as everything had already been taped. After much messing around I finally got things up and working. Unfortunately, I also have to fix the drywall around the box.

Can you tell which light I put in and which was put in by a professional?


Changing Password Encryption

Per my earlier post about changing the encryption methods of passwords, I had a chance to test out the directions I had to see if they really worked. In fact, they worked perfectly. And to check that things actually changed, I took a look at the crypted password before and after I logged in.


That was the encrypted password before I logged in.


And this was the encrypted password after I logged in.

Since the system allowed me to login, it worked fine.