PAC1934 mi

Hi guys,

I am strugling with my PAC 1934 microchip sensor, I want to measure voltage and current with this sensor via I2C communication. I have found library for AVR/PIC written in pure C and i am not able to make it work with my Arduino Uno. I was trying to rewrite example in this library0 to Arduino code but I was not succesfull. Can anyone help me with solution, or give me some advice what to do? I am beginner, learning by doing, but this big challenge for me.

Here are the links:

https://libstock.mikroe.com/projects/view/2173/pac1934-click?fbclid=IwAR0xW-6JCJfwxXYSswstkOKYi1q20AUddbdc0dEBP7O6v45GkHn-ZxM1Vk0

Datasheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/PAC1932-Data-Sheet-DS20005850C.pdf

Thank you guys

I was trying to rewrite example in this library0 to Arduino code but I was not succesfull.

Post the code you have, we may fix it together.

Sorry, I m beginner and modification code is only experiment.

Don't expect us to do the job for you. You don't have to be an expert to get that library change for the Arduino IDE. Read about how to use the Wire library and then try to convert the C code to use that library. Post your result and we give you hints how to proceed.

Hi there,

I also tried to modify the code you told about but i can’t get it works. See my code in attachments.
On my project, i am pulling PWRDN with a MCP23016 and i use 2 different I2C buses for some purpose. ( I am sure that those part are working)

On my arduino code i tried to call refresh methodes before getting U and I value but i don’t have anything :

void loop() {

  //PAC1934.PAC1934_sendCommand(_PAC1934_REFRESH_G_CMD);
  //PAC1934.PAC1934_sendCommand(_PAC1934_REFRESH_V_CMD);

  delay(1000);

  Serial.println("---------------");

  int i = 0;

  float I1 = PAC1934.PAC1934_measureCurrent(i);
  delay(5);
  Serial.println(I1);
  i++;
  I1 = PAC1934.PAC1934_measureVoltage(i);
  delay(5);
  Serial.println(I1);


  delay(500);
    //i2cdetect(first, last, &I2Cone);
    //delay(1000);
}

The output is :

---------------
0
0
0
65535.00
25000.00
sensing voltage on I2C adresse : 11
32.00
---------------

_PAC1934_Driver.cpp (8.35 KB)

_PAC1934_Driver.h (4.64 KB)

On my arduino code i tried to call refresh methodes before getting U and I value but i don't have anything :

That code doesn't compile. Post complete code, the error usually is in that part of the code you're hiding from us.

Hi, thanks for your answer.

Here is the entire test code :

#include <Wire.h>
#include "_PAC1934_Driver.h"
#include <MCP23016_HS.h>
#include <i2cdetect.h>

const uint8_t first = 0x03;
const uint8_t last = 0x77;

TwoWire I2Cone = TwoWire(0); //SDA: 13 SCL: 15
TwoWire I2Ctwo = TwoWire(1); // SDA: 23  SCL: 22

PAC1934 PAC1934(0x0B); //11 en decimal //0X0A ou 0X0C ?
Adafruit_MCP23017 mcp;

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

  // put your setup code here, to run once:
  I2Ctwo.begin(23, 22, 400000);
  I2Cone.begin(13, 15, 100000);

  mcp.begin(&I2Ctwo);

  mcp.pinMode(13, OUTPUT);
  mcp.pinMode(14, OUTPUT);

  delay(100);

  mcp.digitalWrite(13, HIGH);
  mcp.digitalWrite(14, HIGH);

  delay(300);
  Serial.println("pin sate start");

  Serial.println(mcp.digitalRead(13));
  Serial.println(mcp.digitalRead(14));
  Serial.println("pin sate end");
  delay(300);

  PAC1934.begin(&I2Cone);
  Serial.println("PAC start");

  delay(2500);


}

void loop() {

  PAC1934.PAC1934_sendCommand(_PAC1934_REFRESH_G_CMD);

  delay(1000);

  Serial.println("---------------");

  int i = 0;
  float I1 = PAC1934.PAC1934_measureCurrent(i);
  delay(5);
  Serial.println(I1);
  
  I1 = PAC1934.PAC1934_measureVoltage(i);
  delay(5);
  Serial.println(I1);
i++;
   I1 = PAC1934.PAC1934_measureCurrent(i);
  delay(5);
  Serial.println(I1);
  
  I1 = PAC1934.PAC1934_measureVoltage(i);
  delay(5);
  Serial.println(I1);
i++;
   I1 = PAC1934.PAC1934_measureCurrent(i);
  delay(5);
  Serial.println(I1);
  
  I1 = PAC1934.PAC1934_measureVoltage(i);
  delay(5);
  Serial.println(I1);
i++;
   I1 = PAC1934.PAC1934_measureCurrent(i);
  delay(5);
  Serial.println(I1);
  
  I1 = PAC1934.PAC1934_measureVoltage(i);
  delay(5);
  Serial.println(I1);
i++;
  PAC1934.PAC1934_sendCommand(_PAC1934_REFRESH_V_CMD);

  delay(500);
    i2cdetect(first, last, &I2Cone);
    delay(1000);
}

I am testing all channels and the output is :

--------------
25000.00
sensing voltage on I2C adresse : 11

32.00
25000.00
sensing voltage on I2C adresse : 11

32.00
25000.00
sensing voltage on I2C adresse : 11
32.00
25000.00
sensing voltage on I2C adresse : 11
32.00

The PAC is responding “255” though I2C.
The PAC is well seen with i2cdetect.

I made a simpler program that handle i2c “manually”. It seems that slave is receiving but, my master doesn’t get anything in answer :

#include <Wire.h>
#include "_PAC1934_Driver.h"
#include <MCP23016_HS.h>
#include <i2cdetect.h>

const uint8_t first = 0x03;
const uint8_t last = 0x77;

TwoWire I2Cone = TwoWire(0); //SDA: 13 SCL: 15
TwoWire I2Ctwo = TwoWire(1); // SDA: 23  SCL: 22

PAC1934 PAC1934(0x0B); //11 en decimal //0X0A ou 0X0C ?
Adafruit_MCP23017 mcp;

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

  // put your setup code here, to run once:
  I2Ctwo.begin(23, 22, 400000);
  I2Cone.begin(13, 15, 100000);

  mcp.begin(&I2Ctwo);
  mcp.pinMode(13, OUTPUT);
  delay(100);
  mcp.digitalWrite(13, HIGH);
  delay(300);

  //We know mcp is working
  //Serial.println("pin sate start");
  //Serial.println(mcp.digitalRead(13));
  //Serial.println("pin sate end");
  delay(300);

  PAC1934.begin(&I2Cone);
  Serial.println("PAC start");

  delay(250);

  uint8_t reg = 0x06;

  I2Cone.beginTransmission((uint8_t)0x0B);
  int written_bytes = 0;
  int transmission_status = 0;
  written_bytes = I2Cone.write(reg);
  //We rote 1 byte

  Serial.print("number of bytes written: "); Serial.println(written_bytes);

  transmission_status = I2Cone.endTransmission(false);
  Serial.print("    transmission status: "); Serial.println(transmission_status);
  delay(1);
  //It return "0" so its OK

  int cptByte = I2Cone.requestFrom((uint8_t)0x0B, 2, false);
  Serial.print("    recevied nb of byte : "); Serial.println(cptByte);
  //Here we receive nothing 
  if (I2Cone.available() != 0) {
    Serial.println("bit available");
    Serial.println((String)I2Cone.read());
    Serial.println((String)I2Cone.read());
  }
  else {
    Serial.println("nothing availiable");
  }

  delay(2000);

}

Output is :

PAC start
number of bytes written: 1
    transmission status: 0
    recevied nb of byte : 0
nothing availiable

EDIT :
Maybe i’m missing something on the datasheet but i can’t see what. The device well receive only when we send a restart → I2Cone.endTransmission(false);
If → I2Cone.endTransmission(true); the transmission_statut is “2”.
But is it normal to keep the connexion active and to ask for the answer ? So, maybe the problem is in sending side ?

TwoWire I2Cone = TwoWire(0); //SDA: 13 SCL: 15
TwoWire I2Ctwo = TwoWire(1); // SDA: 23  SCL: 22

That doesn’t look like code for an Arduino UNO. It seems you cannot follow the simple rules, so I get explicit: Post a complete wiring diagram and links to all used hardware!

Hi,

Well, my setup is an ESP32 powered by a power supply, and the PAC1934 is wired to the first i2c bus, and the MCP is wired on the second i2c bus both with needed pull-up. The PAC is monitoring a dc motor.

There is nothing else on my system, it is as simple as that. I'm on the last arduino ide version.
Thanks,

Well, my setup is an ESP32 powered by a power supply, and the PAC1934 is wired to the first i2c bus, and the MCP is wired on the second i2c bus both with needed pull-up. The PAC is monitoring a dc motor.

And why do you define these variables again if the Wire library already has the objects Wire and Wire1 defined?

You shouldn't have hijacked this thread if your setup is completely different to the OP's.

If you want help, post a complete wiring diagram and describe your setup and links to the schematics of the breakout boards (if you used them and didn't connect the chips directly to the breadboard, which is not possible for the PAC1934).

How did you get the 0x0B I2C address?

pylon:
And why do you define these variables again if the Wire library already has the objects Wire and Wire1 defined?

You shouldn’t have hijacked this thread if your setup is completely different to the OP’s.

If you want help, post a complete wiring diagram and describe your setup and links to the schematics of the breakout boards (if you used them and didn’t connect the chips directly to the breadboard, which is not possible for the PAC1934).

How did you get the 0x0B I2C address?

  • I am defining those variables because my two I2c bus are not wired to standard pin (on this side it is absolutly working with all other i2c device (and i tested A LOT). PAC1934 is on a custom board (made by a professionnal, according to design recomands. of the datasheet) that is why i used a custom i2c pin for PAC1934. I can’t test it on other pins but i tested other i2c device on those pin with different µc and everything is good.

  • My setup is maybe different from the OP (in fact he didn’t say anything about his hardware) but as the OP, the problem is most probably software. As he didn’t try to adapt the soft driver library, i think it is ok to show what i tried on the same base to help people that will fall in the same problem (no arduino library for the PAC1934 !)

  • 0x0B i2c Adress is from the resistor wired on the ADDRSEL pin, as said at page 26 of the datasheet. (effectively i forgot to tell you that). The PAC1934 is well recognize with i2cdetect i said before.

  • I am 99.9% sure that hardware is allright. (It’s been a long time i’m using those boards and sensors). And I am 99.9% sure the problem comes from the C translation of the PAC software driver. But i can’t see what i missed in this lib.

I am available to answer the best i can to your questions.
Thank you,

  • I am defining those variables because my two I2c bus are not wired to standard pin

Bullshit. Wire and Wire1 are defined identically.

PAC1934 is on a custom board (made by a professionnal, according to design recomands. of the datasheet)

So it shouldn't be a problem to post the schematics of that board (professionals provide schematics of their creations, otherwise I doubt they are professionals).

that is why i used a custom i2c pin for PAC1934.

That's not logical. If the board is designed professionally there shouldn't be a need to use a separate bus.

  • 0x0B i2c Adress is from the resistor wired on the ADDRSEL pin, as said at page 26 of the datasheet. (effectively i forgot to tell you that). The PAC1934 is well recognize with i2cdetect i said before.

That's interesting because there is no resistor value in that table that results in an I2C address of 0x0B. What value did you choose? A resistor of 54.9kΩ will result in an address of 0x1B, did you mean that?

  • I am 99.9% sure that hardware is allright. (It's been a long time i'm using those boards and sensors). And I am 99.9% sure the problem comes from the C translation of the PAC software driver. But i can't see what i missed in this lib.

I'm not convinced yet.

Hi there, its been some time i couldn't work on this.

Just to answer you : the device i'm working on is a modular system where we have to be able to plug different µc. That's why we use 2 different i2c bus (there is different work mode) and they are set with different pins.
Schematics can't be shared publicly, it is damn bad but i can't do anything about this. In compensation, i am ofc able to share my work on this (the software for PAC1934 based on C lib).

The resistor used to set i2c address is 499ohm and then the i2c adress is 0x11 (shame on me for this mistake).

After reviewed my code, it is now working.
Should I create a github to share .h and .cpp ?

Thank you for your time spent here,

TD

the device i'm working on is a modular system where we have to be able to plug different µc. That's why we use 2 different i2c bus (there is different work mode) and they are set with different pins.

That's no explanation. Every microprocessor that is able to do I2C will be able to handle more than one device on that bus. That's standardized.

Of course, everyone knows that. In some circumstances we need 2 differents i2c buses that's all, it is not the question here so i don't get why you get stuck on this.
Have a good day,

I have not tested this myself but it is provided by Microchip and looks good from an initial glance:

http://ww1.microchip.com/downloads/en/DeviceDoc/PAC193x_Arduino_Library_v1_0_0.zip

I plan to give it a go shortly.