Translate

Showing posts with label Grove. Show all posts
Showing posts with label Grove. Show all posts

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.

Installation


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

That's it :)

Use

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.






Friday, December 2, 2016

5V Solar Power Supply for Raspberry Pi - first results

The introductory article was about describing the feasibility of the project.
Let's see some preliminary results.

The measurements


Until now I did run the system with an external voltmeter to see if the solar panel was able to keep up with the system.
It seems that so far the answer is no.


The graph shows the battery level measured in few days.
Note that basically there was no real load to the battery, only the Dc/Dc converter, so very few mA were drawn from the battery.
The days were pretty cloudy all the time, so no full sun for long time. In the best scenario (see the latest days) the battery level barely reached the 2.9V, well well below the minimum of 3.5V, and again I stress the fact there was no real load on the system.

The solar panel used so far is a 6V 2W, capable to provide in full sun a current of 330mA.
Definitively not enough to keep the battery charged AND powering something else (the Raspberry Pi has an estimated drawing current around 300-350mA).

Until there was sun the system did run happily, but as soon as the solar panel was not in full sun, the system had to use more and more the battery to power up the project and of course there was no battery charging there.

The battery is a nominal 3.7V 6600mAh and can last just few hours when not charged, so the system starting with a loaded battery in a sunny day can run almost all the day, but that only the first day.

What to do ?

There are few things to try.

  1. Use a bigger and powerful solar panel.
    A bigger solar panel, still 6V but maybe 6 or 9 W, probably can give more energy even with less light.
    In full sun the power should be enough to charge the battery AND power the system.
    Adafruit has a 6V 5.6 W solar panel, capable to give up to 930 mA in full sun and presumably more juice even in less than ideal conditions.
     
  2. Implement an intelligent power management
    We can assume to don't have the system running 24 hours a day.
    An external circuit (like the RPOf) can monitor the charge of the battery and shutdown the Raspberry when the battery level is below a specific threshold.
    When the battery threshold level is above a specific value the circuit can power on back the Raspberry.
  3. Reduce as much as possible the Raspberry Pi current needs.
    It can be done disabling every thing not needed, like the HDMI port or the LEDs.
    Even better adopting a Raspberry Pi 3, eliminating also the need to power the USB ports (currently the USB ports are in use for the WiFi dongle).
Very probably all the solutions will be needed.

Sensor modification


To better handle the solar management, a modification is needed on the light sensor.
Currently the light sensor is based on a photoresistor.
It can indicate if there is light or dark but is not enough to determine the "quality" of the light.
In other words the value returned is not enough to determine if the light is enough to generate ppower via the solar panel or not.
To do so a better light sensor is needed.  So in the near future I'll use a solar light sensor rather than the generic light sensor.


Wednesday, November 16, 2016

5V Solar Power supply for Raspberry Pi - feasibility phase

Ok, here the deal.
The goal is to have a 5V solar power supply for Raspberry Pi in order to power up a project (fHelper).

Tuesday, August 11, 2015

MSP430 - Energia and Grove


I do have few Arduino around.
Like many people I bought some of them because ... well, I don't know, I guess at the time it was the news, to see what it is.
And I didn't like it much.