Support for digital potentiometer

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
antibill
New user
Posts: 7
Joined: 13 Dec 2017, 16:55

Support for digital potentiometer

#1 Post by antibill » 13 Dec 2017, 17:10

----- EDIT : -----
I'have a working plugin but i need your help... See comments please .





Is it possible to implement support for a digital potentiometer, as mcp41010 for example?
There is a library here : https://github.com/mensink/arduino-lib-MCP42010
or example with spi.h only here : http://electroniqueamateur.blogspot.fr/ ... en-de.html

I need to have 2 mcp41010 or equivalent, on one ESP8266, with differents value on each. value between 0 and 255 and maybe saving last value in the eeprom and restoring at reboot?
Can anyone help me?

Sorry for my bad english.
Last edited by antibill on 28 Dec 2018, 20:30, edited 1 time in total.

antibill
New user
Posts: 7
Joined: 13 Dec 2017, 16:55

Re: Support for digital potentiometer

#2 Post by antibill » 21 Dec 2017, 14:35

Nobody can help me?

Drum
Normal user
Posts: 300
Joined: 07 Feb 2016, 11:56

Re: Support for digital potentiometer

#3 Post by Drum » 21 Dec 2017, 19:47

Your best bet is to try yourself. I don't know how well spi works at this point, I think there is at least one supported spi device but you would have to do some reading.

Most people tend to work on what devices they have. If it was I2C someone might be able to put something together without having to test, but probably not a good idea with spi. Also you are asking for a pretty substantial time investment as well.

Shardan
Normal user
Posts: 1156
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Re: Support for digital potentiometer

#4 Post by Shardan » 21 Dec 2017, 20:19

Indeed SPI might be a problem here.
But as far as i know there are several digital potentiometers on the market that run with I²C,
From Analog there is the AD5243 witch is a double potentiometer out of the box.
Analog offers the AD5171, equivalent is the CAT5171 by Onsemi. Both are single
potentiometers but have one adress line so two can be combined on I²C.
All types above have 256 taps.

You may use an existing I²C device plugin for starting to make your own plugin for digital potentiometer.

Regards
Shardan
Regards
Shardan

antibill
New user
Posts: 7
Joined: 13 Dec 2017, 16:55

Re: Support for digital potentiometer

#5 Post by antibill » 21 Dec 2017, 22:24

Thanks all, i will try again to build a plugin.

antibill
New user
Posts: 7
Joined: 13 Dec 2017, 16:55

Re: Support for digital potentiometer

#6 Post by antibill » 28 Dec 2018, 20:20

Hi.

I made a functional plugin, which corresponds to my expectations, except that ...
When I activate the plugin in device tab, I can not change the state of a GPIO anymore. I have to disable my plugin for it to work again ...

I'm using this Library : https://github.com/mensink/arduino-lib-MCP42010
Can you help me?

Thanks.
And sorry for my bad english...


My plugin is :

Code: Select all

//#######################################################################################################
//#################################### Plugin 151: MCP42010 ############################################
//#######################################################################################################
// written by antibill

// List of commands:
// (1) VAL1,<chambre 0-255>
// (2) VAL2,<second 0-255>

// Usage:
// (1): Set value to potentiometer (http://xx.xx.xx.xx/control?cmd=chambre,255)


#include <MCP42010.h>

static float Plugin_151_PotDest[2] = {0,0};

#define PLUGIN_151
#define PLUGIN_ID_151         151
#define PLUGIN_NAME_151       "MCP42010"
#define PLUGIN_VALUENAME1_151 "P1"
#define PLUGIN_VALUENAME2_151 "P2"

int Plugin_151_pin[3] = {-1,-1,-1};



boolean Plugin_151(byte function, struct EventStruct *event, String& string)
{
  boolean success = false;

  switch (function)
  {
    case PLUGIN_DEVICE_ADD:
      {
        Device[++deviceCount].Number = PLUGIN_ID_151;
        Device[deviceCount].Type = DEVICE_TYPE_DUMMY;           // SPI pins for ESP8266 are CS=15, CLK=14, MOSI=13
        Device[deviceCount].Ports = 0;
        Device[deviceCount].VType = SENSOR_TYPE_DUAL;
        Device[deviceCount].PullUpOption = false;
        Device[deviceCount].InverseLogicOption = false;
        Device[deviceCount].FormulaOption = true;
        Device[deviceCount].ValueCount = 2;
        Device[deviceCount].SendDataOption = true;
        Device[deviceCount].TimerOption = true;
        Device[deviceCount].TimerOptional = true;
        Device[deviceCount].GlobalSyncOption = true;
        break;
      }

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

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

    case PLUGIN_WEBFORM_LOAD:
      {
      //  char tmpString[128];

        addHtml(F("<TR><TD>GPIO:<TD>"));

        addHtml(F("<TR><TD>1st GPIO (CS):<TD>"));
        addPinSelect(false, "taskdevicepin1", Plugin_151_pin[0] = Settings.TaskDevicePluginConfig[event->TaskIndex][0]);
        addHtml(F("<TR><TD>2nd GPIO (CLK):<TD>"));
        addPinSelect(false, "taskdevicepin2", Plugin_151_pin[1] = Settings.TaskDevicePluginConfig[event->TaskIndex][1]);
        addHtml(F("<TR><TD>3rd GPIO (MOSI):<TD>"));
        addPinSelect(false, "taskdevicepin3", Plugin_151_pin[2] = Settings.TaskDevicePluginConfig[event->TaskIndex][2]);

        success = true;
        break;
      }

    case PLUGIN_WEBFORM_SAVE:
      {


        String plugin2 = WebServer.arg("taskdevicepin1");
        Settings.TaskDevicePluginConfig[event->TaskIndex][0] = plugin2.toInt();
        String plugin3 = WebServer.arg("taskdevicepin2");
        Settings.TaskDevicePluginConfig[event->TaskIndex][1] = plugin3.toInt();
        String plugin4 = WebServer.arg("taskdevicepin3");
        Settings.TaskDevicePluginConfig[event->TaskIndex][2] = plugin4.toInt();

        success = true;
        break;
      }

    case PLUGIN_INIT:
      {
        int pCS = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
        int pCLK = Settings.TaskDevicePluginConfig[event->TaskIndex][1];
        int pMOSI = Settings.TaskDevicePluginConfig[event->TaskIndex][2];
        Plugin_151_pin[0] = pCS;
        Plugin_151_pin[1] = pCLK;
        Plugin_151_pin[2] = pMOSI;

        success = true;
        break;
      }

    case PLUGIN_WRITE:
      {
        String command = parseString(string, 1);
          MCP42010 digipot(Plugin_151_pin[0], Plugin_151_pin[1], Plugin_151_pin[2]);


        if (command == F("chambre"))
        {
          int val1;
          val1 = event->Par1;   //Pot1
          Plugin_151_PotDest[0] = val1;
          digipot.setPot(1,val1);

        }

        if (command == F("second"))
        {
          int val2;
          val2 = event->Par1;   //Pot2
          Plugin_151_PotDest[1] = val2;
          digipot.setPot(2,val2);

        }



        success = true;
        break;
      }

    case PLUGIN_READ:
      {

        UserVar[event->BaseVarIndex + 0]= Plugin_151_PotDest[0] ;
        UserVar[event->BaseVarIndex + 1] = Plugin_151_PotDest[1] ;
        success = true;
        break;
      }


  }
  return success;
}


antibill
New user
Posts: 7
Joined: 13 Dec 2017, 16:55

Re: Support for digital potentiometer

#7 Post by antibill » 03 Jan 2019, 18:07

nobody has an idea for helping me ? :(

gab696
New user
Posts: 3
Joined: 18 Jan 2019, 22:23

Re: Support for digital potentiometer

#8 Post by gab696 » 18 Jan 2019, 22:26

Bonjour,
je suppose que vous parlez français ?
votre plugin m'intéresse fortement. avez-vous trouvé une solution ?
Merci !

antibill
New user
Posts: 7
Joined: 13 Dec 2017, 16:55

Re: Support for digital potentiometer

#9 Post by antibill » 17 Feb 2019, 09:34

Effectivement je suis français.
Pour le moment non je n'ai pas pris le temps de m'y repencher. Mais il va bien falloir que je trouve une solution... As tu fais des essais de ton coté?

antibill
New user
Posts: 7
Joined: 13 Dec 2017, 16:55

Re: Support for digital potentiometer

#10 Post by antibill » 17 Feb 2019, 22:34

The plugin is merged on GitHub 😊

gab696
New user
Posts: 3
Joined: 18 Jan 2019, 22:23

Re: Support for digital potentiometer

#11 Post by gab696 » 17 Feb 2019, 22:53

antibill wrote: 17 Feb 2019, 09:34 Effectivement je suis français.
Pour le moment non je n'ai pas pris le temps de m'y repencher. Mais il va bien falloir que je trouve une solution... As tu fais des essais de ton coté?
Salut, non malheureusement, et je dois t'avouer que j'ai abandonné mes recherches. Je ne pouvais pas attendre et pour cette fois je me suis tourné vers une solution a base d'arduino. Mais apparemment ça bouge du côté du GitHub.
Ça m'intéresse, je vais approfondir cela...

gab696
New user
Posts: 3
Joined: 18 Jan 2019, 22:23

Re: Support for digital potentiometer

#12 Post by gab696 » 17 Feb 2019, 22:56

antibill wrote: 17 Feb 2019, 22:34 The plugin is merged on GitHub 😊
Here?
https://github.com/letscontrolit/ESPEasy

flemingp
New user
Posts: 4
Joined: 04 Mar 2019, 11:02

Re: Support for digital potentiometer

#13 Post by flemingp » 04 Mar 2019, 11:14

Please can someone confirm where I can access the code for this plugin. I have tried the link and a search of github with no success.


Post Reply

Who is online

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