Depth-First Message-Passing

Message Passing

In the previous section, what our first Ardestan patch does; It sends out the message: “Hello, world!” to your computer via its serial output. The message is received by the computer at it serial input, resulting the message to be shown in your Serial Monitor window inside the IDE.

Now, let’s learn what is happening in your first patch step-by-step. Before we begin explaining the detail, just keep this in Ardestan in your mind: “An Ardestan program consists of a number of objects that pass messages each other.”

In Ardestan, an object sends out a value from its outlet. When it is received by another object, the object may react to the incoming value; It may store the incoming value for later use, it may output some other value from its own outlet, or it may set the digital output high or low.

Here, we would like to clarify the difference between ‘a value’ and ‘a message’ in Ardestan. A value in Ardestan is some value such as 1, 2, 1.52, -11.3, bang, high, “Hello. world!” etc. We learn more about values in Ardestan in a later section. At this point, just remember it can be any integer number, decimal number, symbol or string (string is a sequence of characters). It can be stored within an Ardestan object and passed to other objects via connections built between objects. In Ardestan, when a value is passed to another object through a connection, we call it a message, as it is sent out from one object and received by another object to exchange the information, in man cases, to trigger a certain behavior at the receiver object.

Thus, an Ardestan patch is made of two or more Ardestan objects. Each object may generate a value, pass it to other objects as a message, receive a message, and do something when it received a message. In short, an Ardestan patch is executed by ‘message passing’ between objects.

Now let’s get into the details of what is happening in your first Ardestan patch. First, we need to know about the loadbang object (Figure 1). The loadbang object has a feature that it sends out a symbol value: bang, when your Arduino starts up (at this point, just think of ‘a symbol’ as a word consists of one or more characters, which is internally given its own unique ID.)

Figure 1: The loadbang object sends out a message (a symbol: bang) from its outlet,
and the string object receives it at its left inlet.

As shown in Figure 1, when the Arduino starts up, the loadbang object sends out a message (a symbol: bang) from its outlet and it is received by the string object at the left inlet. What does the string object do when it receives a message, a symbol: bang, at its inlet? It does immediately output the stored string value as a message (Figure 2).

Figure 2: The string object outputs a message (a string: “Hello, world!”).

Now, the serial_println object just received a message (a string: “Hello, world”).

Serial Monitor

Receiving the Output from Your First Patch

In the previous section, we created our first Ardestan patch and then compiled the patch/uploaded to the Arduino. However, we still haven’t seen anything yet. To see what your program does, let’s click the ‘Serial Monitor’ tab and see the Serial Monitor window in the Ardestan IDE (Figure 1).

Figure 1: The Serial Monitor window.

You see the ‘active’ checkbox on the top left of the Serial Monitor window. Let’s click it as shown in Figure 2. By doing so, we can see the input from your Arduino inside the Serial Monitor window.

Figure 2: activating the serial communication..

Now, You may have seen a message printed out by your Arduino: “Hello, world!” in the Serial Monitor window (Figure 3).

Figure 3: a message received from the Serial output from your Arduino.

If you don’t see any, just reset your Arduino by pushing its reset button on board. If you push it again, then you will see one more “Hello. world!” message inside the Serial Monitor. You can repeat this as many as you want (Figure 4).

Figure 4: More “Hello. world!” messages received from your Arduino.

What is a Serial Monitor?

Now, we are sure that our first Ardestan patch is working fine! Yet, you might still have one question: “What is a Serial Monitor?” at this point, if this is your first experience with the Arduino. So, let’s learn what it is now.

To use an Arduino and upload a program, you need to connect your Arduino and computer with a USB cable, as you already know. Via the USB interface, your computer can ‘talk’ to the Arduino so that you can upload an Arduino program.

This USB connection can be also used to let your Arduino program communicate with the Ardestan IDE (or other software on your laptop). This is what we have done in our first Ardestan patch, and our program used the serial output via the USB interface to let the Arduino output the message to your Serial Monitor window.

Figure 5. Serial Communication

As shown in Figure 5, when a serial connection is established between the Arduino and your computer, The data that your Arduino output at its serial output is received at the serial input of your computer and vice versa. Then, what ‘Serial’ means? At this point, just simply think that it is called ‘serial’ as the communication between your Arduino and computer is by sending just one bit at one time (conversely, if the communication is performed by sending two more bits altogether simultaneously, it is called ‘parallel’).

It is also required to coordinate the speed of the serial communication by making it sure that the both sides (your Arduino and your computer) communicate. Hence, we need to set the ‘baud rate’ (the speed of the serial communication) the same on both sides. In Figures 1, 2, and 4, you see the baud rate is set to 9600 bps (bit per second) on the side of the Serial Monitor (on your computer).

Figure 6: Your first Ardestan patch (reproduced from Figure 9 in the section: Your First Patch).

Similarly, as shown in Figure 6, the ‘serial’ object is given the number 9600 after its object name (such a value is called ‘an argument’ in Ardestan. We will learn about this a bit later). This sets up the speed of the serial communication (baud rate) on your Ardestan to 9600 bps.

Now we learned that we are using the serial output from the Arduino to send out the message “Hello, world!” (which is received by the serial input of your laptop and shown in the Serial Monitor window). In the next section, we learn about the other part of our first patch.

Next: Depth-First Message-Passing

Your First Patch

Now, let’s write your first Ardestan program. Respecting the tradition of the hacker’s culture, we write a very simple program to display a message: “Hello, world!” inside the Serial Monitor pane of the Ardestan IDE.

Patch, Object, and Connection

A visual program in Ardestan is called ‘a patch.’ This is because Ardestan’s language design is originated from its predecessors, such as Max and PureData, both of which are quite popular in computer music and digital arts. In these languages, a visual program is called ‘a patch,’ possibly its visual program looks like a modular synthesizer patch of the good old time (see Figure 1 below).

Figure 1: An example of a modular synthesizer patch
(from the Wikimedia Commons, license: Creative Commons Attribution 2.0 Generic)

Similarly as in a synthesis patch above, a program is created by connecting various software modules in a Ardestan patch. We simply call each software module ‘an object’ or ‘an Ardestan object’ in Ardestan. We also refer a virtual cable that connects an output of an object to an input of another object (or the object that produces output itself) as ‘a connection’ in Ardestan.

Creating a New Patch

First, select the menu item: New Patch from the File menu to create a new program.

Figure 2: The New Patch menu item.

Then, you will see a new window inside the Ardestan IDE, tabbed with a title (“untitled”), as shown in Figure 3.

Figure 3: A New Patch is created.

Creating an Ardestan Object

To create our first Ardestan patch, we first place four Ardestan objects inside the patch window. To create an Ardestan object, just select the menu item: Object Box under the menu: Put.

Figure 4: Creating an object box.

Then, you should see an ‘object box’ in the patch window.

Figure 5: An object box is created inside the patch window.

Alternatively, you can use the shortcut key (command + 1 for macOS or control + 1 for other platforms). An object box will be created below the position under the mouse cursor.

At this point, it is still just an ‘object box’ and it is still not an Ardestan object. Just click the object box and type “loadbang” to the object box, then it will be changed as a “loadbang” object as below.

Figure 6: A loadbang object is created.

An object box can be dragged to anywhere inside the patch window. Let’s create more Ardestan objects and place them as below.

Figure 7: Four Ardestan objects are created.

Connecting Objects: Outlets and Inlets

You might have noticed that some Ardestan objects have one or more small rectangles at the top and at the bottom. These are called ‘inlets’ and ‘outlets’ respectively. An inlet is where an object receives an output value from another object and an outlet is where an object output a value.

In Ardestan, we connect inlets and outlets of various objects so that Ardestan objects can collaborate each other and perform the task you want to realize.

Figure 8: Connecting an inlet and an outlet.

Let’s create a connection between the loadbang object and the string object we already placed in the patch window.

First click an inlet of the loadbang object (left above), and then drag the mouse (right above). Move the mouse at the left outlet of the string object (left below) so that you can connect the inlet and the outlet. After you successfully connect them, the connection will be created between the inlet and the outlet (right below). Now that the connection is created, whenever the loadbang object output a value from its outlet, it will be received by the string object at its left inlet.

Let’s create one more connection between the string object to the serial_println object as below (Figure 9).

Figure 9: Your First Patch.

Now, let’s save your patch by selecting the menu item: File > Save.

Figure 10: The “Save” menu item.

As we haven’t given any file name, a dialog window will be shown as Figure 11. We name this file as ‘hello.ard’ and save it inside the project folder.

Figure 11: The save dialog window (This is the Japanese version).

If you successfully saved your file, it should show up in the Project Explorer window in the Ardestan IDE (Figure 12).

Figure 12: The “hello.ard” file is now shown in the Project Explorer window.

Building and Uploading Your First Patch

Now we have finished ‘coding’ of your first patch in Ardestan! Then. Let’s ‘compile’ your patch and then upload your program to Arduino.

First thing you need to do it to make it sure that your Arduino is connected to your computer. Then, select the menu item: Tools > Select Connected Board.

Figure 13: The “Select Connected Board” menu item

If you select this menu item, Ardestan will look for Arduino devices connected to your computer and show the dialog: “Select the Arduino device” as shown in Figure 14. your Arduino should show up in the connected box. Select one you want to upload your program and then press the OK button.

Figure 14: The Select the Arduino device dialog.

If you successfully selected the Arduino, the names of the Arduino and the connected port should show up in the window title of the Ardestan IDE as below (Figure 15).

Figure 15: The window title is changed.
Now it shows the names of the Arduino device and the connected port.

Now you are ready to compile and upload your program to the Arduino! Yet, how can we do it? Select the menu item: Project > Build and Upload (Figure 16). Then, the Ardestan IDE will start compiling your program and uploading it to the Arduino.

Figure 16: The “Build and Upload” menu item.

If you have successfully compiled and uploaded your patch, you should have seen the messages as in Figure 17 in the Console window in the Ardestan IDE.

Figure 17: The compilation/upload results are shown in the Console window in the Ardestan IDE.

At this point, you may haven’t seen anything even though you successfully compiled and uploaded your patch to the Arduino.

Let’s move to the next section: Serial Monitor to see what your first Ardestan patch is doing!.