Particle Electron ADC fluctuation MCP3428 4-Channel 4-20mA 16-Bit

Hello NCD support,

for reading 4-20mA Signals via I2C, I’m using the MCP3428 4-Channel 4-20mA 16-Bit.

For the Particle Electron (firmware:0.7) I’ve used this example:

However, if I send a constant value to a Channel, the ADC values are fluctuating.
For 4mA I get the digital values like 161;171;175;169.
For 8mA I get the digital values like 353;349;337;357;389.
20mA ranges between 880-905.

If the power supply is USB only, I get for 0mA the digital value 1.
If the power supply is 12V(2 cables), the value for 0mA ranges fom 0-25.

What can I do to fix these fluctuations?

Another matter that confuses me is, why the example converts the data to 12-bits, although the channels are 16-bit?

Thank you for support in advance

Can you try this library and see if you still get odd readings: https://github.com/ncd-io/MCP3428/tree/master/Particle

This is from our official repository.

Thank you for your reply jacob.

I’ve edited the code to get the reading via Serial

void loop() {
adc.takeReadings();
Serial.printlnf(“channel_1: %d”, adc.channel_1);
Serial.printlnf(“channel_2: %d”, adc.channel_2);
Serial.printlnf(“channel_3: %d”, adc.channel_3);
Serial.printlnf(“channel_4: %d”, adc.channel_4);
Serial.println("------------------------------");
}

For my tests on Channel 1 I got for 8,00mA these odd readings:
348;340;350,361,355,359;360;362;340

I’ve used another device which generates my 4-20 mA.
Now the values are between 348 and 349 for 8mA, which should work totally fine.

My apologies for the inconvenience.

Thank you for the code.
Didn’t know this one.
I’m going to use this one for my script.

Just one more question, can I use in your code MCP3428_SAMPLE_16_BIT instead of MCP3428_SAMPLE_12_BIT?

Yes, you can use 16bit. keep in mind it will take more time in sampling.

Thanks

Yes, you should just be able to say deviceObject.sample_rate = MCP3428_SAMPLE_16_BIT

Also according to my docs gain should be set to MCP3428_GAIN_2X for 4-20 mA readings. I believe the default on that library is MCP3428_GAIN_1X.

This should just give you slightly more accurate readings.