Is it normal to have changes on analog readings on pin GPIO36, on an DOIT ESP32 DEVKIT V1?, I’m trying to connect a high current sensor, the sensor is an ACS758LCB-050B-PFF-T, from Allegro, also I was tried with a sensor ACS712, from Allegro too, both kind of sensors give the reading of zero Amps in the middle of the power supply, in both cases I’m using 5 volts, and just to come in to ESP32 a resistors divider with values of 10 Kohm to ground 5,1 Kohm to the output of the sensor, and the joint of both resistors goes to the analog input, the first is to take a measure without current in the sensor, you must subtract 2048 to the reading, and then you’ll have a reading other than zero, this is your offset, you must add it after change the sign, to get zero reading at zero current, and then scale the measure following the values on data sheet, or applying a known current and placing the right multiplier to get the desired value, well, once done all of this, I connect my phone, via legacy bluetooth, to get the readings, then you can see wrong values, at same time you could see on serial monitor how the read value changes, not changing at all in the external world, have you detected this?, do you have any way to solve it?, do you know the reason for it?, I’m here waiting for your valuable answers, and sending you thanks in advance for them.
Regards:
JMEC
Hi.
I haven’t experimented with those sensors myself.
Can you clarify something? Does the Serial Monitor show the right readings? But the phone doesn’t? That’s the real issue, right?
Regards,
Sara
Hi Sara, what I could see on serial monitor, it’s a value, a lot of readings with the read value, and this value continued on screen more or less stable, if at this stable situation I connect my phone using Bluetooth, I could see immediately, on serial monitor, a change, big change, on the value read from the analog output, the value from 0 to 4095, then of course the calculated value change, I was used a good brand digital multimeter, and I can see that the voltage remains unchanged when readings change at mobile phone connection, I can send you my sketch if you want to have a look, I tried to go a lot of things, for example define the analog input as digital input in order to use internal resistors, and not to have any floating voltage, I was trued to have lot of measures and take the average, but results unusable anyway
HI Sara, I’m at this same time writing Rui about same problem via Facebook, please let me know where to place pictures screen captures and so to show you the problem, now i’m repeating the tests using a potentiometer instead a sensor, and the behaviour is still the same, data is changing even if the potentiometer remains unchanged, and analog readed data drops around 30 units when you connect the phone, to do those latest tests I was mounted an electrolytic capacitor on supply, next to the potentiometer, and a 100nF capacitor between the potentiometer output and ground
Hi Jose.
To share images, you can use a link to Imgur, google drive, dropbox, or another service that is more suitable for you.
I guess that what is happening is that Bluetooth is interfering with the analog readings somehow.
Many of our readers reported issues with the ESP32 analog reading function. Maybe the Bluetooth needs a lot of “energy” to run, which messes up the analog readings.
Have you tried using other GPIOs to connect the analog sensor?
Regards,
Sara
Hi again , I was prepared a small web with all the description, conditions, file , scheme and so, the address is:
http://www.escrich-sanchez.com/20210219%20Problems%20on%20analog%20input%20of%20DOIT%20ESP32%20DEVKIT%20V1/
Same working absolutely stable and without problems on an Arduino Nano:
/* This small routine is to show how the current sensor ACS758LCB-050B-PFF-T,from Allegro works on an Arduino system,
* after suffer all kind of problems trying to use an ES32 analog input to do the same, when using bluetooth frame on it.
* Here you could see the sensor output absolutely stable, and how easy is to scale the analog readings, to obtain the real current value in Amperes
* some parts of this code, as the ones breaking the value in two bytes, could result strange for you, this is intended to send the measured value
* via I2C communication, to the ESP32 in charge of communications, to send the right measured value to a phone via Bluetooth
* Probably this sketch will be downloaded to an Attiny85, using one pin as analog input, and two more for I2C communication, two for power supply
* and one more to have the reset working
*
* Jose M. Escrich 20210220
*
*/
int ledPin = 13; // Onboard led output
int entradaPotenciometro = A0; // Potentiometer imput fot test purposes A0
int entradaCorrienteA = A2; // Input where the First sensor PCB output is connected, A2
int entradaCorrienteB = A3; // Input where the Second sensor PCB output is connected,, A2
int corrienteA; // First sensor PCB output
int corrienteB; // Second sensor PCB output
word original = 0; // Original value before to be broken in two bytes, to be sent via I2C
byte partes[2]; // Variable to hold both two bytes to be sent via I2C not yet implemented
float reconstituido = 0.000; // Variable to compose the original value again adding both bytes
float corriente = 0.000; // Digital value por readed current
float factor = 7.647058824; // factor to convert the measured data in real Amperes value
float corrienteReal = 0.000; // Real value of measured current in Amperes after subtract 512 to center the measure, because could be positive or negative, and be divided by factor
void setup() {
Serial.begin(9600);// Standard USB serial connector, this is Serial 0 or simply Serial
}
void loop() {
// original = analogRead(entradaPotenciometro);
original = analogRead(entradaCorrienteA);
corrienteA = analogRead(entradaCorrienteA);
corrienteB = analogRead(entradaCorrienteB);
partes[0] = highByte(original);
partes[1] = lowByte(original);
reconstituido = (partes[0] * 256) + partes[1];
corriente = reconstituido – 512;
corrienteReal = corriente / factor;
Serial.print (” Read value = “);
Serial.print (original);
Serial.print (“\t”); // Tab
Serial.print (” Bytes for I2C = “);
Serial.print (partes[0]);
Serial.print (” “); // Tab
Serial.print (partes[1]);
Serial.print (“\t”); // Tab
Serial.print (” two bytes toghether = “);
Serial.print (reconstituido);
Serial.print (“\t”); // Tab
Serial.print (” Both sensor outputs = “);
Serial.print (corrienteA);
Serial.print (” “); // Tab
Serial.print (corrienteB);
Serial.print (“\t”); // Tab
Serial.print (” Digital value minus 512 = “);
Serial.print (corriente);
Serial.print (“\t”); // Tab
Serial.print (” Amps measured value = “);
Serial.print (corrienteReal);
Serial.println (); // Carriage return + New line
} // End of loop
Hi Jose.
Thanks for sharing all your work in such a detailed way.
It is normal to see values slightly changing even when the potentiometer is not being touched. Here are some tips on how you can reduce the noise:
- https://forum.micropython.org/viewtopic.php?t=399#p2321
- https://www.norwegiancreations.com/2015/10/tutorial-potentiometers-with-arduino-and-filtering/
The values changing with the phone should be related to power consumption because of using Bluetooth.
So, your suggestion to use another board to read the values might be the best solution.
Regards,
Sara
Hi Sara, finally it was what I did, I was connected the sensor to the main computer board, and then I send the values via UART to the ESP32, doing on ESP the memorization of highest values, and the reset of it via Bluetooth, now is working.
Referring analog inputs on ESPs, I’m pretty sure about there should be a way to have reliable readings from analog inputs, I’ll continue investigating for it.
Thanks for your help.
Regards:
José M. Escrich