Skip to content

USB Serial Output

ScottD edited this page Apr 5, 2017 · 2 revisions

There are two functions available which allow for outputting messages and variable values from the Jewelbot.

The primary objective of these messages is typically for debugging purposes, to learn where and how your program is running.

The messages output from the Jewelbot can be viewed on the Serial Monitor. The Serial Monitor is located in the Tools menu of the Arduino IDE. Before accessing the Serial Monitor, the Jewelbot must be plugged in and the proper USB port selected under the Tools -> Port: menu.

Once the Jewelbots Friendship Board is selected, there is an example sketch of this functionality under the File -> Examples -> Jewelbots_Examples called USB_output.ino.

Before getting to outputting messages, a function which sets up the Jewelbot to enable the messaging.

Setup for USB output

  • set_run_loop_charging()

The set_run_loop_charging() function sets an internal switch in the code so the Jewelbot will run the loop() function while it is plugged in to USB power. Typically the Jewelbot does not run the loop() function while charging so that the charge status can be displayed.

In this case, since the USB must be plugged in for the desired output to be sent to the computer, this function tells the Jewelbot to run loop() while plugged in to power.

To utilize set_run_loop_charging(), place the function inside the setup() section of the sketch:

void setup() {
// put your setup code here, to run once:

// Function to tell the Jewelbot to run the loop() function
// while plugged into USB power
set_run_loop_charging();
}

USB output API

  • JWB_SERIAL(string to output)

    This function prints a string message to the Serial Monitor.

    JWB_SERIAL("Debugging message.\n");
  • JWB_SERIAL_PRINTF(string with formatting, variable)

    This function prints a string message and variable value to the Serial Monitor.

    JWB_SERIAL_PRINTF("x = %u\n", x);

Both functions follow the standard C formatting rules. The "\n" character in the above examples is for a new line, so each message will start on its own line.