Pomiar napięcia na ogniwie 18650 Zamek Serwo

Manta
Posts: 7
Joined: Mon Feb 26, 2024 5:43 pm

Post

Wydrukowałem nakładkę na wkładkę zamka wykorzystując serwo jako mechanizm otwierania i zamykania zamka, jako zasilanie użyłem 2 ogniw 18650 , wykorzystałem szkic sterujący serwem "nie mogę znaleźć teraz tematu"

Code: Select all

#define STATUS_LED_GPIO 2 // status diody led
#define BUTTON_CFG_RELAY_GPIO 4 //przycisk zał/wył
#define SERVO_PIN 3  // pin serwa

#include <SuplaDevice.h>
#include <supla/network/client.h>
#include <supla/network/esp_wifi.h>
#include <supla/control/virtual_relay.h>
#include <supla/control/button.h>
#include <supla/device/status_led.h>
#include <supla/storage/littlefs_config.h>
#include <supla/network/esp_web_server.h>
#include <supla/device/supla_ca_cert.h>
#include <supla/network/html/device_info.h>
#include <supla/network/html/protocol_parameters.h>
#include <supla/network/html/status_led_parameters.h>
#include <supla/network/html/wifi_parameters.h>
#include <supla/network/html/custom_parameter.h>
#include <supla/network/html/custom_text_parameter.h>
#include <supla/storage/eeprom.h>
#include <Servo.h>
Servo myservo;

#include <supla/sensor/virtual_binary.h>
Supla::Sensor::VirtualBinary *v_sensor = nullptr;

Supla::Eeprom eeprom;
Supla::ESPWifi wifi;
Supla::EspWebServer suplaServer;
Supla::LittleFsConfig configSupla;
Supla::Device::StatusLed statusLed(STATUS_LED_GPIO, false); 

int servoPosition = 0;
enum default_actions {
  SET_SERVO_POSITION
};

class customIterate : public Supla::Element {
 public: customIterate() {}
 
  void iterateAlways() {
    if (Supla::Network::IsReady()) {
      if (myservo.read() == 0 && v_sensor->getValue() == HIGH) {
        v_sensor->handleAction(0, Supla::CLEAR);
      }
      if (myservo.read() == 180 && v_sensor->getValue() == LOW) {
        v_sensor->handleAction(0, Supla::SET);
      }
    }
  }
};
customIterate *custIterate = new customIterate;

class addedActionsClass : public Supla::ActionHandler, public Supla::Element {
 public: addedActionsClass() {}
  void handleAction(int event, int action) {
    if (action == SET_SERVO_POSITION) {
      if (myservo.read() == 0) {
        servoPosition = 180;
      } else if (myservo.read() == 180) {
        servoPosition = 0;
      }
      myservo.write(servoPosition);
      SUPLA_LOG_DEBUG("# setting up servo position - %d", servoPosition);
    }
  }
};
addedActionsClass *custAct = new addedActionsClass;

void setup() {

  Serial.begin(115200);

  myservo.attach(SERVO_PIN);
  myservo.write(servoPosition);
  
  auto v_relay = new Supla::Control::VirtualRelay();
  v_relay->addAction(SET_SERVO_POSITION, custAct, Supla::ON_TURN_ON);
  v_sensor = new Supla::Sensor::VirtualBinary();
  v_sensor->handleAction(0, Supla::CLEAR);
  auto buttonCfgRelay =
    new Supla::Control::Button(BUTTON_CFG_RELAY_GPIO, true, true);
  buttonCfgRelay->configureAsConfigButton(&SuplaDevice);
  buttonCfgRelay->addAction(SET_SERVO_POSITION, custAct, Supla::ON_CLICK_1);

  SuplaDevice.setSuplaCACert(suplaCACert);
  SuplaDevice.setSupla3rdPartyCACert(supla3rdCACert);
  
  new Supla::Html::DeviceInfo(&SuplaDevice);
  new Supla::Html::WifiParameters;
  new Supla::Html::ProtocolParameters;
  new Supla::Html::StatusLedParameters;
  
  SuplaDevice.setName("SERVO");
  SuplaDevice.begin();
  SuplaDevice.getSrpcLayer()->client->setDebugLogs(false);

};

void loop() {
  SuplaDevice.iterate();
};



działa to wyśmienicie , do szczęścia brakuje mi pomiaru ogniw , siedzę już dłuższa chwile nad tematem ale nic mi nie wychodzi .
Chciałbym prosić dobrą duszyczkę o dopisanie kodu z pomiarem napięcia dla ogniw zasilających urządzenie ,zakres to 2.7-4.2V. Docelowo urządzenie ma pracować na ESP12-E obecnie Wemos D1. Powiadomienie o niskim stanie akumulatorków dodam z cloud_a "chyba 8-) "
User avatar
veeroos
Posts: 1081
Joined: Sun Mar 20, 2022 9:30 am
Location: Głogów
Has thanked: 1 time
Been thanked: 9 times

Post

Hej. Jak chcesz mierzyć taki zakres to pierwsze to musisz zrobić sobie dzielnik napięcia, esp-12 ma napięcie wejściowe 1V, musisz zastosować dzielnik, na przykład 470k/100k. Napięcie chcesz mieć wyświetlane jako kolejny kanał i napięcie w V, czy jako wartość procentowa i na przykład pod ikoną "i", pod tą ikonę nie wstawisz (chyba) wartości wyrażonej w Voltach.
Zamel Mew-01, Zamel PEW-01, Zamel SBW-01, Zamel THW-01, Zamel SRW-01, Zamel mSLW-02, Auraton BOX + Indor Sensor, Airly Gate By Veeroos, Zigbee to Supla Gateway + sensors, Zamel SGW-01 and more

https://github.com/v33r005
[email protected]
Posts: 1585
Joined: Mon Feb 06, 2023 8:56 am
Has thanked: 18 times
Been thanked: 26 times

Post

*dzielnik napięcia jest również jego odbiornikiem i bateria zdechnie 2x szybciej jak go użyjesz
User avatar
veeroos
Posts: 1081
Joined: Sun Mar 20, 2022 9:30 am
Location: Głogów
Has thanked: 1 time
Been thanked: 9 times

Post

[email protected] wrote: Wed Apr 24, 2024 3:59 am *dzielnik napięcia jest również jego odbiornikiem i bateria zdechnie 2x szybciej jak go użyjesz
Dzielnik napięcia który podałem pobiera około 8uA prądu, więc tak naprawdę znikomo, to już więcej może Ci pobrać stabilizator 😉, nie mówiąc, że jak chcemy układ użyć do zamka, to ESP8266 będzie cały czas włączony i pobierał będzie około 70mA ;) .
Zamel Mew-01, Zamel PEW-01, Zamel SBW-01, Zamel THW-01, Zamel SRW-01, Zamel mSLW-02, Auraton BOX + Indor Sensor, Airly Gate By Veeroos, Zigbee to Supla Gateway + sensors, Zamel SGW-01 and more

https://github.com/v33r005
User avatar
veeroos
Posts: 1081
Joined: Sun Mar 20, 2022 9:30 am
Location: Głogów
Has thanked: 1 time
Been thanked: 9 times

Post

No dobra. Umieszczę tu kawałek kodu, który sam używam, zmodyfikowany pod Ciebie, umieszczam informację o stanie baterii pod ikoną "i"

najpierw musisz dodać taki kod:

Code: Select all

Supla::Control::VirtualRelay *v_relay = nullptr;
Następnie tworzysz klasę, która wartość pomiarową przelicza na zakres 0-100% i wpisuje pod ikonę "i" przy włączniku wirtualnym jako pomiar baterii.

Code: Select all

class myElement : public Supla::Element {
 public: myElement(int pin) : pin(pin) {}
  
  void onInit() override {
    //pinMode(pin, INPUT);
  }
  
  double getValue() {
    value = (map(analogRead(pin), 400,785,0,100));
    return value;
  }

  void iterateAlways() override {
    if (millis() - lastReadTime > 2000) {
      lastReadTime = millis();
      v_relay->getChannel()->setBatteryLevel(getValue());
    }
  }
 protected:
  int pin;
  double value;
  uint64_t lastReadTime = 0;
};
myElement *c_analog = nullptr;
w setupie:

Code: Select all

v_relay = new Supla::Control::VirtualRelay();
c_analog = new myElement(A0);
v_relay->getChannel()->setFlag(SUPLA_CHANNEL_FLAG_CHANNELSTATE);
v_relay->getChannel()->setFlag(SUPLA_CHANNELSTATE_FIELD_BATTERYPOWERED);
v_relay->getChannel()->setFlag(SUPLA_CHANNELSTATE_FIELD_BATTERYLEVEL);
Czyli Twój kod będzie wyglądał dokładnie tak:

Code: Select all

#define STATUS_LED_GPIO 2 // status diody led
#define BUTTON_CFG_RELAY_GPIO 4 //przycisk zał/wył
#define SERVO_PIN 3  // pin serwa

#include <SuplaDevice.h>
#include <supla/network/client.h>
#include <supla/network/esp_wifi.h>
#include <supla/control/virtual_relay.h>
#include <supla/control/button.h>
#include <supla/device/status_led.h>
#include <supla/storage/littlefs_config.h>
#include <supla/network/esp_web_server.h>
#include <supla/device/supla_ca_cert.h>
#include <supla/network/html/device_info.h>
#include <supla/network/html/protocol_parameters.h>
#include <supla/network/html/status_led_parameters.h>
#include <supla/network/html/wifi_parameters.h>
#include <supla/network/html/custom_parameter.h>
#include <supla/network/html/custom_text_parameter.h>
#include <supla/storage/eeprom.h>
#include <Servo.h>
Servo myservo;

#include <supla/sensor/virtual_binary.h>
Supla::Sensor::VirtualBinary *v_sensor = nullptr;

Supla::Eeprom eeprom;
Supla::ESPWifi wifi;
Supla::EspWebServer suplaServer;
Supla::LittleFsConfig configSupla;
Supla::Device::StatusLed statusLed(STATUS_LED_GPIO, false); 
Supla::Control::VirtualRelay *v_relay = nullptr;

int servoPosition = 0;
enum default_actions {
  SET_SERVO_POSITION
};

class customIterate : public Supla::Element {
 public: customIterate() {}
 
  void iterateAlways() {
    if (Supla::Network::IsReady()) {
      if (myservo.read() == 0 && v_sensor->getValue() == HIGH) {
        v_sensor->handleAction(0, Supla::CLEAR);
      }
      if (myservo.read() == 180 && v_sensor->getValue() == LOW) {
        v_sensor->handleAction(0, Supla::SET);
      }
    }
  }
};
customIterate *custIterate = new customIterate;

class addedActionsClass : public Supla::ActionHandler, public Supla::Element {
 public: addedActionsClass() {}
  void handleAction(int event, int action) {
    if (action == SET_SERVO_POSITION) {
      if (myservo.read() == 0) {
        servoPosition = 180;
      } else if (myservo.read() == 180) {
        servoPosition = 0;
      }
      myservo.write(servoPosition);
      SUPLA_LOG_DEBUG("# setting up servo position - %d", servoPosition);
    }
  }
};
addedActionsClass *custAct = new addedActionsClass;
class myElement : public Supla::Element {
 public: myElement(int pin) : pin(pin) {}
  
  void onInit() override {
    //pinMode(pin, INPUT);
  }
  
  double getValue() {
    value = (map(analogRead(pin), 400,785,0,100));
    return value;
  }

  void iterateAlways() override {
    if (millis() - lastReadTime > 2000) {
      lastReadTime = millis();
      v_relay->getChannel()->setBatteryLevel(getValue());
    }
  }
 protected:
  int pin;
  double value;
  uint64_t lastReadTime = 0;
};
myElement *c_analog = nullptr;

void setup() {

  Serial.begin(115200);

  myservo.attach(SERVO_PIN);
  myservo.write(servoPosition);
  
  v_relay = new Supla::Control::VirtualRelay();
  c_analog = new myElement(A0);
  v_relay->getChannel()->setFlag(SUPLA_CHANNEL_FLAG_CHANNELSTATE);
  v_relay->getChannel()->setFlag(SUPLA_CHANNELSTATE_FIELD_BATTERYPOWERED);
  v_relay->getChannel()->setFlag(SUPLA_CHANNELSTATE_FIELD_BATTERYLEVEL);;
  v_relay->addAction(SET_SERVO_POSITION, custAct, Supla::ON_TURN_ON);
  v_sensor = new Supla::Sensor::VirtualBinary();
  v_sensor->handleAction(0, Supla::CLEAR);
  auto buttonCfgRelay =
    new Supla::Control::Button(BUTTON_CFG_RELAY_GPIO, true, true);
  buttonCfgRelay->configureAsConfigButton(&SuplaDevice);
  buttonCfgRelay->addAction(SET_SERVO_POSITION, custAct, Supla::ON_CLICK_1);

  SuplaDevice.setSuplaCACert(suplaCACert);
  SuplaDevice.setSupla3rdPartyCACert(supla3rdCACert);
  
  new Supla::Html::DeviceInfo(&SuplaDevice);
  new Supla::Html::WifiParameters;
  new Supla::Html::ProtocolParameters;
  new Supla::Html::StatusLedParameters;
  
  SuplaDevice.setName("SERVO");
  SuplaDevice.begin();
  SuplaDevice.getSrpcLayer()->client->setDebugLogs(false);

};

void loop() {
  SuplaDevice.iterate();
};
sprawdź czy działa, ewentualnie zmień przelicznik. Program się kompiluje, ale nie sprawdzałem czy działa, bo nie mam na czym ;-).
Zamel Mew-01, Zamel PEW-01, Zamel SBW-01, Zamel THW-01, Zamel SRW-01, Zamel mSLW-02, Auraton BOX + Indor Sensor, Airly Gate By Veeroos, Zigbee to Supla Gateway + sensors, Zamel SGW-01 and more

https://github.com/v33r005
[email protected]
Posts: 1585
Joined: Mon Feb 06, 2023 8:56 am
Has thanked: 18 times
Been thanked: 26 times

Post

veeroos wrote: Wed Apr 24, 2024 5:37 am
[email protected] wrote: Wed Apr 24, 2024 3:59 am *dzielnik napięcia jest również jego odbiornikiem i bateria zdechnie 2x szybciej jak go użyjesz
Dzielnik napięcia który podałem pobiera około 8uA prądu, więc tak naprawdę znikomo, to już więcej może Ci pobrać stabilizator 😉, nie mówiąc, że jak chcemy układ użyć do zamka, to ESP8266 będzie cały czas włączony i pobierał będzie około 70mA ;) .
Nie będę się wymądrzał bo z elektroniki jestem cienki, ale ja miałem odwrotne obserwacje, mam stację pogodową, która na 2x18650 wytrzymywała koło doby - absolutnie bez żadnych optymalizacji - to dołożyłem sobie dzielnik chyba 100/4,7k Ohma i po kilku godzinach zdychało
User avatar
veeroos
Posts: 1081
Joined: Sun Mar 20, 2022 9:30 am
Location: Głogów
Has thanked: 1 time
Been thanked: 9 times

Post

no wlaśnie to dlatego, że miałeś niskie wartości rezystancji, ja używam tego dzielnika do moich czujników zasilanych bateryjnie i chodzi to naprawdę dobrze. ja też nie chcę się wymądrzać, poprostu robiłem testy i pomiary. Oryginalnie w wemosie mini, w Node MCU jest dzielnik 220k/100K i wtedy jest pomiar do 3,3V, jak chcesz większy zakres, to dokładasz pierwszy rezystor o większej wartości, dlatego ja dałem 470K. Daj do stacji pogodowej stabilizator HT7333 on ma pobór prądu w granicach pojedynczych uA, LM1117 ma w granicach paru mA.
Zamel Mew-01, Zamel PEW-01, Zamel SBW-01, Zamel THW-01, Zamel SRW-01, Zamel mSLW-02, Auraton BOX + Indor Sensor, Airly Gate By Veeroos, Zigbee to Supla Gateway + sensors, Zamel SGW-01 and more

https://github.com/v33r005
[email protected]
Posts: 1585
Joined: Mon Feb 06, 2023 8:56 am
Has thanked: 18 times
Been thanked: 26 times

Post

veeroos wrote: Wed Apr 24, 2024 6:24 am no wlaśnie to dlatego, że miałeś niskie wartości rezystancji, ja używam tego dzielnika do moich czujników zasilanych bateryjnie i chodzi to naprawdę dobrze. ja też nie chcę się wymądrzać, poprostu robiłem testy i pomiary. Oryginalnie w wemosie mini, w Node MCU jest dzielnik 220k/100K i wtedy jest pomiar do 3,3V, jak chcesz większy zakres, to dokładasz pierwszy rezystor o większej wartości, dlatego ja dałem 470K. Daj do stacji pogodowej stabilizator HT7333 on ma pobór prądu w granicach pojedynczych uA, LM1117 ma w granicach paru mA.
no to wyjaśniłeś :D dzięki! bo ja wziąłem pierwsze dwa które dawały dobre proporcje, ale mogę dać większe o tych samych proporcjach jeśli to zmienia pobór :D

Generalnie to nie zamierzam się z tym bawić, stacja zaraz ponownie zawiśnie na garażu gdzie sobie zrobię gniazdko wewnątrz :P
User avatar
veeroos
Posts: 1081
Joined: Sun Mar 20, 2022 9:30 am
Location: Głogów
Has thanked: 1 time
Been thanked: 9 times

Post

Pewnie że możesz dać większe 😉, nie powinno to robić większego problemu, ale w sumie tak jak piszesz, jak będziesz miał stałe zasilanie układu to nie ma co kombinować jak coś działa, no chyba że chcesz mieć to na przykład bardziej uniwersalne, to zwiększ rezystancję i będzie po problemie 😉.
Zamel Mew-01, Zamel PEW-01, Zamel SBW-01, Zamel THW-01, Zamel SRW-01, Zamel mSLW-02, Auraton BOX + Indor Sensor, Airly Gate By Veeroos, Zigbee to Supla Gateway + sensors, Zamel SGW-01 and more

https://github.com/v33r005
Zibi
Posts: 646
Joined: Wed Jul 31, 2019 9:20 am
Location: Białogard

Post

[email protected] wrote: Wed Apr 24, 2024 3:59 am *dzielnik napięcia jest również jego odbiornikiem i bateria zdechnie 2x szybciej jak go użyjesz
Dlatego wystarczy dodać do układu procek za 7zl np Attiny serii 2, ktory zajmuje tyle miejsca co nic, pobiera 100nA i mierzyć w trybie akumulacji i nie bawić się w żadne dzielniki.
Poza tym dokładność przetwornika Attiny jest mega dokładniejsza i stabilna w trybi akumulacji do 17 bitów. Pomiary są bardzo stabilne i dokładne niż przetwornika ESP, który jest bardzo chwiejny i mało dokładny.

Return to “Pomoc”