Plugin_153 MAX44009, anyone got it working ?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Plugin_153 MAX44009, anyone got it working ?

#1 Post by costo » 23 Dec 2017, 17:19

I have a GY-49 module , it has a MAX44009 lux sensor. I found playground plugin_0153 and gave it a try.
So compiled ESPEasy 148 with plugin153. But the sensor does not show_up in the device list.
Did someone succesfully use this sensor in ESPEasy?

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Plugin_153 MAX44009, anyone got it working ?

#2 Post by grovkillen » 23 Dec 2017, 19:16

Please make sure that the plugin is not #def as testing or development.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Re: Plugin_153 MAX44009, anyone got it working ?

#3 Post by costo » 23 Dec 2017, 21:36

@grovkillen
tnx for the suggestion.

I removed at beginning the line:
#ifdef PLUGIN_BUILD_TESTING
and on the end of plugin the line
#endif

Apparently the plugin was ignored at first, now I get some compile errors like:

Code: Select all

_P153_MAX44009.ino: In function 'boolean Plugin_153(byte, EventStruct*, String&)':
_P153_MAX44009:130: error: 'addFormSelector' was not declared in this scope
_P153_MAX44009:158: error: 'getFormItemInt' was not declared in this scope
I will see if I can fix the errors.

User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Re: Plugin_153 MAX44009, anyone got it working ?

#4 Post by costo » 26 Dec 2017, 14:35

Since a few days plugin 153 basically works for me in ESPEasy148.

To get rid of these 2 compile errors:
'addFormSelector' was not declared in this scope
'getFormItemInt' was not declared in this scope

I had to comment out these 6 lines

Code: Select all

In case PLUGIN_WEBFORM_LOAD
 addFormSelector(string, F("Mode"), F("plugin_153_mode"), 3, options, optionValues, choice_mode)
 addFormSelector(string, F("Current Division Ratio"), F("plugin_153_divide"), 2, options, optionValues, choice_division);
 addFormSelector(string, F("Integration Time"), F("plugin_153_time"), 8, options, optionValues, choice_time);

and in case PLUGIN_WEBFORM_SAVE:
 Settings.TaskDevicePluginConfig[event->TaskIndex][0] = getFormItemInt(F("plugin_153_mode"));
 Settings.TaskDevicePluginConfig[event->TaskIndex][1] = getFormItemInt(F("plugin_153_divide"));
 Settings.TaskDevicePluginConfig[event->TaskIndex][2] = getFormItemInt(F("plugin_153_time"));
wihout these lines the plugin basically works, gives me the lux value with 22bit definition, much better than a BH1750 sensor.
Apparently because I removed the 6 lines from the WEBFORM LOAD/SAVE part, the "Optional Settings" form in the device tab does not function anymore. I cannot use the "Formula Lux" because what is put there is not processed or saved.
Which is sad, because I would like to put there something like %value%^0.1 so that the values communicated to my RaspberryPi based Domoticz server are displayed logarithmic, just like the eye is logarithmic.

I am not used to programming with plugins, so I am not sure how to fix this.
Any clues would be appriciated a lot.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Plugin_153 MAX44009, anyone got it working ?

#5 Post by TD-er » 28 Dec 2017, 11:40

Why stick to the build 148, when you can also use the 2.0 dev series, or even the Mega branch?

User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Re: Plugin_153 MAX44009, anyone got it working ?

#6 Post by costo » 30 Dec 2017, 00:29

TD-er wrote: 28 Dec 2017, 11:40 Why stick to the build 148, when you can also use the 2.0 dev series, or even the Mega branch?
I will try that asap.
Maybe the errors will disappear then.

User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Re: Plugin_153 MAX44009, anyone got it working ?

#7 Post by costo » 30 Dec 2017, 14:17

I tested the MAX44009 plugin in dev2.0 but ...
No difference, same 6 errors as with the old version 148.
There are some omissions somewhere in the sketch or the plugin. I think i must declare the string variables somewhere somehow.
I was hoping someone who has written a plugin before could see the solution and explain what needs to be changed/added.

User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Re: Plugin_153 MAX44009, anyone got it working ?

#8 Post by costo » 30 Dec 2017, 14:57

Tested dev 2.0 again with this MAX44009 plugin, but now with the latest sources from github, also latest libraries.

The compile errors disappeared :P

But . . . . . . . still cannot edit the formula field, everything entered there disappears after clicking "submit" , so it is not saved.

User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Re: Plugin_153 MAX44009, anyone got it working ?

#9 Post by costo » 30 Dec 2017, 19:34

Finally solved it.
The solution was in this post viewtopic.php?f=6&t=3689&p=20157&hilit=formula#p20157

The problem was not in the software nor in the plugin. It was the ESP8266 2.4.0.rc2 core.
When I used the 2.4.0.rc1 core I could save my optional settings agian. :P

Yeah, it took some time to find it out. :(

data
Normal user
Posts: 93
Joined: 10 Dec 2016, 11:26

Re: Plugin_153 MAX44009, anyone got it working ?

#10 Post by data » 30 Mar 2018, 19:15

Any idea, when Plugin #153 / support for MAX44009 will be added to the release?

danilodb
New user
Posts: 1
Joined: 07 Feb 2019, 12:46

Re: Plugin_153 MAX44009, anyone got it working ?

#11 Post by danilodb » 07 Feb 2019, 12:51

Hi everyone! Sorry to revamp an old thread, but this seems to be the only one concerning MAX44009 (plugin153).

I have updated firmware on my ESP8266 and found that this plugin is not yet there (ESPEasy Mega dev).

Has anybody any new about this? I can't find it in offcial plugin list and seems just to be vanished.

Thanks for any help.

Domosapiens
Normal user
Posts: 307
Joined: 06 Nov 2016, 13:45

Re: Plugin_153 MAX44009, anyone got it working ?

#12 Post by Domosapiens » 07 Feb 2019, 22:31

Is part of the playground
https://github.com/letscontrolit/ESPEas ... Playground
So you have to add it to your own compilation.

You could request to add it to the mega here:
https://github.com/letscontrolit/ESPEas ... +is%3Aopen
This will help: http://ko-fi.com/GrovkillenTDer
30+ ESP units for production and test. Ranging from control of heating equipment, flow sensing, floor temp sensing, energy calculation, floor thermostat, water usage, to an interactive "fun box" for my grandson. Mainly Wemos D1.

rippi46
New user
Posts: 1
Joined: 17 Mar 2022, 15:58

Re: Plugin_153 MAX44009, anyone got it working ?

#13 Post by rippi46 » 17 Mar 2022, 16:11

Hallo

vielleicht gibt es ja schon eine Lösung und der Post ist ja auch schon sehr alt, aber ich hatte das gleiche Problem und habe das Plugin compiliert bekommen.

so sieht es jetzt aus:

Code: Select all

#include "_Plugin_Helper.h"

#ifdef USES_P153

//#######################################################################################################
//############################### Plugin 153: MAX44009 I2C 0x4A  #######################################
//#######################################################################################################

// based on :
// 1) https://github.com/RobTillaart/Arduino/tree/master/libraries/Max44009
// 2) https://github.com/dantudose/MAX44009/blob/master/MAX44009.cpp
//
// written by https://github.com/apszowski

#define PLUGIN_153
#define PLUGIN_ID_153 153
#define PLUGIN_NAME_153 "Light/Lux - MAX44009 (GY-49)"
#define PLUGIN_VALUENAME1_153 "Lux"

boolean Plugin_153_init = true;

enum {
  //I2C address
  MAX44009_I2C_ADDR                     = 0x4A,
  // CONFIGURATION
  MAX44009_REGISTER_CONFIGURATION       = 0x02,
  MAX44009_CFG_MANUAL                   = 0x40,
  MAX44009_CFG_CONTINUOUS               = 0x80,
  //LUX READING
  MAX44009_REGISTER_LUX_HIGH            = 0x03,
  MAX44009_REGISTER_LUX_LOW             = 0x04,
};


uint16_t Plugin_153_readRegister(uint8_t reg) {
  uint16_t ret;
  Wire.beginTransmission(MAX44009_I2C_ADDR);
  Wire.write(reg);
  Wire.endTransmission();
  Wire.requestFrom(MAX44009_I2C_ADDR,1);
  ret = Wire.read();
  return ret;
}

void Plugin_153_writeRegister(uint8_t reg, uint8_t value){
  Wire.beginTransmission(MAX44009_I2C_ADDR);
  Wire.write(reg);
  Wire.write(value);
  Wire.endTransmission();
}

float Plugin_153_readLux(void)
{
  uint8_t luxHigh = Plugin_153_readRegister(MAX44009_REGISTER_LUX_HIGH);
  uint8_t luxLow = Plugin_153_readRegister(MAX44009_REGISTER_LUX_LOW);
  uint8_t e = (luxHigh & 0xF0) >> 4;
  uint8_t m = (luxHigh & 0x0F) << 4 | luxLow;
  float lux = pow(2,e) * m * 0.045;
  return lux;
}
void Plugin_153_setModeAutomatic(void)
{
  uint8_t config = Plugin_153_readRegister(MAX44009_REGISTER_CONFIGURATION);
  config &= ~MAX44009_CFG_CONTINUOUS; // off
  config &= ~MAX44009_CFG_MANUAL;     // off
  Plugin_153_writeRegister(MAX44009_REGISTER_CONFIGURATION, config);
}

void Plugin_153_setModeContinuous(void)
{
  uint8_t config = Plugin_153_readRegister(MAX44009_REGISTER_CONFIGURATION);
  config |= MAX44009_CFG_CONTINUOUS; // on
  config &= ~MAX44009_CFG_MANUAL;    // off
  Plugin_153_writeRegister(MAX44009_REGISTER_CONFIGURATION, config);
}

void Plugin_153_setModeManual(uint8_t CDR, uint8_t TIM)
{
  uint8_t config = Plugin_153_readRegister(MAX44009_REGISTER_CONFIGURATION);
  config &= ~MAX44009_CFG_CONTINUOUS; // off
  config |= MAX44009_CFG_MANUAL;      // on
  config &= 0xF0; // clear CDR & TIM bits
  config |= CDR << 3 | TIM;
  Plugin_153_writeRegister(MAX44009_REGISTER_CONFIGURATION, config);
}

boolean Plugin_153(byte function, struct EventStruct *event, String& string)
{
  boolean success = false;
  switch (function)
  {
    case PLUGIN_DEVICE_ADD:
      {
        Device[++deviceCount].Number = PLUGIN_ID_153;
        Device[deviceCount].Type = DEVICE_TYPE_I2C;
        Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_SINGLE;
        Device[deviceCount].Ports = 0;
        Device[deviceCount].PullUpOption = false;
        Device[deviceCount].InverseLogicOption = false;
        Device[deviceCount].FormulaOption = true;
        Device[deviceCount].SendDataOption = true;
        Device[deviceCount].ValueCount = 1;
        Device[deviceCount].TimerOption = true;
        Device[deviceCount].GlobalSyncOption = true;
        break;
      }

    case PLUGIN_GET_DEVICENAME:
      {
        string = F(PLUGIN_NAME_153);
        break;
      }

    case PLUGIN_GET_DEVICEVALUENAMES:
      {
        strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_153));
        break;
      }

    case PLUGIN_WEBFORM_LOAD:
      {
        byte choice_mode = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
        String options[8];
        int optionValues[8];
        options[0] = F("Automatic");
        optionValues[0] = 0;
        options[1] = F("Continuous");
        optionValues[1] = 1;
        options[2] = F("Manual");
        optionValues[2] = 2;
        addFormSelector(F("Mode"), F("plugin_153_mode"), 3, options, optionValues, choice_mode);
        if( choice_mode != 0)
        {
          //########################
          byte choice_division = Settings.TaskDevicePluginConfig[event->TaskIndex][1];
          options[0] = F("Not divided");
          optionValues[0] = 0;
          options[1] = F("Divided 1/8");
          optionValues[1] = 1;
          addFormSelector(F("Current Division Ratio"), F("plugin_153_divide"), 2, options, optionValues, choice_division);
          //########################
          byte choice_time = Settings.TaskDevicePluginConfig[event->TaskIndex][2];
          float integration_time = 800;
          for( uint8_t i = 0 ; i <= 7 ; i++)
          {
            options[i] =  integration_time;
            options[i] += F(" ms");
            optionValues[i] = i;
            integration_time = integration_time/2.0;
          }
          addFormSelector(F("Integration Time"), F("plugin_153_time"), 8, options, optionValues, choice_time);
        }
        success = true;
        break;
      }

    case PLUGIN_WEBFORM_SAVE:
      {
        Settings.TaskDevicePluginConfig[event->TaskIndex][0] = getFormItemInt(F("plugin_153_mode"));
        Settings.TaskDevicePluginConfig[event->TaskIndex][1] = getFormItemInt(F("plugin_153_divide"));
        Settings.TaskDevicePluginConfig[event->TaskIndex][2] = getFormItemInt(F("plugin_153_time"));
        Plugin_153_init = false;
        success = true;
        break;
      }

    case PLUGIN_INIT:
      {
        Plugin_153_init = true;
        uint8_t mode = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
        uint8_t divide = Settings.TaskDevicePluginConfig[event->TaskIndex][1];
        uint8_t tim = Settings.TaskDevicePluginConfig[event->TaskIndex][2];

        String log = F("MAX44009  :\rINIT MODE = ");
        if( mode == 0)
        {
          Plugin_153_setModeAutomatic();
          log += F("Automatic");
        }
        else if ( mode == 1)
        {
          Plugin_153_setModeContinuous();
          log += F("Continuous");
        }
        else
        {
          Plugin_153_setModeManual(divide,tim);
          log += F("Manual , CDR = ");
          log += divide;
          log += F(", Integration Time = ");
          log += tim;
        }
        addLog(LOG_LEVEL_INFO,log);
        success = true;
        break;
      }

    case PLUGIN_READ:
      {
        UserVar[event->BaseVarIndex] = (float) Plugin_153_readLux();
        String log = F("MAX44009  : Ambient Light: ");
        log += UserVar[event->BaseVarIndex];
        addLog(LOG_LEVEL_INFO,log);
        success = true;
        break;
      }
  }
  return success;
}

#endif
Gruß rippi
Attachments
ESP_Easy_mega_20220317_custom_ESP8266_4M1M.bin.gz
(594.36 KiB) Downloaded 163 times

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Plugin_153 MAX44009, anyone got it working ?

#14 Post by Ath » 17 Mar 2022, 20:29

Hi rippi,

You are welcome to adopt the plugin for use in the regular ESPEasy builds, the procedure to obtain the next available plugin ID is described here on the Github repository (we like those plugin ID's sequentially).
In the documentation pages of ESPEasy, on ReadTheDocs, a description is available on how the development of a plugin (or adaptation of a PluginPlayground plugin) is done. You can find that page here. This is focused on development using VSCode & PlatformIO, as that's our preferred IDE, currently, On the same page, a few paragraphs up, you can find a guide on how to configure VSCode with PlatformIO, but you can in fact use any IDE/Editor you prefer, the basic principles are still the same.

NB: This plugin is not really up to date with the current standards for development with ESPEasy, but you will get some guidance during the pull request process ;)
/Ton (PayPal.me)

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 32 guests