Friday, May 12, 2017


Just a brief note for spammers.

Often I receive some comments on some articles of this blog.
Many of them are clearly just spam masked as comment.
I have zero tolerance for spam comments, as soon as I identify one I'm deleting it (if already published) or I can prevent the publication if I recognize it.
On this blog comments must be approved by me, they are NOT automatically published.

So, who wants to post spam here, will have hard time and my total contempt.
Don't bother to post spam.

Wednesday, May 10, 2017

Gnuplot on Raspberry Pi

gnuplot is a program capable to produce graphs starting from set of data.
Ideal to graphically represents sensor readings.

This article assumes to use Raspbian on a Raspberry Pi, specifically in my case the Raspbian version is the one used with Dexter for GrovePi.
Since GrovePi allows to easily connect sensors to the Raspberry, gnuplot is the perfect companion for that environment.


Simple, open a terminal and digit : sudo apt-get install gnuplot

That's it :)


Once gnuplot is installed, is possible to open a terminal and digit the command gnuplot.
An interactive environment command line based will be available.
However the best way is to create a file containing the commands needed to generate a graph and have gplot reading that file to produce the graph as described in these instructions.

Data file

The file containing the data need to be in a specific format.

The time/date in the format of yyyy-mm-dd:hh-mm-ss (see the timefmt line in the command file), then the light value and (in this example) the voltage measured.
Each field is separated by a tab and each line ending with a newline (/r).

Example of data saved in the fhelper_datalogger.txt

# 2016-12-05:10-52-42 - Starting datalogger - time - light - volt 
2016-12-05:10-53-02 758 4.43
2016-12-05:10-53-24 758 4.43
2016-12-05:10-53-44 758 4.43
2016-12-05:10-54-05 758 4.43

Command file

Here an example of a gnuplot file (called testfile) used to display some information collected in the data file.
Specifically the goal is to create a graph showing the data stored in the second column of the file (light)
set title "fHelper light data vs. Time"
set datafile sep '\t'
set xlabel "Time"
set ylabel "Light"
set xdata time
set timefmt '%Y-%m-%d:%H:%M:%S'
set yrange [0:1000]
set style data line
set terminal png size 1500,800 enhanced font "Helvetica,20"
set output 'displight.png'
plot '/home/pi/Desktop/fhelper/fhelper_datalogger.txt' using 1:2
The file is taking a file called fhelper_datalogger.txt (located in the directory /home/pi/Desktop/fhelper) and will produce a file called displight.png.
The file will be saved in the same directory where this file exists and is executed.

To execute it just digit from the prompt : gnuplot testfile

Here a couple of examples of graphs obtained from the log file.
One shows the light reading and the other the voltage reading.
To obtain the voltage reading was enough to change a couple of lines from the command file.
Specifically I changed the Y axis range (0:1000 for light, 0:5 for Volt) and the plot command telling to use the first and third column in the file rather than the first and the second column (plot '/home/pi/Desktop/fhelper/fhelper_datalogger.txt' using 1:3)

Thursday, May 4, 2017

Grove Moisture Sensor bad design

Among many things, time ago I started to play with the Grove Pi system, for a fun project called fHelper, basically a sophisticated alarm to notify when a plant need water.

Basically a Raspberry Pi with a bunch of Grove sensors and among them the Moisture sensor.
Today I found out that who designed this sensor did a very poor job, using a direct current to detect the level of humidity.
The result after months of use is depicted in the pictures below.

Yep. One side is totally corroded !!
No wonder the reading was erratic.


Not sure if it was there when I bought it, but the sensor page now reports that the sensor should be used only for brief tests and not left in the soil because corrosion can happens.
Still I found totally silly to use something to design a system and then not be able to use it in a final design because it destroy itself.
You spend time experimenting with a sensor that can not be used !  Can I say is just stupid ?

Roomba 5xx - repairing a power supply

Time ago I had a Roomba 560 with an Error 5.
The problem was the power supply used to charge the battery.

Time to try to fix it.

It is a classic switch power supply and I did some measurement.
The voltage expected was supposed to be around 22V, but it was around 19V when I measured it.
Even worse, the voltage was slowly decreasing after few minutes.

There are many things that can go bad in a switching power supply, but the symptoms made me think about a bad capacitor.

So I opened it and started to look for damages on the PCB.
Particularly I was looking for discolorations around the capacitors, usually caused by the heat.
A bad capacitor can generate a lot of heat and thus be damaged.

I didn't notice anything apparent, so I checked out the two main capacitors in the circuit.
A 47uF 200V and a 680uF 35V.
Both seemed OK to a visual inspection.  Since I had around only the 47uF capacitor (but 400V) I decided to change it.  Quite unlikely to be that one the problem since is used as main filter on the 110V but better to try.

And in fact it was not that the cause of the problem.
So I ordered from Mouser some 680uF 35V capacitors and, just in case, a mosfet 500V N-channel to eventually replace the one used in the power supply.

When the component arrived I immediately changed the 680uF capacitor and ... voila' !
22.75V stable.

I was lucky this time. A damaged capacitor on the output.

Reassembled the power supply, it worked perfectly to charge the "just fixed" Roomba 510.