PCD8544 - Nokia 5110/3310 LCD - beta plugin

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
adampr1
Normal user
Posts: 16
Joined: 27 Jun 2016, 13:34
Location: Germany

PCD8544 - Nokia 5110/3310 LCD - beta plugin

#1 Post by adampr1 » 27 Jun 2016, 15:26

Hi to all, first of all I'm not programmer man and my native language is not English :)
So I'd like to present modified OLED plugin (in BETA stage) to support Nokia 3310 LCD (PCD8544). (Its not finish) and if some one can help to make it better - is welcome.
Its use (Adafruit-PCD8544 and Adafruit GFX library - version for ESP8266 ) with small modification in Adafruit-GFX library to support 14 characters in line (please modify line 82 from "wrap = true" to "wrap = false").
It's not clean, more garbage from OLED-plugin but I have not much time to make it clean - maybe someone ? And maybe remove Adafruit library and build in direct in PCD8544 plugin like OLED-plugin
Hiere is that code:

Code: Select all

//#######################################################################################################
//#################################### Plugin 208: LCD PCD8544 display #################################
//#######################################################################################################

// Sample templates
//  Temp: [DHT11#Temperature]   Hum:[DHT11#humidity]
//  DS Temp:[Dallas1#Temperature#R]
//  Lux:[Lux#Lux#R]
//  Baro:[Baro#Pressure#R]

#define PLUGIN_208
#define PLUGIN_ID_208         208
#define PLUGIN_NAME_208       "Display - LCD PCD8544"
#define PLUGIN_VALUENAME1_208 "PCD8544"

byte Plugin_208_PCD8544_address = 0x3c;

boolean Plugin_208(byte function, struct EventStruct *event, String& string)
{
  boolean success = false;
  static byte displayTimer = 0;
 
  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 = 0;
        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));
        break;
      }

    case PLUGIN_WEBFORM_LOAD:
      {
        char deviceTemplate[6][64];
        LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
        for (byte varNr = 0; varNr < 6; varNr++)
        {
          string += F("<TR><TD>Line ");
          string += varNr + 1;
          string += F(":<TD><input type='text' size='64' maxlength='64' name='Plugin_208_template");
          string += varNr + 1;
          string += F("' value='");
          string += deviceTemplate[varNr];
          string += F("'>");
        }

        string += F("<TR><TD>Display button:<TD>");
        addPinSelect(false, string, "taskdevicepin3", Settings.TaskDevicePin3[event->TaskIndex]);

        char tmpString[128];

        sprintf_P(tmpString, PSTR("<TR><TD>Display Timeout:<TD><input type='text' name='plugin_208_timer' value='%u'>"), Settings.TaskDevicePluginConfig[event->TaskIndex][2]);
        string += tmpString;

        success = true;
        break;
      }

    case PLUGIN_WEBFORM_SAVE:
      {
        String plugin3 = WebServer.arg("plugin_208_timer");
        Settings.TaskDevicePluginConfig[event->TaskIndex][2] = plugin3.toInt();

        char deviceTemplate[6][64];
        for (byte varNr = 0; varNr < 6; 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:
      {
       Plugin_208_StartUp_PCD8544();
      
        displayTimer = Settings.TaskDevicePluginConfig[event->TaskIndex][2];
        if (Settings.TaskDevicePin3[event->TaskIndex] != -1)
          pinMode(Settings.TaskDevicePin3[event->TaskIndex], INPUT_PULLUP);
        success = true;
        break;
      }

    case PLUGIN_TEN_PER_SECOND:
      {
        if (Settings.TaskDevicePin3[event->TaskIndex] != -1)
        {
          if (!digitalRead(Settings.TaskDevicePin3[event->TaskIndex]))
          {
           // Plugin_208_displayOn(); // DISPLAY ON
          display.display();
            displayTimer = Settings.TaskDevicePluginConfig[event->TaskIndex][2];
          }
        }
        break;
      }

    case PLUGIN_ONCE_A_SECOND:
      {
        if ( displayTimer > 0)
        {
          displayTimer--;
          if (displayTimer == 0)
          Plugin_208_displayOff();      // DISPLAY OFF
        }
        break;
      }

    case PLUGIN_READ:
      {
        display.clearDisplay();
        //display.begin();
        //display.setContrast(50);
        //display.setTextSize(1);
        char deviceTemplate[6][64];
        LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));

        for (byte x = 0; x < 6; x++)
        {
          String tmpString = deviceTemplate[x];
          if (tmpString.length())
          {
            String newString = parseTemplate(tmpString, 14);
            display.setCursor(0,x*8);
            display.print(newString);
          }
        }
        display.display();
        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);
          Plugin_208_sendStrXY(tmpString.c_str(), event->Par1 - 1, event->Par2 - 1);
        }
        if (tmpString.equalsIgnoreCase(F("PCD8544CMD")))
        {
          success = true;
          argIndex = string.lastIndexOf(',');
          tmpString = string.substring(argIndex + 1);
          if (tmpString.equalsIgnoreCase(F("Off")))
          Plugin_208_displayOff();
          else if (tmpString.equalsIgnoreCase(F("On")))
          Plugin_208_displayOn();
          else if (tmpString.equalsIgnoreCase(F("Clear")))
          Plugin_208_clear_display();
         
        }
        break;
      }

  }
  return success;
}

static void Plugin_208_reset_display(void)
{
  Plugin_208_displayOff();
  Plugin_208_clear_display();
  Plugin_208_displayOn();
}


void Plugin_208_StartUp_PCD8544()
{
    display.begin();
    display.setContrast(50);
    display.setTextSize(1);
    display.setTextColor(BLACK);
    display.setCursor(0,0);
    display.println("ESPEasy");;
}


void Plugin_208_displayOn(void)
{
  display.clearDisplay();
  display.display();
}


void Plugin_208_displayOff(void)
{
  display.clearDisplay();
  display.display();
}


static void Plugin_208_clear_display(void)
{
  display.clearDisplay();
  display.display();
}

// Set the cursor position in a 14 COL * 6 ROW map.
static void Plugin_208_setXY(unsigned char row, unsigned char col)
{
 display.setCursor(row,col);
}


// Prints a string regardless the cursor position.
static void Plugin_208_sendStr(unsigned char *string)
{
  display.println(*string);
}


// Prints a string in coordinates X Y, being multiples of 6.
// This means we have 14 COLS (0-13) and 6 ROWS (0-5).
static void Plugin_208_sendStrXY(const char *string, int X, int Y)
{
  Plugin_208_setXY(X, Y);
  display.println(*string);
}

Please use it as STARTPOINT - ALFA version but it work for me now.

BR
Adam

PS. Hope it will good start point.
Attachments
PCD8544_UPS_photo2.jpg
displayed data from LiIo-UPS
PCD8544_UPS_photo2.jpg (174.65 KiB) Viewed 13644 times
PCD8544_UPS.jpg
My Hardware (LiIo 1S charger, StepUp driver - 5V output - for OrangePI PC, INA219, ESP-07 on breadboard PCB, PCD8544 in hardware SPI mode)
PCD8544_UPS.jpg (207.08 KiB) Viewed 13644 times
PCD8544 demo config.jpg
some config for my LiIo-UPS project (used INA219)
PCD8544 demo config.jpg (156.7 KiB) Viewed 13644 times
PCD8544 demo config2.jpg
PCD8544 demo config2.jpg (184.4 KiB) Viewed 13644 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

jblb
Normal user
Posts: 5
Joined: 24 May 2016, 00:44

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

#2 Post by jblb » 18 Jul 2016, 15:14

Hi,

this is a interesting plug-in project for use PCD8544 based lcd display but i need some more details to use it.
the library used is https://github.com/bbx10/Adafruit-PCD85 ... ee/esp8266 ?
that are the modification for the ESPEasy.ino file ? ( i supposed there his some has a test to compile tthe file you provide fail ! )
final question his about how you connect PCD8544 display with also use of I2C, all connection that i find used SDA and SCL pins from ESP8266 module

thank the the help you can give me.

pzaplos
Normal user
Posts: 1
Joined: 19 Jul 2016, 22:03

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

#3 Post by pzaplos » 19 Jul 2016, 22:16

Sorry to ask,

I guess I am in a very similar situation. I have done some wifi battery powered nods measuring external values and now I am thinking about doing something more exciting. But I need to control proximity sensor MPR121 and a 8x8 led with MAX7219 driver. I have found the libraries for these to run with ESP. Now the quest is to write own plugins to make them work within ESPEasy sw. How did you find how to make the plugin please...as this seems to be big task for me just sneaking into Arduino/ESP programming for several nights... Is there any to do/ follow guide how to do it?

7_lol
Normal user
Posts: 3
Joined: 03 Sep 2016, 16:55

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

#4 Post by 7_lol » 03 Sep 2016, 17:02

Hello i took above code and made it works.. at least for me :D
we also need lib from link above.
Pinout is:
Adafruit_PCD8544(14, 13, 12, 5, 4);

Code: Select all

// 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)
Edit: updated a bit, added rotation.

Edit2: updated to use gpio to turn off/on backlight, added loging and UserVars, cleanup.. didnt tested cmds yet and i probably wont since i dont need it,

Warning: Check if current of backlight isnt bigger than 15mA if powered from pin, or 20mA for sink

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][18];
        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][18];
        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)
        {
          lcd2 = new Adafruit_PCD8544(14, 13, 12, 5, 4);
        }
        // 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][18];
        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][18];
        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[][18]){
        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, 18);
            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;
  }
esp1.png
esp1.png (28.9 KiB) Viewed 13267 times
esp2.jpg
esp2.jpg (125.12 KiB) Viewed 13267 times

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

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

#5 Post by adampr1 » 20 Nov 2016, 16:53

Excellent , I'll try it tomorrow.
B.R.
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

walter1604
Normal user
Posts: 1
Joined: 23 Nov 2016, 01:37

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

#6 Post by walter1604 » 23 Nov 2016, 01:51

Nice work however I have compiler errors

C:\Users\walter\Documents\Arduino\libraries\Adafruit-PCD8544-Nokia-5110-LCD-library-zero\Adafruit_PCD8544.cpp: In member function 'void Adafruit_PCD8544::begin(uint8_t, uint8_t)':

C:\Users\walter\Documents\Arduino\libraries\Adafruit-PCD8544-Nokia-5110-LCD-library-zero\Adafruit_PCD8544.cpp:187:17: error: cannot convert 'volatile uint32_t* {aka volatile unsigned int*}' to 'PortReg* {aka volatile unsigned char*}' in assignment

clkport = portOutputRegister(digitalPinToPort(_sclk));

^

C:\Users\walter\Documents\Arduino\libraries\Adafruit-PCD8544-Nokia-5110-LCD-library-zero\Adafruit_PCD8544.cpp:189:17: error: cannot convert 'volatile uint32_t* {aka volatile unsigned int*}' to 'PortReg* {aka volatile unsigned char*}' in assignment

mosiport = portOutputRegister(digitalPinToPort(_din));

ANY ideas ???

kniazio
Normal user
Posts: 49
Joined: 12 Jun 2016, 11:12

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

#7 Post by kniazio » 23 Nov 2016, 09:36

Hello
Do the same esp8266 will it work?
Will it be possible to obtain readings for example. DHT22?
How to connect the display directly to esp8266 12E?
Regards

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

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

#8 Post by adampr1 » 23 Nov 2016, 13:50

Yes , the PCD8544 is connected direct to ESP8266 in hardware SPI configuration (in my example - ESP-07). I'll post today complete how-to based on modification from 7_lol (post No 4). It's working GREAT !!!

hier is modified version of 7_lol plugin for Hardware SPI and my connection (picture under code part).
Pleas 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.

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);
        }
        // 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;
  }

NodeMCU_ESP-07_PCD8544.png
NodeMCU_ESP-07_PCD8544.png (100.71 KiB) Viewed 12747 times
ESPEASY_PCD8544_OLED_K_Temp_.jpg
ESPEASY_PCD8544_OLED_K_Temp_.jpg (145.42 KiB) Viewed 12827 times
Last edited by adampr1 on 24 Nov 2016, 14:02, edited 1 time in total.
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

kniazio
Normal user
Posts: 49
Joined: 12 Jun 2016, 11:12

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

#9 Post by kniazio » 23 Nov 2016, 15:04

Dzieki za odp
Mnie chodzi o esp 12E
http://allegro.pl/nodemcu-v2-lua-develo ... 82577.html
Dokladnie ktory pin z wyswietlacza do ktorego pinu w esp 12E
Jestem poczatkujacy

kvjajoo
Normal user
Posts: 3
Joined: 23 Apr 2017, 07:21

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

#10 Post by kvjajoo » 29 Apr 2017, 12:11

Hi,

I am getting following compile error :

C:\Users\administrator\Documents\Arduino\ESPEasy\_P208_PCD8544.ino: In function 'boolean Plugin_208(byte, EventStruct*, String&)':

_P208_PCD8544:171: error: incompatible types in assignment of 'int' to 'unsigned int [12]'

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

^
exit status 1
incompatible types in assignment of 'int' to 'unsigned int [12]'

I have put your code mentioned in post 8 into file called _P208_PCD8544.ino in ESPEasy directory.

I have very very limited knowledge in Programming. Can you please help ??

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: 16
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
Normal 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: 16
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: 1636
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: 12
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
Normal 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: 92
Joined: 28 Feb 2018, 07:40

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.

User avatar
Cramin
Normal 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: 12
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 99 times

User avatar
Cramin
Normal 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.
WP_20181009_15_51_40_Pro.jpg
ESP8266_5110LCD
WP_20181009_15_51_40_Pro.jpg (259.11 KiB) Viewed 4898 times

User avatar
grovkillen
Core team member
Posts: 3268
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
Normal 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: 3268
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: 12
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: 16
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 4625 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: 13
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: 3268
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: 13
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: 6
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: 13
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: 6
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: 6
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
Normal 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: 6
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: 6
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 2134 times
and my Nokia5110 LCD is this
nokia5110-02.png
nokia5110-02.png (261.91 KiB) Viewed 2095 times

Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests