PCD8544 - Nokia 5110/3310 LCD - beta plugin

Moderators: grovkillen, Stuntteam, TD-er

Message
Author
User avatar
Binder
Normal user
Posts: 10
Joined: 06 Jan 2017, 13:17
Location: Germany

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#11 Post by Binder » 27 May 2017, 11:08

_P208_PCD8544:171: error: incompatible types in assignment of 'int' to 'unsigned int [12]'
I had the same problem with the mega-version. If you go back to R148 and the Arduino IDE, it compiles without errors.

adampr1
Normal user
Posts: 17
Joined: 27 Jun 2016, 13:34
Location: Germany

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#12 Post by adampr1 » 12 Jun 2017, 16:15

please remove that line - is no any more for espeasy important. Below my configuration - right now compiled and tested with IDE 1.8.3 and ESPEasy 2.0.0 dev10

my config is for Hardware SPI and work with 4pin (SPI + C/D on GPIO2, CE on GND, RESET on VCC) or 5pin (SPI, CD on GPIO2, CE on GPIO15, RESET on VCC). 5Pin connection is important when other SPI device is connected eg. SDCARD or termocouple sensor MAX6675.

Code: Select all

//#######################################################################################################
//################################## Plugin 208: NOKIA lcd2 ###############################################
//#######################################################################################################

#define PLUGIN_208
#define PLUGIN_ID_208         208
#define PLUGIN_NAME_208       "Display - LCD PCD8544"
#define PLUGIN_VALUENAME1_208 "Backlight"
#define PLUGIN_VALUENAME2_208 "Contrast"
#define PLUGIN_VALUENAME3_208 "Rotation"

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>

Adafruit_PCD8544 *lcd2;
byte lines = 6;
 
boolean Plugin_208(byte function, struct EventStruct *event, String& string)
{
  boolean success = false;

  switch (function)
  {

    case PLUGIN_DEVICE_ADD:
      {
        Device[++deviceCount].Number = PLUGIN_ID_208 ;
        Device[deviceCount].Type = DEVICE_TYPE_I2C;
        Device[deviceCount].VType = SENSOR_TYPE_SWITCH;
        Device[deviceCount].Ports = 0;
        Device[deviceCount].PullUpOption = false;
        Device[deviceCount].InverseLogicOption = false;
        Device[deviceCount].FormulaOption = false;
        Device[deviceCount].ValueCount = 3;
        Device[deviceCount].SendDataOption = false;
        Device[deviceCount].TimerOption = false;
        break;
      }


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

    case PLUGIN_GET_DEVICEVALUENAMES:
      {
        strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_208));
        strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[1], PSTR(PLUGIN_VALUENAME2_208));
        strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[2], PSTR(PLUGIN_VALUENAME3_208));
        break;
      }


    case PLUGIN_WEBFORM_LOAD:
      {
        byte choice1 = Settings.TaskDevicePluginConfig[event->TaskIndex][3];
        byte choice2 = Settings.TaskDevicePluginConfig[event->TaskIndex][1];
        byte choice3 = Settings.TaskDevicePluginConfig[event->TaskIndex][2];
        byte choice4 = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
        char deviceTemplate[lines][32];
        LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
        char tmpString[128];
        for (byte varNr = 0; varNr < lines; varNr++)
        {
          string += F("<TR><TD>Line ");
          string += varNr + 1;
          string += F(":<TD><input type='text' size='80' maxlength='80' name='Plugin_208_template");
          string += varNr + 1;
          string += F("' value='");
          string += deviceTemplate[varNr];
          string += F("'>");
        }

        sprintf_P(tmpString, PSTR("<TR><TD>Display Contrast(50-100):<TD><input type='text' name='plugin_208_contrast' value='%u'>"), choice2);
        string += tmpString;
        string += F("<TR><TD>Backlight pin:<TD>");
        addPinSelect(false, string, "taskdevicepin3", Settings.TaskDevicePin3[event->TaskIndex]);
        int optionValues3[4];
        optionValues3[0] = 0;
        optionValues3[1] = 1;
        optionValues3[2] = 2;
        optionValues3[3] = 3;
        String options3[4];
        options3[0] = F("0");
        options3[1] = F("90");
        options3[2] = F("180");
        options3[3] = F("270");
        string += F("<TR><TD>Display Rotation:<TD><select name='plugin_208_rotation'>");
        for (byte x = 0; x < 4; x++)
        {
          string += F("<option value='");
          string += optionValues3[x];
          string += "'";
          if (choice1 == optionValues3[x])
            string += F(" selected");
          string += ">";
          string += options3[x];
          string += F("</option>");
        }
        string += F("</select>");
        int optionValues4[2];
        optionValues4[0] = 0;
        optionValues4[1] = 1;
        String options4[2];
        options4[0] = F("ON");
        options4[1] = F("OFF");
        string += F("<TR><TD>Backlight:<TD><select name='plugin_208_backlight'>");
        for (byte x = 0; x < 2; x++)
        {
          string += F("<option value='");
          string += optionValues4[x];
          string += "'";
          if (choice4 == optionValues4[x])
            string += F(" selected");
          string += ">";
          string += options4[x];
          string += F("</option>");
        }
        string += F("</select>");       

        success = true;
        break;
      }

    case PLUGIN_WEBFORM_SAVE:
      {
        int plugin1 = WebServer.arg("plugin_208_rotation").toInt();
        int plugin2 = WebServer.arg("plugin_208_contrast").toInt();
        int plugin3 = Settings.TaskDevicePin3[event->TaskIndex];
        int plugin4 = WebServer.arg("plugin_208_backlight").toInt();
        String options1[4];       
        options1[0] = F("0");
        options1[1] = F("90");
        options1[2] = F("180");
        options1[3] = F("270");
        UserVar[event->BaseVarIndex+2]=options1[plugin1].toInt();
        UserVar[event->BaseVarIndex+1]=plugin2;
        UserVar[event->BaseVarIndex]=!plugin4;
        String log = F("PCD8544: ");
        if (plugin2>100) plugin2=100;
        if (plugin2<50) plugin2=50;
        if (plugin1!=Settings.TaskDevicePluginConfig[event->TaskIndex][3]){
          log += String(F("rotation changed to: ")) + plugin1;
          addLog(LOG_LEVEL_INFO, log);
          Settings.TaskDevicePluginConfig[event->TaskIndex][3] = plugin1;
          }
        if (plugin4!=Settings.TaskDevicePluginConfig[event->TaskIndex][3]){
          log += String(F("backlight is now ")) + plugin4?"off":"on";
          addLog(LOG_LEVEL_INFO, log);
          Settings.TaskDevicePluginConfig[event->TaskIndex][0] = plugin4;
          }
         if (plugin2!=Settings.TaskDevicePluginConfig[event->TaskIndex][3]){
          log += String(F("contrast is changed to: ")) + plugin2;
          addLog(LOG_LEVEL_INFO, log);
          Settings.TaskDevicePluginConfig[event->TaskIndex][1] = plugin2;
          }
        char deviceTemplate[lines][32];
        for (byte varNr = 0; varNr < lines; varNr++)
        {
          char argc[25];
          String arg = F("Plugin_208_template");
          arg += varNr + 1;
          arg.toCharArray(argc, 25);
          String tmpString = WebServer.arg(argc);
          strncpy(deviceTemplate[varNr], tmpString.c_str(), sizeof(deviceTemplate[varNr]));
        }

     //   Settings.TaskDeviceID[event->TaskIndex] = 1; // temp fix, needs a dummy value

        SaveCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
        success = true;
        break;
      }

    case PLUGIN_INIT:
      {
        if (!lcd2)
        {
          // pin 14 - Serial clock out (SCLK)
          // pin 13 - Serial data out (DIN)
          // pin 12 - Data/Command select (D/C)
          // pin 5 - LCD chip select (CS)
          // pin 4 - LCD reset (RST)
          //lcd2 = new Adafruit_PCD8544(14, 13, 12, 5, 4);
		        lcd2 = new Adafruit_PCD8544(15, 2, 16); // CS(CEN) GPIO15 , D/C (need to be connected) GPIO2 , RESET GPIO16
        }
        // Setup lcd2 display
        byte plugin1 = Settings.TaskDevicePluginConfig[event->TaskIndex][3];
        byte plugin2 = Settings.TaskDevicePluginConfig[event->TaskIndex][1];
        byte plugin4 = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
        UserVar[event->BaseVarIndex+2]=plugin1;
        UserVar[event->BaseVarIndex+1]=plugin2;
        UserVar[event->BaseVarIndex]=!plugin4;
        if (plugin1==0 || plugin1==2)
        {
          lines=6;
        }
        else{
          lines=10;
        }
        lcd2->begin();                     // initialize the lcd2
        lcd2->setContrast(plugin2);
        lcd2->setRotation(plugin1);
        lcd2->clearDisplay();
        char deviceTemplate[lines][32];
        LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
        displayText(deviceTemplate);
        lcd2->display();
        if (Settings.TaskDevicePin3[event->TaskIndex] != -1){
          pinMode(Settings.TaskDevicePin3[event->TaskIndex], OUTPUT);
          digitalWrite(Settings.TaskDevicePin3[event->TaskIndex],Settings.TaskDevicePluginConfig[event->TaskIndex][0]);
          setPinState(1, Settings.TaskDevicePin3[event->TaskIndex], PIN_MODE_OUTPUT, Settings.TaskDevicePluginConfig[event->TaskIndex][3]);}
        success = true;
        break;
      }
     
    case PLUGIN_READ:
      {
        char deviceTemplate[lines][32];
        LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
        displayText(deviceTemplate);
        success = false;
        break;
      }
     
    case PLUGIN_WRITE:
      {
        String tmpString  = string;
        int argIndex = tmpString.indexOf(',');
        if (argIndex)
          tmpString = tmpString.substring(0, argIndex);
        if (tmpString.equalsIgnoreCase(F("PCD8544")))
        {
          success = true;
          argIndex = string.lastIndexOf(',');
          tmpString = string.substring(argIndex + 1);
          lcd2->setCursor(event->Par2 - 1, event->Par1 - 1);
          lcd2->println(tmpString.c_str());
        }
        if (tmpString.equalsIgnoreCase(F("PCD8544CMD")))
        {
          success = true;
          argIndex = string.lastIndexOf(',');
          tmpString = string.substring(argIndex + 1);
          if (tmpString.equalsIgnoreCase(F("Clear")))
            lcd2->clearDisplay();
        }
        break;
      }

  }
  return success;
}

  boolean displayText(char deviceTemplate[][32]){
        String log = F("PCD8544: ");
        String string = F("");
        lcd2->clearDisplay();
        lcd2->setTextSize(1);
        lcd2->setTextColor(BLACK);
        lcd2->setCursor(0,0);
        for (byte x = 0; x < lines; x++)
        {
          String tmpString = deviceTemplate[x];
          if (tmpString.length())
          {
            String newString = parseTemplate(tmpString, 32);
            lcd2->setCursor(0,x*8);
            lcd2->print(newString);
            string+=newString+"\\";
          }
        }
        log += String(F("displayed text: \"")) + String(string) + String(F("\""));
        addLog(LOG_LEVEL_INFO, log);
        lcd2->display();
        return true;
  }
BR. Adam

PS.
To disable WRAP text please add line:

Code: Select all

boolean setTextWrap = false;
after line

Code: Select all

lcd2 = new Adafruit_PCD8544(15, 2, 16); // CS(CEN) GPIO15 , D/C (need to be connected) GPIO2 , RESET GPIO16
this will disable wrap text (true 14 characters inline for Nokia display) in Adafruit_GFX library
Domoticz Beta release on OrangePI PC and BananaPI,
2x RFLink (last version),
ESPEasy, ESPEasy32 (different configurations),
MySensors (different configurations),
2x MiLight RGBW (over RFLink)
and others things :D

sthopeless
New user
Posts: 1
Joined: 07 Feb 2018, 00:02

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#13 Post by sthopeless » 07 Feb 2018, 02:06

adampr1 wrote: 12 Jun 2017, 16:15 please remove that line - is no any more for espeasy important. Below my configuration - right now compiled and tested with IDE 1.8.3 and ESPEasy 2.0.0 dev10

my config is for Hardware SPI and work with 4pin (SPI + C/D on GPIO2, CE on GND, RESET on VCC) or 5pin (SPI, CD on GPIO2, CE on GPIO15, RESET on VCC). 5Pin connection is important when other SPI device is connected eg. SDCARD or termocouple sensor MAX6675.

Code: Select all

//#######################################################################################################
//################################## Plugin 208: NOKIA lcd2 ###############################################
//#######################################################################################################

#define PLUGIN_208
#define PLUGIN_ID_208         208
#define PLUGIN_NAME_208       "Display - LCD PCD8544"
#define PLUGIN_VALUENAME1_208 "Backlight"
#define PLUGIN_VALUENAME2_208 "Contrast"
#define PLUGIN_VALUENAME3_208 "Rotation"

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>

Adafruit_PCD8544 *lcd2;
byte lines = 6;
 
boolean Plugin_208(byte function, struct EventStruct *event, String& string)
{
  boolean success = false;

  switch (function)
  {

    case PLUGIN_DEVICE_ADD:
      {
        Device[++deviceCount].Number = PLUGIN_ID_208 ;
        Device[deviceCount].Type = DEVICE_TYPE_I2C;
        Device[deviceCount].VType = SENSOR_TYPE_SWITCH;
        Device[deviceCount].Ports = 0;
        Device[deviceCount].PullUpOption = false;
        Device[deviceCount].InverseLogicOption = false;
        Device[deviceCount].FormulaOption = false;
        Device[deviceCount].ValueCount = 3;
        Device[deviceCount].SendDataOption = false;
        Device[deviceCount].TimerOption = false;
        break;
      }


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

    case PLUGIN_GET_DEVICEVALUENAMES:
      {
        strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_208));
        strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[1], PSTR(PLUGIN_VALUENAME2_208));
        strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[2], PSTR(PLUGIN_VALUENAME3_208));
        break;
      }


    case PLUGIN_WEBFORM_LOAD:
      {
        byte choice1 = Settings.TaskDevicePluginConfig[event->TaskIndex][3];
        byte choice2 = Settings.TaskDevicePluginConfig[event->TaskIndex][1];
        byte choice3 = Settings.TaskDevicePluginConfig[event->TaskIndex][2];
        byte choice4 = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
        char deviceTemplate[lines][32];
        LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
        char tmpString[128];
        for (byte varNr = 0; varNr < lines; varNr++)
        {
          string += F("<TR><TD>Line ");
          string += varNr + 1;
          string += F(":<TD><input type='text' size='80' maxlength='80' name='Plugin_208_template");
          string += varNr + 1;
          string += F("' value='");
          string += deviceTemplate[varNr];
          string += F("'>");
        }

        sprintf_P(tmpString, PSTR("<TR><TD>Display Contrast(50-100):<TD><input type='text' name='plugin_208_contrast' value='%u'>"), choice2);
        string += tmpString;
        string += F("<TR><TD>Backlight pin:<TD>");
        addPinSelect(false, string, "taskdevicepin3", Settings.TaskDevicePin3[event->TaskIndex]);
        int optionValues3[4];
        optionValues3[0] = 0;
        optionValues3[1] = 1;
        optionValues3[2] = 2;
        optionValues3[3] = 3;
        String options3[4];
        options3[0] = F("0");
        options3[1] = F("90");
        options3[2] = F("180");
        options3[3] = F("270");
        string += F("<TR><TD>Display Rotation:<TD><select name='plugin_208_rotation'>");
        for (byte x = 0; x < 4; x++)
        {
          string += F("<option value='");
          string += optionValues3[x];
          string += "'";
          if (choice1 == optionValues3[x])
            string += F(" selected");
          string += ">";
          string += options3[x];
          string += F("</option>");
        }
        string += F("</select>");
        int optionValues4[2];
        optionValues4[0] = 0;
        optionValues4[1] = 1;
        String options4[2];
        options4[0] = F("ON");
        options4[1] = F("OFF");
        string += F("<TR><TD>Backlight:<TD><select name='plugin_208_backlight'>");
        for (byte x = 0; x < 2; x++)
        {
          string += F("<option value='");
          string += optionValues4[x];
          string += "'";
          if (choice4 == optionValues4[x])
            string += F(" selected");
          string += ">";
          string += options4[x];
          string += F("</option>");
        }
        string += F("</select>");       

        success = true;
        break;
      }

    case PLUGIN_WEBFORM_SAVE:
      {
        int plugin1 = WebServer.arg("plugin_208_rotation").toInt();
        int plugin2 = WebServer.arg("plugin_208_contrast").toInt();
        int plugin3 = Settings.TaskDevicePin3[event->TaskIndex];
        int plugin4 = WebServer.arg("plugin_208_backlight").toInt();
        String options1[4];       
        options1[0] = F("0");
        options1[1] = F("90");
        options1[2] = F("180");
        options1[3] = F("270");
        UserVar[event->BaseVarIndex+2]=options1[plugin1].toInt();
        UserVar[event->BaseVarIndex+1]=plugin2;
        UserVar[event->BaseVarIndex]=!plugin4;
        String log = F("PCD8544: ");
        if (plugin2>100) plugin2=100;
        if (plugin2<50) plugin2=50;
        if (plugin1!=Settings.TaskDevicePluginConfig[event->TaskIndex][3]){
          log += String(F("rotation changed to: ")) + plugin1;
          addLog(LOG_LEVEL_INFO, log);
          Settings.TaskDevicePluginConfig[event->TaskIndex][3] = plugin1;
          }
        if (plugin4!=Settings.TaskDevicePluginConfig[event->TaskIndex][3]){
          log += String(F("backlight is now ")) + plugin4?"off":"on";
          addLog(LOG_LEVEL_INFO, log);
          Settings.TaskDevicePluginConfig[event->TaskIndex][0] = plugin4;
          }
         if (plugin2!=Settings.TaskDevicePluginConfig[event->TaskIndex][3]){
          log += String(F("contrast is changed to: ")) + plugin2;
          addLog(LOG_LEVEL_INFO, log);
          Settings.TaskDevicePluginConfig[event->TaskIndex][1] = plugin2;
          }
        char deviceTemplate[lines][32];
        for (byte varNr = 0; varNr < lines; varNr++)
        {
          char argc[25];
          String arg = F("Plugin_208_template");
          arg += varNr + 1;
          arg.toCharArray(argc, 25);
          String tmpString = WebServer.arg(argc);
          strncpy(deviceTemplate[varNr], tmpString.c_str(), sizeof(deviceTemplate[varNr]));
        }

     //   Settings.TaskDeviceID[event->TaskIndex] = 1; // temp fix, needs a dummy value

        SaveCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
        success = true;
        break;
      }

    case PLUGIN_INIT:
      {
        if (!lcd2)
        {
          // pin 14 - Serial clock out (SCLK)
          // pin 13 - Serial data out (DIN)
          // pin 12 - Data/Command select (D/C)
          // pin 5 - LCD chip select (CS)
          // pin 4 - LCD reset (RST)
          //lcd2 = new Adafruit_PCD8544(14, 13, 12, 5, 4);
		        lcd2 = new Adafruit_PCD8544(15, 2, 16); // CS(CEN) GPIO15 , D/C (need to be connected) GPIO2 , RESET GPIO16
        }
        // Setup lcd2 display
        byte plugin1 = Settings.TaskDevicePluginConfig[event->TaskIndex][3];
        byte plugin2 = Settings.TaskDevicePluginConfig[event->TaskIndex][1];
        byte plugin4 = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
        UserVar[event->BaseVarIndex+2]=plugin1;
        UserVar[event->BaseVarIndex+1]=plugin2;
        UserVar[event->BaseVarIndex]=!plugin4;
        if (plugin1==0 || plugin1==2)
        {
          lines=6;
        }
        else{
          lines=10;
        }
        lcd2->begin();                     // initialize the lcd2
        lcd2->setContrast(plugin2);
        lcd2->setRotation(plugin1);
        lcd2->clearDisplay();
        char deviceTemplate[lines][32];
        LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
        displayText(deviceTemplate);
        lcd2->display();
        if (Settings.TaskDevicePin3[event->TaskIndex] != -1){
          pinMode(Settings.TaskDevicePin3[event->TaskIndex], OUTPUT);
          digitalWrite(Settings.TaskDevicePin3[event->TaskIndex],Settings.TaskDevicePluginConfig[event->TaskIndex][0]);
          setPinState(1, Settings.TaskDevicePin3[event->TaskIndex], PIN_MODE_OUTPUT, Settings.TaskDevicePluginConfig[event->TaskIndex][3]);}
        success = true;
        break;
      }
     
    case PLUGIN_READ:
      {
        char deviceTemplate[lines][32];
        LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
        displayText(deviceTemplate);
        success = false;
        break;
      }
     
    case PLUGIN_WRITE:
      {
        String tmpString  = string;
        int argIndex = tmpString.indexOf(',');
        if (argIndex)
          tmpString = tmpString.substring(0, argIndex);
        if (tmpString.equalsIgnoreCase(F("PCD8544")))
        {
          success = true;
          argIndex = string.lastIndexOf(',');
          tmpString = string.substring(argIndex + 1);
          lcd2->setCursor(event->Par2 - 1, event->Par1 - 1);
          lcd2->println(tmpString.c_str());
        }
        if (tmpString.equalsIgnoreCase(F("PCD8544CMD")))
        {
          success = true;
          argIndex = string.lastIndexOf(',');
          tmpString = string.substring(argIndex + 1);
          if (tmpString.equalsIgnoreCase(F("Clear")))
            lcd2->clearDisplay();
        }
        break;
      }

  }
  return success;
}

  boolean displayText(char deviceTemplate[][32]){
        String log = F("PCD8544: ");
        String string = F("");
        lcd2->clearDisplay();
        lcd2->setTextSize(1);
        lcd2->setTextColor(BLACK);
        lcd2->setCursor(0,0);
        for (byte x = 0; x < lines; x++)
        {
          String tmpString = deviceTemplate[x];
          if (tmpString.length())
          {
            String newString = parseTemplate(tmpString, 32);
            lcd2->setCursor(0,x*8);
            lcd2->print(newString);
            string+=newString+"\\";
          }
        }
        log += String(F("displayed text: \"")) + String(string) + String(F("\""));
        addLog(LOG_LEVEL_INFO, log);
        lcd2->display();
        return true;
  }
BR. Adam

PS.
To disable WRAP text please add line:

Code: Select all

boolean setTextWrap = false;
after line

Code: Select all

lcd2 = new Adafruit_PCD8544(15, 2, 16); // CS(CEN) GPIO15 , D/C (need to be connected) GPIO2 , RESET GPIO16
this will disable wrap text (true 14 characters inline for Nokia display) in Adafruit_GFX library
Is it possible to use commands to print text on the screen?
lcd.1,1,{msg} works on normal LCD's
or lcdcmd,clear

adampr1
Normal user
Posts: 17
Joined: 27 Jun 2016, 13:34
Location: Germany

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#14 Post by adampr1 » 22 May 2018, 12:13

After long time new (adapted) version of PCD8544 lcd display plugin. After changes in ESPEASY (permit strings for html), previous display plugin not compiles with latest ESPEASY. Now refreshed version - no compile errors and display working again :)

Code: Select all

//#######################################################################################################
//################################## Plugin 208: NOKIA lcd2 ###############################################
//#######################################################################################################

#define PLUGIN_208
#define PLUGIN_ID_208         208
#define PLUGIN_NAME_208       "Display - LCD PCD8544"
#define PLUGIN_VALUENAME1_208 "Backlight"
#define PLUGIN_VALUENAME2_208 "Contrast"
#define PLUGIN_VALUENAME3_208 "Rotation"

//#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>

Adafruit_PCD8544 *lcd2;
byte lines = 6;
 
boolean Plugin_208(byte function, struct EventStruct *event, String& string)
{
  boolean success = false;

  switch (function)
  {

    case PLUGIN_DEVICE_ADD:
      {
        Device[++deviceCount].Number = PLUGIN_ID_208 ;
        Device[deviceCount].Type = DEVICE_TYPE_SINGLE;
        Device[deviceCount].VType = SENSOR_TYPE_SINGLE;
        Device[deviceCount].Ports = 0;
        Device[deviceCount].PullUpOption = false;
        Device[deviceCount].InverseLogicOption = false;
        Device[deviceCount].FormulaOption = false;
        Device[deviceCount].ValueCount = 3;
        Device[deviceCount].SendDataOption = false;
        Device[deviceCount].TimerOption = true;
        break;
      }


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

    case PLUGIN_GET_DEVICEVALUENAMES:
      {
        strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_208));
        strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[1], PSTR(PLUGIN_VALUENAME2_208));
        strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[2], PSTR(PLUGIN_VALUENAME3_208));
        break;
      }


    case PLUGIN_WEBFORM_LOAD:
      {
        addFormNumericBox(F("Display Contrast(50-100):"), F("plugin_208_contrast"), Settings.TaskDevicePluginConfig[event->TaskIndex][1]);
        
        addFormPinSelect(F("Backlight PIN"), F("taskdevicepin3"), Settings.TaskDevicePin3[event->TaskIndex]);

        byte choice3 = Settings.TaskDevicePluginConfig[event->TaskIndex][2];
        int optionValues3[4] = { 0, 1, 2, 3 };
        String options3[4] = { F("0"), F("90"), F("180"), F("270") };
        addFormSelector(F("Display Rotation"), F("plugin_208_rotation"), 4, options3, optionValues3, choice3);
        
        byte choice4 = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
        String options4[2] = { F("ON"), F("OFF") };
        int optionValues4[2] = { 0, 1 };
        addFormSelector(F("Backlight"), F("plugin_208_backlight"), 2, options4, optionValues4, choice4);

        char deviceTemplate [lines][48];
        LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
        for (byte varNr = 0; varNr < lines; varNr++)
        {
          addFormTextBox(String(F("Line ")) + (varNr + 1), String(F("Plugin_208_template")) + (varNr + 1), deviceTemplate[varNr], 80);
        }
        
        success = true;
        break;
      }

    case PLUGIN_WEBFORM_SAVE:
      {
        Settings.TaskDevicePluginConfig[event->TaskIndex][0] = getFormItemInt(F("plugin_208_backlight"));
        Settings.TaskDevicePluginConfig[event->TaskIndex][1] = getFormItemInt(F("plugin_208_contrast"));
        Settings.TaskDevicePluginConfig[event->TaskIndex][2] = getFormItemInt(F("plugin_208_rotation"));
        
        char deviceTemplate[lines][48];
        for (byte varNr = 0; varNr < lines; varNr++)
        {
          char argc[25];
          String arg = F("Plugin_208_template");
          arg += varNr + 1;
          arg.toCharArray(argc, 25);
          String tmpString = WebServer.arg(argc);
          strncpy(deviceTemplate[varNr], tmpString.c_str(), sizeof(deviceTemplate[varNr]));
        }

     //   Settings.TaskDeviceID[event->TaskIndex] = 1; // temp fix, needs a dummy value

        SaveCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
        success = true;
        break;
      }

    case PLUGIN_INIT:
      {
        if (!lcd2)
        {
          // pin 14 - Serial clock out (SCLK)
          // pin 13 - Serial data out (DIN)
          // pin 12 - Data/Command select (D/C)
          // pin 5 - LCD chip select (CS)
          // pin 4 - LCD reset (RST)
          //lcd2 = new Adafruit_PCD8544(14, 13, 12, 5, 4);
          #if defined(ESP8266)
              lcd2 = new Adafruit_PCD8544(15, 2, -1); // D/C (need to be connected) GPIO2 , CS(CEN) GPIO15 , RESET not connected
          #endif
          #if defined(ESP32)
              lcd2 = new Adafruit_PCD8544(16, 17, -1); // D/C (need to be connected) GPIO16 , CS(CEN) GPIO17 , RESET not connected
          #endif
		        
           boolean setTextWrap = false;
        }
        // Setup lcd2 display
        byte plugin1 = Settings.TaskDevicePluginConfig[event->TaskIndex][2]; // rotation
        byte plugin2 = Settings.TaskDevicePluginConfig[event->TaskIndex][1]; // contrast
        byte plugin4 = Settings.TaskDevicePluginConfig[event->TaskIndex][0]; // backlight_onoff
        UserVar[event->BaseVarIndex+2]=plugin1;
        UserVar[event->BaseVarIndex+1]=plugin2;
        UserVar[event->BaseVarIndex]=!plugin4;
        if (plugin1==0 || plugin1==2)
        {
          lines=6;
        }
        else{
          lines=10;
        }
        lcd2->begin();                     // initialize the lcd2
        lcd2->setContrast(plugin2);
        lcd2->setRotation(plugin1);
        lcd2->clearDisplay();
        char deviceTemplate[lines][48];
        LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
        displayText(deviceTemplate);
        lcd2->display();
        if (Settings.TaskDevicePin3[event->TaskIndex] != -1){
          pinMode(Settings.TaskDevicePin3[event->TaskIndex], OUTPUT);
          digitalWrite(Settings.TaskDevicePin3[event->TaskIndex],Settings.TaskDevicePluginConfig[event->TaskIndex][0]);
          setPinState(1, Settings.TaskDevicePin3[event->TaskIndex], PIN_MODE_OUTPUT, Settings.TaskDevicePluginConfig[event->TaskIndex][3]);}
        success = true;
        break;
      }
     
    case PLUGIN_READ:
      {
        char deviceTemplate[lines][48];
        LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
        displayText(deviceTemplate);
        success = false;
        break;
      }
     
    case PLUGIN_WRITE:
      {
        String tmpString  = string;
        int argIndex = tmpString.indexOf(',');
        if (argIndex)
          tmpString = tmpString.substring(0, argIndex);
        if (tmpString.equalsIgnoreCase(F("PCD8544")))
        {
          success = true;
          argIndex = string.lastIndexOf(',');
          tmpString = string.substring(argIndex + 1);
          lcd2->setCursor(event->Par2 - 1, event->Par1 - 1);
          lcd2->println(tmpString.c_str());
        }
        if (tmpString.equalsIgnoreCase(F("PCD8544CMD")))
        {
          success = true;
          argIndex = string.lastIndexOf(',');
          tmpString = string.substring(argIndex + 1);
          if (tmpString.equalsIgnoreCase(F("Clear")))
            lcd2->clearDisplay();
        }
        break;
      }

  }
  return success;
}

  boolean displayText(char deviceTemplate[][48]){
        String log = F("PCD8544: ");
        String string = F("");
        lcd2->clearDisplay();
        lcd2->setTextSize(1);
        lcd2->setTextColor(BLACK);
        lcd2->setCursor(0,0);
        for (byte x = 0; x < lines; x++)
        {
          String tmpString = deviceTemplate[x];
          if (tmpString.length())
          {
            String newString = parseTemplate(tmpString, 48);
            lcd2->setCursor(0,x*8);
            lcd2->print(newString);
            string+=newString+"\\";
          }
        }
        log += String(F("displayed text: \"")) + String(string) + String(F("\""));
        addLog(LOG_LEVEL_INFO, log);
        lcd2->display();
        return true;
  }
please test and any suggestion are welcome.

BR.
Adam
Domoticz Beta release on OrangePI PC and BananaPI,
2x RFLink (last version),
ESPEasy, ESPEasy32 (different configurations),
MySensors (different configurations),
2x MiLight RGBW (over RFLink)
and others things :D

BasemAlsaeed
Normal user
Posts: 10
Joined: 11 Sep 2016, 16:43

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#15 Post by BasemAlsaeed » 05 Sep 2018, 00:56

Hi, i am trying to compile using PlatformIO, and i get the below messages

D:/ESPEasy-mega-20180904/src/_P208_PCD8544.ino: In function 'boolean Plugin_208(byte, EventStruct*, String&)':
D:/ESPEasy-mega-20180904/src/_P208_PCD8544.ino:126:20: warning: unused variable 'setTextWrap' [-Wunused-variable]
boolean setTextWrap = false;
^
D:/ESPEasy-mega-20180904/src/_P208_PCD8544.ino:148:35: error: 'displayText' was not declared in this scope
displayText(deviceTemplate);
^

D:/ESPEasy-mega-20180904/src/_P208_PCD8544.ino:162:35: error: 'displayText' was not declared in this scope
displayText(deviceTemplate);
^

any ideas ? :)
thanks

BasemAlsaeed
Normal user
Posts: 10
Joined: 11 Sep 2016, 16:43

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#16 Post by BasemAlsaeed » 05 Sep 2018, 02:09

ok now it compiles successfully however the plugin does not appear in the devices list to pick
here is the code i used

Code: Select all

#ifdef USES_P208
//#######################################################################################################
//################################## Plugin 208: NOKIA lcd2 ###############################################
//#######################################################################################################

#define PLUGIN_208
#define PLUGIN_ID_208 208
#define PLUGIN_NAME_208 "Display - LCD PCD8544 [TESTING]"
#define PLUGIN_VALUENAME1_208 "Backlight"
#define PLUGIN_VALUENAME2_208 "Contrast"
#define PLUGIN_VALUENAME3_208 "Rotation"

//#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>

Adafruit_PCD8544 *lcd2;
byte lines = 6;

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

  switch (function)
  {

    case PLUGIN_DEVICE_ADD:
      {
        Device[++deviceCount].Number = PLUGIN_ID_208 ;
        Device[deviceCount].Type = DEVICE_TYPE_SINGLE;
        Device[deviceCount].VType = SENSOR_TYPE_SINGLE;
        Device[deviceCount].Ports = 0;
        Device[deviceCount].PullUpOption = false;
        Device[deviceCount].InverseLogicOption = false;
        Device[deviceCount].FormulaOption = false;
        Device[deviceCount].ValueCount = 3;
        Device[deviceCount].SendDataOption = false;
        Device[deviceCount].TimerOption = true;
        break;
      }


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

    case PLUGIN_GET_DEVICEVALUENAMES:
      {
        strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_208));
        strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[1], PSTR(PLUGIN_VALUENAME2_208));
        strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[2], PSTR(PLUGIN_VALUENAME3_208));
        break;
      }


    case PLUGIN_WEBFORM_LOAD:
      {
        addFormNumericBox(F("Display Contrast(50-100):"), F("plugin_208_contrast"), Settings.TaskDevicePluginConfig[event->TaskIndex][1]);

        addFormPinSelect(F("Backlight PIN"), F("taskdevicepin3"), Settings.TaskDevicePin3[event->TaskIndex]);

        byte choice3 = Settings.TaskDevicePluginConfig[event->TaskIndex][2];
        int optionValues3[4] = { 0, 1, 2, 3 };
        String options3[4] = { F("0"), F("90"), F("180"), F("270") };
        addFormSelector(F("Display Rotation"), F("plugin_208_rotation"), 4, options3, optionValues3, choice3);

        byte choice4 = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
        String options4[2] = { F("ON"), F("OFF") };
        int optionValues4[2] = { 0, 1 };
        addFormSelector(F("Backlight"), F("plugin_208_backlight"), 2, options4, optionValues4, choice4);

        char deviceTemplate [lines][48];
        LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
        for (byte varNr = 0; varNr < lines; varNr++)
        {
          addFormTextBox(String(F("Line ")) + (varNr + 1), String(F("Plugin_208_template")) + (varNr + 1), deviceTemplate[varNr], 80);
        }

        success = true;
        break;
      }

    case PLUGIN_WEBFORM_SAVE:
      {
        Settings.TaskDevicePluginConfig[event->TaskIndex][0] = getFormItemInt(F("plugin_208_backlight"));
        Settings.TaskDevicePluginConfig[event->TaskIndex][1] = getFormItemInt(F("plugin_208_contrast"));
        Settings.TaskDevicePluginConfig[event->TaskIndex][2] = getFormItemInt(F("plugin_208_rotation"));

        char deviceTemplate[lines][48];
        for (byte varNr = 0; varNr < lines; varNr++)
        {
          char argc[25];
          String arg = F("Plugin_208_template");
          arg += varNr + 1;
          arg.toCharArray(argc, 25);
          String tmpString = WebServer.arg(argc);
          strncpy(deviceTemplate[varNr], tmpString.c_str(), sizeof(deviceTemplate[varNr]));
        }

      //  Settings.TaskDeviceID[event->TaskIndex] = 1; // temp fix, needs a dummy value

        SaveCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
        success = true;
        break;
      }

    case PLUGIN_INIT:
      {
        if (!lcd2)
        {
          // pin 14 - Serial clock out (SCLK)
          // pin 13 - Serial data out (DIN)
          // pin 12 - Data/Command select (D/C)
          // pin 5 - LCD chip select (CS)
          // pin 4 - LCD reset (RST)
          //lcd2 = new Adafruit_PCD8544(14, 13, 12, 5, 4);
          #if defined(ESP8266)
              lcd2 = new Adafruit_PCD8544(15, 2, -1); // D/C (need to be connected) GPIO2 , CS(CEN) GPIO15 , RESET not connected
          #endif
          #if defined(ESP32)
              lcd2 = new Adafruit_PCD8544(16, 17, -1); // D/C (need to be connected) GPIO16 , CS(CEN) GPIO17 , RESET not connected
          #endif

          boolean setTextWrap = false;
        }
        // Setup lcd2 display
        byte plugin1 = Settings.TaskDevicePluginConfig[event->TaskIndex][2]; // rotation
        byte plugin2 = Settings.TaskDevicePluginConfig[event->TaskIndex][1]; // contrast
        byte plugin4 = Settings.TaskDevicePluginConfig[event->TaskIndex][0]; // backlight_onoff
        UserVar[event->BaseVarIndex+2]=plugin1;
        UserVar[event->BaseVarIndex+1]=plugin2;
        UserVar[event->BaseVarIndex]=!plugin4;
        if (plugin1==0 || plugin1==2)
        {
          lines=6;
        }
        else{
          lines=10;
        }
        lcd2->begin();                     // initialize the lcd2
        lcd2->setContrast(plugin2);
        lcd2->setRotation(plugin1);
        lcd2->clearDisplay();
        char deviceTemplate[lines][48];
        LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
        displayText(deviceTemplate);
        lcd2->display();
        if (Settings.TaskDevicePin3[event->TaskIndex] != -1){
          pinMode(Settings.TaskDevicePin3[event->TaskIndex], OUTPUT);
          digitalWrite(Settings.TaskDevicePin3[event->TaskIndex],Settings.TaskDevicePluginConfig[event->TaskIndex][0]);
          setPinState(1, Settings.TaskDevicePin3[event->TaskIndex], PIN_MODE_OUTPUT, Settings.TaskDevicePluginConfig[event->TaskIndex][3]);}
        success = true;
        break;
      }

    case PLUGIN_READ:
      {
        char deviceTemplate[lines][48];
        LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
        displayText(deviceTemplate);
        success = false;
        break;
      }

    case PLUGIN_WRITE:
      {
        String tmpString  = string;
        int argIndex = tmpString.indexOf(',');
        if (argIndex)
          tmpString = tmpString.substring(0, argIndex);
        if (tmpString.equalsIgnoreCase(F("PCD8544")))
        {
          success = true;
          argIndex = string.lastIndexOf(',');
          tmpString = string.substring(argIndex + 1);
          lcd2->setCursor(event->Par2 - 1, event->Par1 - 1);
          lcd2->println(tmpString.c_str());
        }
        if (tmpString.equalsIgnoreCase(F("PCD8544CMD")))
        {
          success = true;
          argIndex = string.lastIndexOf(',');
          tmpString = string.substring(argIndex + 1);
          if (tmpString.equalsIgnoreCase(F("Clear")))
            lcd2->clearDisplay();
        }
        break;
      }

  }
  return success;
}

boolean displayText(char deviceTemplate[][48]){
        String log = F("PCD8544: ");
        String string = F("");
        lcd2->clearDisplay();
        lcd2->setTextSize(1);
        lcd2->setTextColor(BLACK);
        lcd2->setCursor(0,0);
        for (byte x = 0; x < lines; x++)
        {
          String tmpString = deviceTemplate[x];
          if (tmpString.length())
          {
            String newString = parseTemplate(tmpString, 48);
            lcd2->setCursor(0,x*8);
            lcd2->print(newString);
            string+=newString+"\\";
          }
        }
        log += String(F("displayed text: \"")) + String(string) + String(F("\""));
        addLog(LOG_LEVEL_INFO, log);
        lcd2->display();
        return true;
  }
#endif // USES_P208


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

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#17 Post by TD-er » 05 Sep 2018, 22:03

You also have to define "USES_P208"
Add it to the appropriate line with "build_flags" in the platformio.ini file.
You add a define using the -D flag.


So for example in the [common] section:
build_flags = -D BUILD_GIT='"${sysenv.TRAVIS_TAG}"'
-D NDEBUG
-lstdc++ -lsupc++
-DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
-DVTABLES_IN_FLASH
-DUSES_P208

(See last part)

BasemAlsaeed
Normal user
Posts: 10
Joined: 11 Sep 2016, 16:43

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#18 Post by BasemAlsaeed » 06 Sep 2018, 18:17

TD-er wrote: 05 Sep 2018, 22:03 You also have to define "USES_P208"
Add it to the appropriate line with "build_flags" in the platformio.ini file.
You add a define using the -D flag.


So for example in the [common] section:
build_flags = -D BUILD_GIT='"${sysenv.TRAVIS_TAG}"'
-D NDEBUG
-lstdc++ -lsupc++
-DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
-DVTABLES_IN_FLASH
-DUSES_P208

(See last part)
thanks for your response, i have tried that too, i think it is the same as adding the plugin to define_plugin_sets.h file under PLUGIN_SET_EXPERIMENTAL section and compile the dev build only, in both cases it does not show up in the list of plugins, i think it has something to do with the web form lines

woocashewski
Normal user
Posts: 13
Joined: 22 Sep 2018, 19:09
Location: Poland

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#19 Post by woocashewski » 22 Sep 2018, 19:16

thanks for this post, i've succesfully add this plugin to espeasy, to do that You have to define this plugin into define_plugin_sets.h file - add a line " #define USES_P208 // nokia_lcd" in a version you choose - maybe "developer" one is the best option :)

without that, plugin won't be added to complied flash file.

after that all works a a charm.

PS. sorry for my english, that was my first attempt to compile firmware on my own by the way

hattemp
New user
Posts: 1
Joined: 30 Sep 2018, 20:23

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#20 Post by hattemp » 30 Sep 2018, 20:30

is there someone on this forum who has a working Bin file for me that supports the nokia 5110?
i have been trying to get this working with the source code and atom and arduino ide butt only get errors compiling.
tried the latest version and the 147 rc8 butt no luck just errors.
don't unther stand why they aren't supported yet with the latest versions.

thanks for responding.

whatsupskip
Normal user
Posts: 125
Joined: 28 Feb 2018, 07:40
Location: Melbourne, Australia

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#21 Post by whatsupskip » 01 Oct 2018, 04:49

hattemp wrote: 30 Sep 2018, 20:30 is there someone on this forum who has a working Bin file for me that supports the nokia 5110?
It would be really great if people could do this as it helps others at least experience what has been do so far. For beginners it is often difficult to compile.

This plugin will be a great addition to the project. Thanks to all those who have contributed.
Friends with kangaroos and some time koala rescuer.

User avatar
Cramin
New user
Posts: 4
Joined: 04 Oct 2018, 08:34
Location: Poland, Myszkow
Contact:

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#22 Post by Cramin » 04 Oct 2018, 08:36

+1 for someone with precompiled firmware with added support for Nokia LCD.

woocashewski
Normal user
Posts: 13
Joined: 22 Sep 2018, 19:09
Location: Poland

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#23 Post by woocashewski » 08 Oct 2018, 23:25

compiled firmware in an attachment. (unpack & change extension of course...)

1st gpio - 2 (d4)

wiring as in this topic.

and of course I'm not responsible for blah blah blah ;)
Attachments
firmware.rar
(496.1 KiB) Downloaded 673 times

User avatar
Cramin
New user
Posts: 4
Joined: 04 Oct 2018, 08:34
Location: Poland, Myszkow
Contact:

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#24 Post by Cramin » 09 Oct 2018, 16:02

Thank You!
I have different pinouts, but i change that and LCD works.
ESP8266_5110LCD
ESP8266_5110LCD
WP_20181009_15_51_40_Pro.jpg (259.11 KiB) Viewed 84836 times

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

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#25 Post by grovkillen » 09 Oct 2018, 16:19

That is a nice display, nice price as well?
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
Cramin
New user
Posts: 4
Joined: 04 Oct 2018, 08:34
Location: Poland, Myszkow
Contact:

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#26 Post by Cramin » 09 Oct 2018, 17:00

2,5€ in Poland.

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

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#27 Post by grovkillen » 09 Oct 2018, 17:34

Cramin wrote: 09 Oct 2018, 17:00 2,5€ in Poland.
Cool, we should consider it for the main repository then.
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:

woocashewski
Normal user
Posts: 13
Joined: 22 Sep 2018, 19:09
Location: Poland

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#28 Post by woocashewski » 09 Oct 2018, 21:35

the problem with this display is that it require much more gpios than i2c displays.

cieszę się, że mogłem pomóc ;)

pozdrawiam.

adampr1
Normal user
Posts: 17
Joined: 27 Jun 2016, 13:34
Location: Germany

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#29 Post by adampr1 » 22 Oct 2018, 09:47

Hi all, I am very pleased that other ESPeasy enthusiasts also use the Nokia display. In many applications using the hardware SPI allows you to use the I2C and OneWire interface. And we still have Tx and Rx which can also be used - if we don't need a serial login :) I would be very grateful if you manage to include PCD8544 in the repository. I also have positive tests of NOKIA display with ESP32.
On the following photo - ESP07 (updated to 4MB) , BME280, Si7021, AM2305, 0,91" OLED Display, Nokia display and ... still RX and TX free. ;)

Bestr regards ... i pozdrowienia dla kolegów z Polski ;)

Adam
Attachments
IMG_20181022_093450_resized_20181022_093526854.jpg
IMG_20181022_093450_resized_20181022_093526854.jpg (174.45 KiB) Viewed 84563 times
Domoticz Beta release on OrangePI PC and BananaPI,
2x RFLink (last version),
ESPEasy, ESPEasy32 (different configurations),
MySensors (different configurations),
2x MiLight RGBW (over RFLink)
and others things :D

User avatar
Malanow
Normal user
Posts: 12
Joined: 18 Mar 2018, 22:47
Location: Poland
Contact:

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#30 Post by Malanow » 25 Dec 2018, 21:30

Hi!
How to, the easiest way to add a PCD8544 plugin, to my Wemos D1 mini. I use this bin file ->ESP_Easy_mega-20181220_dev_ESP8266_4096. A small warning, I'm not a programmer :)
Armageddon was yesterday, today we have a serious problem.

RobertM
Normal user
Posts: 23
Joined: 22 Oct 2017, 15:23

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#31 Post by RobertM » 26 Dec 2018, 10:55

I'm interested too.
I don't know why not include this small and cheap display to official release 8-)

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

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#32 Post by grovkillen » 26 Dec 2018, 12:05

RobertM wrote: 26 Dec 2018, 10:55 I'm interested too.
I don't know why not include this small and cheap display to official release 8-)
We're planning on adding a generic display plugin so at this time we're not accepting new display plugins. But I will make sure we support this display (I got a couple of them myself). ;)
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:

RobertM
Normal user
Posts: 23
Joined: 22 Oct 2017, 15:23

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#33 Post by RobertM » 26 Dec 2018, 13:06

Malanow wrote: 25 Dec 2018, 21:30 Hi!
How to, the easiest way to add a PCD8544 plugin, to my Wemos D1 mini. I use this bin file ->ESP_Easy_mega-20181220_dev_ESP8266_4096. A small warning, I'm not a programmer :)
Now i'm tray and work 8-)
Just upload file from post #23 (firmware.rar - change extension from .jpg to . bin !!!)

Connect: Wemos D1 mini > 5110 LCD:
// D5 > Serial clock out (SCLK)
// D7 > Serial data out (DIN)
// D8 > Data/Command select (D/C)
// D4 > LCD chip select (CS)
// GND > LCD reset (RST)
// GND > GND
// 3.3V> VCC
// GND > Light (if you need)

SET: 1st gpio - 2 (d4)
:P

svasiliou
Normal user
Posts: 13
Joined: 04 May 2019, 20:46

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#34 Post by svasiliou » 04 May 2019, 20:52

Hello to fellow users.

I have this board
https://www.ebay.co.uk/itm/NodeMCU-V3-2 ... SwI7Fb3x~a
I flash it with firmware.bin from post
I have this NOKIA 5110 module
https://grobotronics.com/graphic-lcd-84 ... -5110.html
Module is capable to work with 3V & 5V controller (test it with my board from Andruino IDE)

Could anyone give any info about wiring?
I have read in detail all posts but something is missing I think.

Thanks in advance.

PS. I see CARMIN has similar devices. Could give wiring diagram? Thanks

RobertM
Normal user
Posts: 23
Joined: 22 Oct 2017, 15:23

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#35 Post by RobertM » 05 May 2019, 11:34

Did you try with my pinout - i think it's same

svasiliou
Normal user
Posts: 13
Joined: 04 May 2019, 20:46

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#36 Post by svasiliou » 05 May 2019, 13:48

Nope I have tried and it didn't work.
But I am waiting a new Mini D1 just to check it out.

It is possible that D4 (GPIO2) maybe it is reserved in my board?
If so it need recompile plugin?

My opinion that NOKIA 5110 display is a MUST for stable tree.

Thanks for your answers.

svasiliou
Normal user
Posts: 13
Joined: 04 May 2019, 20:46

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#37 Post by svasiliou » 08 May 2019, 14:43

I think that following question is probably stupid, but I have to ask.

I am uploading firmware.bin with latest EASYESP Flash tool.
Is it OK or I have to use a specific version?
Is there any chance bootloader of ESP8266 to be different from older boards and
won't work my Nokia 5110.

Is there any special "treatment" on line fields of plugin?

Thanks again for your answers

User avatar
Cramin
New user
Posts: 4
Joined: 04 Oct 2018, 08:34
Location: Poland, Myszkow
Contact:

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#38 Post by Cramin » 08 May 2019, 18:37

My nick is Cramin not Carmin.
Look at pinout:
adampr1 wrote: 23 Nov 2016, 13:50 Please check if you display have equal pin sequence :
PIN1 > Vcc,
PIN2 > GND,
PIN3 > SCE,
PIN4 > RST,
PIN5 > D/C,
PIN6 > DIN,
PIN7 > SCLK,
PIN8 > LED

IMPORTANT - in ESPEasy configuration it shows as I2C device with suggest that PIN 4 and 5 are used by PCD8544 plugin but they are NOT (I'll correct it next week - sorry no time). Followed code use only GPIO2,13,14,15
PIN's connection for display are hardcoded. Don't change them.
Image
And look at my image and pin layout, its changed. But when you properly connect it its working fine. PIN1 > VCC > in my LCD VCC is PIN6
Image

svasiliou
Normal user
Posts: 13
Joined: 04 May 2019, 20:46

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#39 Post by svasiliou » 09 May 2019, 15:52

Cramin wrote: 08 May 2019, 18:37 My nick is Cramin not Carmin.
My apologies. It is the daemon of the keyboard! I am in Greece.

Yes I checked & double checked wiring and pin out.
Your display is same with mine (mine its just blue PCB).
ESP8266 it is not the same.
Yes I have remap wiring according to diagram but no it does not working with my ESP8266 board.
I have also checked and enabled init SPI on Hardware tab.

Still no luck.
But when I implement the following project
https://simple-circuit.com/esp8266-node ... -5110-lcd/
everything works fine!
Attention this project uses 5GPIO wiring! Not 4 as I understand uses plugin.

So where is the mystery? Is it possible some library causes overlap pin configuration?
My goal is to have just an ESPEasy with Nokia module only to display values.
Nothing more.

svasiliou
Normal user
Posts: 13
Joined: 04 May 2019, 20:46

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#40 Post by svasiliou » 09 May 2019, 16:00

FIXED UP!

You have to connect RST from Nokia 5110 to RST of ESP8266 Board.
Do not check enable init SPI on Hardware Tab.
First GPIO2 (D4)
Don't check GPIO LED & Inversed LED on Hardware Tab

Working wiring is following
Vcc -> 3.3V
GND -> GND
CE -> D4
RST -> RST of ESP8266 lolin
D/C -> D8
DIN -> D7
CLK -> D5
B/L -> any pin of your choice (specific board is 3.3/5V compatible and you can use direct connection of BL to
esp pin but it is recommended to use a 330Ω resistor-BE Careful not fried up your board)

My board is this
Node-mcd-3-2-LUA-ESP8266-12E-Lolin.jpg
Node-mcd-3-2-LUA-ESP8266-12E-Lolin.jpg (51.01 KiB) Viewed 82072 times
and my Nokia5110 LCD is this
nokia5110-02.png
nokia5110-02.png (261.91 KiB) Viewed 82033 times

svasiliou
Normal user
Posts: 13
Joined: 04 May 2019, 20:46

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#41 Post by svasiliou » 22 Nov 2019, 11:37

OK now I have a probably logical question!
Why NOKIA5110 plugin is not at least in development firmware of ESPeasy?

I mean if it is alpha/beta or anything else it should be at least on testing or development firmware.
Right?

User avatar
Andrew Mamohin
Normal user
Posts: 95
Joined: 12 Jun 2020, 08:30
Location: Belarus, Gomel
Contact:

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#42 Post by Andrew Mamohin » 30 Jul 2020, 18:36

I have two such displays. I would like to use them in ESPeasy. Maybe someone will give me a fresh build, including a plugin for NOKIA5110?
Andy.

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

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#43 Post by Ath » 01 Aug 2020, 15:14

Andrew Mamohin wrote: 30 Jul 2020, 18:36 I have two such displays. I would like to use them in ESPeasy. Maybe someone will give me a fresh build, including a plugin for NOKIA5110?
Well, it's a bit hard (for me at least) to create a build, for a couple of reasons. a) It is an older plugin, and uses no longer supported functions and objects, b) it uses a not yet supported library, c) it is using the SPI interface, and that isn't much used with ESPEasy, d) I don't have such display, and it will take a couple of weeks to get one here, so while I may eventually get it working, it'll have to await testing until I receive a display.
/Ton (PayPal.me)

User avatar
Andrew Mamohin
Normal user
Posts: 95
Joined: 12 Jun 2020, 08:30
Location: Belarus, Gomel
Contact:

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#44 Post by Andrew Mamohin » 01 Aug 2020, 16:18

Ath wrote: 01 Aug 2020, 15:14 Well, it's a bit hard
Then don't worry! I just won't be using these displays with espeasy. I will attach them to arduino.
Andy.

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

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#45 Post by Ath » 01 Aug 2020, 16:53

Andrew Mamohin wrote: 01 Aug 2020, 16:18 Then don't worry! I just won't be using these displays with espeasy. I will attach them to arduino.
The advantage of these displays over the OLed displays is that they are a bit larger, thus easier to read from some 'distance' (~1 meter), while an average OLed requires me to be within ~60 cm to be readable (age has quite an influence on the eyes :roll:), so experimenting with it is just for fun, and they aren't expensive when buying from Aliexpress ;).
Disadvantage is the rather low resolution (84x48), but I'll be able to squeeze all the info on it, I think.

I'll probably want to add the oledframed-like commands too, so, not being a C++ programmer, that'll be a bit of a challenge (though I've contributed a few PRs to ESPEasy).
/Ton (PayPal.me)

User avatar
Andrew Mamohin
Normal user
Posts: 95
Joined: 12 Jun 2020, 08:30
Location: Belarus, Gomel
Contact:

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#46 Post by Andrew Mamohin » 01 Aug 2020, 17:17

Ath wrote: 01 Aug 2020, 16:53 The advantage of these displays over the OLed
I find these displays are more durable with continuous use.
Andy.

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

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#47 Post by TD-er » 01 Aug 2020, 21:07

What about e-ink?

User avatar
Andrew Mamohin
Normal user
Posts: 95
Joined: 12 Jun 2020, 08:30
Location: Belarus, Gomel
Contact:

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#48 Post by Andrew Mamohin » 01 Aug 2020, 22:12

TD-er wrote: 01 Aug 2020, 21:07 What about e-ink?
Example? Price?
Andy.

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

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#49 Post by TD-er » 01 Aug 2020, 22:44

Plugin: https://github.com/letscontrolit/ESPEas ... 6_eInk.ino
In the file are some links.

User avatar
Andrew Mamohin
Normal user
Posts: 95
Joined: 12 Jun 2020, 08:30
Location: Belarus, Gomel
Contact:

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#50 Post by Andrew Mamohin » 02 Aug 2020, 07:19

TD-er wrote: 01 Aug 2020, 22:44 In the file are some links.
This is a very high price for me. $9.90 + $5.28 = $15.18
I bought the display 5110 for $1.8
Andy.

joost d
Normal user
Posts: 53
Joined: 24 Dec 2020, 17:55
Location: Netherlands/ Haarlem

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#51 Post by joost d » 24 Dec 2020, 18:05

It looks like, this plugin is not working any more on ESPEasy_ESP32_mega-20201130.
Does somebody knows how to solve this compiling error: I'v treid to sole this problem for many hours....
C:/Users/xx/Documents/PlatformIO/Projects/ESPEasy3_P208/src/_P208_LCD_PCD8544.ino:99:39: error: expected primary-expression before '.' token
String tmpString = WebServer.arg(argc);
^
C:/Users/xx/Documents/PlatformIO/Projects/ESPEasy3_P208/src/_P208_LCD_PCD8544.ino:127:20: warning: unused variable 'setTextWrap' [-Wunused-variable]
boolean setTextWrap = false;
^
C:/Users/xx/Documents/PlatformIO/Projects/ESPEasy3_P208/src/_P208_LCD_PCD8544.ino:149:35: error: 'displayText' was not declared in this scope
displayText(deviceTemplate);
^
C:/Users/xx/Documents/PlatformIO/Projects/ESPEasy3_P208/src/_P208_LCD_PCD8544.ino:154:138: error: 'setPinState' was not declared in this scope
setPinState(1, Settings.TaskDevicePin3[event->TaskIndex], PIN_MODE_OUTPUT, Settings.TaskDevicePluginConfig[event->TaskIndex][3]);}
^
^
*** [.pio\build\custom_ESP32_4M316k\src\ESPEasy.ino.cpp.o] Error 1

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

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#52 Post by TD-er » 24 Dec 2020, 19:27

There are probably more things to change, but for starters, change WebServer into web_server.

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

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#53 Post by Ath » 24 Dec 2020, 21:59

I have done some initial work on this plugin, but didn't get it to display any text yet :shock: , I've shelved it for a while already, and probably give it a retry in the new year
/Ton (PayPal.me)

joost d
Normal user
Posts: 53
Joined: 24 Dec 2020, 17:55
Location: Netherlands/ Haarlem

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#54 Post by joost d » 25 Dec 2020, 11:28

Great, changing WebServer into web_server works.

Now i'm struggling with these two errors. Does anyone have any advice?

_P208_LCD_PCD8544.ino:149:35: error: 'displayText' was not declared in this scope
displayText(deviceTemplate);
_P208_LCD_PCD8544.ino:154:138: error: 'setPinState' was not declared in this scope
setPinState(1, Settings.TaskDevicePin3[event->TaskIndex], PIN_MODE_OUTPUT, Settings.TaskDevicePluginConfig[event->TaskIndex][3]);}

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

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#55 Post by TD-er » 25 Dec 2020, 15:02

I guess adding this as the first line of your .ino file will fix a lot of (future) compile errors:

Code: Select all

#include "_Plugin_Helper.h"
But setPinState is no longer implemented in the code, so you will need to make a lot more changes which makes it very hard to tell you what you should change.
This means I probably have to look at the code myself to see what else is missing or needs to be changed.

joost d
Normal user
Posts: 53
Joined: 24 Dec 2020, 17:55
Location: Netherlands/ Haarlem

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#56 Post by joost d » 26 Dec 2020, 08:30

I had already included the line "#include "_Plugin_Helper.h".....

Stephan2204
New user
Posts: 8
Joined: 06 Feb 2021, 20:25

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#57 Post by Stephan2204 » 06 Feb 2021, 20:33

Hi Everybody,

i have successfully connected the LCD with the precompiled Image.
On thing won't work. Sending of display text via http cmd won't work.
As i understand the plugin code the behaviour should be compatible to the lcd2004 plugin:

http://192.168.1.242/control?cmd=pcd854 ... TTODISPLAY


But nothing appears. No Logging. But no message "wrong or unknown command". Thats appearing if you use cmd=whatever.

Code: Select all

 case PLUGIN_WRITE:
      {
        String tmpString  = string;
        int argIndex = tmpString.indexOf(',');
        if (argIndex)
          tmpString = tmpString.substring(0, argIndex);
        if (tmpString.equalsIgnoreCase(F("PCD8544")))
        {
          success = true;
          argIndex = string.lastIndexOf(',');
          tmpString = string.substring(argIndex + 1);
          lcd2->setCursor(event->Par2 - 1, event->Par1 - 1);
          lcd2->println(tmpString.c_str());
        }
        if (tmpString.equalsIgnoreCase(F("PCD8544CMD")))
        {
          success = true;
          argIndex = string.lastIndexOf(',');
          tmpString = string.substring(argIndex + 1);
          if (tmpString.equalsIgnoreCase(F("Clear")))
            lcd2->clearDisplay();
        }
        break;
      }

It's a pity, that the code isn'T working with the actual ESPEasy Source.

Any Idea, or what i'm doing wrong?

BR
Stephan

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

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#58 Post by TD-er » 07 Feb 2021, 00:37

What exact build did you use?
Asking this because lots of users still install old builds linked from some blog post for example.

Stephan2204
New user
Posts: 8
Joined: 06 Feb 2021, 20:25

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#59 Post by Stephan2204 » 07 Feb 2021, 04:35

Hi,

I don't have tried to compile it by myself.
I have downloaded the binary from Post #23:
viewtopic.php?p=32154#p32154
And i have read the draft for the plugin. And read within this thread, that the plugin is only usable with sources around 2018.

So the next step for me is:
try to update the plugin to compile with actual releases, and / or use a release from ~2018.
Then it's possible to (re)check, if the http command will work.

In the precompiled version only the following informations are found on the info page:

Code: Select all

Build	20102 - Mega
Libraries	ESP82xx Core 2_4_2, NONOS SDK 2.2.1(cfd48f3), LWIP: 2.0.3
GIT version	
Plugins	73 [Normal] [Testing]
Build Md5	4d44355f4d44355f4d44355f4d44355f
Md5 check	fail !
Build time	Sep 22 2018 19:29:53
Binary filename	ThisIsTheDummyPlaceHolderForTheBinaryFilename64ByteLongFilenames 
Update:
Setting up platformio with visual studio code and compiling a unchanged repository successfully.
Now i have made the first advises to create a updated plugin.

Change for setPinState (might be the right way, after study of other plugins)

Code: Select all

 
          pinMode(Settings.TaskDevicePin3[event->TaskIndex], OUTPUT);
          digitalWrite(Settings.TaskDevicePin3[event->TaskIndex],Settings.TaskDevicePluginConfig[event->TaskIndex][0]);        
          // setPinState(1, Settings.TaskDevicePin3[event->TaskIndex], PIN_MODE_OUTPUT, Settings.TaskDevicePluginConfig[event->TaskIndex][3]);}
          portStatusStruct newStatus;
          const uint32_t   key = createKey(1, Settings.TaskDevicePin3[event->TaskIndex]);
          // WARNING: operator [] creates an entry in the map if key does not exist
          newStatus         = globalMapPortStatus[key];
          newStatus.command = 1;
          newStatus.mode    = PIN_MODE_OUTPUT;
          newStatus.state   = Settings.TaskDevicePluginConfig[event->TaskIndex][3];
          savePortStatus(key, newStatus);}
 


Compiling done and image is working. Display is showing the configured lines.

Next step: verify http command....

BR
Stephan

Stephan2204
New user
Posts: 8
Joined: 06 Feb 2021, 20:25

Re: PCD8544 - Nokia 5110/3310 LCD - beta plugin

#60 Post by Stephan2204 » 07 Feb 2021, 21:28

One step forward.

Find here the code for the PCD8544 Display compatible to ESP_Easy_mega_20210207.
Something might be buggy. The ESP was sometime not directly reachable. But i don't find any reason or logging about.
Feel free to optimize the code, but give here some feedback.

// Working:
// - Display Text & Var via ESPEasy Webinterface (Line1-LineX)
// - Clear Display via httpcmd (http://ESP-IP/control?cmd=pcd8544cmd,clear)
// - Send Text via httpcmd (but don't clear the line :-( ) (http://ESP-IP/control?cmd=pcd8544,1,1,Hello%20World!)
//
// Mixed Mode (Display Data from ESP Easy and HTTP-request) is not easy to handle. Some problems are known from P012 LCD2004 Plugin
// Set Interval to 0 seconds for only using the http requests. Otherwise display clear will occur every cycle.
//
//
// ToDo:
// - If no Data via Webinterface (Line 1-x) exists. don't clear the display or no update!
// - How to "overwrite" via Webcmd the actual line. -> No garbage character
// (introduce clear line command? depending on orientation write n spaces. then write the new text?)



Code: Select all

#ifdef USES_P208
//#######################################################################################################
//################################## Plugin 208: NOKIA lcd2 ###############################################
//#######################################################################################################

// Working:
// - Display Text & Var via ESPEasy Webinterface (Line1-Linex)
// - Clear Display via httpcmd (http://ESP-IP/control?cmd=pcd8544cmd,clear)
// - Send Text via httpcmd (but don't clear the line :-( ) (http://ESP-IP/control?cmd=pcd8544,1,1,Hello%20World!)
//
// Mixed Mode (Display Data from ESP Easy and HTTP-request) is not easy to handle. Some problems are known from P012 LCD2004 Plugin
// Set Interval to 0 seconds for only using the http requests
//
// ToDo:
// - If no Data via Webinterface (Line 1-x) exists. don't clear the display or no update!
// - How to "overwrite" via Webcmd the actual line. -> No garbage character
//


#define PLUGIN_208
#define PLUGIN_ID_208 208
#define PLUGIN_NAME_208 "Display - LCD PCD8544 [TESTING]"
#define PLUGIN_VALUENAME1_208 "Backlight"
#define PLUGIN_VALUENAME2_208 "Contrast"
#define PLUGIN_VALUENAME3_208 "Rotation"

#include "_Plugin_Helper.h"
//#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>

Adafruit_PCD8544 *lcd2;
byte lines = 6;

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

  switch (function)
  {

    case PLUGIN_DEVICE_ADD:
      {
        Device[++deviceCount].Number = PLUGIN_ID_208 ;
        Device[deviceCount].Type = DEVICE_TYPE_SINGLE;
        Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_SINGLE;
        Device[deviceCount].Ports = 0;
        Device[deviceCount].PullUpOption = false;
        Device[deviceCount].InverseLogicOption = false;
        Device[deviceCount].FormulaOption = false;
        Device[deviceCount].ValueCount = 3;
        Device[deviceCount].SendDataOption = false;
        Device[deviceCount].TimerOption = true;
        Device[deviceCount].TimerOptional = true;
        break;
      }


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

    case PLUGIN_GET_DEVICEVALUENAMES:
      {
        strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_208));
        strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[1], PSTR(PLUGIN_VALUENAME2_208));
        strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[2], PSTR(PLUGIN_VALUENAME3_208));
        break;
      }


    case PLUGIN_WEBFORM_LOAD:
      {
        addFormNumericBox(F("Display Contrast(50-100):"), F("plugin_208_contrast"), Settings.TaskDevicePluginConfig[event->TaskIndex][1]);

        addFormPinSelect(F("Backlight PIN"), F("taskdevicepin3"), Settings.TaskDevicePin3[event->TaskIndex]);

        byte choice3 = Settings.TaskDevicePluginConfig[event->TaskIndex][2];
        int optionValues3[4] = { 0, 1, 2, 3 };
        String options3[4] = { F("0"), F("90"), F("180"), F("270") };
        addFormSelector(F("Display Rotation"), F("plugin_208_rotation"), 4, options3, optionValues3, choice3);

        byte choice4 = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
        String options4[2] = { F("ON"), F("OFF") };
        int optionValues4[2] = { 0, 1 };
        addFormSelector(F("Backlight"), F("plugin_208_backlight"), 2, options4, optionValues4, choice4);

        char deviceTemplate [lines][48];
        LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
        for (byte varNr = 0; varNr < lines; varNr++)
        {
          addFormTextBox(String(F("Line ")) + (varNr + 1), String(F("Plugin_208_template")) + (varNr + 1), deviceTemplate[varNr], 80);
        }

        success = true;
        break;
      }

    case PLUGIN_WEBFORM_SAVE:
      {
        Settings.TaskDevicePluginConfig[event->TaskIndex][0] = getFormItemInt(F("plugin_208_backlight"));
        Settings.TaskDevicePluginConfig[event->TaskIndex][1] = getFormItemInt(F("plugin_208_contrast"));
        Settings.TaskDevicePluginConfig[event->TaskIndex][2] = getFormItemInt(F("plugin_208_rotation"));

        char deviceTemplate[lines][48];
        for (byte varNr = 0; varNr < lines; varNr++)
        {
          char argc[25];
          String arg = F("Plugin_208_template");
          arg += varNr + 1;
          arg.toCharArray(argc, 25);
          String tmpString = web_server.arg(argc);
          strncpy(deviceTemplate[varNr], tmpString.c_str(), sizeof(deviceTemplate[varNr]));
        }

      //  Settings.TaskDeviceID[event->TaskIndex] = 1; // temp fix, needs a dummy value

        SaveCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
        success = true;
        break;
      }

    case PLUGIN_INIT:
      {
        if (!lcd2)
        {
          // pin 14 - Serial clock out (SCLK)
          // pin 13 - Serial data out (DIN)
          // pin 12 - Data/Command select (D/C)
          // pin 5 - LCD chip select (CS)
          // pin 4 - LCD reset (RST)
          //lcd2 = new Adafruit_PCD8544(14, 13, 12, 5, 4);
          #if defined(ESP8266)
              lcd2 = new Adafruit_PCD8544(15, 2, -1); // D/C (need to be connected) GPIO2 , CS(CEN) GPIO15 , RESET not connected
          #endif
          #if defined(ESP32)
              lcd2 = new Adafruit_PCD8544(16, 17, -1); // D/C (need to be connected) GPIO16 , CS(CEN) GPIO17 , RESET not connected
          #endif

          boolean setTextWrap = false;
        }
        // Setup lcd2 display
        byte plugin1 = Settings.TaskDevicePluginConfig[event->TaskIndex][2]; // rotation
        byte plugin2 = Settings.TaskDevicePluginConfig[event->TaskIndex][1]; // contrast
        byte plugin4 = Settings.TaskDevicePluginConfig[event->TaskIndex][0]; // backlight_onoff
        UserVar[event->BaseVarIndex+2]=plugin1;
        UserVar[event->BaseVarIndex+1]=plugin2;
        UserVar[event->BaseVarIndex]=!plugin4;
        if (plugin1==0 || plugin1==2)
        {
          lines=6;
        }
        else{
          lines=10;
        }
        lcd2->begin();                     // initialize the lcd2
        lcd2->setContrast(plugin2);
        lcd2->setRotation(plugin1);
        lcd2->clearDisplay();
        char deviceTemplate[lines][48];
        LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
        displayText(deviceTemplate);
        lcd2->display();
        if (Settings.TaskDevicePin3[event->TaskIndex] != -1){
          pinMode(Settings.TaskDevicePin3[event->TaskIndex], OUTPUT);
          digitalWrite(Settings.TaskDevicePin3[event->TaskIndex],Settings.TaskDevicePluginConfig[event->TaskIndex][0]);
 
          // setPinState(1, Settings.TaskDevicePin3[event->TaskIndex], PIN_MODE_OUTPUT, Settings.TaskDevicePluginConfig[event->TaskIndex][3]);}
 
          portStatusStruct newStatus;
          const uint32_t   key = createKey(1, Settings.TaskDevicePin3[event->TaskIndex]);
          // WARNING: operator [] creates an entry in the map if key does not exist
          newStatus         = globalMapPortStatus[key];
          newStatus.command = 1;
          newStatus.mode    = PIN_MODE_OUTPUT;
          newStatus.state   = Settings.TaskDevicePluginConfig[event->TaskIndex][3];
          savePortStatus(key, newStatus);}
 
        success = true;
        break;
      }

    case PLUGIN_READ:
      {
        char deviceTemplate[lines][48];
        LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
        displayText(deviceTemplate);
        success = false;
        break;
      }

    case PLUGIN_WRITE:
      {
        String tmpString  = string;
        int argIndex = tmpString.indexOf(',');
        if (argIndex)
          tmpString = tmpString.substring(0, argIndex);
        if (tmpString.equalsIgnoreCase(F("PCD8544")))
        {
          success = true;
          argIndex = string.lastIndexOf(',');
          tmpString = string.substring(argIndex + 1);
          lcd2->setTextSize(1);
          int colPos  = event->Par2 - 1;
          int rowPos  = event->Par1 - 1;
          lcd2->setCursor(colPos, rowPos*8); // 8 Pixel
          //addLog(LOG_LEVEL_INFO, F("Position set"));

          lcd2->println(tmpString.c_str());
          lcd2->display();
        }
        if (tmpString.equalsIgnoreCase(F("PCD8544CMD")))
        {
          success = true;
          argIndex = string.lastIndexOf(',');
          tmpString = string.substring(argIndex + 1);
          if (tmpString.equalsIgnoreCase(F("Clear")))
            // addLog(LOG_LEVEL_INFO, F("Clear Display"));
            // Works! 
            lcd2->clearDisplay();
            lcd2->display();
        }
        break;
      }

  }
  return success;
}

boolean displayText(char deviceTemplate[][48]){
        String log = F("PCD8544: ");
        String string = F("");
        lcd2->clearDisplay();
        lcd2->setTextSize(1);
        lcd2->setTextColor(BLACK);
        lcd2->setCursor(0,0);
        for (byte x = 0; x < lines; x++)
        {
          String tmpString = deviceTemplate[x];
          if (tmpString.length())
          {
            String newString = parseTemplate(tmpString, 48);
            lcd2->setCursor(0,x*8);
            lcd2->print(newString);
            string+=newString+"\\";
          }
        }
        log += String(F("displayed text: \"")) + String(string) + String(F("\""));
        addLog(LOG_LEVEL_INFO, log);
        lcd2->display();
        return true;
  }
#endif // USES_P208


Post Reply

Who is online

Users browsing this forum: No registered users and 116 guests