Hello,
I have been trying to read a typical PT100 4-20mA temperature sensor (-50 to 150c) with the 12 channel board and the ESP32. I am probably doing something terribly wrong here but I am seeing very large jumps between readings.
I made a quick loop just on one channel and that is when I noticed the huge swings. The sketch comes from an example I got off github from controleverything.
My concern isn’t the slapdash attempt to convert this to current or Celsius but the raw readings are all over the place. The signal I am getting is unusable in its current form. Is this something wrong with my hardware or am I doing something wrong here? The 4-20mA loop is currently working with an Industruino and has been rock solid for about a year now.
Output example;
Analog: 13487 Current: 9.30603 Temp: 16.32537
Analog: 13374 Current: 9.22806 Temp: 15.35075
Analog: 13088 Current: 9.03072 Temp: 12.88400
Analog: 12721 Current: 8.77749 Temp: 9.71863
Analog: 12530 Current: 8.64570 Temp: 8.07125
Analog: 12588 Current: 8.68572 Temp: 8.57150
Analog: 12905 Current: 8.90445 Temp: 11.30562
Analog: 13252 Current: 9.14388 Temp: 14.29850
Analog: 13516 Current: 9.32604 Temp: 16.57550
Analog: 13687 Current: 9.44403 Temp: 18.05038
Analog: 13791 Current: 9.51579 Temp: 18.94737
Analog: 13802 Current: 9.52338 Temp: 19.04225
Analog: 13747 Current: 9.48543 Temp: 18.56787
Analog: 13684 Current: 9.44196 Temp: 18.02450
Analog: 13614 Current: 9.39366 Temp: 17.42075
Analog: 13523 Current: 9.33087 Temp: 16.63587
Analog: 13477 Current: 9.29913 Temp: 16.23913
Analog: 13435 Current: 9.27015 Temp: 15.87687
Analog: 13349 Current: 9.21081 Temp: 15.13513
Analog: 13183 Current: 9.09627 Temp: 13.70337
Analog: 12938 Current: 8.92722 Temp: 11.59025
Analog: 12712 Current: 8.77128 Temp: 9.64100
Analog: 12570 Current: 8.67330 Temp: 8.41625
Arduino code below;
/****************************************************************************
/*
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 <MCP3428.h>
#include <Wire.h>
MCP3428 MCP(0x6F); // Declaration of MCP3428: A2, A1, A0 bits (000, 0x68)
void setup() {
// Start serial communication and set baud rate = 9600
Serial.begin(115200);
Serial.println(“MCP3428 Analog to Digital Converter”);
delay(500);
}
double mapf(double x, double in_min, double in_max, double out_min, double out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
void loop() {
MCP.SetConfiguration(1, 16, 1, 2);
// Note that the library waits for a complete conversion
long raw = MCP.readADC();
double current = raw * 0.00069;
double temp = mapf(current, 4.0, 20.0, -50.0, 150.0);
//double f = ((temp * 9.0 / 5.0) + 32.0);
// print results
Serial.print("Analog: “);
Serial.print(raw);
Serial.print(” Current: “);
Serial.print(current, 5);
Serial.print(” Temp: ");
Serial.println(temp, 5);
delay(1000);
}