CretileProLogicManual-0 91
CretileProLogicManual-0 91
Table of Contents
1.1 Cretile ProLogic ..................................................................................................................................... 3
1.2 Capabilities............................................................................................................................................ 4
1.2.1 INputs and OUTputs ....................................................................................................................... 4
1.2.2 Motor Control ................................................................................................................................ 4
1.2.3 Wireless Communication ............................................................................................................... 4
1.3 Internal details ...................................................................................................................................... 4
1.4 Software Installation guide ................................................................................................................... 5
1.4.1 Installing Arduino for Cretile .......................................................................................................... 5
1.4.2 Installing USB drivers for Cretile ProLogic (Windows 7, Windows 8) ............................................. 6
1.4.3 Using Android App Inventor extension .......................................................................................... 7
1.5 Using Arduino IDE and Ardublock ......................................................................................................... 8
1.5.1 Opening & configuring Arduino IDE and Ardublock ....................................................................... 8
1.5.2 Introduction to Ardublock ............................................................................................................ 12
1.6 ProLogic & Arduino Programming using Ardublock ............................................................................ 14
1.6.1 ProLogic program structure (Setup & Loop) ................................................................................ 14
1.6.2 Control structure .......................................................................................................................... 16
a. If then, if then else .................................................................................................................... 16
b. Loops ......................................................................................................................................... 18
a. While Loops............................................................................................................................... 18
b. Repeat Loops............................................................................................................................. 19
1.6.3 Variables ...................................................................................................................................... 20
1.6.4 Time functions ............................................................................................................................. 21
1.7 Details of ProLogic blocks in Ardublock .............................................................................................. 21
1.7.1 Working with ProLogic local INputs and OUTputs........................................................................ 21
a. Ready ProLogic without remote ................................................................................................ 22
b. WRITE ProLogic local output ..................................................................................................... 22
c. READ ProLogic local input ......................................................................................................... 22
Examples ........................................................................................................................................... 23
1.7.2 ProLogic remote INputs and OUTputs.......................................................................................... 27
1
2
2
3
Image 1
Image 2
3
4
1.2 Capabilities
4
5
commands actually used in programs. For details about Arduino please visit
Arduino.cc
Image 3
5
6
6
7
7
8
Image 4
Locate Tools menu in Arduino and click on the menu. All options under
the menu will be listed. Locate and select “Board” menu option from this and
list of all available boards will appear. Select “Arduino Nano” from list as shown
below. Now Arduino IDE is configured for use with Cretile ProLogic.
8
9
Image 5
9
10
Image 6
Locate tools menu in Arduino IDE and locate Ardublock as shown below
in image 7. Click on Ardublock menu item. Ardublock will open as shown below
in image 8.
10
11
Image 7
Image 8
11
12
Canvas
Blocks
Block Drawers
Image 9
ProLogic drawer and then click and hold on “READY ProLogic without remote”
block. Now drag and drop the block in setup section of program as shown
below in image 10.
Image 10
13
14
Generated Code
Status
Image 11
14
15
15
16
Setup section of
Program
Loop section of
Program
Image 12
16
17
You can skip else portion of if then else block and just provide set of
commands to be executed if a condition is true. In that case block to be
used is if then block.
If then else and if then blocks appear in Ardublock as shown in image
below.
Image 13
Image 14
17
18
b. Loops
When you want to repeat commands for certain number of time e.g.
five times or repeat commands until certain condition occurs, then these
loop type of control blocks can be used. Example of loop control blocks are
for, while and repeat.
a. While Loops
While type of loops have a condition and body of loop. Condition is
checked during every iteration of loop.
There are two types of while loops in Ardublock, while and do while.
While loop first checks condition and then executes commands if
condition is satisfied. do while loop first executes all commands once and
then check condition. So do while loop at least executes one time. In case
of while loop, condition can fail at the start of the loop itself. In that case
no commands from body of while loop will execute.
Following image 15 & 16 shows example of while and do while loops.
While loop
Image 15
18
19
Image 16
b. Repeat Loops
These types of loops are used to execute commands for certain
number of times generally. There are two important types of repeat loop in
Ardublock. 1) Repeat 2) Repeat and count.
Repeat loop has two portions, first we need to provide integer value.
Second we need to provide commands to be executed in every iteration.
Repeat loops executed for number of times as given in integer value.
Repeat and count loop has three portions. First, a variable name
which is used to count and you can read its value to get current count.
Second portion is integer value, which tells number of times loop
commands should be executed. Third portion is commands which need to
be executed in every iteration of loop.
Following image 17 & 18 shows example of repeat and repeat and
count loops.
19
20
Image 17
Image 18
1.6.3 Variables
Variables are place holders or memory of a specific type of value like
number or text. They are symbols which can remember value of specific type. A
number variable can remember any value between 1 to N.
Value of variable can be set by various commands e.g. command to read
ProLogic input can set value of variable with whatever is the value of ProLogic
20
21
input. You can also set value of a number variable to any number for example
10 by using assignment block.
When you want read value of variable remembered by it you can simply
place the variable where some number value is required by block e.g. while
setting value of one variable to value of some other variable as shown in below
image 19.
Image 19
Image 20
21
22
Image 21
Image 22
22
23
Image 23
Examples
Let’s use these blocks to develop two simple programs
1. Blink
You will develop a program which will blink a light connected to
ProLogic OUT-1. For this program, you need Battery, ProLogic and Light
module. Connect these modules as show in image 24 below.
Image 24
program. You don’t have to use READY ProLogic MOTORs block since you
are not going use motors in this program.
To blink a Light every 1 second indefinitely you need to switch ON
light for 1 second and switch OFF light for 1 second and repeat these
commands indefinite.
Cretile Light is connected on OUT-1 so you need to switch on
OUT-1 for 1 second and switch off OUT-1 for 1 second and
repeat this indefinitely.
After this delay SECONDS block you need to switch off OUT-1
so again you need to use “WRITE ProLogic OUT” block and
write value 0 on OUT-1.
24
25
Image 25
Image 26
25
26
You will use delay MILLIS block to keep OUT-1 ON or OFF for
calculated duration. For this you need to calculate delay time
in milliseconds. When dimmerValue changes from 0 to 99,
delay time should change from 1000 milliseconds to 10
milliseconds. For this formula is
delayTime = (100 – dimmerValue) * 10
Image 27
26
27
Image 28
27
28
Image 29
Image 30
Image 31
28
29
Image 32
Examples
29
30
Image 33
Image 34
30
31
31
32
32
33
Motor 1
Connection
Motor 2
Connection
Image 36
Image 37
33
34
Part II
2. Developing ProLogic App on Android phone
2.1 Introduction
App Inventor is a tool by MIT which provides Scratch like graphical user
interface to develop Android application. Cretile provides extension in App
Inventor for communicating with ProLogic using Android phone’s USB port. This
communication works only when phone has USB-OTG support.
ProLogic local INputs and remote INputs are sent to Android phone,
Android phone then can read these values. Android phone can send values of
ProLogic local OUTputs and remote OUTputs over USB. In ProLogic program
you can choose to write values sent by Android phone on respective OUTputs.
There are blocks provided in App Inventor as well as Ardublock for this
communication. In following sections you will learn use of these blocks for
communication between Android Phone and ProLogic.
34
35
Image 38
You will be presented with terms of service, please read the terms and
accept or reject depending on whether you agree to terms or not. If you reject
the terms of service then you will not be able to use App Inventor. Rest of the
document will be useful to you after you accept the terms of service and
proceed to use App Inventor.
Image 39
35
36
Image 40
36
37
Image 41
37
38
Image 42
38
39
Click here to
import Cretile
Extension
Image 43
Image 44
39
40
Cretile ProLogic
Extension
Image 45
Now you are ready to use ProLogic extension for App Inventor to
develop Android-ProLogic applications.
2.3 Writing your first Cretile Android App and ProLogic program
We will go through description of all blocks available in App Inventor
Cretile extension. Later we will write a simple application which reads local IN-1
of ProLogic and display that on screen of phone.
a. ProLogic.Start
ProLogic.Start block is used to initialize Cretile android
component for communication with ProLogic. There are two types of
40
41
Image 46
b. ProLogic.ConnectionStatusChanged
This is a event which occurs when there is any change to connection
status between phone and ProLogic e.g. USB cable is plugged or unplugged.
You can add commands in body of this block. All the commands
added there will be executed whenever there is change in connection
status between ProLogic and Android phone.
Image 47
c. ProLogic.InputValuesReceived
This is an event which occurs whenever new data is received by
phone sent by ProLogic.
41
42
You can add commands in body of this block. All commands added
there will be executed whenever new data is received by phone. You can
update values of user interface component or perform any action by
reading latest data available.
Image 48
d. ProLogic.READ_IN
ProLogic.READ_IN block is used to read local input value sent by
ProLogic. This block takes input_number as argument and gives value of
ProLogic local input at input_number. For example, if you provide 1 as
argument to this block then it will give value of ProLogic local IN-1 port.
ProLogic.READ_IN will be able to provide latest value only when ProLogic
send the data to phone. For information on how to send data from ProLogic
to phone see section 2.3.4.
ProLogic.READ_IN block appears in App Inventor as shown below.
Image 49
e. ProLogic.READ_remoteIN
ProLogic.READ_remoteIN block is used to read remote input value
sent by ProLogic. This block takes input_number as argument and gives
value of ProLogic remote input at input_number. For example, if you
provide 1 as argument to this block then it will give value of ProLogic
remoteIN-1 port. ProLogic.READ_remoteIN will be able to provide latest
42
43
value only when ProLogic send the data to phone. For information on how
to send value of remote inputs from ProLogic to phone see section 2.34.
ProLogic.READ_remoteIN block appears in App Inventor as shown
below.
Image 50
f. ProLogic.WRITE_OUT
ProLogic.WRITE_OUT block is used to send value for local output of
ProLogic. This block takes output_number and value to be sent to ProLogic
as arguments. For example, if you provide 1 as output_number argument
and 99 as value argument to this block then it will send value 99 to ProLogic
for local output OUT-1. However this value will not appear on OUTPUT until
ProLogic program use this value to update OUT-1. For information on how
to update ProLogic local outputs using data sent from phone please see
section 2.34.
ProLogic.WRITE_OUT block appears in App Inventor as shown below.
Image 51
g. ProLogic.WRITE_remoteOUT
ProLogic.WRITE_remoteOUT block is used to send value for remote
output of ProLogic (which appears on Receiver module). This block takes
output_number and value to be sent to ProLogic as arguments. For
example, if you provide 1 as output_number argument and 99 as value
argument to this block then it will send value 99 to ProLogic for local output
43
44
OUT-1. However this value will not appear on remote OUTPUT until
ProLogic program use this value to update remote OUT-1. For information
on how to update ProLogic remote outputs using data sent from phone
please see section 2.3.5.
ProLogic.WRITE_remoteOUT block appears in App Inventor as shown
below.
Image 52
h. ProLogic.SET_motorSpeed
ProLogic.SET_motorSpeed block is used to send value for motor
speed for motors connected to on-board motor drivers. This block takes
motor_number and speed value to be sent to ProLogic as arguments. For
example, if you provide 1 as motor_number argument and 99 as speed
argument to this block then it will send value 99 to ProLogic for motor M1.
However speed of motor M1 will not be updated until ProLogic program
use this value to update motor speed. For information on how to update
ProLogic motor speed using data sent from phone please see section 2.3.5.
ProLogic.SET_motorSpeed block appears in App Inventor as shown
below.
Image 53
i. ProLogic.SET_motorDirection
44
45
Image 54
In this folder there will be Cretile.apk file present which need to be installed
on your android phone. To install this apk file you need to transfer this file
45
46
to your android phone. Please copy this file to Android phone Downloads
folder. Please use help on transferring data from PC to Android phone
provided on this link How to Transfer Files From Android to PC Using USB
Cable
Please enable installation of application from Unknown Sources to install
this application on your android phone. You can take help provided on this
link How to Install Apps from Unknown Sources in Android.
46
47
Image 55
47
48
Image 56
Image 57
48
49
Image 58
49
50
Image 59
From ProLogic1 component under Screen1, drag & drop when ProLogic1
InputValuesReceived block to block screen. This block is executed whenever
ProLogic INput values are received by Android phone.
Now Click on valueIN1 component under Screen1 and select set Text to
block and drag & drop this block in when ProLogic1 InputValuesReceived as
shown in image 60.
Click on ProLogic1 component. Drag & drop Read ProLogic IN block to
attach the block to set Text to block of valueIN1 as shown in image 60 below.
50
51
Image 60
Drag & drop number block from Math component drawer and attach it
to ProLogic1.READ_IN block and set number to 1 as shown in image 61 and
image 62 below. This will read value of ProLogic local input IN-1. Text of
valueIN1 will get updated with recent value of ProLogic IN-1.
51
52
Image 61
52
53
Image 62
53
54
Image 63
54
55
55
56
Image 64
56
57
Image 65
57