Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. Battery percentage incorrectly send to gateway.

Battery percentage incorrectly send to gateway.

Scheduled Pinned Locked Moved Development
6 Posts 3 Posters 2.9k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pjeterinfo
    wrote on last edited by pjeterinfo
    #1

    I ordered a custom pcb with a ATMega328P and a dallas tempsensor , powered by 2AA batteries. Simular like http://forum.mysensors.org/topic/1107/sensors-in-boxes/7.

    I use allso the sketch as shown in that topic, however the battery status allways read 102%. I'm sure the batteries are not full.
    Can you point me in the right direction why my battery percentage is not send correctly?

    // Example sketch showing how to send in OneWire temperature readings
    #include <MySensor.h>
    #include <SPI.h>
    #include <DallasTemperature.h>
    #include <OneWire.h>

    #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected
    #define MAX_ATTACHED_DS18B20 16
    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature sensors(&oneWire);
    MySensor gw;
    float lastTemperature[MAX_ATTACHED_DS18B20];
    int numSensors=0;
    boolean receivedConfig = false;
    boolean metric = true;
    // Initialize temperature message
    MyMessage msg(0,V_TEMP);
    MyMessage msgvolt(1,V_VOLTAGE);
    int BATTERY_SENSE_PIN = A0;
    int oldBatteryPcnt = 0;

    void setup()
    {
    analogReference(INTERNAL);
    // Startup OneWire
    sensors.begin();

    // Startup and initialize MySensors library. Set callback for incoming messages.
    gw.begin();

    // Send the sketch version information to the gateway and Controller
    gw.sendSketchInfo("Temperature Sensor", "1.0");

    // Fetch the number of attached temperature sensors
    numSensors = sensors.getDeviceCount();

    // Present all sensors to controller
    for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
    gw.present(i, S_TEMP);
    }
    }

    void loop()
    {
    // Process incoming messages (like config from server)
    gw.process();

    // Fetch temperatures from Dallas sensors
    sensors.requestTemperatures();

    // Battery Monitoring
    int sensorValue = analogRead(BATTERY_SENSE_PIN);
    float batteryV = sensorValue * 0.003363075;
    int batteryPcnt = sensorValue / 10;

    Serial.print("Battery Voltage: ");
    Serial.print(batteryV);
    Serial.println(" V");

    Serial.print("Battery percent: ");
    Serial.print(batteryPcnt);
    Serial.println(" %");

    if (oldBatteryPcnt != batteryPcnt) {
    gw.send(msgvolt.set(batteryPcnt,1));
    oldBatteryPcnt = batteryPcnt;
    }
    // Read temperatures and send them to controller
    for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {

    // Fetch and round temperature to one decimal
    float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
    
    // Only send data if temperature has changed and no error
    if (lastTemperature[i] != temperature && temperature != -127.00) {
    
      // Send in the new temperature
      gw.send(msg.setSensor(i).set(temperature,1));
      lastTemperature[i]=temperature;
    }
    

    }
    gw.sleep(SLEEP_TIME);
    }

    1 Reply Last reply
    0
    • DwaltD Offline
      DwaltD Offline
      Dwalt
      wrote on last edited by
      #2

      I believe the sketch you linked was built for 2-AAA batteries, not 2-AA.

      Veralite UI5 :: IBoard Ethernet GW :: MyS 1.5

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pjeterinfo
        wrote on last edited by
        #3

        I tried just with 2 AAA batteries (used from a remotecontrol), again it shows 102%. :-(

        1 Reply Last reply
        0
        • sundberg84S Offline
          sundberg84S Offline
          sundberg84
          Hardware Contributor
          wrote on last edited by
          #4

          Did you wire the voltage divider like this? http://www.mysensors.org/build/battery or how does your wiring look like=?

          Controller: Proxmox VM - Home Assistant
          MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
          MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
          RFLink GW - Arduino Mega + RFLink Shield, 433mhz

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pjeterinfo
            wrote on last edited by pjeterinfo
            #5

            @sundberg84
            This is a screenshot of the schema. ( left out the top layer which is only used for the radio)

            Schermafbeelding 2015-08-25 om 19.29.43.png

            I tried the basic battery sensor sketch. I see that the sensor value is devided 10.
            Should this be default or can I calculate how the devider should be programmed?

            float batteryV = sensorValue * 0.003363075;
            int batteryPcnt = sensorValue / 10;

            end: 1-1-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=o x00x00send: 1-1-0-0 s=255,c=0,t=17,pt=0,l=3,sg=0,st=ok:1.5
            send: 1-1-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:0
            read: 0-0-1 s=255,c=3,t=6,pt=0,l=1,sg=0:M
            sensor started, id=1, parent=0, distance=1
            send: 1-1-0-0 s=255,c=3,t=11,pt=0,l=13,sg=0,st=ok:Battery Meter
            send: 1-1-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=ok:1.0
            1023
            Battery Voltage: 3.44 V
            Battery percent: 102 %
            send: 1-1-0-0 s=255,c=3,t=0,pt=1,l=1,sg=0,st=ok:102

            1 Reply Last reply
            0
            • P Offline
              P Offline
              pjeterinfo
              wrote on last edited by
              #6

              Ok... resistors are switched place , problem solved ;-) make a big difference offcource.

              send: 1-1-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:0
              read: 0-0-1 s=255,c=3,t=6,pt=0,l=1,sg=0:M
              sensor started, id=1, parent=0, distance=1
              send: 1-1-0-0 s=255,c=3,t=11,pt=0,l=13,sg=0,st=ok:Battery Meter
              send: 1-1-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=ok:1.0
              934
              Battery Voltage: 3.14 V
              Battery percent: 93 %
              send: 1-1-0-0 s=255,c=3,t=0,pt=1,l=1,sg=0,st=ok:93

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              16

              Online

              11.7k

              Users

              11.2k

              Topics

              113.0k

              Posts


              Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • MySensors
              • OpenHardware.io
              • Categories
              • Recent
              • Tags
              • Popular