Sadly, I've had to do things like work instead of play with my Raspberry Pi, but I was able to squeeze in a small project that may be of interest to others. I wanted to be able to view the current CPU temp and fan speed of my desktop while in a full-screen application, so I created a WL-RPi solution to grab information from the temp/fan log and display it on an LCD Pi plate (by Adafruit).
Details of the design are on my website and the code is available at my github repository.
Previously, I created some WolframLink code to use the Wiring Pi libraries in Mathematica. This project utilizes that code to print to the LCD screen and create custom character definitions for displaying a rudimentary plot of CPU temperature vs. time. I spent some time working on the plot in order to get a smooth and efficient result. Originally tried playing around with Binarize
and Rasterize
on a ListPlot
of the data that I wanted to plot; however this route was a bit too resource intensive and it took several seconds to generate the output. The code below turned out to give me the desired response:
pmPlotMatrix[data_List]:=Module[{lo = 40,hi=60},
(* Prevent rescaling problems *)
lo = Min[data,lo];
hi = Max[data,hi];
(* Creates a matrix-style barchart with dimensions *)
(* amenable to lcdCharDef *)
1-Normal@SparseArray[
Flatten@MapIndexed[
Table[{i,First@#2}->1,{i,#1}]&,
(Round@Rescale[#,{lo,hi},{16,1}]&/@data)],{16,20}]
];
I avoid all of the graphics generation and instead create a matrix that in turn can be chopped into 5x8 custom characters. I eek out a little more performance by noting that, once the custom characters are on the display, I can just update the character definition which will update the display. This saves several 10's of ms on the screen refresh by not having to run the code to put 8 characters on the screen every iteration.
If anyone is interested, I'd like some input on a bug mentioned at the end of my website discussion of this project. Simply put, a ScheduledTask set to run infinitely will eventually kick me out of the wolfram interpreter and do some whacky stuff to my terminal. I haven't had much time to debug this problem yet.