Torxgewinde / Firebeetle-2-ESP32-E

Using the Firebeetle ESP32-E as battery powered sensor (SKU:DFR0654-F)
GNU General Public License v2.0
57 stars 2 forks source link

Firebeetle (1) Version 4 #3

Closed Stefan774 closed 1 year ago

Stefan774 commented 1 year ago

Hi I tried your code with my Firebeetle esp32 board but it does not work. I noticed that you used the Firebeetle 2. Is it possible to add support vor Firebeetle (v1) as well? Or is HW missing?

Here is the board I'm using https://eckstein-shop.de/DFRobotFireBeetleESP32IOTMicrocontrollerSupportsWi-Fi26amp3BBluetoothEN

Thanks in advance

Torxgewinde commented 1 year ago

Hello Stefan, The sketch in its current state is quite specific to the Firebeetle-2, but in general it should be doable to adjust it to also work with the predecessor. Certainly the GPIOs and internal peripheral names need to be checked and adjusted.

There is a schematic for Firebeetle v1 at https://raw.githubusercontent.com/DFRobot/Wiki/master/DFR0478/%5BDFR0478%5DFireBeetle%20Board-ESP32(V4.0)%E7%94%9F%E4%BA%A7%E6%A3%80%E6%9F%A5%E5%9B%BE.PDF

If you write "does not work", can you be more precise? Does it generate no output at all or can you paste the serial output after powering the Firebeetle v1 up? Can you please post the output of the serial console?

Torxgewinde commented 1 year ago

Hey Stefan, I am closing this for being stale. Please let me know if this is to be reopened.

Stefan774 commented 1 year ago

Hi Sorry had no time to reproduce the output and past it here. It showed an static value which seems not to represent the bat voltage. I think the v1 is missing the built in voltage defider. So add HW is needed? But dont know

Torxgewinde commented 1 year ago

No worries, all good. The v1 seems to have the voltage divider as well and it seems to be connected to A0. The schematic actually shows this: Bildschirmfoto_2022-11-21_21-37-44

If you find the time, can you please paste the output? Perhaps it gives some better insight.

For the Firebeetle v1 the Pin A0 is connected to another GPIO, it should be GPIO 36: Bildschirmfoto_2022-11-21_21-45-52

According to the Espressif SDK documentation that corresponds to another ADC-Channel (see: https://docs.espressif.com/projects/esp-idf/en/v4.1.1/api-reference/peripherals/adc.html#_CPPv414ADC1_CHANNEL_0): ADC1_CHANNEL_0 Considering this, the function to read the battery might work if changed as follows:

/******************************************************************************
Description.: reads the battery voltage through the voltage divider at GPIO36 for v1
              if the ESP32-E has calibration eFused those will be used.
              In comparison with a regular voltmeter the values of ESP32 and
              multimeter differ only about 0.05V
Input Value.: -
Return Value: battery voltage in volts
******************************************************************************/
float readBattery() {
  uint32_t value = 0;
  int rounds = 11;
  esp_adc_cal_characteristics_t adc_chars;

  //battery voltage divided by 2 can be measured at GPIO36, which equals ADC1_CHANNEL0 for v1
  adc1_config_width(ADC_WIDTH_BIT_12);
  adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_DB_11);
  switch(esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12, 1100, &adc_chars)) {
    case ESP_ADC_CAL_VAL_EFUSE_TP:
      Serial.println("Characterized using Two Point Value");
      break;
    case ESP_ADC_CAL_VAL_EFUSE_VREF:
      Serial.printf("Characterized using eFuse Vref (%d mV)\r\n", adc_chars.vref);
      break;
    default:
      Serial.printf("Characterized using Default Vref (%d mV)\r\n", 1100);
  }

  //to avoid noise, sample the pin several times and average the result
  for(int i=1; i<=rounds; i++) {
    value += adc1_get_raw(ADC1_CHANNEL_0);
  }
  value /= (uint32_t)rounds;

  //due to the voltage divider (1M+1M) values must be multiplied by 2
  //and convert mV to V
  return esp_adc_cal_raw_to_voltage(value, &adc_chars)*2.0/1000.0;
}

Can you please give it a try and also paste the output with the changed function?

tomkeuper commented 1 year ago

I also have a Firebeetle ESP32 V4.0 and I wanted to get the battery voltage but using the readBattery function you sent here its giving me a voltage of 0.284000 but it fluctuates quite a bit to 0.754, 0.688 etc quite far from the exptected 3 Volts. I connected the battery through the Li-ion connector and all my script is doing atm is sending some sensor data over MQTT.

Could it be some calculation issue?

Its also saying: Characterized using eFuse Vref (1072 mV) This seems quite low imo

EDIT: I saw some poeple complaining about missing zero Ohm resistors on the ESP. causing the potential divider not to work. Cant really find much info about it tho...