Graphical programming with ArduBlock

The Dwenguino is programmed in a textual programming language C++ within the Arduino IDE environment. However, for those who are reluctant to start textual programming, a user-friendly textual programming language is made available. It allows the user to acquire the different components of programming languages. One such language is ArduBlock. In this tutorial we get you started with graphical programming of the Dwenguino in ArduBlock.


  1. One Dwenguino board
  2. Enclosed USB cable

Installing the ArduBlock plugin

ArduBlock is a Java plugin for Arduino IDE which was originally build by David Li and He Quichen. We have adapted ArduBlock to make it easy to program the Dwenguino. If you want to use it, you will need to download ArduBlock first, and unzip it in the tools folder of your Arduino workspace. If the tools folder does not exist yet in your Arduino workspace you will need to make it. After installing ArduBlock you should be able to see it in the Tools menu of Arduino IDE. Click on ArduBlock to start the graphical programming environment. Don't forget to open a new sketch in Arduino IDE first! It is also a good idea to connect the Dwenguino before starting ArduBlock and choose Tools > Board > Dwenguino and connect to the Dwenguino by selecting the correct port.

ArduBlock in Arduino IDE

Hello World

When you open ArduBlock you should see a graphical programming environment with an empty sketch in front and the available blocks on the left: Graphical programming environment

By dragging a block from the left to the sketch you can program your Dwenguino. In the menu Dwenguino you can find the Dwenguino compatible blocks. Similar to the Arduino sketch, we start with a program block which has a setup and loop block. If you want to use the Dwenguino you will need to initialise the Dwenguino by calling the InitDwenguino block after which you can print a simple Hello World message to the LCD with the LCD block:

Hello World in ArduBlock

Now we are ready to upload our program to our Dwenguino. Therefore, click on Upload to Arduino in ArduBlock. If you did not forget to connect and select the Dwenguino before starting ArduBlock, you will see the Hello World message on your LCD!

A blinking LED example

As you know the Dwenguino has 9 programmable LEDs. One LED can be found on pin 13 which can be set with the set digital pin:

Blinking LED 13

Note that we also added a delay function in order to control the blinking frequency of the LED.

The other LEDs can be found on pins 32 to 39. With the LEDS block the eight LEDs can be controlled directly:

Counting LEDs

Note that we used a integer variable here to start a counting process.

Press the buttons

The easiest way to interact with your Dwenguino board is by using one of the five buttons: SW_C, SW_N, SW_E, SW_S and SW_W. In order to get the buttons working, you only need to use the digital pin block. The argument of the digital pin block determines from which digital pin you want to read. This can be one of the buttons (SW_C, SW_N, SW_E, SW_S and SW_W) or any other digital pin. After that you can evaluate wether a button is pressed or not with an if...else statement:


Please note the not in the condition of the buttons. Due to the internal pull-up resistors, the buttons will be read as a 1 when not pressed and a 0 when pressed.

Controlling motors

You can connect easily two different kind of motors to your Dwenguino. The first type is a servo motor which you need to attach to the servo connector SERVO 1 or SERVO 2. Please connect the black wire of the servo to the minus (-) and the red wire to the plus (+). The third, coloured wire, should be connected to the leftover pin marked with a pulse. ArduBlock provides a servo function which can be dragged from the generic hardware menu. You need to provide the pin the servo is connected to and the angle the servo motor should be positioned in. If you want to control the servo on pin SERVO 1 you need to configure the channel (chann) as a while this is 2 for SERVO 2. The angle can be anything between 0 and 180 degrees. Here SERVO 1 is set to 90 degrees:

controlling a servo

When you use the servo-block in ArduBlock, Pulse Width Modulation (PWM) will be used to set the servo-pin of your choice. Depending on the pulse width, the position of the servo motor will be set:

PWM servo

The second type of motor you can connect is a standard DC motor, which can be connected to blue motor connector (4 screw pins) pairwise marked with M1 and M2. The speed of the motor is controlled with a PWM signal.

PWM dc motor

The motor channel and speed can be set by using the DcMotor block. The maximal speed that can be chosen is 255. This means that the motors will get the battery input voltage. In the following program two motors are controlled at maximal speed but into opposite directions:

dc motor

Making sound with the buzzer

The Dwenguino has an onboard buzzer connected to pin 46 to make music. The frequency of the buzzer can be set with the tone block of the Pins menu in ArduBlock. This block takes two arguments: the tone frequency (for example 440 Hz which is a A4 note) and the duration. Note that if you don't want to mix any tones you need to use a delay function. For example, in the following program the tone is switched from 440 Hz to 220 Hz and vice versa every second:


The sonar sensor

ArduBlock example with sonar

Analog to digital conversion

A lot of sensors are analog: the phototransistor, long range distance sensors of Sharp, the short range distance sensor. For a few overview how you can connect we refer to the sensors for robots tutorial. When the sensor is properly connected it should have one pin connected to one of the Dwenguino A/D pins (pin A0 to A5). You can then read the analog sensor with the analog pin block in which you have to select the channel (A0 to A5) to which your sensor is connected. In the following example, an analog sensor connected to pin A3 determines whether the LEDS will be on or off:

Example A/D conversion