PCF8591 AD/DA Converter Arduino Tutorial 1: A Simple Analog Measurement

A Versatile Device

PCF8591 Arduino TutorialHave you ever wanted to output an analog voltage?  What about extending the number of your analog inputs? How about making a differential voltage measurement?  The PCF8591 may be the way to get that done.

This tutorial examines how to make a simple voltage measurement using just one of the channels on the PFC8591.

Other tutorials will examine other chip features.

 

Getting One

While this particular guide focuses on DIP version,  the device is offer in SMD packages as well. It is also offered as modules or bricks that are just as easily interfaced to your Arduino.

eBay     Amazon      Deal Extreme      Bang Good     IC Station

PCF8591 Pin Outs

There are sixteen pins.  In the DIP format, these are arranged and defined as illustrated below.

Notice the Vref input on this device.  We won’t use it in this tutorial,  but it is available and if you wish, you can use a device like LM4040 to make your measurement more accurate.

PCF8591 Pin Outs

Arduino PCF8591 Simple Analog Measurement Tutorial

In this tutorial, you will measure the 3.3 output from your Arduino using Analog Input 0.

Connect the Arduino to the PCF8591

Notice how the inputs to AIN1, AIN2, AIN3 are grounded.  This comes from a datasheet recommendation that suggests tying unused inputs either high or low.

The 1K resistors and the capacitor are also data sheet recommendations.

PCF8591 Tutorial 1 hook upCopy, Paste and Load the Arduino PCF8591 Sample Sketch

When powered up, the PCF8591 is set to measure analog inputs at each of its four channels.  Thus there are no additional configuration commands required in this sketch.

// Henry's Bench
// PCF8591 Simple Voltage Measurement

#define PCF8591 (0x90 >> 1) // I2C bus address
#define AIn0 0x00

int RawValue0 = 0;
float Voltage = 0.0;

void setup()
{
 Wire.begin();
 Serial.begin(9600);
}
void loop()
{
 Wire.beginTransmission(PCF8591); // Start your PCF8591
 Wire.write(AIn0); // Tell it to make an Analog Measurement
 Wire.endTransmission(); //  
 Wire.requestFrom(PCF8591, 1); // Get the Measured Data

 RawValue0=Wire.read();
 Voltage = (RawValue0 * 5.0 )/ 256.0;
 Serial.print("Raw ADC Value = ");
 Serial.println(RawValue0);
 Serial.print("Voltage = ");
 Serial.println(Voltage,3);
 delay(500); 
 
}

Verifying the Output

Open your serial monitor.  If you are successful, you will see an output similar to the one pictured below.

PCF8591 Tutorial 1 Output