Plotting Analog Data Ascii Format

Analog data can be sent from the controller to be plotted by sending the values as text or ASCII strings. For example, the following lines of code will send data as text. The debug command is used to send data from the controller back to the computer.

Analog data is formatted as a text value followed by a carriage-return (cr).

V In StampPlot, disconnect from the Com Port if you have not already done so. This will allow you to send a new program to your BASIC Stamp module.

V Enter the program below into your BASIC Stamp Editor.

V Run the program.

V Monitor the BASIC Stamp Editor's Debug Terminal to observe data being sent before closing it.

V Use the No-Frills choice of StampPlot for testing: Connect, Plot, and Data Flushing (F11).

'{$STAMP BS2} '{$PBASIC 2.5} 'Plotting 1 analog value x VAR Byte

'{$STAMP BS2} '{$PBASIC 2.5} 'Plotting 1 analog value x VAR Byte

DO

FOR x =

0 TO 255

DEBUG

DEC x, CR

PAUSE

100

NEXT

LOOP

As can be seen in your Debug Terminal, the data arrives as a 0, then 1 and so on. Each value is represented by 1, 2 or 3 characters (bytes) forming each number. This is due to the dec modifier formatting the values as text.

When StampPlot is connected and plotting you will see the values plotted. The pause command is used to prevent the data queue from filling from high-speed data.

Multiple analog values may be plotted by separating each value with a comma. Notice the form is a dec followed by a variable, a comma, a comma in quotes, a comma and another value. PBASIC requires a comma between each value or string sent, and StampPlot requires commas as part of the text.

V Disconnect the Com Port from StampPlot.

V Enter and run the following program in the BASIC Stamp Editor.

'Plotting 3 analog values

'Plotting 3 analog values

val

VAR

Byte

val2

VAR

Byte

val3

VAR

Byte

the format of Enable Shifting

DO

FOR Val = 0 TO 255

val2 = val / 2

val3 = val * 2

DEBUG DEC val, ","

, DEC val2, ",

,", DEC val3, CR

PAUSE 100

NEXT

LOOP

V Look at the Debug Terminal to ensure your data is properly formatted. It should look like the example seen below:

100,50,200

V Close the Debug Terminal

V Open StampPlot and connect.

V Click on the Plot button. Your graph should look like the one below.

Figure C-3

Plotting Three Analog Values

Figure C-3

Plotting Three Analog Values

Up to 10 values may be plotted simultaneously by separating them with commas.

DIY Battery Repair

DIY Battery Repair

You can now recondition your old batteries at home and bring them back to 100 percent of their working condition. This guide will enable you to revive All NiCd batteries regardless of brand and battery volt. It will give you the required information on how to re-energize and revive your NiCd batteries through the RVD process, charging method and charging guidelines.

Get My Free Ebook


Post a comment