Lesson 11 Voltmeter

Share for us

Introduction

In this lesson, we will use a Raspberry Pi and an ADC0832 to make a voltmeter.

Experimental Conditions

– 1*Raspberry Pi

– 1*Network cable (or USB wireless network adapter)

– 1*Potentiometer

– Jumper wires

Experimental Principle

In this experiment, we use the potentiometer to divide voltage.

Since the Raspberry Pi can only read digital signals, but what the adjusting end of the potentiometer outputs is an analog signal, so we need to convert the analog signal into digital signal with an ADC (Analog to Digital Convertor). Then we make this digital output voltage display on the screen.

Experimental Procedures

Step 1: Connect the circuit as shown in the following diagram

Step 2: Edit and save the code (see path/Rpi_UniversalStartKit /11_voltmeter/vol.c)

Step 3: Compile the code

gcc  vol.c  -lwiringPi

Step 4: Run the program

./a.out

Press Enter, if you adjust the potentiometer , you will see the voltage value displayed on the screen changed.

vol.c

``````#include <wiringPi.h>
#include <stdio.h>

typedef unsigned char uchar;
typedef unsigned int  uint;

{
//10:CH0
//11:CH1
uchar i;
uchar dat1=0, dat2=0;

for(i=0;i<8;i++)
{

}

for(i=0;i<8;i++)
{
}

return(dat1==dat2) ? dat1 : 0;
}

int main(void)
{
float vol;

if(wiringPiSetup() == -1){
printf("setup wiringPi failed !");
return 1;
}

while(1){
printf("Current Voltage : %0.2f V\n", adcVal*(5.0/255));

delay(400);
}

return 0;
}
``````

Python Code

``````#!/usr/bin/env python
import time

def init():

def loop():
while True: