Example AD/DA I2C converter with PCF8591p

AD/DA I2C converter with PCF8591p

For this example we will use the integrated PCF8591, it is an ADC converter with I2C communication.



The PCF8591 has 4 analog inputs and one analog output.

In this example we will only use an analog input.

It can be seen in the diagram that we have put all the address pins to GND, that means that our peripheral I2C will have the address 000, which translated to our code 0x48.

The outline of our converter is as follows:




The following image shows what we are in the PCB, the 4 analog inputs and the communication connector with the power supply, which is the one that mainly interests us.pcb-bottom-pcf85911.jpg


The plate I have designed for the converter has the pins that are compatible with the I2C connectors that are prepared in the Shiny Mioio Motor, as well as the Srf04 ultrasonics.

img_20140121_163613 img_20140121_163849

To put it into action in our program we must include the following:

1. The library that has the I2C communication:


import ioio.lib.api.TwiMaster;

2. In the setup: (Note how I2C port number 1 is used, which corresponds to pins 47 and 48 of the MIOIO).

twi = ioio_.openTwiMaster(1, TwiMaster.Rate.RATE_100KHz, true);

3. In the loop:

final float sensorain1 = Readpcf8591(0x48, twi);
 setText(Float.toString(reading), Float.toString(sensorain1));

4. The functions used are as follows:

//Para la lectura de la conversión:
public float Readpcf8591(int address, TwiMaster port) {
float returnval = 0;
byte[] request = new byte[] { 0x30 };
 byte[] tempdata = new byte[2];
 try {
 port.writeRead(address, false, request,request.length,tempdata,tempdata.length);
float ain1 = tempdata[0];
ain1= -ain1;
return ain1;
 } catch (ConnectionLostException e) {
 // TODO Auto-generated catch block
 } catch (InterruptedException e) {
 // TODO Auto-generated catch block
 } finally {}
return returnval;
//La función settext para la visialización del dato en un textView que nos hayamos creado.
private void setText(final String str, final String str01) {
 runOnUiThread(new Runnable() {
 public void run() {

Leave a Reply

Your email address will not be published.