Read MSEGQ7 with ESP32 (Read 5v from a 3.3v input)

ESP-LED
Posts: 3
Joined: Thu Mar 21, 2024 3:27 pm

Read MSEGQ7 with ESP32 (Read 5v from a 3.3v input)

Postby ESP-LED » Thu Mar 21, 2024 5:47 pm

I'm trying to read the output of MSEGQ7 (DfRobot) from an ESP32.

I have done 2 tests:

Arduino Mega (works):
- Analog input 0-5v
- 10 bits (0-1023)

ESP32 (not working):
- Analog input 0-3.3v
- 12 bits (0-4095)

Comparative video on YouTube https://youtu.be/1cE5tiCEpbg


As explained here https://github.com/G6EJD/ESP32-ADC-Accu ... n/issues/3 I have used a voltage divider (R1 = 1700 ohm, R2 = 3300 ohm) and I convert the 5v into 3.3v , but something doesn't work.

The values that I recover in ESP32 are very low:
0,243,12,44,190,167,0
0.242.0.0.204.74.0
0,153,114,207,250,242,0
0.75,12,140,237,231.0
0,0,34,128,149,154,0
0,0,63,45,69,76,0
0,0,0,0,9,21,0
0,0,0,0,0,0,0
0.252,19,0,199,179,0

The first and last columns are almost always worth 0

The code I run for the 2 tests is the same. I guess I have to do something like

Code: Select all

map(value,0.4095,0.1023); //12 bits to 10 bits
but the values that I recover in ESP32 are very low


My Loop()

Code: Select all

Audio.ReadFreq(FreqVal);//return 7 value of 7 bands pass filiter
 //Frequency(Hz):63 160 400 1K 2.5K 6.25K 16K
 //FreqVal[]: 0 1 2 3 4 5 6
 for(int i=0;i<7;i++) {
  Serial.print(max((FreqVal[i]-100),0));
  if(i<6) Serial.print(",");
  else Serial.println();
 }
 
 paintColumns();

lbernstone
Posts: 826
Joined: Mon Jul 22, 2019 3:20 pm

Re: Read MSEGQ7 with ESP32 (Read 5v from a 3.3v input)

Postby lbernstone » Fri Mar 22, 2024 3:01 am

First, hook a multimeter up to your voltage divider and make sure it is reading in the range you want. I would actually recommend taking it down so that the very top of your range is 1V (maybe 10K and 2K7) so you can use the lowest attenuation on the ESP32, which will have the best accuracy.
arduino-esp32 will provide a calibrated millivolt reading for you. You can manually map it, you should just be able to multiply by your divider level to get back to the original voltage.

Code: Select all

analogSetAttenuation(ADC_0db);
uint32_t readV = analogReadMilliVolts(GPIO_NUM_4) * 5 / 1.063; // 10K/2K7 divider

Who is online

Users browsing this forum: No registered users and 28 guests