Firmata reading custom values from Arduino

Hi there. When I upload StandardFirmata.ino to my Arduino board, it all works ok :slight_smile:

But, I have some custom code, from that code I would like to pass a value to HASS via: Firmata.sendAnalog(analogPin, MyOwnValue);

I get stuck very fast, taking again StandardFirmata, then only add/modify this part in the main loop:

void loop()
{
  byte pin, analogPin;
  
  /* DIGITALREAD - as fast as possible, check for changes and output them to the
   * FTDI buffer using Serial.print()  */
  checkDigitalInputs();

  /* STREAMREAD - processing incoming messagse as soon as possible, while still
   * checking digital inputs.  */
  while (Firmata.available())
    Firmata.processInput();

  // TODO - ensure that Stream buffer doesn't go over 60 bytes

  currentMillis = millis();

  if(currentMillis - prev_cntr_millis > 1000)
  {
    prev_cntr_millis += 1000;
    
    if(test_cntr < 255)
      test_cntr++;
    else
      test_cntr = 0;    
  }
     
  if (currentMillis - previousMillis > samplingInterval) 
  {
    previousMillis += samplingInterval;
  
    /* ANALOGREAD - do all analogReads() at the configured sampling interval */
    for (pin = 0; pin < TOTAL_PINS; pin++) 
    {
      if (IS_PIN_ANALOG(pin) && Firmata.getPinMode(pin) == PIN_MODE_ANALOG) {
        analogPin = PIN_TO_ANALOG(pin);
       
        if (analogInputsToReport & (1 << analogPin)) 
        {          
            //Firmata.sendAnalog(analogPin, analogRead(analogPin));
            Firmata.sendAnalog(analogPin, test_cntr);
        }       
      }
    }
   
    // report i2c data for all device with read continuous mode enabled
    if (queryIndex > -1) {
      for (byte i = 0; i < queryIndex + 1; i++) {
        readAndReportData(query[i].addr, query[i].reg, query[i].bytes, query[i].stopTX);
      }
    }
  }

#ifdef FIRMATA_SERIAL_FEATURE
  serialFeature.update();
#endif
}

Idea is that the variable test_cntr should be send when reading a certain Analog input, for some reason, in HASS, I see this input changing about eacht 30sec, from 0-40-80-120-160-200-0

Strange thing is, that in the “Windows Remote Arduino Experience” App, it simply works! What can be wrong, something with timing?

Controlling a digital pin via HASS does work responsive fast. The issue seems to be analog input related.