Microcontroller Example Code

Nearly every feature of MakerPlot-J may be controlled through serial data, from basic plotting to configuring controls to creating an entire interface. Below are some examples to test with. This data may come from a control’s event code, the Debug/CLI Window or from the controller.

These examples use Arduino coding to demonstrate operations from the controller side but can be adapted for nearly any other microcontroller.

All strings must end in a Carriage Return (ASCII 13) or Line Feed (ASCII 10).


Analog values are sent as string such as 10,20,30
Send 2 analog values for plotting and to be used in other ways, they are accessed in MPJ as [ain0] and [ain1]:

Serial.print(value1); // send first value
Serial.print(“,”); // comma separator
Serial.println(value2); // send second value with LF

Note: If plotted on an analog plot named “plot”, they can be accessed in MPJ with [plot.ch0] and [plot.ch1].


Digital values are sent as %10010
Send 2 digital values for digital plotting and to be used in other ways, they are accessed in MPJ as [din0] and [din1] (highest – MSB to lowest – LSB):

Serial.print(“%”); // send binary indicator
Serial.print(bit1); // send first Boolean value
Serial.println(bit2); // send second Boolean value with LF

Note: If plotted on a digital plot named “dplot”, they can be accessed in MPJ as [dplot.ch1] – MSB, and [dplot.ch0] – LSB or
as [dplot.bit1] – MSB, and [dplot.bit0] – LSB


A string starting with ? sends data to the Debug/CLI Window.
Send a message to be shown in the Debug/CLI Window:

Serial.println(“? Hello World!”);


Strings that do not start with a value, %, ! ? or @ are processed as messages.
Send a message to be shown in the Message Window:

Serial.println(“Pump is on”) // cannot start with value, !, % or @

Note: MPJ can access the value as [messageString]


MakerPlot-J Instructions begin with !
To send a general environment instruction to MPJ:

Serial.println(“!bell”); // sound the computer bell


To operate a control, such as resetting a plot control named ‘plot’:

Serial.println(“!plot.reset”); // reset the plot named “plot”

Or setting the maximum value of a meter named ‘met0’:

Serial.println(“!met0.max=200”); // set maximum on meter 0


Interface controls can be created by the microcontroller!
To create a textbox on the interface called txtStatus in lower right:
!makeTextBox name, left, top, width, height, text

Serial.println(“!makeTextBox txtStatus, 85, 90, 15, 5, Status”);


To update a control’s value manually, such as setting the value of a meter named ‘metPower’:

Serial.print(“!metPower=”); // define control to update, such as a meter
Serial.println(intPower); // send value

Or updating the text in the status textbox created previously:

Serial.print(“!txtStatus=Pump On”); // set a text box named txtStatus


To read a control’s value, such as a slider named ‘sldPower’ and accept returning data:

Serial.println(“!read sldPower”); // request to read slider from MPJ
int data = Serial.parseInt(); // Accept returning value

Note: Please see the installed interactive code for retrieving multiple values with minimal delay and error trapping.


MakerPlot-J supports drawing on interfaces, plots and canvas controls.
To draw a line on the plot using plot coordinates:
!plotName.drawLine x1, y1, x2, y2, color, thickness (Just !draw… for drawing on the main Interface)

Serial.println(“!plot.drawLine 24, 10, 60, 90, RED , 3”);


To place a textbox to mark a point based on time into plot and
analog value 0:
!plotname.drawText x, y, text, size, color

Serial.println(“!plot.drawText [plot.now], [ain0], Cycled, 10, RED”);


MakerPlot-J can perform high-level math operations on your data.
To place a textbox to mark a point based on time into plot and
analog value 0 plus 5 to move it up some:
Math is performed by enclosing in { }

Serial.println(“!plot.drawText [plot.now], { [ain0] + 5 }, Cycled, 10, RED”);