Arduino node red intermittent serial issues

rate I only get the first few, I guess closest reading a back these are wired where each group of 3 for average purposes are on a pin and I call the function to return the data via serial see below

#include <OneWire.h>
#include <DallasTemperature.h>

const byte numChars = 32;
char receivedChars[numChars];
boolean newData = false;

#define RELAY_OFF 0
#define RELAY_ON 1

void ProcessSerialData()
{
  static boolean recieveInProgress = false;
  static byte ndx = 0;
  char startMarker = '<';
  char endMarker = '>';
  char rc;

  while(Serial.available() > 0 && newData == false)
  {
    rc = Serial.read();

    if(recieveInProgress == true)
    {
      if(rc != endMarker)
      {
        receivedChars[ndx] = rc;
        ndx++;

        if(ndx >= numChars)
        {
          ndx = numChars - 1;
        }
      }
      else
      {
        receivedChars[ndx] = '\0';
        recieveInProgress = false;
        ndx = 0;
        newData = true;
      }
    }
    else if(rc == startMarker)
    {
      recieveInProgress = true;
    }
  }
}

void ShowNewData()
{
  if(newData == true)
  {
    ProcessSerialInput(receivedChars);
    //Serial.println(receivedChars);
    newData = false;
  }
}

void ProcessSerialInput(String data)
{
  if(data.substring(0, 5) == "relay")
  {
    if(data.substring(7, 9) == "on")
    {
      int p = data.substring(5, 7).toInt();
      RelayControl(p, RELAY_ON);
    }
    else if(data.substring(7, 9) == "of")
    {
      int p = data.substring(5, 7).toInt();
      RelayControl(p, RELAY_OFF);
    }
  }
  else if(data.substring(0, 5) == "tstat")
  {
    if(data.substring(7, 9) == "aa")
    {
      int p = data.substring(5, 7).toInt();
      ProcessTemperature(p);
    }
  }
}

void RelayControl(int Pin, unsigned char Status)
{ 
  pinMode(Pin, OUTPUT);
  digitalWrite(Pin, Status);
  Serial.println("RELAY,PIN," + String(Pin) + "," + String(Status));
}

String GetSensorAddress(DeviceAddress device)
{
  String address;
  address += "[";

  for(uint8_t i = 0; i < 8; i++)
  {
    address += String("0x");

    if(device[i] < 0x10)
    {
      address += String("0");
    }

    address += String(device[i], HEX);

    if(i < 7)
    {
      address += String(", ");
    }
  }

  address += String("]");

  return address;
}

void ProcessTemperature(int Pin)
{
  
  String serialDataTemp = "";
  String address = "";
  float tempC;

  OneWire OneWireBus(Pin);
  DallasTemperature Sensor(&OneWireBus);
  Sensor.begin();
  Sensor.requestTemperatures();
  
  for(int i = 0; i < Sensor.getDeviceCount(); i++)
  {
    tempC = Sensor.getTempCByIndex(i);
    Serial.println("TEMP,PIN," + String(Pin) + "," + String(tempC));
  }
}

void setup()
{
  Serial.begin(115200);
}

void loop()
{
  ProcessSerialData();
  ShowNewData();
}

Then I have another issue where when I send another command to turn relays on I either get a working system or nothing happens at all, the relay does not act at all.

With node red I’m sending commands such as

to get the data from a pin with 3 ds18b20 on so that returns 3 messages.

Such as

[ “temp”, 22, 18.0 ]

Which I can then work with, this is working ok except the random missing sensors with certain call intervals

The relays my biggest issue is send

or

Sometimes it works sometimes it doesn’t, not sure what’s happening here. It either works great or completely not at all.

I can’t post the node red code here as it’s too large but I build a string as msg.payload and send it to Arduino via serial.

I’m using serial response for the temperature calls which seems to work well, not sure if that’s relevant

  • Limit reading the sensor to once per 2 seconds.

BTW

Always show us a good schematic of your proposed circuit.
Show us good images of your ‘actual’ wiring.
Give links to components.

i have reduced my sensor reading but still seem to be sending commands to the relays quite often, i guess i shouldn't send the same on command to the relay every few seconds but im worried that it will miss a command for some reason so repeated should help with that.

it has been working great, ive done some re wiring on the system today and when i left it the code was instantly turning a mixture of the 8 relays on, ive just been reading this

and im wondering if i should be powering the relay board from its own power supply, also the arduino is getting power from the raspberry pi usb port at the moment also, that and the fact the load switching could have damaged the relay board.

edit

im basically using one of these

im using a hat for my arduino mega that turns the pins into push connectors, the theory is once working i will convert to a circuit board layout

Those cards should be wired as this is:

image

that may be my issue then, im not using a dedicated power supply for the relay board. It has been working well even today but this is obviously my first step.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.