DFR0972 4-20mA output board not responding on I2C

userHead anonymous 2023-06-13 06:17:13 1387 Views11 Replies

I have purchased 2 x DFR0972 I2C to 4-20mA output boards.  I am unable to get any response from these boards at all.  I have found a library for Micropython with example code at:  

https://github.com/DFRobot/DFRobot_GP8302

 But running this example on a Pi4 gives a error saying the device is not connected.  When I run an I2Cdetect no I2C addresses are found.  I have tried both DFR0972 boards, 2 different Pi4's and tried I2C connect from from 2 different Pi Pico's but I get no response on anything.  I have also tried various different I2C pin connections on the Pi and Pi Pico without success. 

 

Does the 24VDC supply need to be connected for board to respond on I2C?  I assume it is using the 3.3 or 5VDC supply from the Pi for I2C comms.

Does the board have the required pull up resistors for the I2C network?  I can find no mention of this in the documentation.

 

Any other suggestions before I toss these in the bin and go find something else?

 

 

 

2023-12-02 09:37:31

Hi,

 

I'm currently testing the DFR0972 I2C to 4-20mA module and have a question about it. I have it working but only with 8 bit resolution and the first byte being sent over the I2C network. With the first byte the current increases by 0.1mA from 0 to 25mA for the value of 0-255 (0-FF) for the first byte. When I try using the second byte the module starts messing up and sending random mA values. Is there a guide to get the full 12 bit resolution working correctly?

 

thanks,

Jonathan

userHeadPic Jonathan.Wright
2023-06-21 06:24:48

This actually does work.  The GP_8XXX is a global library which supports a list of hardware.  Read the gitHub data for information.  Be sure the drill down to the examples because the functions have changed.

 

Below is the code I used to verify operation along with the serial monitor output.

 

#include <Wire.h>

#include <DFRobot_GP8XXX.h>

DFRobot_GP8302 mA_Source;

DFRobot_GP8403 VDC_Source(0x59);

int16_t VDC_Value = 4096; //This equals 10VDC

int16_t mA_Value = 3276; //This equals 20mA.  652 will equal 4mA

 

void setup() {

  Serial.begin (9600);

  Serial.println ();

  Serial.println ("I2C scanner. Scanning ...");

  byte count = 0;

   

  Wire.begin();

  for (byte i = 8; i < 120; i++)

  {

    Wire.beginTransmission (i);

//    Serial.print ("Checking...  ");

//    Serial.println (i);

    if (Wire.endTransmission () == 0)

      {

      Serial.print ("Found address: ");

      Serial.print (i, DEC);

      Serial.print (" (0x");

      Serial.print (i, HEX);

      Serial.println (")");

      count++;

      delay (1);  // maybe unneeded?

      } // end of good response

      delay (1);

  } // end of for loop

  Serial.println ("Done.");

  Serial.print ("Found ");

  Serial.print (count, DEC);

  Serial.println (" device(s).");

  while(VDC_Source.begin()!=0){

    Serial.println("Voltage Source Initialization Error");

    delay(100);

  }

  Serial.println("Voltage Source Initialzation Succeeded");

  while(mA_Source.begin()!=0){

    Serial.println("mA Source Initialization Error");

    delay(100);

  }

  Serial.println("mA Source Initialization Succeeded");

  VDC_Source.setDACOutRange(VDC_Source.eOutputRange10V);

  VDC_Source.setDACOutVoltage(VDC_Value,0);

  mA_Source.setDACOutElectricCurrent(mA_Value); //control the converter module to output a current of 12mA and return the corresponding DAC value  Serial.print("DAC value: 0x"); Serial.print(dac, HEX); Serial.print ("   "); Serial.println(dac, DEC);

}  // end of setup

 

void loop() {}

 

I2C scanner. Scanning ...

Found address: 88 (0x58)

Found address: 89 (0x59)

Done.

Found 2 device(s).

Voltage Source Initialzation Succeeded

mA Source Initialization Succeeded

 

userHeadPic Jerry.Ridder
2023-06-19 19:04:11

Sorry for the posting issues.  This is my first time using the forum.  Please read the 2023-06-19 10:50:56 post first, followed by the code post 2023-06-19 10:58:52 and then followed by the result post 2023-06-19 10:54:43.

userHeadPic Jerry.Ridder
jenna wrote:

Hi!

 

We have updated the library, please try again.

 

https://github.com/DFRobot/DFRobot_GP8XXX

2023-06-21 02:04:46
1 Replies
2023-06-19 18:58:52

Here is the code:

 

#include <Wire.h>

#include <DFRobot_GP8302.h>

#include <DFRobot_GP8403.h>

DFRobot_GP8302 mA_Source;

DFRobot_GP8403 VDC_Source(&Wire,0x59);

int16_t VDC_Value = 2400;

uint16_t dac = 0;

int scl = 1;

int sda = 1;

float current_mA = 8.00;

 

void setup() {

  Serial.begin (9600);

  Serial.println ();

  Serial.println ("I2C scanner. Scanning ...");

  byte count = 0;

   

  Wire.begin();

  for (byte i = 8; i < 120; i++)

  {

    Wire.beginTransmission (i);

//    Serial.print ("Checking...  ");

//    Serial.println (i);

    if (Wire.endTransmission () == 0)

      {

      Serial.print ("Found address: ");

      Serial.print (i, DEC);

      Serial.print (" (0x");

      Serial.print (i, HEX);

      Serial.println (")");

      count++;

      delay (1);  // maybe unneeded?

      } // end of good response

      delay (1);

  } // end of for loop

  Serial.println ("Done.");

  Serial.print ("Found ");

  Serial.print (count, DEC);

  Serial.println (" device(s).");

  while(VDC_Source.begin()!=0){

    Serial.println("Voltage Source Initialization Error");

    delay(1000);

  }

  Serial.println("Voltage Source Initialzation Succeeded");

  Wire.beginTransmission (88);

//    Serial.print ("Checking...  ");

//    Serial.println (i);

    if (Wire.endTransmission () == 0)

      {

      Serial.print ("Found address: ");

      Serial.print (88, DEC);

      Serial.print (" (0x");

      Serial.print (88, HEX);

      Serial.println (")");

      } // end of good response

      delay (1);

  Serial.println("I2C to 0-25 mA analog current module initialization ... ");

  uint8_t status = mA_Source.begin(scl, sda); // use the pin used by the I2C Wire object of the MCU hardware by default

  delay (1000);

  if(status != 0){

    Serial.print("failed. Error code: ");

    Serial.println(status);    Serial.println("Error Code: ");

    Serial.println("\t1: _scl or _sda pin is invaild.");

    Serial.println("\t2: Device not found, please check if the device is connected.");

    while(1) yield();

  }

  Serial.print("DAC value: "); Serial.println(dac, DEC);

  VDC_Source.setDACOutRange(VDC_Source.eOutputRange10V);

  VDC_Source.setDACOutVoltage(VDC_Value,0);

  mA_Source.calibration4_20mA(654,3276);

  dac = mA_Source.output(current_mA); //control the converter module to output a current of 10mA and return the corresponding DAC value

  Serial.print("DAC value: 0x"); Serial.print(dac, HEX); Serial.print ("   "); Serial.println(dac, DEC);

}  // end of setup

 

void loop() {}

userHeadPic Jerry.Ridder
2023-06-19 18:54:43

I will try to make my post readable:

 

Here is the serial monitor output:

 

I2C scanner. Scanning ...

Found address: 88 (0x58)

Found address: 89 (0x59)

Done.

Found 2 device(s).

Voltage Source Initialzation Succeeded

Found address: 88 (0x58)

I2C to 0-25 mA analog current module initialization ...

DAC value: 0

DAC value: 0x51E   1310

 

userHeadPic Jerry.Ridder
2023-06-19 18:50:56

I am also having great difficulty working with the device.  I have confirmed that an 18 to 24 VDC power input is required to have the device respond and I can get what I think is a response from the device using the following code running on a Mega2560:

 

Hardware includes a MEGA2560, a DFR0971 (with address set to 0x59) and a DFR0972 (with a default address of 0x58).

 

#include <DFRobot_GP8302.h>

#include <DFRobot_GP8403.h>

DFRobot_GP8302 mA_Source;

DFRobot_GP8403 VDC_Source(&Wire,0x59);

int16_t VDC_Value = 2400;uint16_t dac = 0;

int scl = 1;int sda = 1;float current_mA = 8.00;

 

void setup() {

 Serial.begin (9600);

 Serial.println (); Serial.println ("I2C scanner. Scanning ..."); byte count = 0;    Wire.begin(); for (byte i = 8; i < 120; i++) {   Wire.beginTransmission (i);//    Serial.print ("Checking...  ");//    Serial.println (i);   if (Wire.endTransmission () == 0)     {     Serial.print ("Found address: ");     Serial.print (i, DEC);     Serial.print (" (0x");     Serial.print (i, HEX);     Serial.println (")");     count++;     delay (1);  // maybe unneeded?     } // end of good response     delay (1); } // end of for loop Serial.println ("Done."); Serial.print ("Found "); Serial.print (count, DEC); Serial.println (" device(s)."); while(VDC_Source.begin()!=0){   Serial.println("Voltage Source Initialization Error");   delay(1000); } Serial.println("Voltage Source Initialization Succeeded"); Wire.beginTransmission (88);

    if (Wire.endTransmission () == 0)     {     Serial.print ("Found address: ");     Serial.print (88, DEC);     Serial.print (" (0x");     Serial.print (88, HEX);     Serial.println (")");     } // end of good response     delay (1);

  Serial.println("I2C to 0-25 mA analog current module initialization ... "); uint8_t status = mA_Source.begin(scl, sda); // use the pin used by the I2C Wire object of the MCU hardware by default delay (1000); if(status != 0){   Serial.print("failed. Error code: ");   Serial.println(status);    Serial.println("Error Code: ");   Serial.println("\t1: _scl or _sda pin is invaild.");   Serial.println("\t2: Device not found, please check if the device is connected.");   while(1) yield(); }

  Serial.print("DAC value: "); Serial.println(dac, DEC);

  mA_Source.calibration4_20mA(654,3276); dac = mA_Source.output(current_mA); //control the converter module to output a current of 10mA and return the corresponding DAC value Serial.print("DAC value: 0x"); Serial.print(dac, HEX); Serial.print ("   "); Serial.println(dac, DEC);}  // end of setup

 

I get the following output on the Serial monitor:

 

I2C scanner. Scanning ...Found address: 88 (0x58)Found address: 89 (0x59)Done.Found 2 device(s).Voltage Source Initialization SucceededFound address: 88 (0x58)I2C to 0-25 mA analog current module initialization ... DAC value: 0DAC value: 0x51E   1310 

 

The dac value does change when I change the current_mA @ initialize value however the device does not output a current on the terminals.  I have a 250 ohm resistor connected directly accross the 4-20mA OUT terminals and am attempting to read the voltage accross this resistor (as opposed to putting the meter inline with the resistor and reading current).  The scl and sda values can be 1, 1 or -1, -1 but not different.  Funny thing is that I can completely disconnect the device from IIC and VCC/GND and it will still send the same response after a Mega2560 reset (except that the scanner portion of the code finds only one address (0x59)).  So I don't know where the dac response is coming from.  Could it be stored in the library function somehow?

 

The GP8403 library and DFR0971 PCB always work as expected.

 

This is certainly not a good example of quality code, but it gets the point accross.

 

Can anyone spot what I am doing wrong?

 

Thanks.

userHeadPic Jerry.Ridder
2023-06-13 18:49:16

Have you verified the I2C address?

userHeadPic bidrohini.bidrohini
2023-06-13 17:33:39

You could check the schematic below, the main chip is powered by the VIN, so you have to power the module with 18-24DC in the VIN port to use the module.

 

userHeadPic Yeez_B
2023-06-13 10:46:54

The 24VDC supply is typically required to power the output circuitry of the board, but it shouldn't affect the I2C communication itself. The I2C communication relies on the 3.3V or 5V supply from the Pi or Pi Pico, as you mentioned.

 

The presence of pull-up resistors on the I2C lines is crucial for proper I2C communication. Unfortunately, I couldn't find specific information about the DFR0972 board's pull-up resistors in the available documentation. However, it's common for I2C devices to include internal pull-up resistors. If the boards you purchased don't have pull-up resistors, you'll need to connect external pull-up resistors (typically around 2.2kΩ) to the SDA and SCL lines.

Ensure that the 24VDC power supply is connected and providing a stable voltage to the boards.

userHeadPic bidrohini.bidrohini
Yeez_B wrote:

I think the pull-up resistors are on the IIC wire after I checked the schematic:

And the schematic also shows that you have to power the module in the VIN port to power the main chip"GP8302"

You could check my answer above.

 

2023-06-13 17:32:21
1 Replies