Stampplot to Arduino

I would like to test status of button on Stampplot side.
Stampplot start with macros below:
INIT:

!MACR .OBJECTS
’ Set as default/startup macro
!DEFS (ME)
’ Use DLBCLICK Routine
!USEC ON
’ Set analog span
!SPAN 0, 100
’ Set max time
!TMAX 400
’ Set X label
!XLBL PLATE VOLTAGE
’ Set Y Label
!YLBL PLATE CURRENT
’ Title plot
!TITL None
’ Set display information
!DISP D9 G2 A0 S0 B15 R
’ Use double-click Routine
!USEC ON

ENDMAC

OBJECTS:
!POBJ Clear
!PPER 75,100

’ Set Back Color ********
!POBJ oBack=8

’ butRun – OBUTTON *****
!POBJ oButton.butRun=78,36,5,4,Run,8
!POBJ butRun.F=Arial,8,1,0,0
'-- Event Code
!POBJ butRun.C=!POBJ chkRun=1(:wink:
!POBJ Stat = Waiting To Run

’ butSTOP – OBUTTON *****
!POBJ oButton.butSTOP=85,36,5,4,STOP!,8
!POBJ butSTOP.F=Arial,8,1,0,0
'-- Event Code
!POBJ butSTOP.C=!POBJ ChkRun=0(:wink:
!POBJ Stat = Waiting To Stop(:wink:

’ chkRun – OCHECK *****
!POBJ oCheck.chkRun=78.,32.,15.,5.,chkRun,0,0,9
’ !POBJ chkRun.V=0

ENDMAC

So if Run button pressed chkRun changes his status

And Arduino sketch:

// from book

int LED = 13;
int in = 0;

void setup()
{
Serial.begin(9600);
pinMode(LED,OUTPUT);

delay(5000);

//
Serial.println("!RSET");
Serial.println("!TITL Arduino DEMO-PLOT");
Serial.println("!PNTS 300");
Serial.println("!TMAX 60");
Serial.println("!SPAN 0,1023");
Serial.println("!AMUL 1");
Serial.println("!DELD");
Serial.println("!SAVD ON");
Serial.println("!TSMP ON");
Serial.println("!CLMM");
Serial.println("!CLRM");
Serial.println("!PLOT ON");
Serial.println("!RSET");
delay(5000);
}

void loop()
{
while (in != 49)
{
Serial.flush();
delay(300);
Serial.println("!READ (chkRun)");
int in = Serial.read();
delay(500);
Serial.print(“in=”);
Serial.println(in);
}
Serial.println(“Good job!”);
}

Problem is - I cannot catch when object change his status
In log I see that status ( on Stampplot side) has changed but Arduino cannot catch it.

You don't think those errors being shown in the upper right window are important?

Hi Kuka,
I've been working with you through support Email, but just as a general post here for all interested parties on using the Arduino to read StampPlot:

  • A value from StampPlot may be read by sending a string asking to read the control name:
    Serial.println("!READ (control_name)");

StampPlot will return the value in ASCII + a carriage return. Ensure "Micro Echoes Data" under "Configuration" is unchecked or it will also append a "|Q|" so the StampPlot ignores the returned data.

The Arduino native code is not real robust at reading a returning value. It reads only one byte at a time using Serial.read. For a simple "1" or "0" returned, this may be sufficient. For a longer value, extra code or a serial library is needed.

For your code, you cannot "read" a pushbutton - it does not have a state of 1 or 0, it is momentarily down to active code for it. Some options where you can get a "1" or "0" back are:

  • A check box control.
  • An image button control (two images, 2 states)
  • An imgButton2 control in the Additional Objects list.

So, if you create a checkbox names "chkRun", from the Arduino you can do a:
Serial.println("!READ (chkRun)");
And StampPlot will send back a "0" or "1" (ASCII) + ASCII 13 to be read by the arduino with Serial.read

We are currently making extensive changes to StampPlot, including a totally new help document which will highlight using all aspects of it with the Arduino. Unfortunately, I haven't gotten any code similar to above done yet. A little concerning using it with the Arduino is posted on our downloads page, and there are BASIC Stamp centered primers up as well.

The new build and help files should be available by the end of summer '12, but I hope to have some example code to read done soon.

Sincerely,
Martin Hebel
SelmaWare Solutions
http://www.stampplot.com