The terminal module allows you to both send data to the hardware device and receive data from the hardware device.
This module is similar to the serial monitor where you see the data sent and received from the device in real-time.
Options for displaying data
You can display the sent and received data on the terminal in the following formats:
You can toggle between the options by clicking on the tree verticle dots on the top right side of the screen and clicking on the option.
Functions for Arduino IDE
To include the Terminal module in the Arduino program, you have to include the following header:
After defining the above mention headers, you have to include the dabble library:
You can download the zip of Arduino Library for
depending on the board you are using.
Enabling Bluetooth Communication
To enable Bluetooth communication, you have to initialize serial communication using the following code:
- For evive and Arduino Mega, Uno and Nano
Here Baud_Rate is the baud rate set for the Bluetooth module. With evive, you normally get 115200 baud rate HC-05 or HM-10 modules.
- For ESP32
In place of Bluetooth_Name enter name that you want to keep for Bluetooth of ESP32. Default name given in the library is “MyEsp32”.
Refreshing the data
To refresh the data that the device has got from the mobile app, you have to use the following line of code:
Following are the function available for the Terminal module:
- Terminal.available(): This function tells if there is new data present in the terminal queue or not. It returns 0 if there is not data, and 1 if there is data present.
- Terminal.read(): This function returns the first byte available in the terminal queue. This function returns one character at a time.
- Terminal.readString(); This function returns the whole string of data available on the Terminal.
- Terminal.compareString(String text): This function takes a string in the argument and compares whether the string available in the Terminal is same or not. If the string matches, it returns 1, otherwise returns 0.
- Terminal.readNumber(): This function reads the last number available in the Terminal and returns its value in int data type.
- Terminal.print(data): This function sends the argument to the mobile app.
- Terminal.println(data): This function sends the argument to the mobile app with a newline added at the end of the message.
PictoBlox (Scratch) Blocks
You can use the terminal in the following three ways.
- To compare a string of data: There is a boolean block “is data from terminal()”, using this you can compare a string received from the terminal.
- To send data to the terminal: There is a stack block “send () to terminal”, using this you can send a string of data to the terminal.
- To receive a number from the terminal: There is a reporter block “get Number from terminal”, It will always return a number. Using this, You can receive any number from the terminal.
The example given below shows how to carry out a general communication between the Terminal module and your board.
1. Upload the code and open Serial Monitor.
2. Send any data from the Serial Monitor. You will be able to see it on your terminal screen. Similarly, send any data from terminal it will be displayed on Serial Monitor.
Code for all boards is given below. Copy the code as per your board. You can also find the code by navigating to “Files>>Examples>>Dabble>>” and select “Terminal” example as per your board.
Mega, Uno, and Nano
Turn Lights ON/OFF
In this example, you will learn how to switch ON or OFF pin 13 led of your board by sending the “lights on” and “lights off” commands using Dabble’s Terminal module. Below is the script in Stage mode in Pictoblox.
This script will run on evive but for Mega, Uno, and Nano add the “set bluetooth baud rate to” block below “when flag clicked” block. The rest of the script remains the same. For now, PictoBlox does not support ESP32; however, it will be added soon.