unknown message

Hi,
I am programming a C# interface for one of my Arduino projects which controls a machine.
I capture the messages back from the Arduino when I send a command.
The funny think is that I get also messages that have not been requested with the usual serial.write.

These back messages, common to all commands I send, looks like a confirmation back from Arduino. The messages look like these:

VMDPE_3|131_VMDPE (here I sent to Arduino a command to setup the PWM on analog 3 to 131)
VMDPE_3|0_VMDPE (here I sent to Arduino a command to setup the PWM on analog 3 to 0)
VMDPE_4|255_VMDPE (here I sent to Arduino a command to setup the PWM on analog 5 to 255)
VMDPE_4|0_VMDPE (here I sent to Arduino a command to setup the PWM on analog 5 to 0)
VMDPE_7|1_VMDPE (here I sent a command to setup pin 2 HIGH)
VMDPE_6|0_VMDPE (here I sent a command to setup pin 2 LOW)
VMDPE_5|1_VMDPE (here I sent a command to setup pin 13 HIGH)
VMDPE_8|0_VMDPE (here I sent a command to setup pin 13 LOW)

Now, looking at the above messages, I see that only in the case relevant the command sent to analog 3 the message is directly related to the pin that received the command. In all the other cases, and this is a mystery for me, there is apparently no link between the received message and the command I sent even if the Arduino is acting correctly as per command (I got that pin doing what I asked).

Is anyone of you able to give me some comment on the above?
And, what is the meaning of the VMPDE?

I think that once I have understood what is going on with these message, I can implement or use the Arduino better.


Thanks
Felice

Is anyone of you able to give me some comment on the above?

Without seeing the Arduino code? No.

Ohpssss....sorry.
Here it is:

char inData[10];
int index;
boolean started = false;
boolean ended = false;


void setup(){
  Serial.begin(9600);
  Serial.println("ready");
  pinMode (13, OUTPUT);
  pinMode (2, OUTPUT);
  pinMode (3, OUTPUT);
  pinMode (5, OUTPUT);
}

void loop()
{
  while(Serial.available() > 0)
  {
    char aChar = Serial.read();
    if(aChar == '>')
    {
      started = true;
      index = 0;
      inData[index] = '\0';
    }
    else if(aChar == '<')
    {
      ended = true;
    }
    else if(started)
    {
      inData[index] = aChar;
      index++;
      inData[index] = '\0';
    }
  }

	if(started && ended)
  {
	int inInt = atoi(inData);
	//Serial.println(inInt);
    
	// setta PWM temperatura su pin analogico 3
    if (inInt < 1000 )
     {
      int temp = (inInt);
      analogWrite(3, temp);
      //Serial.println(inInt);
      }

	// setta PWM motore su pin analogico 5
      else if (inInt < 2000)
     { 
       int speed = (inInt- 1000);
       analogWrite(5, speed);
     }

	// setta il pin 13 HIGH
       else if (inInt < 3000)
     { 
       digitalWrite(13, HIGH);
     }

	  //setta il pin 13 LOW
     else if (inInt < 4000)
     { 
       digitalWrite(13, LOW); 
     }
    
    //setta il pin 2 HIGH
       else if (inInt < 5000)
     { 
       digitalWrite(2, HIGH);
     }

	 //setta il pin 2 LOW
     else if (inInt < 6000)
     { 
       digitalWrite(2, LOW);
     }
 
    // Get ready for the next time
    started = false;
    ended = false;

    index = 0;
    inData[index] = '\0';
  }  
}

The output of that sketch is NOT the output shown in your initial post. In fact, that sketch produces NO output.

So, what is producing the output that you showed? I was under the impression that you were trying to read that as input.

I don't see your bug yet, unless you send more than 10 characters between angle brackets.

But there is a bug in such a case: if you send more than 9 characters you'll overflow the inData buffer and overwrite index, which is the sort of thing that can lead to the weird behavior you're seeing.

It's best to check to see if there's room in a buffer before adding a character to it.

-br

PaulS,
that was exactly my question!

However, I have to check in my c# serial.read if something is appended in the message received from the Arduino but still I do not understand why there is a clear relation with the sent command only in the message related to analog 3!


VMDPE_3|131_VMDPE (here I sent to Arduino a command to setup the PWM on analog 3 to 131)
VMDPE_3|0_VMDPE (here I sent to Arduino a command to setup the PWM on analog 3 to 0)


All the other messages clearly report the status but to a pin that has nothing to do with the command!
ny idea?

It would be helpful to see exactly what text is sent…

-br

PaulS,
sorry I forgot to confirm that the sketch I posted is the one that is sending back those message.
To avoid any misunderstanding between the sent message and the Arduino, I have also tested the same with the Arduino IDE directly.
In the attached image you see the Arduino sketch I posted,that is being loaded and the message sent with the serial monitor >100< that according to the sketch is supposed to setup PWM on analog 3 to 100
the message I get back from the Arduino is "VMDPE_3|100_VMDPE".
May be you can try my sketch on an Arduino UNO and confirm.

The code you posted does NOT send back "VMDPE_3|100_VMDPE". Clearly, the code that you posted is not the code that is executing on the Arduino.

This is the code I tested in the last two pics.
This code is giving me the messages I mentioned before.
I am going mad with this!!!

char inData[10];
int index;
boolean started = false;
boolean ended = false;


void setup(){
  Serial.begin(9600);
  Serial.println("ready");
  pinMode (13, OUTPUT);
  pinMode (2, OUTPUT);
  pinMode (3, OUTPUT);
  pinMode (5, OUTPUT);
}

void loop()
{
  while(Serial.available() > 0)
  {
    char aChar = Serial.read();
    if(aChar == '>')
    {
      started = true;
      index = 0;
      inData[index] = '\0';
    }
    else if(aChar == '<')
    {
      ended = true;
    }
    else if(started)
    {
      inData[index] = aChar;
      index++;
      inData[index] = '\0';
    }
  }

	if(started && ended)
  {
	int inInt = atoi(inData);
	//Serial.println(inInt);
    
	// setta PWM temperatura su pin analogico 3
    if (inInt < 1000 )
     {
      int temp = (inInt);
      analogWrite(3, temp);
      //Serial.println(inInt);
      }

	// setta PWM motore su pin analogico 5
      else if (inInt < 2000)
     { 
       int speed = (inInt- 1000);
       analogWrite(5, speed);
     }

	// setta il pin 13 HIGH
       else if (inInt < 3000)
     { 
       digitalWrite(13, HIGH);
     }

	  //setta il pin 13 LOW
     else if (inInt < 4000)
     { 
       digitalWrite(13, LOW); 
     }
    
    //setta il pin 2 HIGH
       else if (inInt < 5000)
     { 
       digitalWrite(2, HIGH);
     }

	 //setta il pin 2 LOW
     else if (inInt < 6000)
     { 
       digitalWrite(2, LOW);
     }
 
    // Get ready for the next time
    started = false;
    ended = false;

    index = 0;
    inData[index] = '\0';
  }  
}

wait.........I am doing another check!

That code works fine here (tested on serial monitor) on an old Duemilanove with a '328.

What kind of Arduino do you have?

-br

Billroy,
thanks for testing. I found the possible problem as explained in my last post.

Thanks

Quite interesting!!!

The sketch is the same.
The difference is in the IDE used to load it to Arduino.

In the pics I posted, the sketch was loaded using Visual Studio 2010 (Visual Micro plugin).
As you have seen even using the Arduino serial monitor (in that case I did not reload the sketch from the Arduino IDE), I got back those funny messages.

After your answers, in order not to appear like a puppy, I reloaded the sketch from the Arduino IDE and tested again........the messages have disappeared.

I need to investigate with the guys at Visual Micro. It looks quite obvious now that when the sketch is loaded from the VB10 plugin, something happen!

Thanks for your reply, actually forced me to do some more testing.

I finally understood what was going on.
I think is good to know for the future.

I write my code for Arduino and for my applications in C# using visual studio 2010 and two plugins:
Visual Micro
Visual Micro debugger
http://www.visualmicro.com

To test the Arduino sketch with the debugger I use break points in the sketch. See this picture:

The sketch is then loaded to the Arduino and the debugger wait for the messages back to show the output.
I just realize now that those messages "VMDPE_3|131_VMDPE" are for the debugger.

This is the reason why after I loaded the sketch from the Arduino IDE the messages disappeared.
In this case there where no break points in the sketch. Those break points are only there in the Visual Studio IDE.
And this explain also why the messages are not related to the Arduino PIN but, instead, to the break point ID.

Lesson learned.

Answer explained here, you either need to build the project in Release (non-debug) mode or use a different dedicated Serial/SoftwareSerial port for debugging.

In summary, the debugger provides options to either share the main serial port (default) or use a dedicated serial port (or switch off debugging) :slight_smile: