SoftSerial

Moderators: grovkillen, Stuntteam, TD-er

Message
Author
arnoldg
Normal user
Posts: 14
Joined: 29 Aug 2017, 07:02

SoftSerial

#1 Post by arnoldg » 27 Mar 2018, 21:01

Hello,

I'm trying to develop a dimmer which is controlled by serial.
For this i use softserial on puin D1 and D2
But when i compill all looks good, but it isn't working.
What could be wrong ?

for testing purpose the esp should spit out the whole alfabet, but this isn't working.
on the TX and RX pin's i connected a serial to USB print to monitor the serial port.
and yes TX and RX are connected the right way.

this is when i upload the softserial example it is working !

Code: Select all

//#######################################################################################################
//#################################### Plugin 200: Dimmer ##################################################
//#######################################################################################################

#define PLUGIN_200
#define PLUGIN_ID_200         200
#define PLUGIN_NAME_200       "Dimmer 230V "
#define PLUGIN_VALUENAME1_200 "Dimmer"

#define MinDim                15
#define MaxDim                250

#include <SoftwareSerial.h>                     // to use pin 4 and 5 as RX and TX ports

SoftwareSerial DimSerial(D1,D2,false,256); // RX, TX

boolean Plugin_200_init = false;

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

  switch (function)
  {
    case PLUGIN_DEVICE_ADD:
      {
        Device[++deviceCount].Number = PLUGIN_ID_200;
        Device[deviceCount].Type = DEVICE_TYPE_SINGLE;
                Device[deviceCount].VType = SENSOR_TYPE_SWITCH;


        Device[deviceCount].SendDataOption = false;
        break;
      }

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

        case PLUGIN_WEBFORM_LOAD:
          {
            success = true;
            break;
          }

        case PLUGIN_WEBFORM_SAVE:
            {
              success = true;
              break;
            }

      case PLUGIN_INIT:
        {
          DimSerial.begin(9600);
          addLog(LOG_LEVEL_INFO, F("Dimmer: Init OK "));
  for (char ch = ' '; ch <= 'z'; ch++) {
    DimSerial.write(ch);
  }
  DimSerial.println("");
          
          break;
        }



          case PLUGIN_READ:
            {
              // This routine does not output any data and so we do not need to respond to regular read requests
              success = false;
              break;
            }


      case PLUGIN_WRITE:
      {
        String log = "";
        String command = parseString(string, 1);
        byte payload = (event->Par2 * 2.55);
        if (payload<MinDim) { payload = 0; };
        if (payload>MaxDim) { payload = 255; };

        String status = "Command : "+ command + ",    Payload : " + payload;
        addLog(LOG_LEVEL_INFO, status);

        if (command == F("dim"))
        {
          DimSerial.write(payload);
          log = String(F(" Set Dim level to ")) + String(payload);
          addLog(LOG_LEVEL_INFO, log);
        }
        success = true;
        break;
      }
    }
  return success;
}

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: SoftSerial

#2 Post by toffel969 » 28 Mar 2018, 13:28

Is i2c activated on D1+2? That would be the default settings
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

arnoldg
Normal user
Posts: 14
Joined: 29 Aug 2017, 07:02

Re: SoftSerial

#3 Post by arnoldg » 29 Mar 2018, 07:04

Thanks,

That was the problem, i overlooked it for 3 days :oops:

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: SoftSerial

#4 Post by toffel969 » 29 Mar 2018, 09:11

arnoldg wrote: 29 Mar 2018, 07:04 Thanks,

That was the problem, i overlooked it for 3 days :oops:
Great :) ! Glad to have been of assistance.
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

Who is online

Users browsing this forum: Anthropic Claude Bot [bot] and 13 guests