Ardublock Programming

Approx. Time: 
30

Ardublock is a blocks-based graphical environment for creating Arduino programs. Those who have experience using Scratch 2.0 or Snap! with Hummingbird will find many of Ardublock's programming structures familiar. As Ardublock allows users to see the Arduino code behind the blocks, and as it allows downloading of the program to the Hummingbird Duo, it is a great next step for those who are familiar with Scratch or Snap! programming.

Ardublock was developed by David Li and HE Qichen. Our branch of Ardublock has been customized for Hummingbird Duo. 

User Guide

  1. Installation
  2. Creating Programs
    1. Duo Blocks Descriptions
    2. Example Programs
  3. Uploading to Duo
  4. Ardublock Advanced
  5. Source code for Ardublock Hummingbird Branch

1. Installation

Follow our complete installation guide for Arduino, Hummingbird Duo libraries, and Ardublock.

Once the Arduino environment and Ardublock are installed, launch Ardublock by opening the Arduino environment and selecting Tools->Ardublock:

You also need to make sure that your Hummingbird is in Arduino mode. To do this, follow our tutorial for converting Hummingbird Duo to Arduino mode.

2. Creating Programs

The core Ardublock blocks are divided into the following categories:

  • Control: These blocks determine the logical flow of a program; blocks include structures like delay, loop, while, and if/else
  • Pins: These blocks provide control over the Arduino side pins. You do not need them if working with the Hummingbird Duo's top-side connectors.
  • Tests: These blocks contain logical tests, such as whether one number is less than or greater than another.
  • Math Operators: These blocks allow you to perform mathematical operations like +,-,*,/, as well as absolute value, modulus, and more.
  • Variables/Constants: These blocks contain constant number blocks, as well as ways to set different types of variables (integers, floats, chars) to specific values.
  • Communication: These blocks provide ways to send information over serial or I2C ports.
  • Storage: These blocks provide access to an Arduino's permanent EEPROM memory storage.
  • Code Blocks: These blocks allow you to write custom Arduino code into your Ardublock program.

Each block provides a helpful hint as to its function when you hover over it with a mouse:

1. Hummingbird Duo Blocks

In addition to the core Ardublock blocks, our version of Ardublock also contains a number of blocks used for reading Duo sensors and setting Duo outputs. These are: 

  • LED: Sets the brightness of one of the four single color LED ports with an intensity ranging from 0 to 255. 
  • TRI-COLOR LED: Sets the brightness and color of one of the two tri-color LED ports with red, green, and blue intensities ranging from 0 to 255.
  • STATUS: Sets the brightness of the Duo's green STATUS LED with an intensity ranging from 0 to 255.
  • MOTOR: Sets the direction and speed of one of Duo's two gear motor ports. Negative velocity values cause the motor to spin in the opposite direction of positive velocity values.
  • SERVO: Sets the angle of one Duo's four servo ports from 0 degrees to 180 degrees. 
  • VIBRATION: Sets the intensity of vibration from 0 to 255 for one of Duo's two vibration motor ports.
  • SENSOR: Reads the raw value of one of Duo's four sensor ports. This value ranges from 0 to 1023, with 0 corresponding to 0 volts, and 1023 corresponding to 5 volts.
  • SYSTEM VOLTAGE: Reads the voltage of the  Duo's Auxiliary Power port. The value returned is a floating point value from 0.0 to 10.0 volts. Values below 2.0 generally mean no power supply is attached. This can be used for low battery warning if the Duo is being powered solely from this port.

2. Example Programs

Hummingbird Ardublock example programs were placed in your Arduino Sketchbook folder when you installed Ardublock. You can also get them by downloading this zip file. These examples include:

  • BlinkLED: Blinks the status LED and the LED on port 1 for 0.5 seconds on, 1 second off.
  • FadeLED: Fades on and off the status LED and LED on port 1.
  • KnobMotorControl: Controls the speed of a gear motor on port 1 with a knob sensor attached to sensor port 1.
  • LEDThermometer: Sets the color of a tri-color LED on port 1 to correspond with a temperature from a temperature sensor attached to port 4. Also prints the temperature in Celsius over the serial port. Blue is 10 C or less, green is 25 C, and red is 40 C.
  • SensorPrinter: Prints the values of the four sensor ports, first as raw values, and then converted into units assuming a light or knob sensor attached to port 1, a sound sensor on port 2, a distance sensor on port 3, and a temperature sensor on port 4. Also prints the system voltage.
  • SensorTrigger: Checks the sensor value on port 1, if it's below 100 it turns off the status LED and turns on a vibration motor and an LED. If it's 100 or more, it turns on the status LED and turns off the LED and vibration motor.
  • SerialHummingbirdInterface: Allows control of outputs and reading of sensors via a serial interface.
  • SimpleServo: Moves the servos in order from port 1 to 4 between 0 degrees and 180 degrees.
  • SlowMotionServo: Moves one servo from 0 to 180 degrees and back slowly.

3. Uploading the Program

Videos blocked? View or download them here!

Once you've completed your program, follow these steps to upload it to your Hummingbird Duo.

1. Switch over to the Arduino IDE and make sure your board type is set to Hummingbird Duo (Tools->Board):

2. Make sure you have set the Arduino's serial port. Go to Tools->Port and select the correct port (if there are two options, it is almost never the first option):

3. Now simply hit the Upload to Arduino button in Ardublock and monitor the status message in the Arduino IDE: 

4. If uploading fails after two or three tries, try pressing the reset button as the computer is uploading the program. This button is located on the underside of the Hummingbird.

5. Any time you hit Upload to Arduino, Ardublock will translate the contents of the program to a text-based version that is displayed in the regular Arduino IDE. Take a look at this code and see if you can match it to the program you made in Ardublock! Here's what the Arduino IDE looks like right after hitting the Upload to Arduino button in Ardublock with the SlowMotionServo example program:

4. Ardublock Advanced

The version of Ardublock installed by our utility is a branch created by us that strips out most contributed libraries and some core Ardublock blocks to created a cleaner interface. If you prefer to use Ardublock on Hummingbird Duo with all blocks enabled, check the box in the installer. You can run the installer as many times as desired, checking and unchecking the box to switch between Ardublock versions:

On some systems Ardublock advanced seems to cause Arduino to crash due to an out of memory error. If this is the case, attempt to launch Arduino with a larger Java memory allocation or use the basic Ardublock instead of advanced.

5. Source Code

The source for the branch of Ardublock that incorporates Hummingbird Duo blocks is available on Github.