Scilab and Arduino
Scilab and Arduino
List of Figures v
List of Tables ix
List of Acronyms xv
1 Introduction 1
2 Hardware Environment 3
2.1 Microcontroller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.1.1 Organization of a Microcontroller . . . . . . . . . . . . . . . . 3
2.1.2 Microcontroller Peripherals . . . . . . . . . . . . . . . . . . . 5
2.2 Open Source Hardware (OSHW) . . . . . . . . . . . . . . . . . . . . 7
2.3 Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.3.1 Brief History . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.3.2 Arduino Uno Board . . . . . . . . . . . . . . . . . . . . . . . 9
2.3.3 Popular Arduino Projects . . . . . . . . . . . . . . . . . . . . 9
2.4 Shield . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.5 Experimental Test Bed . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3 Software Environment 17
3.1 Arduino IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.1.1 Downloading and installing on Windows . . . . . . . . . . . . 18
3.1.2 Downloading and installing on GNU/Linux Ubuntu . . . . . . 18
3.1.3 Arduino Development Environment . . . . . . . . . . . . . . . 21
3.1.4 Testing Arduino with a sample program . . . . . . . . . . . . 23
ii Contents
3.2 Scilab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.2.1 Downloading and installing Scilab . . . . . . . . . . . . . . . 24
3.2.2 Scilab Arduino toolbox . . . . . . . . . . . . . . . . . . . . . . 25
3.2.3 Identifying Arduino communication port number . . . . . . . 27
3.2.4 Testing Scilab-Arduino toolbox . . . . . . . . . . . . . . . . . 29
3.3 Xcos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.3.1 Downloading, installing and testing . . . . . . . . . . . . . . . 33
3.3.2 Use case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
3.3.3 Xcos-Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
3.4 Arduino Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
3.5 Scilab Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
5 Interfacing a Pushbutton 55
5.1 Preliminaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
5.2 Reading the Pushbutton status from the Arduino IDE . . . . . . . . 55
5.3 Reading the Pushbutton status from Scilab Scripts . . . . . . . . . . 57
5.4 Accessing the Pushbutton from Xcos . . . . . . . . . . . . . . . . . . 58
5.5 Arduino Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
5.6 Scilab Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
7 Interfacing a DC motor 73
7.1 Preliminaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
7.2 Controlling the DC motor from Arduino . . . . . . . . . . . . . . . . 75
7.3 Controlling the DC motor from Scilab . . . . . . . . . . . . . . . . . 77
Contents iii
7.3.1 Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
7.3.2 Rotation for a specified time . . . . . . . . . . . . . . . . . . 77
7.3.3 Using the capabilities of Scilab . . . . . . . . . . . . . . . . . 79
7.4 Driving the DC motor from Xcos . . . . . . . . . . . . . . . . . . . . 79
7.5 Arduino Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
7.6 Scilab Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
8 Interfacing a Potentiometer 87
8.1 Preliminaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
8.2 Reading the potentiometer from the Arduino IDE . . . . . . . . . . . 88
8.3 Reading the potentiometer from Scilab Script . . . . . . . . . . . . . 89
8.4 Reading the potentiometer from Scilab Xcos . . . . . . . . . . . . . . 90
8.5 Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
8.6 Arduino Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
8.7 Scilab Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
9 Interfacing a Thermistor 95
9.1 Preliminaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
9.2 Reading thermistor from Arduino IDE . . . . . . . . . . . . . . . . . 96
9.3 Reading thermistor from Scilab scripts . . . . . . . . . . . . . . . . . 98
9.4 Reading thermistor from Xcos . . . . . . . . . . . . . . . . . . . . . . 99
9.5 Arduino Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
9.6 Scilab Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
References 133
List of Figures
v
vi List of Figures