Ardublock with Intel Galileo

Page 1


1. Implement ‘Blink’ Sketch with ArduBlock Galileo and Scratch look quite different. They have their own pros and cons. Scratch could easily and quickly execute fancy jobs such as games, but it worked only on the monitor screen while Galileo could implement our idea in actual physical world. General input devices of Scratch are keyboard and mouse, and output device is monitor. However, input and output devices of Galileo are limitless. Especially, the input devices named sensors can mimic human cognitive function or help to physically utilize the environment surrounding them. We can do programing Scratch to run Galileo using an application called ‘S4A.’ Here, we will use ‘ArduBlock’ instead, because it can compile and upload directly to Galileo. ArduBlock is easier than ‘Processing’ since it is like building blocks as we did with Scratch.

Click ‘Preferences’ in ‘File’ menu of Galileo IDE and check for ‘Sketchbook location’ at the new window.

Under the directory of ‘File Explorer,’ create ‘\tools\ArduBlockTool\tool’ folder

2


and copy ‘ardublock-all.jar’ file, which you have downloaded from the homepage, into the new folder.

Now, you can see ‘ArduBlock’ in ‘Tools’ menu of IDE. New window will open when you click it.

Using blocks in ‘Control’ and ‘Pins’ buttons on left side of the new window, program the ‘Blink’ sketch. Lastly, click ‘Upload to Arduino’ menu to check out the result on Galileo and the breadboard.

3


2. Implement ‘Fade’ Sketch with ArduBlock If LED did not react when you clicked ‘Upload,’ check first to match up ‘Galileo COM’ on ‘Device Manager’ of ‘Control Panel’ with ‘Serial Port COM’ on IDE’s ‘Tools’ menu.

Now, we will use ArduBlock to implement ‘Fade’ Sketch programed originally in ‘Processing’ language. First, open the ‘Fade’ Sketch from IDE for your reference. Switch to ArduBlock window. Bring ‘set analog pin’ block into the ‘loop’ socket of the ‘program’ block. This will implement analogWrite() command inside of Loop() function. Fill with two ‘number variable name’ blocks into the right sockets. Rename them as ‘led’ and ‘brightness’. Then, click ‘Upload to Arduino’ menu and compare the new Sketch with original.

4


To define three variables, bring ‘set number variable’ blocks into the ‘setup’ socket in the ‘program’ block. Bring another one into the ‘loop’ socket to implement the calculation of ‘brightness = brightness + fadeAmount.’

Use ‘if’ block in ArduBlock for if statement of ‘Fade’ Sketch. The value of the variable ‘fadeAmount’ should always be +5 or -5. In ArduBlock, it should be implemented as ‘fadeAmount = 0 – fadeAmount.’ Click ‘Upload to Arduino’ menu to check out the result.

5


3. Implement ‘Potentiometer’ Sketch with ArduBlock Sketch for ‘Potentiometer’ can be found at File>Examples>03.Analog>AnalogInput in IDE.

‘analogRead()’ command reads input values when you turn the handle of potentiometer. Let’s see how it works in ArduBlock. ‘sensorPin’ variable, which belongs to analog input, is connected to Galileo board’s A0. Thus, there must be ‘analog pin #’ block between ‘set number variable’ and ‘sensorPin.’

To initialize the variable ‘sensorPin’ and ‘ledPin,’ bring ‘set number variable’ block into ‘setup’ socket of ‘program’ block. Look at the changed Sketch in IDE by clicking ‘Upload to Arduino’ menu.

6


As we learned before, there is an electronic device called ADC inside the Galileo board. It changes analog voltage INPUT value between 0 to 5 volt, to digital value that ranges from 0 to 1023. Click ‘Upload to Arduino’ menu, after you complete ArduBlock that makes it blink as much as converted digital value. New IDE Sketch looks different from the original. However, the outcome on the Galileo LED is the same since there are no syntax errors and they are logically identical. You don’t have to look at the new sketch in IDE because ArduBlock’s program immediately uploads to Galileo. But it helps you a lot in debugging and understanding the logic of the program.

7


4. Implement ‘Light sensor’ Sketch ArduBlock ‘Light sensor’ has a ‘photo resistor’, so it can cognize the brightness of the light. Resistance decreases as it gets brighter and increases as it gets darker. Use the ‘jumper wires’ that were plugged into Galileo when experimenting ‘Potentiometer.’ Insert ‘Light sensor’ on the breadboard. Notice that the ‘jumper wires’ that were connected with Galileo’s 5V pin and GND pin should be connected with VCC pin and GND pin of the ‘Light sensor.’ The ‘jumper wire’ on Galileo’s A0 pin should be connected to OUT pin of ‘Light sensor.’ Click ‘Upload to Arduino’ menu. You will see the change in Galileo’s LED as you cover or expose the ‘Light sensor.’ We can see the degree of brightness through ‘Serial Monitor’ by implementing with ArduBlock. Drag ‘serial println’ block in ‘Communication’ component.

In the ‘Text message’ block, enter ‘The lower the brighter.’

In order to print the number in the monitor using ‘Serial.println()’ function, the ‘glue’ block should be attached on right side socket.

8


Click ‘Upload to Arduino’ menu and see how it converted into sketch in the IDE window. Click ‘Upload to Arduino’ menu and see how it converted into sketch in the IDE window. You have to use ‘Serial.println()’ function to proceed to the next line. Click ‘Serial Monitor’ menu to observe the converting value on the new window.

9


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.