A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna, tincidunt vitae molestie nec, molestie at mi. Nulla nulla lorem, suscipit in posuere in, interdum non magna.

Raspberry Web Analog Data Logger

On this post I’ll explain you how to grab analog data from an 8-channel, 12 bit ADC. The ADC used is the Custard-PI 3 . You can buy it directly from them on that page.

I use it to log value from different type of sensors. As you know ADC for raspberry can read only voltage from 0 to 2.5V (or higher with partitor) but lot of industrial sensors are based on 4-20mA range.


With this scripts you will be able to obtain a CSV and graph of the real value with only some easy configuration. You just need to know what’s the range of your sensor (ex: 0-100°C), what’s the range of output value of the sensor (ex: 4-20 mA), what does ADC read when the output value is at minimum and at the maximum. To obtain this last values we need only a simple more step.


The setup is very easy, you just need to connect the board to raspberry, power it on, copy the software on it and everything is done. Let’s go step by step:

  1. Connect the board to raspberry and power it on.
  2. Connect to PI with ssh, update it and install apache with php:
    # sudo apt-get update && apt-get upgrade# sudo apt-get install libapache2-mod-php5
  3. Download the tarball and extract it on root ( / ) directory.

    cd /tmp
    cd /
    tar xvf /tmp/adc_grabber.tar

  4. It will extract two files in /etc/init.d and /etc/default ; these are needed for startup at boot.
    It will extract the file in /usr/local/bin and the directory cpi3adc in /usr/local/lib (this contains two included file). Every web page is extracted on /var/www/adc
  5. We need four more steps manually:

    Edit sudoers file with command:
    # sudo visudo
    and add this line at the end:
    www-data ALL=(ALL) NOPASSWD: ALL
    add user www-data to group pi with this:
    # sudo adduser www-data pi
    Enable startup of the logger on boot:
    # sudo update-rc.d cpi3adc defaults
    And finally edit /etc/apache2/sites-enabled/000-default, find the paragraph starting with:
    <Directory /var/www>
    and add these lines inside it:
    Options +ExecCGI

    AddHandler cgi-script .cgi .pl
    RedirectMatch ^/$ /adc/

  6. Via web browser connect to your raspberry (you need to know the ip address, ex:
  7. On this page you can set up global parameters or different ones for each channel (in case you have different sensors).
    In my example I have a thermometer with range 0° – 100°C and output of 4 – 20 mA.
    I have connected it to channel 1 with 100 ohm resistor, look at this image to have an idea:
    The problem now is that the resistor is not usually perfect and we need to make some adjustment.
  8. I disconnect my sensor and i connect to analog input a current generator, I set it with 4mA and i click on “Leggi Valori Attuali”, this is the result:

    CANALE – Volt Ingresso – Valore Ingresso Puro – Ingresso  mA – Valore Calcolato °C
    CH 1 – Voltage 0.40 – Value 655 – In 4.00 mA – 0.00 °C
    CH 2 – Voltage 0.08 – Value 131 – In 0.80 mA – -20.05 °C
    CH 3 – Voltage 0.05 – Value 81 – In 0.50 mA – -21.96 °C
    CH 4 – Voltage 0.03 – Value 43 – In 0.26 mA – -23.41 °C
    CH 5 – Voltage 0.01 – Value 21 – In 0.13 mV – -12.13 V
    CH 6 – Voltage 0.01 – Value 15 – In 0.09 mA – -24.48 °C
    CH 7 – Voltage 0.01 – Value 11 – In 0.07 mA – -24.64 °C
    CH 8 – Voltage 0.00 – Value 7 – In 0.04 mA – -24.79 °C

    Our interest is for the second line (channel 1) and the second field (value), this is the value that ADC reads with an input of 4mA and our resistor.
    Now the same thing setting the generator to 20mA, change the generator and press F5 to reload the page, this is the output:

    CANALE – Volt Ingresso – Valore Ingresso Puro – Ingresso  mA – Valore Calcolato °C
    CH 1 – Voltage 2.00 – Value 3269 – In 20.0 mA – 100.00 °C

    The second value is 3269, this is the ADC reading with 20mA.

  9. Now on the homepage you can set the value needed. And you need how to obtain the value for the third column (ADC).
  10. When everything is done you can press “Salva Valori”, and then you can start the logger with “Avvia”.
  11. If you want to start automatically the logger at boot check “Avvia automaticamente” and press “Salva Valori”.
  12. The logger grab the data every seconds setted in “Intervallo in secondi per letture”, and calculate the average every “Nr di valori per media” setted.
  13. You can see the graph in realtime clicking on “Visualizza Grafico”, and download CSV clicking on “Download CSV”.

Download scripts: adc_grabber

Thanks to:


2 comments to Raspberry Web Analog Data Logger

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>