ArduinoGeneral

SKU : DFR0972(4-20mA analog current module) I2C Connect Error

userHead HoJin.Yoo 2023-04-27 17:16:22 423 Views1 Replies

DFR0972 product link
https://wiki.dfrobot.com/SKU_DFR0972_I2C_4_20mA_DAC_Module#target_10


I want to output the analog current with the above module and output it to the I2C LCD.

We succeeded in verifying the wiring and implementing the current output using the example program.
If I2C communication is attempted at the same time as the LCD, communication with the DFR0972 fails.

 

I am attaching the Arduino code I wrote.


Please help me to solve it.

 

 

Arduino Code

 

[code]
#include <LiquidCrystal_I2C.h>  // I2C LCD Header file
#include <Wire.h>
#include "DFRobot_GP8302.h"     // I2C 4-20mA Analog current Header file

float current = 4.00;
int Vol = 0;


LiquidCrystal_I2C lcd(39, 16, 2);

DFRobot_GP8302 module;

void setup()
{
 Serial.begin(9600);

 Wire.begin();

 lcd.init();
 lcd.clear();
 lcd.backlight();


 //analog current I2C Setup
   while(!Serial){
     //Wait for USB serial port to connect. Needed for native USB port only
   }
 
   Serial.println("I2C to 0-25 mA analog current moudle initialization ... ");
 
   uint8_t status = module.begin(); // Default to use the pins used by the MCU hardware I2C Wire object
 
   while(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.");
     delay(3000);
   }
   Serial.println("done!");
 module.calibration4_20mA(/*dac_4 =*/655, /*dac_20 =*/3277);

}

void loop()
{
 //  UpperTest();
 VtoA();
}

 

void UpperTest()
{
 for (current = 0; current <= 25; current++)
 {
   uint16_t dac = module.output(/*current_mA =*/current); //Control the DAC module to output the current of 10mA and return the DAC value corresponding to the current of 10mA
   float ampVal = module.output_mA(dac);

   Serial.print("DAC value: ");
   Serial.print(dac);
   Serial.print("\t");
   Serial.print("Current: ");
   Serial.println(ampVal);

   lcd.clear();
   lcd.setCursor(2, 0);
   lcd.print(dac);
   lcd.setCursor(10, 0);
   lcd.print("DAC");

   lcd.setCursor(2, 1);
   lcd.print(ampVal);
   lcd.setCursor(10, 1);
   lcd.print("mA");

   delay(1000);
 }
}


void VtoA()
{
 Vol = analogRead(A0); // input Analog Voltage
 float VolVal = map(Vol, 0, 1023, 0, 5000); // Analog input mapping(0V-5V)
 Serial.print("Vol: ");
 Serial.println(VolVal / 1000, 2);

 lcd.clear();
 lcd.setCursor(0, 0);
 lcd.print("Vol");
 lcd.setCursor(10, 0);
 lcd.print(VolVal / 1000, 2);

 current = map(Vol, 0, 1023, 4000, 20000); // Volt 0V to 5V current(uA)

 uint16_t dac = module.output(/*current_mA =*/current / 1000); //Control the DAC module to output the current of 10mA and return the DAC value corresponding to the current of 10mA
 float ampVal = module.output_mA(dac);

 Serial.print("DAC value: ");
 Serial.print(dac);
 Serial.print("\t");
 Serial.print("Current: ");
 Serial.println(ampVal);

 lcd.setCursor(0, 1);
 lcd.print("DAC");
 lcd.setCursor(4, 1);
 lcd.print(dac);

 lcd.setCursor(8, 1);
 lcd.print("Amp");
 lcd.setCursor(11, 1);
 lcd.print(ampVal);

 delay(500);
}
[/code]

icon 4-20mA.zip 1KB Download(0)
2023-05-06 15:02:17

What is the iic address of the LCD? Is it the same as the iic address of DFR0972?

userHeadPic jenna