Hello NCD support,
for reading 4-20mA Signals via I2C, I’m using the MCP3428 4-Channel 4-20mA 16-Bit.
low cost 4 channel 4-20mA current receiver board with Wifi, Cellular, electron, USB, RS485, Bluetooth,cloud interface with on board 4-20mA signal amplifier
Price: USD 64.95
For the Particle Electron (firmware:0.7) I’ve used this example:
// Distributed with a free-will license.
// Use it any way you want, profit or free, provided it fits in the licenses of its associated works.
// MCP3428
// This code is designed to work with the MCP3428_I2CADC I2C Mini Module available from ControlEverything.com.
// https://www.controleverything.com/content/Analog-Digital-Converters?sku=MCP3428_I2CADC#tabs-0-product_tabset-2
#include <application.h>
#include <spark_wiring_i2c.h>
// MCP3428 I2C address is 0x68(104)
#define Addr 0x68
int raw_adc = 0;
void setup()
{
// Set variable
Particle.variable("i2cdevice", "MCP3428");
Particle.variable("rawADC", raw_adc);
// Initialise I2C communication as MASTER
This file has been truncated. show original
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
jacob
August 27, 2018, 3:01pm
2
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
jacob
August 28, 2018, 2:59pm
6
michaelas:
MCP3428_SAMPLE_16_BIT
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.