ipst-microbox secondary education lab manual
DESCRIPTION
ÂTRANSCRIPT
IPST-MicroBOX [SE] Lab manual1
Lab manual
2IPST-MicroBOX [SE] Lab manual
Credits
IPST-SE and IPST-MicroBOX [SE] logo are trademarks of The Institute for the Promotion of
Teaching Science and Technology THAILAND
INEX, and INEX logo are trademarks of Innovative Experiment Co., Ltd.
AVR, Atmel, Atmel logo, AVR Studio are registered trademarks of Atmel Corporation.
WinAVR is trademark of SourceForge, Inc.
AVR-GCC is copyright of Free Software Foundation, Inc.
Arduino is an open source project supported by many. The Team is composed of Massimo
Banzi, David Cuartielles, Tom Igoe, Gianluca Martino, and David Mellis. Nicholas Zambetti
has contributed since the beginning. Yaniv Steiner and Giorgio Olivero have been supporting
the project and are working at using it with the Instant Soup platform. The Arduino platform
used to include the avr-gcc tool chain, uisp, and the Procyon AVR-LIB by Pascal Stang. The
Arduino language syntax is based on Wiring by Hernando Barragan. The Arduino environment
is based on Processing by Ben Fry and Casey Reas. Thanks to all the people who are supporting
arduino.
I2C is a registered trademark of NXP Semiconductors.
Microsoft, Windows are registered trademarks of the Microsoft Corporation.
Windows 2K, Windows XP, Windows Vista and Windows7 are registered trademarks of the
Microsoft Corporation.
Macintosh, MAC OSX are registered trademarks of the Apple computer.
All product and service names mentioned herein are the trademarks of their respective owners.
IPST-MicroBOX [SE] Lab manual3
Contents
Chaptor 1 : Getting start with IPST-MicroBOX (SE)............................................................................5
Chaptor 2 : Introduction and part list of IPST-MicroBOX (SE).....................................................17
Chaptor 3 : Wiring IDE introduction.............................................................................................33
Chaptor 4 : Hardware experiment of IPST-SE controller board........................................................39
Chaptor 5 : IPST-MicroBOX [SE] library file.................................................................................57
Chaptor 6 : Using the color display of IPST-SE board....................................................................83
Chaptor 7 : LED controller..........................................................................................................105
Chaptor 8 : Multi-channel LED controller...................................................................................113
Chaptor 9 : Reading switch..........................................................................................................133
Chaptor 10 : Analog sensor......................................................................................................147
4IPST-MicroBOX [SE] Lab manual
IPST-MicroBOX [SE] Lab manual5
The programming development for the IPST-MicroBOX Secondary Education (SE) is the
process by outlining the diagram in figure 1-1. The suitable software tools are Arduino IDE1.0.5
and Wiring IDE 1.0 for IPST-MicroBOX [SE] version. Download from www.ipst-microbox.com.
This chapter will be focus and describes step by step for getting started the IPST-MicroBOX
[SE] kit by using the Arduino IDE 1.0.5.
Chapter 1
Getting start with
Preparation for programming
1. Open the Wiring or Arduino IDE 1.0 and createdthe new sketch2. Choose the hardware by selected menu Tools >Board > IPST-SE > ATmega644@16MHz3. Choose the serial port at menus Tools > Serialport > COMx
Create the C/C++ code and save as the sketch file.
Compile the sketch
Software installation- Wiring 1.0 or Arduino IDE 1.0
- USB driver for the IPST-SE board
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Check the interface port of computer
- Connect the miniB-USB cable betweencomputer's USB port and the IPST-SE board
- Open Control panel > System > Hardware >Device Manager > Ports. See the USB serialport (COMx)
- Record the USB serial port (COMx) and usethis port number for interfacing with the IPST-SE board
Upload the sketch
The IPST-SE board starts to run
Figure 1-1 : Programming development diagram of IPST-MicroBOX [SE]
6IPST-MicroBOX [SE] Lab manual
1.1 Software and USB driver installation
1.1.1 Supported operating system
The software for the program development is Wiring Development Environment or
sometimes called Wiring IDE and it can work with these operating systems or platforms.
Mac OS X 10.4 or higher (both models using Powerpc and Intel CPU)
Windows XP, Windows Vista, 7 and 8 or higher
Linux, both Fedora Core and Debian (including Ubuntu as well)
Other platforms which support the operation of Java 1.4 up
1.1.2 Software installation
(1) Insert the CD Rom, come with the IPST-MicroBOX [SE]. Click the file named
Wiring1000_IPST_SE_140620.exe (the number of the installation file may be changeable)
and then the window of welcoming to the Wiring 1.0 setup will appear.
(2) Next, click to agree in each step of the setup as installation of other applications of
Windows until completion.
IPST-MicroBOX [SE] Lab manual7
(3) Next, the USB driver installation wizard will be appear. Click on the Install button
to start the driver installation.
(4) Test to start the program by select START > All Programs > Wiring1.0 IPST-SE >
Wiring 1.0 IPST-SE. Then for a few moment, the window of Wiring IDE will be present.
After That you can use the Wiring IDE in the program development for IPST-MicroBOX
[SE].
8IPST-MicroBOX [SE] Lab manual
1.2 IPST-SE : The main board of IPST-MicroBOX (SE)
Ther figure 1-2 shows the details of the IPST-SE; main controller board of the IPST-
MicroBOX [SE]. It consists of ATmega644P microcontroller chip and many input output
devices on-board such as Digial input/output port, Analog input, PWM output, DC motor
driver circuits, Servo motor driver ports and the graphic color LCD 128x160 dots for displaying
the text and graphic in color.
This board is programmed via USB port by using the Wiring IDE 1.0 software.
The IPST-SE controller board is an Arduino/Wiring compatible. It is preloaded with the
Arduino/Wiring bootloader. The Arduino 1.0 or Wiring 1.0 software is recommended.
1.3 Uploading the code
The procedure of sending the code to the IPST-SE board is called “Upload”
The first time of uploading the sketch has 2 steps include checking the interfaced port
between the IPST-SE with computer’s ISB port and setting the hardware for uploading.
Figure 1-2 : Layout of the IPST-SE board of the IPST-MicroBOX (SE)
27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC M
OTO
R
3 TxD1
LOW+5
2 RxD1
UART1
SERVO
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
RESET2019
18
17
16
KNOB
OK
SW1
ON
IPST-MicroBOX [SE] Lab manual9
1.3.1 Checking the USB Serial port for the IPST-SE board
(1) Plug the USB cable connecting IPST-SE board with the USB port of the computer.
Turn on and wait for the blue LED at the position of USB on the circuit board is on as the
figure 1-3.
(2) Click the START button and go to the Control Panel.
(3) Then double-click the System
(4) Go to the tab of Hardware and click on the Device Manager button
27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC M
OTO
R
3 TxD1
LOW+5
2 RxD1
UART1
SERVO
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
RESET2019
18
17
16
KNOB
OK
SW1
ON
Turn onthe POWER switch
3
1
2
4
Plug the adaptor
Connect the USB cable
Wait until theUSB indicator is on
Figure1-3 : Preparation the IPST-SE board for getting start
10IPST-MicroBOX [SE] Lab manual
(5) Check the hardware listing at Port. You should see USB Serial port . Check the
position. Normally it is COM3 or higher (for example; COM3). You must use this COM port
with the Wiring IDE software.
1.3.2 Connect the IPST-SE with Wiring IDE
(1) Open Wiring IDE. Wait for a while. The main window of Wiring IDE will appear.
(2) Choose the suitable hardware by select menu Tools > Board > IPST-SE >IPST-SE,
ATmega644P @16MHz
IPST-MicroBOX [SE] Lab manual11
(3) Select menu Tools > Serial Port to choose the USB serial port of the IPST-SE. It is
COM3 (for example).
Must do this step for every new connection of the IPST-SE with Wiring IDE
Now the IPST-SE board is ready for interfacing and code development with the Wiring
IDE.
1.3.3 Getting start the programming
(1) Create the new sketch by clicking on the New button at tool bar or choose from
menu File > New
(2) Type the C/C++ code as follows :
12IPST-MicroBOX [SE] Lab manual
#include <ipst.h> // include file for IPST-SE
void setup()
{
glcdClear(); // Clear screen
glcdMode(0); // Set the dsiplay mode 0
}
void loop()
{
setTextSize(2); // Set text size x2
setTextColor(GLCD_YELLOW); // Set text color as yellow
glcd(1,1,"Hello"); // Set message on line 1 column 1
setTextColor(GLCD_SKY); // Set text color as sky blue
glcd(3,1,"IPST"); // Set message on line 3 column 1
glcd(4,1,"MicroBOX"); // Set message on line 4 column 1
setTextSize(1); // Set text size as normal
glcd(10,2,"Secondary Education"); // Set message on line 10 column 2
}
This program is used to test the basic operation of the IPST-SE board. It displays some
message with different size and color on the GLCD.
(3) To menu File > Save As for saving the code as HelloIPST-SE. The HelloIPST-SE.pde
file is created in the HelloIPST-SE folder.
IPST-MicroBOX [SE] Lab manual13
(4) Check the code syntax by clicking on the Run button at tool bar or select from
menu Sketch > Compile/Verify
If there is any error occurring from compilation, a warning message will be
appeared in the messsage area. Therefore, you will have to correct the program.
If all are correct, the message area will display Done compiling message.
After the compilation is finished, in the folder of HelloIPST-SE there will be a
new folder are in named HelloIPST-SE and within this folder it contains the source file of
C++ programming language and a supplementary file.
14IPST-MicroBOX [SE] Lab manual
(5) Connect the IPST-SE board with USB port. Turn-on power. Wait until USB connection
is completely ( blue LED at USB is turned-on) .
(6) Click on the Upload to Wiring Hardware. Code uploading is started. Wait
until uploading complete. The message Done uploading. RESET to start the new program. is
shown in the status bar of Wiring IDE.
If there is error occurring from uploading, a warning message will be appeared
in the messsage area as follows
This mostly occurs if the serial port is invalid or not selected the board to work
in the program mode. Correction can be read in the topic of Troubleshooting of uploading
error.
(7) After uploading, the IPST-SE will run immediately following the performance.
IPST-MicroBOX [SE] Lab manual15
1.4 Troubleshooting of uploading error.
1.4.1 In case that you have clicked the Upload buttonalready but no any action
Cause :
Wiring software cannot link with the IPST-SE board.
Solution :
(1) Check the USB ccable connection.
(2) Check the interfaced COM port.
(3) Check the selection hardware. Make sure to select the IPST-SE board.
(4) Press the Ctrl, Alt and Delete key simultaneously and then the Window Security
window will pop up. Next, click on Task Manager to choose. In some computers, the
program may lead to the Window Task manager window immediately, in this case, you
can choose the Processes tab and search for the file named avrdude.exe. Finally, click
on that file and the End Process button respectively.
Wiring IDE program will resume in a normal status and supply power to the
board again. Select the correct COM port and then set the IPST-SE board to the programming
mode in order to upload the program again.
16IPST-MicroBOX [SE] Lab manual
1.4.2 In case if you click the Upload button, there is an error
message that not find any hardware for uploading
Cause :
Wiring software cannot connect with the IPST-SE board because selecting a COM port
is not correct.
Solution :
You need to choose an another COM port used for the connection again and correctly
by doing at the Tools > Serial port.
1.5 How to open the example sketch
Installation the Wiring softwarte also copy the many examples of sketch into the C:/
WiringIPST/Examples/IPST-SE folder for helping the beginner.
The openning the example sketch is easy. To menu Help > Example > IPST-SE. You
will see the many example folder. Enter the selected folder to selects the any .pde file. You
can edit, save as and upload the sketch anytime.
1.6 Terms of edit and save the sketch
In order to edit the original sketch. Need to open it, edit or modify the code. Check
syntax with the compilation. There is two ways to save files.
1. Save in same name with the Save command.
2. Save the new name with the Save As command, but do not overwrite existing files
that have not been opened. Because the file links will be confusion. If you want to overwrite
the original file is not open. Will need to delete the old file folders that out first.
IPST-MicroBOX [SE] Lab manual17
IPST-MicroBOX (SE) is a set of general purpose programmable controller board that
works with a computer connected to uploading the code and data communication. This kit
contains the main controller board; IPST-SE, a set of input/output devices such as LED, digital
sensor and analog sensor. As a result, the user can use this set to learn, experiment and
develop scientific projects related to the automatic control system in a convenient and efficient.
For students and teachers; this kit comes with a comprehensive set of activities and
introducing sensors and microcontrollers using the well-popular Wiring and Arduino platform.
No soldering is required so the kit is perfectly safe for the classroom. The IPST-MicroBOX [SE]
kit comes with 2 versions :
1. Standard 1 : It includes the IPST-SE controller board that uses the ATmega644P
microcontroller and on-board color graphic LCD. It also includes simple sensors (touch sensors,
light sensor, variable resistor and temperature sensor), single LED output board, serial 8-LED
board, USB cable and DC adaptor. This version is most affordable for beginners.
2. Standard 2 . It also includes all components that are in the Standard 1 kit with
additional DC motor gearboxes, many mechanical parts that allow you to make an autonomous
robot. With the standard 2 version, it allows users to learn more about robotics in education
as well as competition.
Both version of IPST-MicroBOX [SE] also suitable for starting to learn the C/C++
programming language for basic embedded system and also for STEM education with
microcontroller.
Chapter 2
Introduction and part list of
18IPST-MicroBOX [SE] Lab manual
2.1 Part list
Standard 1 :
1. IPST-SE controller board
2. ZX-LED : Single LED output board with JST3AA-8 cable x 3
3. LED 8 : Serial 8-LED outpu board with JST3AA-8 cable
4. ZX-SPEAKER : Piezo speaker board with JST3AA-8 cable
5. ZX-SWITCH01 : Switch input board or Touch sensor with JST3AA-8 cable x 2
6. ZX-LDR : Light sensor board with JST3AA-8 cable
7. ZX-POT : Variable resistor board with JST3AA-8 cable x 2
8. Temperature sensor with JST3AA-8 cable
9. DC adaptor +9V 1A
10. miniB-USB cable for uploading code and communication with computer
11. CD-ROM contains software and example code
12. Lab manual
13. Screwdriver
IPST-MicroBOX [SE] Lab manual19
Standard 2 :
Includes all parts from Standard 1 and more items as follows :
14. ZX-03 : Infrared reflector sensor with JST3AA-8 cable x 2
15. DC motor gearbox BO-2 ratio 48:1 with IDC cable x 2
16. Circle wheel and tires x 2
17. 80 x 60 mm. and 80 x 80 mm. grid plate x 2
18. Circle base chasis with free wheel
19. Circle base plate for making robot chasis
20. Set of palstic joiners, Strip joiners and plastic standoffs
21. Set of metal standoffs, nuts and screws
22. 6-AA batter holder with barrel plug
23. Printed line tracking robot demo field
24. Plastic enclosure
20IPST-MicroBOX [SE] Lab manual
2.2 IPST-SE controller board
IPST-SE is a controller board using the Atmel AVR microcontroller ATmega644P
(www.atmel.com). It is connected to the USB port directly for communication and upload the
running code. It is easy to use and very convenient . IPST-SE can be used with Arduino1.0 and
Wiring 1.0 development software. The IPST-SE controller board is a complete, low-cost
development platform designed for those interested in learning and using Arduino or Wiring
in microcontroller, robotic and STEM applications. Its compact size, convenient features, and
low price make it an ideal tool for the student and educator. Figure 2-1 shows the layout of
IPST-SE board.
This is technical features of IPST-SE board :
The main microcontroller is ATmega644P/PA of Atmel. It includes 64KB flash
memory (10,000 times erasable), 4KB of RAM and 2KB of EEPROM.
Run with 16MHz clock.
RESET switch
7-ch of Analog input with 10-bit A/D converter (A0 to A6). Support the analog
voltage 0 to +5V.
13 of Digital Input/Output. Share with I2C bus and UART1.
Upload with computer via USB port
128x160 dots color GLCD. It only supports line-art , color background and text
with 21 characters 16 lines (no support the image file).
2-ch of DC motor driver with LED indicator. Support 4.5 to 9V motor
4-ch of Servo motor outputs
1 of KNOB and OK switch for analog experiment (connected port 31/A7)
1 of Switch input on-board (connected port 22)
2 of power inputs ; DC adaptor jack and 2-pin terminal block for battery
Power switch and RESET switch available
All ports available with 3-pin of 2.00mm. header. (+5V, Signal and GND)
Requires +6 to 9V 500mA supply voltage in normal operation (no motor driving)
and/or at least 1500mA for robotics application.
+5V switching regualator on--board with polarity protection circuit
Low battery indicator
ISP connector for upgrading and recovery firmware (for manufacturer)
IPST-MicroBOX [SE] Lab manual21
Figure 2-1 : Layout of the IPST-SE board of the IPST-MicroBOX (SE)
27
A3
30
A6
29
A5
26
A2
28
A4
25
A1
24 A0
USB
D
9SD
A8
SCL
12 13 14 15SV0SV1SV2SV3
12
6VG
13
6VG
14
6VG
15
6VG
21
DC MOTOR
3TxD
1
LOW
+5
2RxD
1
UART1
SERVO
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
RESET
20
19
18
17
16
KN
OB
OK
SW
1
ON
22IPST-MicroBOX [SE] Lab manual
2.3 Output device features
2.3.1 ZX-LED : Single LED output board
This module use 8mm. diameter LED. It requires logic “1” or “high” for driving LED.
The schematic diagram is shown in trhge figure 2-2
Figure 2-3 : The LED8 serial LED output board of the IPST-MicroBOX [SE]
Q1KRC102
(DTC114)
R1(Default = 510)
LED1
+
S
Figure 2-2 : Photo of ZX-LED and schematic diagram
2.3.2 LED8 : Serial 8-LED output board
The LED8 is a circuit board with 8 of 3mm. LED for displaying and the peripheral
output to be used to drive a relay by using optional relay driver board. The LED8 is connected
to one port of the IPST-SE controller board for control and extinguish the LED 8 bits. The look
of the circuit board shown in figure 2-3.
IPST-MicroBOX [SE] Lab manual23
The LED8 is interfaced with the IPST-SE board in serial data communications. Developers
can program the LED8 operation to blink from 1 to 8 or be programmed to function as running
lights from 1 to 8 bulbs as well.
At the top of the LED8 board have the 3-pin of JST connector. They are connected and
shared from LEDs. They activate with the logic "1". DC voltage output is +5V. User can use
the output from this point to connect with the extenal high power load driver board such as
relay driver board for controlling without more programing code.
2.3.3 ZX-SPEAKER : Piezo speaker board
The schematic diagram is shown in figure 2-4. There is technical features as follow :
32 Peizo speaker
Resonant frequency 1kHz to 3kHz
Figure 2-4 : Photo and schematic diagram of ZX-SPEAKER
C110/16V
SP1Piezo
speaker
S+
K1SOUND
24IPST-MicroBOX [SE] Lab manual
2.4.2 ZX-LDR : Light sensor
Detect the ambient light. There is 2 outputs :
+ Output voltage increase when detect the light
Output voltage decrease when detect the light
Module and schematic of ZX-LDR are shown in the figure 2-6.
DATAR3220
R210k
R1510
LED1
S1Switch
Indicator
Signal output
GND
+V
Outs logic "1" when switchis released and LED is off.Z
X-S
WIT
CH
01 D Outs logic "0" when switch
is pressed and LED is on.
2.4 Sensor module features
2.4.1 Switch module/Touch sensor
The switch input is used to detect collision at logic "0". Two sets along with the
connecting cable are provided.
The pressed operation is driving logic "0" to output pin and LED is on. If not press, the
output pin as logic "1" and LED is off.
A ZX-LDR
10k
LDR
+
+
+S
+S
LDRLight
A
HIGH output :Detect more light; outputvoltage is increased.
++ LOW output :
Detect more light; outputvoltage is decreased.
Figure 2-5 : Photo and schematic diagram of ZX-SWITCH01 touch sensor/
switch module
Figure 2-6 : Photo and schematic diagram of ZX-LDR Light sensor
IPST-MicroBOX [SE] Lab manual25
2.4.3 ZX-POT : Variable resistor module
It is the circuit module for applying voltage 0 to +5V following rotate the shaft. It can
be used to measure the angle and distance. There is 2 kinds of output. One for increasing
voltage when clockwise turning. Another one for decresing voltage when anticlockwise turning.
Circuit and layout of the ZX-POT are shown in Figure 2-7.
Output voltage isincreased when turnanti-clockwise direction
A
POTENTIOMETER
Output voltage isincreased when turnclockwise direction
A ZX-POTV
10kB
+
S
+
S
2.4.4 Temperature sensor : MCP9701
MCP9701 is temperature sensor integrated circuit. It can detect and measure the ambient
temperature. Output is Dc voltage in linear. Recognized the change of temperature in less
than 2 seconds. Connect this sensor to the analog input A0 to A6 of IPST-SE board. Figure 2-8
shows the pin and the graph of IC temperature sensor; MCP9701.
Figure 2-7 : Photo and schematic diagram of ZX-POT Variable resistor module
Figure 2-8 : Pin assignment, photo and characreristic graph of MCP9701
Temperature sensor IC.
26IPST-MicroBOX [SE] Lab manual
Technical features of MCP9701 temperature sensor are as follows :
Tiny Analog Temperature Sensor
Wide Temperature Measurement Range: -40oC to +125oC
Accuracy: ±2oC average
Output voltage/Temperature ratio 19.5mV/oC
Wide Operating Voltage Range +3.1V to +5.5V
No external compensated device require
2.4.5 ZX-03 : Infrared reflector sensor (only for Standard 2)
Circuit and layout of the ZX-03 sensor are shown in Figure 2-9. It is used to detect the
reflected infrared light. It includes a infrared LED and photo-transistor in the same chassis.
The heart of this sensor is TCRT5000. It is designed for close proximity infrared (IR)
detection. There’s an infrared diode behind its transparent blue window and an infrared transistor
behind its black window. When the infrared emitted by the diode reflects off a surface and
returns to the black window, it strikes the infrared transistor’s base, causing it to conduct current.
The more infrared incident on the transistor’s base, the more current it conducts.
When used as an analog sensor, the ZX-03 can detect shades of gray on paper and
distances over a short range if the light in the room remains constant.
The suitable distance from sensor to line or floor is during 3 to 8mm. The output
voltage is during 0.1 to 4.8V and digital value from10-bit A/D converter is 20 to 1,000. Thus,
ZX-03 will suitable to apply to line tracking sensor.
So to use the IPST-SE board must be connected to the analog inputs (A0 to A6) of the
IPST-SE board. Then, using knowledge from reading the analog signal to read values from this
sensor for applying to make the Line tracking robot.
10k
TCRT5000
510
+V
GND
OUT
Infrared Reflector
Signal connector
Figure 2-9 : Photo and schematic diagram of ZX-03 Infrared reflector sensor
IPST-MicroBOX [SE] Lab manual27
2.5 Mechnical part features of IPST-MicroBOX [SE]Standard 2
2.5.1 DC motor gearbox
This kit provides 48:1 ratio DC motor gearbox; model BO-2 with IDC connector cable.
Features include :
Operating voltage is +3 to +9Vdc
Current consumption 130mA @ +6Vdc and no load)
Average speed 170 to 250 round per minute (RPM) @ +6V and no load
Weight is 30 grams
Minimum torque is 0.5 kg.cm.
Attached with the plastic mounting with 5 of insert nuts
42 x 45 x 22.7 mm. (WxLxH) dimension
2.5.2 Circle wheel and Tire set
Includes 2 pairs of the suitable circle wheel for BO-2 DC motor gearbox and tread
rubber tire. Fix the wheel with gearbox shaft by 2mm. self-tapping screws
28IPST-MicroBOX [SE] Lab manual
2.5.3 Plastic grid plate set
Includes each of the universal plastic grid palte 2 sizes; 80x60mm. and 80x80mm.
Each plate provides 3mm. diameter holes with 5mm. pitch.
2.5.4 Circle base
This base is injected from high quality ABS plastic. Diameter is 250mm. The base has
a diameter of 3 mm for installation or construction of additional mechanisms. There is 2
types. One is base that attache 2 free ball wheels at both sides. Another one is simple base
without any free wheel.
2.5.5 Plastic joiners
There is 30 pieces of varied color joiners made from PVC plastic. They can be connected
together or by using screws and 3 mm nuts in installation. There are 3 types; Right angle,
Obtuse and Straight joiner.
IPST-MicroBOX [SE] Lab manual29
2.5.6 Strip joiners
They are made from plastic. Each joiner has 3mm. hole 5mm. pitch. Each joiner can
connect for lenght expansion. They are 4 pieces of 3 sizes; 3, 5 and 12 holes type. Total 12
pieces.
2.5.7 Screw and Nut set
Includes 4 of 3mm. thump-wheel screw, 2 of 2mm. self-tapping screws, 4 of 3x8mm.
M3 screws, 30 of 3x10mm. M3 screws, 4 of 3x15 mm. M3 screws, 4 of 3x40mm. M3 screws,
10 of 3x8mm. flat-head screws and 30 of 3mm. M3 nuts.
2.5.8 Metal standoffs
They are metal parts for supporting the plate and sensor board. They are made from
nikle plating metal. Includes 6 of 32mm. metal hexagonal spacers. Each standoff has 3mm.
thread through-hole.
2.5.9 Plastic standoffs
They are some mechanical parts for supporting the plate and sensor board. This kit
includes 4 pieces set of plastic spacer (3mm., 10mm., 15mm. and 25mm.) 4 sets
30IPST-MicroBOX [SE] Lab manual
2.5.10 6-AA battery holder
This battery holder is used to contain AA size battery 6 pieces. It includes wires with
barrel plug for plugging into the DC adaptor jack on the IPST-SE board.
2.5.11 9V 2A DC adaptor
The IPST-MicroBOX [SE] kit all versions includes +9V 2A adaptor. It is DC switching
regulator. It can operated with 110V/220Vac system.
IPST-MicroBOX [SE] Lab manual31
2.6 IPST-MicroBOX [SE] cable information
The IPST-MicroBOX [SE] kit includes some signal cables for the interfacing between
the controller board, sensor module and the computer. They includes the JST3AA-8 cables for
interconnection to the sensor module and the standard USB-miniB cable for interfacing with
the computer.
1.6.1 JST3AA-8 cable
This is standard cable, 3-wires combined with 2mm. The JST connector is at each end.
8 inches (20cm.) in length. Used for connecting between microcontroller board and all the
sensor modules in the IPST-MicroBOX [SE] kit. The wire assignment is shown in the diagram
below.
2mm. pitch
GNDS
+5V
2mm. pitchGND
S/Data
+5V
2.6.2 Standard USB-miniB cable
This is used to connect between the computer’s USB port and the IPST-SE controller
board. Its length is 1.5 metres approximation.
32IPST-MicroBOX [SE] Lab manual
IPST-MicroBOX [SE] Lab manual33
This chapter presents preliminary information of Wiring, which is the software tool for
developing the operation of IPST-SE controller board. For the details of program structure of C/
C++ language Wiring supports, you can read in the Wiring IDE help.
Wiring IDE consist of two important parts which are text editor and C/C++ compiler.
There are many tools and command buttons to help the program development as appeared in
the figure 3-1.
Chapter 3
Wiring IDE Introduction
Figure 3-1 : Main window of Wiring IDE software used in the program
development
34IPST-MicroBOX [SE] Lab manual
3.1 Menu bar
Including File, Edit, Sketch, Tools and Help menu, will affect work files doing at the
present only.
3.1.1 File
New (Ctrl+N) : Create new files. This is called sketch in Wiring and given name following
the recent date in the format sketch_YYMMDDa, such as sketch_080407a or click the button
on the tool bar.
Open (Ctrl+O) : Open the exist sketch file or click on the button .
Close (Ctrl+W) : Choose to close the sketch file.
Save (Ctrl+S) : Save the open sketch file in the old name and work similarly to click the
button on the tool bar.
Save as…(Ctrl+Shift+O) : Save the open sketch file in the new name and the old file
will not disappear.
Upload to Wiring hardware (Ctrl+U) : Exports the program to the Wiring I/O Board
(inthis document is the IPST-SE controller board). After the files are exported, the directory
containing the exported files is opened. There is more information about uploading below. It
works in the same way as click the button on the tool bar.
Preference : Customize the operation of Wiring IDE
Quit (Ctrl+Q) : Quit the Wiring program and close all windows of Wiring program.
IPST-MicroBOX [SE] Lab manual35
3.1.2 Edit
The menu contains commands used to edit the sketch file that develops on the Wiring IDE.
Undo (Ctrl+Z) : cancel the previous action of a command or the lastest typing. You
can cancel Undo command by click Edit > Redo.
Redo (Ctrl+Y) : To return to make a statement made before the Undo command is
available only when done Undo already.
Cut (Ctrl+X) : Delete and copy the selected text to store at the clipboard, which functions
as the temporary memory unit to preserve information.
Paste (Ctrl+V) : Place the data in the clipboard on the desired position or replace the
selected text.
Select All (Ctrl+A) : Select all letters or text in the open file in the text editor at that time.
Find (Ctrl+F) : Search for any text in the open file in the text editor. In addition, it is also
able to find and replace another text.
Find Next (Ctrl+G) : Find text or words we use to search for the next one within the
open file in the text editor.
36IPST-MicroBOX [SE] Lab manual
3.1.3 Sketch
Sketch menu is a command menu relating to compile a sketch file.
Verify/Compile (Ctrl+R) : It is a command of program compilation and its function is
similar to pressing the button on the tool bar.
Import Library : Open the included library of Wiring.
Show Sketch Folder : Show the folder of the current sketch file.
Add File: Add the required program file to the sketch file.
3.1.4 Tools
Tools menu is a command menu relating to selection of tools helped to develop a
program. Important commands you should know are as follows.
Auto Format : Try to format program code in the completed form.
Serial Monitor : Open the serial data terminal.
Board : Choose the interfaced hardwarere with the Wiring 1.0.
Serial Port : Choose the interfaced port of the Wiring I/O hardware.
IPST-MicroBOX [SE] Lab manual37
3.1.5 Help
Getting Started : Open the window about the using Wiring of the Wiring website.
Examples : Open a sketch file of an example program.
Reference : Open Reference window of the Wiring website. It consists of language,
programming environment, libraries, and language comparison. You have to connect with the
internet if you would like to see the information.
Find in Reference (Ctrl+Shift+F) : Choose text in your program code. Here you will
drag black bar and click on it. The program will take the text you have chosen to find in
reference and if it cannot find anything, there will be a warning message in the window of the
program.
Wiring Hardware : Browse the information of Wiring I/O hardware via internet.
Troubleshooting : Open the window about solutions in performance of the Wiring of
the Wiring website.
Visit wiring.org.co (Ctrl+5) : Open the web browser to visit the homepage of Wiring at
http://wiring.org.co.
About Wiring : Show the copyright on the Wiring software
38IPST-MicroBOX [SE] Lab manual
3.2 Toolbar
There are six buttons of basic functions and initial operation as follows.
Run or Compile : This button is used to compile the program code.
New : This button is used to create a sketch file.
Open : Open the exist sketch file
Save : Save the open sketch file in the old name. If would like to change
filename, use Save As command instead.
Upload to Wiring hardware : Exports the program to the IPST-SE controller
board). This procedure is called UPLOAD.
Serial monitor : opens the serial data communication between the Wiring
I/O hardware and the monitor of Wiring IDE through serial ports (or COM port) to check the
information sent back from Wiring I/O hardware (here it is IPST-SE controller board, which is
very useful for the detection of the program’s operation).
3.3 Serial monitor
Wiring IDE has a Serial monitor. It is a serial data communication tool. User can transmit,
receive and show the serial data via this monitor with USB serial port of computer. In the
developed sketch code, must put two imporatant commnands as follows :
1. Serial.begin() : Set the baud rate of serial data communication. Normally the baud
rate value is 9600 bit per second. Must add this command into Setup() of sketchbook.
2. Serial.println() : Assign the sending message to Serial monitor on the Wiring IDE.
Openning the Serial monitor is very easy. Click on the button at Toolbar. The
Serial monitor window is appeared following the figure below.
IPST-MicroBOX [SE] Lab manual39
This chapter presents examples of the hardware experiment with the IPST-SE controller
board of the IPST-MicroBOX [SE] kit. There are 4 main activities as follows.
Activity 1 : Shows message on the display of the IPST-SE board (5 sub-activities)
Activity 2 : Reading KNOB button and OK switch of the IPST-SE board
Activity 3 : Control the simple output devices
Activity 4 : Sound activity
The procedure of development of each activity is the same. That is open Wiring1.0
software, create the sketch, compiled and uploaded onto the IPST-SE board. Finally, test the
running program.
The important thing to emphasize is every time you turn on the power to the IPST-SE
board. Wait for the controller to ready first. It takes about 3 to 5 seconds after turning on the
power or after pressing the RESET switch. If it is uploaded before it IPST-SE board ready, The
work may cause an error in the connection or the uploaded code does not work as it should
be. It will not damage the controller board. It just the board does not work or work not
properly.
Chapter 4
Hardware experiment of IPST-SEcontroller board
40IPST-MicroBOX [SE] Lab manual
Activity 1 : Shows message on the display of theIPST-SE board
Activity 1-1 Hello World
(A1.1.1) Open the Wiring 1.0 IPST-SE software.Create the new sketch file. Type the code
following the Listing A1-1. then save as the sketch.
(A1.1.2) Apply the supply voltage to the IPST-SE board and turn on power. Connect the USB
cable between IPST-SE board and computer.
27A3 30A6
29A526A2
28A425A1
24
A0
USB
D9SDA 8SCL
12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC M
OTO
R
3 TxD1
LOW+5
2 RxD1
UART1
SERVO
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
RESET2019
18
17
16
KNOB
OK
SW1
ON
Turn onthe POWER switch
3
1
2
4
Plug the adaptor
Connect the USB cable
Wait until theUSB indicator is on
(A1.1.3) Choose the hardware at menu Tools > Board > IPST-SE > ATmega644P @16MHz
IPST-MicroBOX [SE] Lab manual41
(A1.1.4) Choose the interfaced port at menu Tools > Serial Port (Number of interfaced port
may be different depend on each computer)
(A1.1.5) Compile and upload the sketch to IPST-SE board by clicking on the button or
choose at menu File > Upload to Wiring Hardware
At the IPST-SE screen, the message Hello World will be displayed.
27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC M
OTO
R
3 TxD1
LOW+5
2 RxD1
UART1
SERVO
00000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
RESET2019
18
17
16
KNOB
OK
SW1
ON
Hello0 rld00Wo
#include <ipst.h> // Incldue IPST-SE libraryvoid setup(){ glcd(1,0,"Hello World"); // Send message to display}void loop(){}
Code description
This code will send the messge ; Hello World to display at the line 1 column 0 of
GLCD screen. It works at once because the code is contained in void setup() bracket only.
Listing A1-1 : HelloGLCD.pde; the sketch file for sending message to display
on the GLCD scrren of the IPST-SE board
42IPST-MicroBOX [SE] Lab manual
Activity 1-2 Multipleline display
The GLCD screen of IPST-SE board size is 128 x 160 dots. Show the character with 5 x
7 dots resolution by 21 charactes 16 lines. Developer can define the position of each line and
column on the screen by using glcd function of the ipst.h library file.
Additionally, glcd function provides the special characters for setting the display position
insteadto use the position number. It will be show in the Listing A1-2.
(A1.2.1) Open the Wiring 1.0 IPST-SE software.Create the new sketch file. Type the code
following the Listing A1-2. then save as the sketch.
#include <ipst.h> // Include IPST-SE libraryint i,j;void setup(){
glcdFillScreen(GLCD_WHITE); // Set background color as whitesetTextColor(GLCD_BLACK); // Set text color as blacksetTextBackgroundColor(GLCD_WHITE); // Set text background as whitefor (i=0;i<16;i++) // Loop 16 times for displaying messages
{glcd(i,i,"Row %d ",i); // Display messages on the screen
}}void loop(){}
Code description
This sketch add 3 functions of GLCD displaying as follows :
1. glcdFillScreen - Set the screen background color function
2. setTextColor - Set the text color function
3. setTextBackground - Set the text background color function
After screen setting already, the sketch will send the Row message following line number
that get from increase the value of i variable and also shift the position by using i variable
value.
Thus, firt line will be displayed Row0 message at column 0. Next on the line 2 will
show Row1 message respcetively untill line 15. It will be show Row 15 message at the
column 15
Listing A1-2 : GLCDmultipleline.pde; the sketch file for sending message to
display on the GLCD screen of the IPST-SE board in multiline process.
IPST-MicroBOX [SE] Lab manual43
(A1.2.2) Apply the supply voltage to the IPST-SE baord and turn on power. Connect the USB
cable between IPST-SE board and computer.
(A1.2.3) Compile and upload the sketch to IPST-SE board by clicking on the button or
choose at menu File > Upload to Wiring Hardware
At the IPST-SE screen, it shows Row0 to Row15 message on each line respectively.
27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC M
OTO
R
3 TxD1
LOW+5
2 RxD1
UART1
SERVO
00000000
0Row01000000000000000
00Row0200000000000000
000Row030000000000000
0000Row04000000000000
00000Row0500000000000
000000R00060000000000
0000000R0007000000000
00000000Row0800000000
000000000Row090000000
0000000000Row01000000
00000000000Row0110000
000000000000Row012000
0000000000000Row01300
00000000000000Row0140
000000000000000Row015
RESET2019
18
17
16
KNOB
OK
SW1
ON
Rowl00 rld00Wo
44IPST-MicroBOX [SE] Lab manual
Activity 1-3 Fun with size and rotation text on GLCD
Font size displayed on the GLCD screen of the IPST-SE board when it starts is the smallest.
The number of dots per character is 6 x 10 dots (the actual font size is 5 x 7 dots). To adjust the
font size, use setTextSize() function. The value size in () is time of the default size. For example
:
setTextSize(2) is set text size to 2 times of the default size. The number of dots
per character is 12 x 20 dots.
setTextSize(3) is set text size to 3 times of the default size. The number of dots
per character is 18 x 30 dots.
When adjusting the font size is larger. Number of characters per line was reduced
from 21 characters 16 lines. Afdter set the text size 2 times, it will display 10 characters 8
lines. This is important factor that all programmers have to concentrate.
In addition to setting the font size, programmer can rotate the displaying by using the
function glcdMode (). The default mode is 0 (glcdMode (0)) is displayed vertically. For another
3 modes 1, 2 and 3, rotate the displaying 90 degrees each. That is from 0 to 90 degrees (mode
1), 90 to 180 degress (mode 2) and 180 to 270 degrees (mode 3).
#include <ipst.h>int x,m;void setup(){
//glcdSetColorWordRGB(); // Enable this function if displaying color// of GLCD incorrect
setTextColor(GLCD_RED); // Set text color as red}void loop(){
for (x=1;x<6;x++){
setTextSize(x); // Set text sizefor(m=0;m<4;m++){
glcdClear(); // Clear screenglcdMode(m); // Set rotation of displayglcd(0,0,"%dX",x); // Show text sizeglcd(1,0,"M=%d",m); // Show rotation mode numbersleep(500);
}}
}
Listing A1-3 : GLCDtextFlip.pde; the sketch file for trsting about setting text
size and rotation display direction of GLCD screen of the IPST-SE board
IPST-MicroBOX [SE] Lab manual45
(A1.3.1) Open the Wiring 1.0 IPST-SE software.Create the new sketch file. Type the code
following the Listing A1-3. then save as the sketch.
(A1.3.2) Apply the supply voltage to the IPST-SE baord and turn on power. Connect the USB
cable between IPST-SE board and computer.
(A1.3.3) Compile and upload the sketch to IPST-SE board by clicking on the button or
choose at menu File > Upload to Wiring Hardware
IPST-SE display shows the number of text size and number of display mode. Starts from
the upper left, upper right, lower right and lower left corner. Surrounding the display starts
from 1X, 2X, 3X, 4X and 5X each with 4 display direction by the M value.
M = 0; display in vertical M = 1; rotate displaying to 90o
Text size is 3 times (3X) Text size is 4 times (4X)
M = 2; rotate displaying to 180o M = 3; rotate displaying to 270o
Text size is 4 times (4X) Text size is 5 times (5X)
46IPST-MicroBOX [SE] Lab manual
Activity 1-4 : Simple graphic displaying
The glcd() function is main function for GLCD screen of IPST-SE board operation. Except
showing text messages, this function also support more commands for drawing lines and
simple geometry shape. Includes :
glcdRect(int x1,int y1,int width,int height,uint color) is function to draw a rectangle
shape.
glcdFillRect(int x1,int y1,int width,int height,uint color) is function to create a solid
rectangle shape.
glcdLine(int x1, int y1, int x2, int y2,uint color) is function to draw the line.
glcdCircle(int x, int y, int radius,uint color) is function to draw a circle.
glcdFillCircle(int x, int y, int radius,uint color) is function to create a solid circle
shape.
glcdClear(uint color) is clear display function.
The testing program is shown in the Listing A1-4. Create the sketch, compile and upload
to the IPST-SE board. The result is as follows :
If the color of the display is not correct, may be due to the version of the GLCD
monitor. This GLCD monitor has 2 versions that different data setting. The solution is remove
// symbol from the glcdSetColorWordRGB (); function in setup(); . It will be change the color
data setting.
IPST-MicroBOX [SE] Lab manual47
#include <ipst.h> // Include IPST-SE library
int i,j;
void setup()
{
//glcdSetColorWordRGB(); // Enable this function if displaying color// incorrect
}
void loop()
{
glcdClear; // Clear screen and set background to black
sleep(300);
for (i=0;i<160;i+=4)
{
glcdLine(0,0,128,i,GLCD_WHITE); // Draw the white line from 0,0// coordinate to target
}
for (i=0;i<128;i+=4)
{
glcdLine(0,0,i,160,GLCD_RED); // Draw the red line from 0,0// coordinate to target
}
sleep(2000);
glcdRect(32,40,64,80,GLCD_BLUE); // Draw the blue rectangle layout
sleep(300);
glcdFillCircle(32,40,31,GLCD_GREEN); // Create the solid green circle
glcdFillCircle(96,40,31,GLCD_YELLOW); // Create the solid yellow circle
glcdFillCircle(32,120,31,GLCD_MAGENTA); // Create the solid margenta circle
glcdFillCircle(96,120,31,GLCD_SKY); // Create the solid light blue circle
sleep(1000);
glcdCircle(64,40,31,GLCD_GREEN); // Draw the green circumference
glcdCircle(32,80,31,GLCD_BLUE); // Draw the blue circumference
glcdCircle(64,120,31,GLCD_YELLOW); // Draw the yellow circumference
glcdCircle(96,80,31,GLCD_SKY); // Draw the light blue circumference
sleep(1000);
glcdFillRect(0,0,128,160,GLCD_YELLOW); // Create the solid yellow rectangle
sleep(1000);
}
Listing A1-4 : GLCDsimpleGraphic.pde; the sketch file for demonstration of
simple graphic displaying of the IPST-SE board
48IPST-MicroBOX [SE] Lab manual
Activity 1-5 : Draw the curve
Except the circles and rectangle, the curve is a key component in creating graphics. In
glcd function also provides a function to create the curve. It is glcdArc(). The parameter that
must be reasonable. See more detail in chapter of the GLCD library.
(A1.5.1) Open the Wiring 1.0 IPST-SE software. Create the new sketch file. Type the code
following the Listing A1-5. then save as the sketch.
(A1.5.2) Apply the supply voltage to the IPST-SE baord and turn on power. Connect the USB
cable between IPST-SE board and computer.
(A1.5.3) Compile and upload the sketch to IPST-SE board by clicking on the button or
choose at menu File > Upload to Wiring Hardware
#include <ipst.h>
int i;
// Smiley face graphic function
void face(){
glcdFillCircle(64,70,50,GLCD_WHITE);
glcdArc(48,60,16,30,150,GLCD_RED);
glcdCircle(48,55,5,GLCD_BLUE);
glcdCircle(80,55,5,GLCD_BLUE);
glcdArc(80,60,16,30,150,GLCD_RED);
glcdFillCircle(64,70,7,GLCD_YELLOW);
glcdArc(64,80,30,220,320,GLCD_RED);
glcdArc(64,80,29,220,320,GLCD_RED);
}void setup(){
//glcdSetColorWordRGB(); // Enable this function if displaying color// incorrect
}void loop(){
for(i=0;i<4;i++){
glcdClear();
glcdMode(i); // Rotate displaying
face();
sleep(1000);
}
}
Listing A1-5 : GLCDarcTest.pde; the sketch file for demonstration of creating
the curve on GLCD screen of the IPST-SE board
IPST-MicroBOX [SE] Lab manual49
(A1.5.4) Run the sketch. See the IPST-SE board operation.
The display shows a smiley face for 1 second and turn it each 90 degrees respectively
and then loop back to the start page. The display will go all the time.
50IPST-MicroBOX [SE] Lab manual
Activity 2 : Reading KNOB button and OK switchof the IPST-SE board
Normal automatic control system must be configured with a switch in user interface
hardware. The IPST-SE board also provides the user interface hardware as well. It contains
KNOB button, OK switch and SW1 switch.
27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC M
OTO
R3 TxD1
LOW+5
2 RxD1
UART1
SERVO
00000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
RESET2019
18
17
16
KNOB
OK
SW1
ON
Hello0 rld00Wo
KNOB button, OK andSW1 switch are the userinterface hardware of theIPST-SE board
(A2.1) Create the new sketch with Listing A2-1 and save as to KnobSwitchTest.pde.
(A2.2) Compile and upload to the IPST-SE board then run the sketch.
IPST-SE monitor shows below message :
Press OK (text size 2x)
(A2.3) Press the OK switch to continue.
GLCD monitor shows a yellow circle 1 second then show message :
Knob value (text size 2x)
XXXX (text size larger to 3x)
therefore; xxxx value is 94 to 1023
(A2.4) Adjust the KNOB button on the IPST-SE board.
Knob’s value at the screen is changed following adjustment at KNOB button.
(A2.5) Press the OK switch and release.
GLCD shows the solid green circle 1 second then shows message and KNOB value.
(A2.6) Finally, press the SW1 switch and release.
GLCD shows the solid red circle 1 second then shows message and KNOB value.
IPST-MicroBOX [SE] Lab manual51
#include <ipst.h> // Include the main library
void setup(){
//glcdSetColorWordRGB(); // Enable this function if displaying color// incorrect
glcdClear(); // Clear screen and set black backgound
setTextSize(2); // Set text size as 2x
glcd(1,1,"Press OK"); // Show entry essage
sw_OK_press(); // Loop for pressing the OK switch
glcdClear(); // Clear screen and set black backgound
glcdFillCircle(64,70,50,GLCD_YELLOW); // Draw the solid yellow circle
delay(1000); // Show graphic 1 second
glcdClear(); // Clear screen and set black backgound
}
void loop()
{if (sw_OK()) // Check the OK switch pressed{
glcdClear(); // Clear screen and set black backgound
glcdFillCircle(64,70,50,GLCD_GREEN);// Draw the solid green circle
delay(1000); // Show graphic 1 second
glcdClear(); // Clear screen and set black backgound
}
if(sw1()) // Check the SW1 switch pressed
{
glcdClear(); // Clear screen and set black backgoundglcdFillCircle(64,70,50,GLCD_RED); // Draw the solid red circle
delay(1000); // Show graphic 1 second
glcdClear(); // Clear screen and set black backgound}
glcd(1,0,"Knob value"); // Show message
setTextSize(3); // Set text size as 3x
glcd(2,2,"%d ",knob()); // Show the value of KNOB button
setTextSize(2); // Set text size as 2x
}
Listing A2-1 : KnobSwitchTest.pde; the sketch for demonstration about reading
the value of KNOB button, OK and SW1 switch on the IPST-SE board
52IPST-MicroBOX [SE] Lab manual
Activity 3 : Control the simple output devices
The library file ipst.h provides out (int num, int _dat) function for sending a logic "0" or
"1" to the microcontrolle’s digital output pin. It helps the IPST-SE to to drive the output device
easier. The simplest example device is LED.
In this activity, connect the ZX-LED board to IPST-SE board at any pin. LED on ZX-LED
board will be on when receive the logic "1" and off when receive the logic "0"
(A3.1) Connect the first ZX-LED board to pin 17 and second one to pin 18.
KRC102
510
LED
+
S
ZX-LED
connect with JST3AA-8 cable27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC M
OTO
R
3 TxD1
LOW+5
2 RxD1
UART1
SERVO
00000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
RESET2019
18
17
16
KNOB
OK
SW1
ON
Hello0 rld00Wo
KRC102
510
LED
+
S
ZX-LED
connect with JST3AA-8cable
IPST-MicroBOX [SE] Lab manual53
#include <ipst.h> // Include the main library
void setup()
{setTextSize(2); // Set text size as 2x
glcd(1,1,"Press OK"); // Show the title message
sw_ok_press(); // Loop for pressing the OK switch
}
void loop()
{
out(17,1); // LED at pin 17 is on
out(18,0); // LED at pin 18 is off
sleep(400);
out(17,0); // LED at pin 17 is off
out(18,1); // LED at pin 18 is on
sleep(400);
}
(A3.2) Create the new sketch with Listing A3-1 and save as LEDTest.pde file.
(A3.3) Apply the supply voltage to the IPST-SE board and turn on power. Connect the USB
cable between IPST-SE board and computer. Compile and upload to the IPST-SE board then
run the sketch.
(A3.4) Observe the operation of both ZX-LED board.
The IPST-SE monitor shows the title message :
Press OK
Press the OK switch to start. LED of both ZX-LED boards on and off alternately
continuous.
Listing A3-1 : LEDTest.pde; the sketch for demonstration about simple driving
the output devices of the IPST-SE board
54IPST-MicroBOX [SE] Lab manual
Activity 4 : Sound activity
IPST-MicroBOX [SE] kit provides the sound output device. It is ZX-
SPEAKER. It uses a small piezo speaker. The speaker’s resonance frequency is
range of about 300 to 3,000Hz. For programming to drive this device, use
beep () and sound () function.
Listing A4-1 is example about how to use beep() function to drive “beep”
signal with fix frequency every 1 second.
Listing A4-2 is example about how to use sound() function to drive the sound at any
frequency in defined period.
(A4.1) Connect the ZX-SPEAKER to pin 19 of the IPST-SE board.
SPEAKER O
+ S
+
S
27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC M
OTO
R
3 TxD1
LOW+5
2 RxD1
UART1
SERVO
00000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
RESET2019
18
17
16
KNOB
OK
SW1
ON
Hello0 rld00Wo
(A4.2) Create the new sketch with Listing A4-1 and save as BeepTest.pde file.
(A4.3) Apply the supply voltage to the IPST-SE board and turn on power. Connect the USB
cable between IPST-SE board and computer. Compile and upload to the IPST-SE board.
IPST-MicroBOX [SE] Lab manual55
#include <ipst.h> // Include the main library
void setup()
{}
void loop()
{
sound(19,500,500); // Generate the 500Hz signal to pin 19 in 0.5 second
sound(19,2500,500); // Generate the 2500Hz signal to pin 19 in 0.5 second
}
#include <ipst.h> // Include the main library
void setup()
{}
void loop()
{
beep(19); // Generate the “beep” signal to pin 19
sleep(1000);
}
(A4.4) Run the sketch. Observe the operation of ZX-SPEAKER board.
To hear "beep" sound in every 1 second from the speaker of the ZX-SPEAKER.
(A4.5)Create the new sketch with Listing A4-2 and save as SoundTest.pde file. Compile and
upload to the IPST-SE board again.
(A4.6) Run the sketch. Observe the operation of ZX-SPEAKER board.
To hear sound 2 frequencies alternately continuous from the ZX-SPEAKER.
Listing A4-1 : BeepTest.pde; the sketch for demonstration about generate the
beep signal of the IPST-SE board
Listing A4-2 : SoundTest.pde; the sketch for demonstration about generate
the sound with any frequency of the IPST-SE board
56IPST-MicroBOX [SE] Lab manual
IPST-MicroBOX [SE] Lab manual57
The development of C/C++ language programming for the IPST-MicroBOX [SE] is
performed under the support of library file; ipst.h. It helps to reduce the complexity of
programming to control the hardware.
The sturcture of the ipst.h library file is shown below.
Chapter 5
library file
ipst.h library
Color Graphic LCD
TB6612FNG
M
M
Servo motor
ZX-SPEAKER
DC motor driver
Analog sensors
16-ch. Serialservo motorcontroller
XBEE
Bluetooth
Serial MonitorWiring/Arduino IDE ZX-LED
ZX-SWITCH01
LED8 board
58IPST-MicroBOX [SE] Lab manual
5.1 ipst.h library
To run the instructions for IPST-MicroBOX [SE] program development; developers have
to include ipst.h mainly library file at the beginning of the C/C++ code with this command
:
#include <ipst.h>
to declare the compiler know all statements of the ipst.h library.
The ipst.h library consist of many sub-library. Includes :
ipst_glcd.h contains the functions and statements of the display message, number
and line art graphic on the color graphic LCD of IPST-SE board (not support the image file).
ipst_sleep.h contains the function and statements of delayed time.
ipst_in_out.h contains the functions and statements of reading digital input port and
sending digital data to digital output port.
ipst_analog.h contains the functions and statements of reading analog input. Also
included KNOB button and OK switch value.
ipst_sound.h contains the functions and statements of sound generation.
ipst_motor.h contains the functions and statements of DC motor driving.
ipst_servoMotor.h contains the functions and statements of servo motor control.
This library work with fixed microcontroller port.
ipst_serial.h contains the functions and statements of serial data communication via
USB and TxD1/RxD1 of the IPST-SE controller board.
ipst_led8.h contains the functions and statements of interfacing with the LED8
board to control the LED operations.
IPST-MicroBOX [SE] Lab manual59
5.2 Built-in library of Wiring1.0
Wiring1.0 IDE includes many library file to support the interfacing with special function
devices and any kind of sensors. It includes :
1. EEPROM.h - This library helps to manage the main micrcontroller’s EEPROM.
2. LiquidCrystal.h - It is character LCD interfacing library.
3. Encoder.h - It is special library for encoder circuit. Requires the specific device.
4. Wire.h - It is library of serial communication on 2-wires or I2C bus.
5. Matrix.h - This is dot-matrix LED library. Requires the specific device.
6. Sprite.h - This is custom library for making the animation on LED dot-matrix.
Requires the specific device.
7. SoftwareSerial.h - This is one of important library to extends the serial
communication port of the main microcontroller by using any digital port.
8. Stepper.h - It is library for interfacing with the external stepper motor driver
circuit. Requires the specific device.
9 . OneWire.h - It is optional library for interfacing with 1-wire serial
communication bus.
In learning to use the IPST-SE board will be used the Wiring built-in library and ipst.h
library together. To helps the program development for maximum efficiency and easiset to
understand for learners in a wide range.
5.3 How to execute the ipst.h library and sub-library
There is 2 method for executing the ipst.h library and all sub-libraries.
1. Execute a whole library files by using command #include <ipst.h>. This method
is easiest. But it requires more memory space to contains all instructions and related variables.
2. Excute only the used sub-library by using command #include <ipst_xxxx.h>. The
xxxx letters are the name of any sub-library of ipst.h. See detais in topic 5.1 of this chapter.
This method has the advantage of reduce the size of the sketch. Because run-down due to a
function or set of instructions as needed.
60IPST-MicroBOX [SE] Lab manual
5.4 Library description
This topic describes all sub-libraries of ipst.h library file. Includes important functions
and commands.
5.4.1 ipst_sleep.h : The delay time library
This library file has functions for time delaying. This library must be included at the
top of the program with the command #include as follows :
#include <ipst_sleep.h> or #include <ipst.h>
Important functions of this library file are consisted of :
5.4.1.1 sleep and delay
sleep and delay are same operation. They delayed time in millisecond unit.
Syntax
void sleep(unsigned int ms)
void delay(unsigned int ms)
Parameter
ms - Set the delay time in millsecond unit. Range is 0 to 65,535.
Example 5-1
sleep(20); // Delay 20 millisecond
delay(1000); // Delay 1 second
5.4.1.2 delay_us
It is delay time function in microsecond unit.
Syntax
void delay_us(unsigned int us)
Parameter
us - Set the delay time in microsecond unit. Range is 0 to 65,535.
Example 5-2
delay_us(100); // Delay 100 microsecond
IPST-MicroBOX [SE] Lab manual61
5.4.2 ipst_sound.h : The sound library
This library file has functions for time delaying. This library must be included at the top
of the program with the command #include as follows :
#include <ipst_sound.h> or #include <ipst.h>
Important functions of this library file are consisted of :
5.4.21 beep
It is "beep" signal generated function for any digitla port of IPST-SE board. Beep signal
frequency is 500Hz witrh duration time 100 millisecond. IPST-SE board will drive the beep
signal to heard when connect to any speaker. The ZX-SPEAKER module is recommended.
Syntax
void beep(int pin)
Parameter
pin - Digital pin of IPST-SE board. It is 0 to 30. Pin 19 or 20 is recommended.
Example 5-3
beep(19); // Generate the signal 500Hz with 100ms to pin 19.
5.4.2.2 sound
It is sound generated function for any digitla port of IPST-SE board. This function sets
the frequency, duration time and output pin. IPST-SE board will drive the sound signal to
heard when connect to any speaker. The ZX-SPEAKER module is recommended.
Syntax
void sound(int pin, int freq, int time)
Parameter
pin - Digital pin of IPST-SE board. It is 0 to 30. Pin 19 or 20 is recommended.
freq - Frequency value. It is 0 to 32,767 in Hz unit.
time - Duration time. It is 0 to 32,767 in millisecond unit.
Example 5-4
sound(19,1200,500); // Generate the signal 1200Hz with 500ms to pin 19
62IPST-MicroBOX [SE] Lab manual
5.4.3 ipst_in_out.h : Digital input/output port library
This library file has functions for reading and sending the digital value to any digital
input/output port of IPST-SE board. . This library must be included at the top of the program
with the command #include as follows :
#include <ipst_in_out.h> or #include <ipst.h>
Important functions of this library file are consisted of :
5.4.3.1 in
Read data from the specific digital port
Syntax
char in(x)
Parameter
x - Digital pin of IPST-SE board. It is 0 to 30. Pin 19 or 20 is NOT recommended.
Return value
0 or 1
Example 5-5
char x; // Declare x variable for keeping reading input data
x = in(16); // Read pin 16 and store data to x variable.
5.4.3.2 out
Write or send the data to the specific digital port
Syntax
out(char _bit,char _dat)
Parameter
_bit - Set digital pin of IPST-SE board. It is 0 to 30.
_dat - Set data output as 0 ot 1.
Example 5-6
out(17,1); // Out oin 17 with “1”
out(18,0); // Out pin 18 with “0”
IPST-MicroBOX [SE] Lab manual63
5.4.3.3 sw1_press
This function loops to check the SW1 pressing. It returns value after switch is released.
Syntax
void sw1_press()
Example 5-7
................
sw1_press(); // Wait until the SW1 is pressed and released
................
5.4.3.4 sw1
This function check the SW1 pressing in any time.
Syntax
char sw1()
Return value
“0” - SW1 is pressed
“1” - SW1 is not pressed
Example 5-8
char x; // Declare x variable for keeping the value
x = sw1(); // Get SW1 status and store to x variable
SW1 switch status is read by sw1() and sw1_press()function
64IPST-MicroBOX [SE] Lab manual
5.4.4 ipst_analog.h : Analog inut library
This library file supports all instructions for reading the analog input port (A0 to A6),
KNOB button and OK switch (both are connected to A7 analog input port) of the IPST-SE
controller board. This library must be included at the top of the program with the command
#include as follows :
#include <ipst_analog.h> or #inclue <ipst.h>
5.4.4.1 analog
This gets digital data from the analog to digital converter module of any analog port; A0
to A6 of the IPST-SE board.
Syntax
unsigned int analog(unsigned char channel)
Parameter
channel - Analog input port. It is 0 to 6 (means A0 to A6)
Return value
Digital data from analog to digital converter module. The value is 0 to 1023 (in
decimal). It represents 0 to +5Vdc.
KNOB button and OK switch on the IPST-SE boardare read value or status by knob(), sw_OK()and sw_OK_press()
IPST-MicroBOX [SE] Lab manual65
Example 5-9
#include <ipst.h> // Include main library
int val=0; // Declare stored variable
void setup()
{
glcdClear();
setTextSize(2); // Set text size as 2x
}
void loop()
{
glcd(1,0,"AnalogTest"); // Show message on GLCD
val = analog(2); // Read A2 input and store to val variable
setTextSize(3); // Set text size as 3x
glcd(2,2,"%d ",val); // Show A2 value
setTextSize(2); // Set text size back to 2x
}
30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC M
OTO
R
3 TxD1
LOW+5
2 RxD1
UART1
SERVO
00000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
RESET2019
18
17
16
KNOB
OK
SW1
ON
0 00
AnalogTest
543
ZX
-PO
TV
A
Connect ZX-POT to A2 inputof IPST-SE board and test byExample 5-9 code.
27A3
66IPST-MicroBOX [SE] Lab manual
5.4.4.2 knob( )
Read the KNOB button data of the IPST-SE board.
Syntax
unsigned int knob()
Retuen value
Digital data from analog to digital converter module of KNOB button. It is 95
to 1,023
Example 5-10
#include <ipst.h> // Include main library
void setup()
{
glcdClear();
setTextSize(2); // Set text size as 2x
}
void loop()
{
glcd(1,0," KnobTest"); // Show message on GLCD
setTextSize(3); // Set text size as 3x
glcd(2,2,"%d ",knob()); // Show KNOB button value on GLCD
setTextSize(2); // Set text size back to 2x
}
27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC M
OTO
R
3 TxD1
LOW+5
2 RxD1
UART1
SERVO
00000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
RESET2019
18
17
16
KNOB
OK
SW1
ON
0 00
KnobTest
958Adjust
KNOB button
IPST-MicroBOX [SE] Lab manual67
5.4.4.3 sw_OK()
Read status of the OK switch on the IPST-SE board.
Syntax
unsigned char sw_ok()
Retun value
1 (true) when the switch is pressed
0 (false) no press the switch
Note : Pressing the OK switch effects to KNOB value as 0 (zero)
Example 5-11#include <ipst.h> // Include main library
void setup()
{
glcdClear();
}
void loop()
{
if (sw_OK()) // Check OK switch pressing
{
glcdFillScreen(GLCD_YELLOW); // Change background to yellow
delay(3000); // Show time 3 seconds
}
glcdClear(); // Clare screen and set backgoround color to black
}
5.4.4.4 sw_OK_press()
Loop to check the OK switch pressing function
Example 5-12
............
sw_OK_press(); // Wait until the OK switch is pressed
.............
68IPST-MicroBOX [SE] Lab manual
5.4.5 ipst_led8.h : Serial LED8 library
This library file provides the function for interfacing the LED8; serial 8-LED driver board
to send the data for driving LED on it. This library must be included at the top of the program
with the command #include as follows :
#include <ipst_led8.h> or #inclue <ipst.h>
For interfacing between IPST-SE board and LED8, use only one port following the figure
5-1
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
MSB LSB
+5V
RxD
GN
D
Secondary Education
LED8Serial LED-8UART communication9600 bps. Baud
27A3 30A6
29A526A2
28A425A1
24
A0
USB
D9SDA 8SCL
12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC M
OTO
R
3 TxD1
LOW+5
2 RxD1
UART1
SERVO
00000000
0Row01000000000000000
00Row0200000000000000
000Row030000000000000
0000Row04000000000000
00000Row0500000000000
000000R00060000000000
0000000R0007000000000
00000000Row0800000000
000000000Row090000000
0000000000Row01000000
00000000000Row0110000
000000000000Row012000
0000000000000Row01300
00000000000000Row0140
000000000000000Row015
RESET2019
18
17
16
KNOB
OK
SW1
ON
Rowl00 rld00Wo
Connect with JST3AA-8
Recommended Digital port for LED8 interfacing
Intercing port of IPST-SE forLED8
Optional -1 : pin 2 and 3 (disable I2C bus)
Most suitable : pin 16 to 20
Optional -2 : pin 8 and 9 (disable UART1)
Optional -3 : pin 24 to 30 (stop analog)
Figure 5-1 : Connection diagram of IPST-SE board and LED8 driver board
IPST-MicroBOX [SE] Lab manual69
5.4.5.1 pinLED8
Set port of IPST-SE board to connect with LED8 board.
Syntax
void pinLED8(int pin)
Parameter
pin - Digital pin of IPST-SE board. It is 0 to 30. Pin 16 to 20 is recommended.
Example 5-13
pinLED8(20); // Set pin 20 of IPST-SE board to connect with// LED8 board
5.4.5.2 LED8
Data display function for LED8 board
Syntax
void LED8(unsigned char _dat) (for using pinLED8 funtion to declare
the interfaced port)
void LED8(int pin, unsigned char _dat)
Parameter
pin - Digital pin of IPST-SE board. It is 0 to 30. Pin 16 to 20 is recommended.
_dat - Display data. Itr is 0 to 255
Example 5-14
#include <ipst.h> // Include main libraryvoid setup(){
pinLED8(20); // Set pin 20 to connect with LED8 board}void loop(){
unsigned char i=0;while(1){
LED8(i++); // Show 8-bit binary data (00000000 to 11111111)delay(500); // Delay 0.5 second
}}
70IPST-MicroBOX [SE] Lab manual
Example 5-15
#include <ipst.h> // Include main libraryvoid setup(){}void loop(){
unsigned char i=0;while(1){
LED8(20,i++); // Set pin 20 to conect with LED8 board// Then, show 8-bit binary data// (00000000 to 11111111)
delay(500); // Delay 0.5 second}
}
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
MSB LSB
+5V
RxD
GN
D
Secondary Education
LED8Serial LED-8UART communication9600 bps. Baud
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
MSB LSB
+5V
RxD
GN
D
Secondary Education
LED8Serial LED-8UART communication9600 bps. Baud
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
MSB LSB
+5V
RxD
GN
D
Secondary Education
LED8Serial LED-8UART communication9600 bps. Baud
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
MSB LSB
+5V
RxD
GN
D
Secondary Education
LED8Serial LED-8UART communication9600 bps. Baud
Display data = 00000000
Display data = 00000001
Display data = 00001111
Display data = 11111111
IPST-MicroBOX [SE] Lab manual71
5.4.6 ipst_motor.h : DC motor control library
The IPST-SE controller board has 2 of DC motor driver outputs. It can drive 3 to 9V DC
motor. This library must be included at the top of the program with the command #include as
follows :
#include <ipst_motor.h> or #inclue <ipst.h>\
Important functions of this library file are consisted of :
5.4.6.1 motor
Drive DC motor function.
Syntax
void motor(char _channel,int _power)
Parameter
_channel - DC motor output. It is 1 or 2.
_power - Power value. It is -100 to 100If set _power as positive value (1 to 100), motor moves forward
If set_power as negative value (-1 to -100), motor moves backward
If set as 0, motor stop but not recommended. Please choose the motor_stop
function better.
Example 5-16
#include <ipst.h>void setup(){}void loop(){
motor(1,60);// Drive motor 1 with 80% powerdelay(500);// Driving time 0.5 secondmotor(1,-60);// Drive mortor 1 backward// with 60% powerdelay(500);// Driving time 0.5 second
}
27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
15
SV0
SV1
SV
2SV3
126VG
136VG
146VG
156VG
21
DC M
OTO
R
3 TxD1
LOW+5
2 RxD1
UART1
SERVO
00000000
0Row01000000000000000
00Row0200000000000000
000Row030000000000000
0000Row04000000000000
00000Row0500000000000
000000R00060000000000
0000000R0007000000000
00000000Row0800000000
000000000Row090000000
0000000000Row01000000
00000000000Row0110000
000000000000Row012000
0000000000000Row01300
00000000000000Row0140
000000000000000Row015
RESET2019
18
17
16
KNOB
OK
SW1
ON
Rowl00 rld00Wo
DC motor #1
72IPST-MicroBOX [SE] Lab manual
5.4.6.2 motor_stop
Stop motor driving function
Syntax
void motor_stop(char _channel)
Parameter
_channel - DC motor output. It is 1, 2 and ALL (choose bothoutputs)
Example 5-17
#include <ipst.h> // Include main libraryvoid setup(){
sw_OK_press(); // Check the OK switch pressing}void loop(){
motor(1,60); // Drive motor1 with 60% powerdelay(500); // Driving time 0.5 secondmotor(1,-60); // Drive motor1 backward with 60% powerdelay(500); // Driving time 0.5 secondif (sw1()) // Check the SW1 switch pressing{
motor_stop(1); // If SW1 switch is pressed, stop motor1while (1);
}}
IPST-MicroBOX [SE] Lab manual73
Example 5-18
#include <ipst.h> // Include main libraryvoid setup(){}void loop(){
motor(1,50); // Drive motor1 with 50% powermotor(2,50); // Drive motor2 with 50% powersleep(3000); // Driving time 3 วิ นาที motor(1,-50); // Drive motor1 backward with 50% powermotor(2,-50); // Drive motor 2 backward with 50% powersleep(3000); // Driving time 3 secondmotor_stop(ALL); // Stop both motorssleep(3000); // Delay 3 second
}
27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC M
OTO
R
3 TxD1
LOW+5
2 RxD1
UART1
SERVO
00000000
0Row01000000000000000
00Row0200000000000000
000Row030000000000000
0000Row04000000000000
00000Row0500000000000
000000R00060000000000
0000000R0007000000000
00000000Row0800000000
000000000Row090000000
0000000000Row01000000
00000000000Row0110000
000000000000Row012000
0000000000000Row01300
00000000000000Row0140
000000000000000Row015
RESET2019
18
17
16
KNOB
OK
SW1
ON
Rowl00 rld00Wo
DC motor#1 DC motor#2
74IPST-MicroBOX [SE] Lab manual
5.4.7 ipst_servoMotor.h : Servo motor library
This is library for control the servo motor of IPST-SE board. It has 4 servo motor outputs.
It can drive each output or all in same time. This library must be included at the top of the
program with the command #include as follows :
#include <ipst_servoMotor.h> or #inclue <ipst.h>\
There is only one function in this library. It is servo.
Syntax
void servo(unsigned char _ch, int _angle)
Parameter
_ch - Servo motor output. It is 0 to 3
_pos - Servo motor shaft position. It is 0 to 180 and -1.
If set to -1, it means stop that servo motor output
Example 5-19
#include <ipst.h> // Include main library
void setup()
{}
void loop()
{
servo(0,60); // Drive servo motor0 to 60 degress position
sleep(5000); // Delay 5 seconds
servo(0,120); // Drive servo motor0 to 120 degree position
sleep(5000); // Delay 5 seconds
}
IPST-MicroBOX [SE] Lab manual75
5.4.8 ipst_serial.h : Serial data communication
It is library that contains function and statement for supporting the serial data
communication with UART of IPST-SE board. This library must be included at the top of the
program with the command #include as follows :
#include <ipst_serial.h> or #inclue <ipst.h>
5.4.8.1 Hardware connection
IPST-SE board has 2 channels for support serial data communication. They are UART0
and UART1. Hardware connection could be done as follows :
UART0 (connectd with USB port via USB to UART circuit)
Connect USB cable between IPST-SE board and computer’s USB port.
UART1
Connect the cable to RXD1 (pin 2) and TXD1 (pin 3) on the IPST-SE board
Using uart() function for interfacingwith computer via USB port
รู ปที ่ 5-2 แสดงจุ ดต อสั ญญาณของแผงวงจร IPST-SE เมื ่อมี การใช งานไลบรารี ipst_serial.h
Using uart1() function for interfacingwith any serial devices (such asbluetooth, XBEE or WiFi module) viaRxD1 (pin 2) and TxD1 (pin 3)
76IPST-MicroBOX [SE] Lab manual
5.4.8.2 uart
This is serial data sending function via UART0 port. The default baudrate is 115,200 bit
per second.
Syntax
void uart(char *p,...)
Parameter
*p - Type of data. Support the special character for setting display method.
Command Operation
%c or %CDisplay 1 character
%d or %D Display the decimal value -32,768 to +32,767
%l or %L Display the decimal value -2,147,483,648 to +2,147,483,647
%f or %F Display floating point 3 digits
\r Set the message left justify of the line
\n Display message on the new line
Example 5-20
#include <ipst.h> // Include main library
void setup()
{}
void loop()
{
uart(“Hello IPST-MicroBOX (SE)!\r\n”);
// Transmit data to computer with carriage returm
sleep(2000); // Delay 2 seconds
}
For running this sketch, still connect the USB cable after uploading. Open the
Serial Monitor by clicking on button or choose at menu Tools > Serial Monitor
IPST-MicroBOX [SE] Lab manual77
Wait a moment, The Serial Monitor is appeared and shows the messages
following the picture below. Click to mark at Auto Scroll box and select No line ending.
Last box is selected to 115200 Baud.
5.4.8.3 uart_set_baud
Baud rate setting function of UART0
Syntax
void uart_set_baud(unsigned int baud)
Parameter
baud - Baud rate value of UART0. It is 2,400 to 115,200
Example 5-21
uart_set_baud(4800); // Set baud rate to 4,800 bit per second
5.4.8.4 uart_available
This is receiveing data testing function of UART0.
Syntax
unsigned char uart_available(void)
Return value
- “0” : no data received
- more than 0 : received character
Example 5-22
char x =uart_available();
// Check receiving data of UART0.
// If x is more than 0, it means now data is received
// Must read data by using uart_getkey funtion immediately
78IPST-MicroBOX [SE] Lab manual
5.4.8.5 uart_getkey
This is data reading function from receiver’s buffer of UART0
Syntax
char uart_getkey(void)
Return value
- “0” : no data received
- data : received character in ASCII code
Example 5-23
#include <ipst.h>void setup(){}void loop() // Main loop{
if(uart_available()) // Received data checking{
if(uart_getkey()==’a’) // Key a is pressed ?{
glcd(3,1,“Key a Active!”); // Show message to responsesleep(2000); // Delay 2 seconds
}else{
glcdClear(); // Clear screen}
}}
Note Using uart() function to send data out from UART0 and uart_getkey()
function to get character, baud rate is set to 115,200 bit per second, 8-bit data and none
parity checking automatically. It is default value. If requres to change baud rate, have
to use uart_set_baud funtion.
For running this sketch, still connect the USB cable after uploading. Open the
Serial Monitor by clicking on button or choose at menu Tools > Serial Monitor
IPST-MicroBOX [SE] Lab manual79
Wait a moment, The Serial Monitor is appeared and shows the messages
following the picture below. Click to mark at Auto Scroll box and select No line ending.
Last box is selected to 115200 Baud.
After IPST-SE board gets the a character, it shows message Key a Active!
on th color GLCD screen.27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC M
OTO
R
3 TxD1
LOW+5
2 RxD1
UART1
SERVO
00000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
RESET2019
18
17
16
KNOB
OK
SW1
ON
0 00
Key a Active!
Connect USB cable alltime
80IPST-MicroBOX [SE] Lab manual
5.4.8.6 uart1
This is serial data sending function via UART1 port (TxD1 andc RxD1). The default
baud rate is 9,600 bit per second.
Syntax
void uart1(char *p,...)
Parameter
*p - Type of data. Support the special character for setting display method.
See details in uart0 function.
5.4.8.7 uart1_set_baud
This is baud rate setting function for UART1.
Syntax
void uart1_set_baud(unsigned int baud)
Parameter
baud - Baud rate of UART1. It is 2,400 to 115,200
Example 5-24
uart1_set_baud(19200); // Set baud rate as 19,200 bit per second
5.4.8.8 uart1_available
This is receiving data testing function of UART1.
Syntax
unsigned char uart1_available(void)
Return value
- “0” : no data received
- more than 0 : received character
Example 5-25
char x =uart1_available();
// Check receiving data of UART1.
// If x is more than 0, it means now data is received
// Must read data by using uart1_getkey funtion immediately
5.4.8.9 uart1_getkey
This is data reading function from receiver’s buffer of UART1.
Syntax
char uart1_getkey(void)
Return value
- “0” : no data received
- data : received character in ASCII code
IPST-MicroBOX [SE] Lab manual81
5.4.8.10 When does using UART1 ?
1. Connnect with wirelss devices such as bluetooth, XBEE, WiFi, etc.
IPST-SE board BlueStick
Serial bluetooth(slave)
TXD1
RXD1
Rx
Tx
ComputerLaptop
Smartphonethat supportbluetooth(master)
Example of the connection diagram between IPST-SE board with smartphone/tablet(Android) or computer in wirelessly via bluetooth.
2. Communicate between 2 of IPST-SE board
27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC
MO
TO
R
3 TxD1
LOW+5
2 RxD1
UART1
SERVO
00000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
RESET2019
18
17
16
KNOB
OK
SW1
ON
0 00
27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC
MO
TO
R
3 TxD1
LOW+5
2 RxD1
UART1
SERVO
00000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
RESET2019
18
17
16
KNOB
OK
SW1
ON
0 00
Connect RxD1 to TxD1 andTxD1 to RxD1 pin of each board
3. Interface with any serial devices and modules such as ZX-SERVO16i : Serial servo
motro controller board, Serial LCD16x2 (SLCD16x2), Serial Real-time clock (ZX-17), Pixy Camera
module, RFID reader board, etc.
IPST-MicroBOX [SE] Lab manual83
In the development of modern applied science projects that related to programming,
must have automatic control systems involved. Including the need to have contact with any
sensor. User need to know the value of the sensor measuring or detecting it. One of the most
important devices is display device. It is used to display or report the value or data.
IPST-SE controller board also available an on-board display device. It is color graphic
LCD module. This chapter describes about features, library, how to interface and some of
examples.
6.1 Features of GLCD module of the IPST-SE board
1.8” size and 128 x 160 dots resolution
Support line art and simple graphic with 65,536 color. Not support the image or
photo file.
Support the standard character (5 x 7 dots) with 21 characters 16 lines maximum.
Built-in LED back light
Programming support with ipst_glcd.h library
6.2 Library file for GLCD executation
The suitable library file for worlking with GLCD module of IPST-SE board will be installed
together with Wiring 1.0 IDE/Arduino 1.0 IDE installation. The ipst_glcd.h file is located to
folder C:\WiringIPST\libraries\IPST
This library must be included at the top of the program with the command #include as
follows :
#include <ipst_glcd.h> or #include <ipst.h>
Chapter 6
Using the color display of IPST-SEboard
84IPST-MicroBOX [SE] Lab manual
6.3 IPST-SE board’s color GLCD function description
6.3.1 glcd
It is the function for display message on the color graphic LCD screen. The default
display is 21 characters, 16 lines with smallest (default) font size.
Syntax
void glcd(unsigned char x, unsigned char y ,char *p,...)
Parameter
x - line number. Value is 0 to 15
y - character position. Value is 0 to 20
*p - the display message and special character or symbol for determine the
display as follows :
%c or %C - display one character
%d or %D - display integer from -32,768 to 32,767
%l or %L - display integer from -2,147,483,648 to 2,147,483,647
%f or %F - display floating point ( 3-digit maximum)
defghijk
0 0000000000
300000000000000000000
400000000000000000000
500000000000000000000
600000000000000000000
700000000000000000000
800000000000000000000
900000000000000000000
a00000000000000000000
b00000000000000000000
c00000000000000000000
d00000000000000000000
e00000000000000000000
f00000000000000000000
012345 89abc67
20000 0000d
100000000000000000000
Figure 6-1 : Illustated of details and displayed dot location of the GLCD
module that used in IPST-SE board
IPST-MicroBOX [SE] Lab manual85
Example 6-1
glcd(2,0,"Hello World");
// Show message; Hello World at left end position of line 2
defghijk
0 0000000000
300000000000000000000
400000000000000000000
500000000000000000000
600000000000000000000
700000000000000000000
800000000000000000000
900000000000000000000
a00000000000000000000
b00000000000000000000
c00000000000000000000
d00000000000000000000
e00000000000000000000
f00000000000000000000
012345 89abc67
Hello World
100000000000000000000
Column 0(first digit)
Line 2
Line 0Line 1
First is line number. Begin from 0.2 is line 2 or 3rd line.
Display message
Next digit is column position.Begin from 0. 0 is first digit or column.
Example 6-2
int x=20;
glcd(1,2,"Value = %d",x);
// Display both charater and number same line
// Start from column 2 of line 1
27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
SV1
SV2
SV3
126VG
136VG
146VG
G
DC M
OTO
R
KNOB
OK
SW1
ON000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
00000000
00 e0=020000000000
0 0000000000
Hello0 rld00Wo
Hello World
Valu
86IPST-MicroBOX [SE] Lab manual
6.3.2 colorRGB
It is color changing function in RGB (Red Blue Green) format to 16-bit data. It divides 5-
bit for Red , 6-bit for Green and last 5-bit for Blue.
Syntax
unsigned int colorRGB(uint red,uint green,uint blue)
Parameter
red - Red value is between 0 to 31. If applied data is greater than 31, adjsut to 31
green - Green value is between 0 to 63. If applied data is greater than 63,
adjust to 63
blue - Blue value is between 0 to 31. If applied data is greater than 31, adjsut to
31
Example 6-3
#include <ipst.h>
int colors;
void setup()
{
int colors;
colors=colorRGB(31,0,0); // Set 16-bit data of red to colors variable
glcdFillScreen(colors); // Fill background color
}
void loop()
{}
6.3.3 color[ ]
It is array type variable. It is uesd for set the 8 basic colors. Developers can also
use color[] directly or use the color name.
Syntax
unsigned int color[]= { GLCD_RED,
GLCD_GREEN,
GLCD_BLUE,
GLCD_YELLOW,
GLCD_BLACK,
GLCD_WHITE,
GLCD_SKY,
GLCD_MAGENTA};
IPST-MicroBOX [SE] Lab manual87
Parameter
GLCD_RED - Select red
GLCD_GREEN - Select grren
GLCD_BLUE - Select blue
GLCD_YELLOW - Select yellow
GLCD_BLACK - Select black
GLCD_WHITE - Select white
GLCD_SKY - Select sky blue color
GLCD_MAGENTA - Select magenta
Example 6-4
glcdFillScreen(color[5]); // Set background color as white
Example 6-5
glcdFillScreen(GLCD_BLUE); // Set backgrounbd color as blue
6.3.4 glcdSetColorWordBGR
It is factory color data setting function in BGR type. The setting data consists of 5-bit of
blue, 6-bit of green and 5-bit of red. There is 2 models of this color GLCD productions. One is set
the color data as RGB. Another is RGB.
The default of ipst_glcd.h is set to BGR. No need to put this function into the sketch.
Syntax
glcdSetColorWordBGR()
Example 6-6
#include <ipst.h>
void setup()
{
glcdSetColorWordBGR();
// Set color data setting of GLCD to BGR type. Normally not require
}
void loop()
{}
88IPST-MicroBOX [SE] Lab manual
6.3.5 glcdSetColorWordRGB( );
It is factory color data setting function in RGB type. The setting data consists of 5-bit of
red, 6-bit of green and 5-bit of blue.
Need to put this function into the sketch if GLCD operation after uploading shows
incorrect color. It means the current color GLCD is RGB type. Developer have to put this
function in the setup() on the top of sketch.
Syntax
glcdSetColorWordRGB()
Example 6-7
#include <ipst.h>
void setup()
{
glcdSetColorWordBGR(); // Set color data setting to RGB type
}
void loop()
{}
6.3.6 setTextColor
This function is used to set the text color that displayed with glcd() function. The default
color is white.
Syntax
void setTextColor(unsigned int newColor)
Parameter
newColor - This is to set the target color. It is 16-bit data or variable data which
is defined from the variable color[]
Example 6-8
setTextColor(GLCD_YELLOW); // Set text color as yellow
IPST-MicroBOX [SE] Lab manual89
6.3.7 setTextBackgroundColor
It is to set the text background color function. The default color is black. The text
background color is not screen background. Setting the screen background color, need to use
the glcdFillScreen function.
Syntax
void setTextBackgroundColor(unsigned int newColor)
Parameter
newColor - This is to set the target color. It is 16-bit data or variable data which
is defined from the variable color[]
Example 6-9
setTextBackgroundColor(GLCD_GREEN);
// Set text backgorund color as green
27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
SV1
SV2
SV3
126VG
136VG
146VG
KNOB
OK
SW1
ON
00000000
000000000000000000000
0 0000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
00
Hello World
Hello0 rlWo d
90IPST-MicroBOX [SE] Lab manual
6.3.8 glcdClear
It is clear screen function. The background color will be latest the text backgorund
color. If not defined before, the background color will be black
Syntax
void glcdClear()
Example 6-10
glcdClear(); // Clear screen
IPST-SE
Screen status
Before executeglcdClear();
Screen status
After executeglcdClear();
IPST-MicroBOX [SE] Lab manual91
6.3.9 glcdFillScreen
This will clear the screen and change to the background color function. After executing
this function, all contents on scrren will be cleared and it will change the backgtround color to
the target color.
Syntax
void glcdFillScreen(unsigned int color)
Parameter
color - This is to set the target color. It is 16-bit data or variable data which is
defined from the variable color[]
Example 6-11
glcdFillScreen(GLCD_YELLOW); // Fill GLCD screen with yellow
Screen status
Before executeglcdFillScreen(GLCD_YELLOW);
Screen status
After executeglcdFillScreen(GLCD_YELLOW);
92IPST-MicroBOX [SE] Lab manual
6.3.10 glcdMode
It is for setting the display orientation. There are 4 modes; 0 (0 degree), 1 (oritentate right
90 degrees), 2 (orientate 180 degrees or invert) and 3 (orientate 270 degrees from origin)
Syntax
glcdMode(unsigned int modeset)
Parameter
modeset - Orientation mode number. It is 0 to 3 for determine 0, 90, 180 and 270
degrees orientation. The default is 0 degree in vertical.
IPST-SEIPST-SE
IPST-SE
IPST-SE
glcdMode00o
glcdMode1orientate 90o
glcdMode2orientate 180o
glcdMode3orientate 270o
Example 6-12
#include <ipst.h>void setup(){
setTextSize(2); // Set text size as 2x}void loop(){
glcdClear(); // Clear screenglcdMode(0); // Set display orientation mode 0glcd(0,0,"IPST-SE"); // Show messagesw_ok_press(); // Wait OK switch pressingglcdClear();glcdMode(1); // Set display orientation mode 1glcd(0,0,"IPST-SE");sw_ok_press();glcdClear();glcdMode(2); // Set display orientation mode 2glcd(0,0,"IPST-SE");sw_ok_press();glcdClear();glcdMode(3); // Set display orientation mode 3glcd(0,0,"IPST-SE");sw_ok_press();
}
IPST-MicroBOX [SE] Lab manual93
6.3.11 setTextSize
This function is used to set the text size. The text size is 1x time by default. It requires 6
x 10 dots include character gap. With the default size, this display shows 21 characters 16
lines maximum in vertical.
height 7 dots
width5 dots
gap 1 dot
line space2 dots
pitch 1 dot
Syntax
setTextSize(unsigned int newSize)
Parameter
newSize - times number of the default size. It is 1 to 16.
text size 1 contains 21 characters 16 lines
text size 2 contains 10 characters 8 lines
text size 3 contains 7 characters 5 lines
text size 4 contains 5 characters 4 lines
text size 5 contains 4 characters 3 lines
text size 6 and 7 contains 3 characters 2 lines
text size 8 contains 2 characters 2 lines
text size 9 and 10 contains 2 characters 1 line
text size 11 to 16 contains only 1 character and 1 line to fit in screen.
94IPST-MicroBOX [SE] Lab manual
Example 6-13
#include <ipst.h>
void setup()
{
setTextSize(1); // Set text size as default
setTextColor(GLCD_GREEN); // Set text color as green
glcd(0,0,"Size1"); // Show message
setTextSize(2);
glcd(1,0,"Size2"); // Set text size 2x
setTextSize(3);
glcd(2,0,"Size3"); // Set text size 3x
setTextSize(4);
glcd(3,0,"Size4"); // Set text size 4x
}
void loop()
{}
6.3.12 getTextColor
Get the current text color.
Syntax
unsigned int getTextColor()
Return value
textColor - It is 16-bit data. It refer colorRGB[] function
Example 6-14
unsigned int color;
color=getTextColor(); // Store current text color data to variable
IPST-MicroBOX [SE] Lab manual95
6.3.13 getTextBackgroundColor
Get the current text background color.
Syntax
unsigned int getTextBackgroundColor()
Return value
textColor - It is 16-bit data. It refer colorRGB[] function
Example 6-15
unsigned int color;
color=getTextBackgroundColor();
// Store current text background color data to variable
6.3.14 getTextSize
Get the currect text size.
Syntax
unsigned int getTextSize()
Return value
textSize - The size is times number from the default size. Range is 1 to 16.
Example 6-16
unsigned int textSize;
textSize=getTextSize(); // Store current text size value to variable
6.3.15 glcdGetMode
Get the current orientation in display mode.
Syntax
unsigned int glcdGetMode()
Return value
mode - The orientation display mode number. It is 0 to 3. See details in glcdMode
function
Example 6-17
unsigned int Mode;
Mode=glcdGetMode(); // Get the current orientation display mode number
96IPST-MicroBOX [SE] Lab manual
6.3.16 glcdPixel
This plots the dots on the coordinator of the display. It refers to 128 x 160 dots display.
Syntax
void glcdPixel(unsigned int x,unsigned int y,unsignedint color)
Parameter
x - Horizontal axis coordinator or x-axis. Value is 0 to 127.
y - Vertical axis coordinator or y-axis. Value is 0 to 159
color - The target color. It is 16-bit data or variable data which is defined from
the variable color[]
Example 6-18
#include <ipst.h>
int i;
void setup()
{
for (i=0;i<128;i+=4)
{
glcdPixel(i,80,GLCD_RED);
// Plot a dot every 4 dots on x-axis at the center of screen
}
for (i=0;i<160;i+=4)
{
glcdPixel(64,i,GLCD_RED);
// Plot a dot every 4 dots on y-axis at the center of screen
}
}
void loop()
{}
6.3.1.17 glcdRect
27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
SV1
SV2
SV3
126VG
136VG
146VG
DC M
OTO
R
KNOB
OK
SW1
ON000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
IPST-MicroBOX [SE] Lab manual97
Draw the rectangular shape that refer dot coordinator at 128 x 160 dots resolution of
color GLCD screen following the figure 6-2.
Syntax
void glcdRect(unsigned int x1,unsigned int y1,
unsigned int width,unsigned int height,
unsigned int color)
Parameter
x1 - Start point of the rectangular shape on x-axis. Value is 0 to 127
y1 - Start point of the rectangular shape on y-axis. Value is 0 to 159
width - The width of rectangular shape. Value is 1 to 128
height - The height of rectangular shape. Value is 1 to 158
color - Line color. It is 16-bit data or variable data which is defined from the
variable color[]
Example 6-19
x-axis
y-axis
dot 0
dot 159dot 158dot 157
dot 1dot 2dot 3
dot 0 dot 4 dot 127
Figure 6-2 : Dot coordinator of IPST-SE board’s color display
98IPST-MicroBOX [SE] Lab manual
#include <ipst.h>
void setup()
{
glcdRect(32,40,64,80,GLCD_RED);
// Draw the red rectangle with 64 x 80 dots size
}
void loop()
{}
300000000000000000000
400000000000000000000
500000000000000000000
600000000000000000000
700000000000000000000
800000000000000000000
900000000000000000000
a00000000000000000000
b00000000000000000000
c00000000000000000000
d00000000000000000000
e00000000000000000000
f00000000000000000000
X1 point(32)
Y1 point(40)
width 64 dots
height 80 dots
width
heightline colorStart dot of x-axis
Start dot of y-axis
IPST-MicroBOX [SE] Lab manual99
6.3.18 glcdFillRect
This creates a filled rectangle. It is only fill color without an outline.
Syntax
void glcdFillRect(unsigned int x1, unsigned int y1,unsigned int width, unsigned int height,
unsigned int color)
Parameter
x1 - Start point of the rectangular shape on x-axis. Value is 0 to 127
y1 - Start point of the rectangular shape on y-axis. Value is 0 to 159
width - The width of rectangular shape. Value is 1 to 128
height - The height of rectangular shape. Value is 1 to 158
color - Fill color. It is 16-bit data or variable data which is defined from the
variable color[]
Example 6-20
#include <ipst.h>
void setup()
{
glcdFillRect(32,40,64,80,GLCD_RED);
// Create the solid red rectangle 64 x 80 pixels
}
void loop()
{}
300000000000000000000
400000000000000000000
500000000000000000000
600000000000000000000
700000000000000000000
800000000000000000000
900000000000000000000
a00000000000000000000
b00000000000000000000
c00000000000000000000
d00000000000000000000
e00000000000000000000
f00000000000000000000
X1 point(32)
Start dot of x-axis
Y1 point(40)
width 64 dots
Height80 dots
Start dot of y-axis
widthheight
target color
100IPST-MicroBOX [SE] Lab manual
6.3.19 glcdLine
Draw the straight line from point to point.
Syntax
void glcdLine(unsigned int x1,unsigned int y1,
unsigned int x2,unsigned int y2,unsigned int color)
Parameter
x1 - Start point on the x-axis. Value is 0 to 127.
y1 - Start point on the y-axis. Value is 0 ro 159
x2 - Destination point on the x-axis. Value is 0 to 127.
y2 - Destination point on the y-axis. Value is 0 ro 159
color - Line color. It is 16-bit data or variable data which is defined from the
variable color[]
Example 6-21
#include <ipst.h>
void setup()
{
glcdLine(0,0,127,159,GLCD_RED);
// Draw a red diagonal line from top left to bottom right
}
void loop()
{}
3 0
0000000000000000
4 0
0000000000000000
500000000000000000000
600000000000000000000
700000000000000000000
800000000000000000000
900000000000000000000
a00000000000000000000
b00000000000000000000
c00000000000000000000
d00000000000000000000
e00000000000000000000
f00000000000000000000
X1(0)
Y1(0)
3 0
4 0
X2(127)
Y2(159)
IPST-MicroBOX [SE] Lab manual101
6.3.20 glcdCircle
Draw a circle function.
Syntax
void glcdCircle(unsgined int x, unsgined int y,
unsgined int radius,unsgined int color)
Parameter
x - Center of thge circle coordinator on x-axis. Value is 0 to 127
y - Center of thge circle coordinator on y-axis. Value is 0 to 159
radius - Radius value
color - Circumference color. It is 16-bit data or variable data which is defined
from the variable color[]
Example 6-22
#include <ipst.h>void setup(){
glcdCircle(32,120,31,GLCD_RED);//Draw a red circle with 31 dots radius
}void loop(){}
0000000000000000
0000000000000000
500000000000000000000
600000000000000000000
700000000000000000000
800000000000000000000
900000000000 00000000
a000000000 0000000000
b00000000000000000000
c00000000000000000000
d00000000000000000000
e00000000000000000000
f00000000000000000000
y-coordinator(120)
radius 31 dots
x-coordinator(32)
102IPST-MicroBOX [SE] Lab manual
6.3.21 glcdFillCircle
Creates a filled circle without the circumference.
Syntax
void glcdFillCircle(unsigned int x,unsigned int y,
unsigned int radius,unsigned int color)
Parameter
x - Center of thge circle coordinator on x-axis. Value is 0 to 127
y - Center of thge circle coordinator on y-axis. Value is 0 to 159
radius - Radius value
color - Circle color. It is 16-bit data or variable data which is defined from the
variable color[]
Example 6-23
#include <ipst.h>
void setup()
{
glcdFillCircle(32,120,31,GLCD_RED);
// Create the solid red circle with radius 31 dots
}
void loop()
{}
0000000000000000
0000000000000000
500000000000000000000
600000000000000000000
700000000000000000000
800000000000000000000
900000000000 00000000
a000000000 0000000000
b00000000000000000000
c00000000000000000000
d00000000000000000000
e00000000000000000000
f00000000000000000000
y-coordinator(120)
radius 31 dots
x-coordinator(32)
IPST-MicroBOX [SE] Lab manual103
6.3.22 glcdArc
Draw the arc line function.
Syntax
void glcdArc(unsigned int x,unsigned int y,
unsigned int r,int start_angle,int end_angle,uint color)
Parameter
x - Center of thge circle coordinator on x-axis. Value is 0 to 127
y - Center of thge circle coordinator on y-axis. Value is 0 to 159
radius - Radius value of the arc
start_angle - Start angle of the arc
end_angle - Ending angle of the arc
color - Arc line color. It is 16-bit data or variable data which is defined from the
variable color[]
Example 6-24
#include <ipst.h>
void setup()
{
glcdArc(48,80,16,30,150,GLCD_RED);
glcdCircle(48,75,5,GLCD_YELLOW);
glcdCircle(80,75,5,GLCD_YELLOW);
glcdArc(80,80,16,30,150,GLCD_RED);
glcdFillCircle(64,90,7,GLCD_GREEN);
glcdArc(64,100,30,220,320,GLCD_RED);
}
void loop()
{}
104IPST-MicroBOX [SE] Lab manual
IPST-MicroBOX [SE] Lab manual105
The simplest application of automatic controller is LED controller. Because LED is very
simple output device, low cost, easy to use and very flexible for applying to make so many
applications, projects and inventions
This chapter describes about how to control the LED by using IPST-SE controller board
with C/C++ programming by Wiring IDE.
7.1 Introduction to LED
A light emitting diode (LED) emits light when current passes through it. The color of the
LED usually just tells you what color it will glow when current passes through it. The important
markings on an LED are contained in its shape. Since an LED is a one-way current valve, you
have to make sure to connect it the right way, or it won’t work as intended.
The symbol and structure of LED are shown in the figure 7-1
LED has 2 terminals. One is called the anode, and the other is called the cathode. On
the schematic symbol, the cathode is the line across the point of the triangle and part drawing.
For the part drawing, note that the LED’s leads are different lengths. The longer lead is connected
to the LED’s anode, and the shorter lead is connected to its cathode.
The suitable current that the modern LED need is 5 to 20mA. The simple circuit is
shown in the figure 7-2.
Limit-current resistor (RS)can assgin by formula below :
RVcc V
IS
F
F
Vcc is Supply voltage, VF is forward bias voltage cross LED and IF is forward bias current
If apply the reverse bias, LED will not work and damage. Because LED can hold the
reverse bias voltage in range 3 to 10V only.
Figure 7-1 : Symbol and structure of LED
R1
LED1Vs
I1
+
Figure 7-2 : LED circuit application
AnodeCathode
(B) LED structure
A K
(A) LED symbol
Chapter 7
LED controller
106IPST-MicroBOX [SE] Lab manual
7.2 How to control LED with IPST-SE board and C/C++ programming by Wiring 1.0 IDE
To control on / off the LED, the developer can use the signals from any port on the IPST-
SE board. It is controlled by software. The function of Wiring 1.0 IDE and Arduino 1.0 IDE for
IPST-SE that suitable for driving LED is out().
out () function is contained in the library file ipst_in_ouyt.h. Also execute from ipst.h
main library. This library must be included at the top of the program with the command #include
as follows :
#include <ipst_in_out.h> or #include <ipst.h>
Details of out() function can be summarized as follows :
out() is function of writing or sending the digtial data to the specific digital port of IPST-
SE controller board
Syntax
out(char _bit,char _dat)
Parameter
_bit - Set digital pin of IPST-SE board. It is 0 to 30.
_dat - Set data output as 0 ot 1.
Example 7-1
out(17,1); // Out oin 17 with “1”
out(18,0); // Out pin 18 with “0”
IPST-MicroBOX [SE] Lab manual107
The equipment is in working condition at all times. What should be done every
time you use the IPST-MicroBOX [SE] is :
1. Turn power off before removing or plugging the controller board with the
computer .
2. Turn power off before removing or plugging any sensors with the controller
board.
3. After each experiment is finished, suggest to turn power off before removing
all cables.
4. Do not remove or plug any cables during the controller board still work or
under the opertation. Unless there are any other procedures that require specific
connection during operation.
5. If any error is occured, must turn power off immediately.
6. Do not use the DC adaptor that supply output voltage over +9V with the IPST-SE
controller board.
7. After all experiments are finished, remove all cables from controller board,
sensors and computer.
Practical notice for
108IPST-MicroBOX [SE] Lab manual
#include <ipst.h> // Include main library
void setup()
{}
void loop()
{
out(17,1); // On LED at pin 17
delay(500); // Delay 0.5 second
out(17,0); // Off LED at pin 17
delay(500); // Delay 0.5 second
}
Listing L1-1 : LedTest01.pde ; the sketch file for demonstration of simple LED
controller by IPST-SE
Practical 1 : Simple LED controller
Practical 1-1 : Turning on LED
Hardware connection
Connect ZX-LED board to pin 17 of IPST-SE board
connect
with
JST3AA-8
cable
27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC M
OTO
R3 TxD1
LOW+5
2 RxD1
UART1
SERVO
00000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
RESET2019
18
17
16
KNOB
OK
SW1
ON
Hello0 rld00Wo
ZX-LED
+ S
+
S
O
IPST-MicroBOX [SE] Lab manual109
Prodedure
1.1.1 Open the Wiring 1.0 IPST-SE software.Create the new sketch file. Type the code following
the Listing L1-1. then save as the sketch to LEDtest01.
1.1.2 Apply the supply voltage to the IPST-SE board and turn on power. Connect the USB cable
between IPST-SE board and computer.
27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC M
OTO
R
3 TxD1
LOW+5
2 RxD1
UART1
SERVO
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
RESET2019
18
17
16
KNOB
OK
SW1
ON
Turn onthe POWER switch
3
1
2
4
Plug the adaptor
Connect the USB cable
Wait until theUSB indicator is on
1.1.3 Choose the hardware at menu Tools > Board > IPST-SE > ATmega644P @16MHz
110IPST-MicroBOX [SE] Lab manual
1.1.4 Choose the interfaced port at menu Tools > Serial Port (Number of interfaced port may
be different depend on each computer)
1.1.5 Compile and upload the sketch to IPST-SE board by clicking on the button or
choose at menu File > Upload to Wiring Hardware
1.1.6 Run the sketch and observe the ZX-LED operation.
LED on the ZX-LED that connected with pin 17 of IPST-SE board is blinking every 0.5
second.
Note Experimenter can adjust the blkinking rate with change the time value in delay();
function within Listing L1-1
1.1.7 Edit code in Listing L1-1 to change the blinking speed faster.
1.1.8 Edit code in Listing L1-1 to change the blinking speed slower
1.1.9 Edit code in Listing L1-1 to change the controller board pin to pin 18, 19 and 20.
Practical 1-2 : LED timer
Hardware connection
Connect ZX-LED board to pin 17 of IPST-SE board
Prodedure
1.2.1 Open the Wiring 1.0 IPST-SE software.Create the new sketch file. Type the code following
the Listing L1-2. then save as the sketch to LEDtimer.
1.2.2 Compile and upload the sketch to IPST-SE board by clicking on the button or
choose at menu File > Upload to Wiring Hardware
1.2.3 Run the sketch and observe the ZX-LED operation.
LED is on 4 seconds then off.
1.2.4 Edit code in Listing L1-2 to turn on LED longer time.
1.2.5 Edit code in Listing L1-2 to turn on LED shorter time.
IPST-MicroBOX [SE] Lab manual111
#include <ipst.h> // Include main library
void setup()
{}
void loop()
{
out(17,1); // Turn on LED at pin 17
delay(4000); // Delay 4 seconds
out(17,0); // Turn off LED at pin 17
while(1); // Endless loop
}
Code description
This code send data “1” to pin 17 of IPST-SE board to turn on LED 4 seconds. After that,
send data “0” to same pin for turning off LED and loop at while(); command. It is endless
loop. Program will not back to restart until reset the bord or turn off power and turn on power
again.
Listing L1-2 : Ledtimer.pde ; the sketch file for demonstration controlling LED
with time
112IPST-MicroBOX [SE] Lab manual
IPST-MicroBOX [SE] Lab manual113
In the previous chapter, presents how to control LED with programming for only one
channel. This chapter presents how to control more LEDs up to 8-ch. in same time by still using
only one digital port of IPST-SE controller board.
The output device for this practical is LED8 board. It consists of 8 LEDs and serial controller
circuit. The data that used to control LED displaying is generated by basic mathematics in
binary number plus simple data structure in bit and byte.
Instructor can be use the pracicals in this chapter to teach about number system and
basic logic according to STEM education.
8.1 Binary number
In the binary number system is the only 2 number that is "0" and "1". They can be used
instead of the low - high, off -on and open-close. If the binary number greater than 1 this was
considered for example, 2. there is 4 status occured. They could be represent off-off, off-on, on-
off and on-on.
Summary of mathematical equation relate with digit of binary number are as follows :
Number of data = 2 digit
If there are 2 digits, the data number are 22 = 4
If there are 3 digits, the data number are 23 = 8
If there are 4 digits, the data number are 24 = 16
8.1.1 Binary number counting
Because binary number are only 0 and 1, when count up it must be added more digits.
To see a significant changing, the decimal number will be used to compare as follows :
Chapter 8
Muti-channels LED controller
Binary Decimal
0 0
1 1
10 2
11 3
Binary Decimal
100 4
101 5
110 6
111 7
Binary Decimal
1000 8
1001 9
1010 10
1011 11
Binary Decimal
1100 12
1101 13
1110 14
1111 15
114IPST-MicroBOX [SE] Lab manual
8.1.2 Bit variables
The binary is used more and more from 1 digit to 2, 3, ... and 8 digits cause the following
new variables.
(1) bit. It is binary digit. Includes 0 and 1 only.
(2) byte. It is 8 bits binary number. It is important unit of binary number because in
the computer system will use at least 8-bit data for processing.
(3) LSB : Least Significant Bit. It is last right digit of binary number. The digit weight
is 20. If “1” is last right digit, it is equal to 1 x 20 = 1 x 1 = 1. But it is “0”, the value is changed
to 0 x 20 = 0 x 1= 0
(4) Digit defination. Last right digit is called bit 0 (b0) or LSB. Next digit is bit1 (b1)
scroll to the last left. Final are b7, b6, b5, b4, b3, b2, b1 and b0.
(5) MSB : Most Significant Bit. It is last left digit of binary number. For 8-bit data, the
MSB is bit7. The digit weight is 27 or 128. For the less than digit, the digit power is lower one
step such as for 6-bit MSB digit weight is 25, for 5-bit it is 24 for example.
8.1.3 Digit power
In decimal number, the digit weight is calculated from power of 10. For 1’s digit is 100
or 1, 10’s digit is 101 or 10, 100’s digit is 102 or 100 and so on.
Similar the decimal number, the digit weight of binary number also calculate from power
of 2. The last right bit or LSB has digit weight as 20 or equal is 1. Next digit is bit 1, digit weight
is 21 or 2. Bit 2 digit weight is 22 or 4. Consider to 8-bit, the digit weight of each bit is summarized
as follows :
Binary bit Digit weight Decimal number
0 20 1
1 21 2
2 22 4
3 23 8
4 24 16
5 25 32
6 26 64
7 27 128
IPST-MicroBOX [SE] Lab manual115
8.2 Binary number conversion
8.2.1 Binary to Decimal conversion
Refer the digit weight of binary number, you can convert number system from Binary to
Decimal following some examples as follows.
Example 8-1
Convert the binary number 1011 to decimal
(1) Define the digit weight
Digit b3 b2 b1 b0
Digit weight 23 22 21 20
Binary 1 0 1 1
(2) multiply the digit weight by binary number at each bit. After that, add all
multiplication together.
Decimal = (1x23) + (0x22) + (1x21) + (1x20)
= (1x8) + (0x4) + (1x2) + (1x1)
= 8+0+2+1 = 11
8.2.2 Decimal to Binary conversion
The suggession method is Repeated Division by 2. Any decimal number divided by 2
will leave a remainder of 0 or 1. Repeated division by 2 will leave a string of 0s and 1s that
become the binary equivalent of the decimal number.
Example 8-2
Convert the decimal number 13 to binary
(1) Divide the decimal number by 2 and note a remainder
13/2 = 6 + remainder 1 (LSB)
The remainder is the least significant bit of the binary equivalent of 13.
(2) Divide the quotient from the previous division and note the remainder. The
remainder is the second LSB.
6/2 = 3 + remainder 0
(3) Continue this process until the quotient is 0. The last remainder is the most
significant bit of the binary number.
3/2 = 1 + remainder 1
1/2 = 0 + remainder 1 (MSB)
(4) To write the binary equivalent of the decimal number, read the remainders
from the bottom up.
1310 = 11012
116IPST-MicroBOX [SE] Lab manual
8.3 Signed of Binary number
Binary number can assign to Positive and Negative value by assignment at MSB bit. If
MSB is "0", that binary number is positive. In the other hand, if MSB is "1" that binary number
is negative.
These informations below present the unsigned and signed binary number compare
with decimal number to make the understanding clearly.
Binary Decimal
Signed number Unsigned number
0000 0 0
0001 1 1
0010 2 2
0011 3 3
0100 4 4
0101 5 5
0110 6 6
0111 7 7
1000 - 8 8
1001 - 7 9
1010 - 6 10
1011 - 5 11
1100 - 4 12
1101 - 3 13
1110 - 2 14
1111 - 1 15
In signed binary number to decimal conversion can use similar technique.
For examaple, 1000 binary number the MSB is "1". The digit weight is 23 or 8. This
signed binary number is equal -8. In conversion the remain 3 bit is positive value. Thus, the
conversion is -8 + 0 = -8.
Next example, convert 1101 signed number to decimal. At MSB is -8 and 3 last right bit
is positive as +5 [101 = (22 x 0) + (21 x 0) + (20 x 1)]. The conversion is -8 + 5 = -3
IPST-MicroBOX [SE] Lab manual117
8.4 Data format
The data used in the processing of a microcontroller that can be made from 1-bit. For
microcontroller in IPST-SE board; ATmega644 works with 1 to 16 bits data. They are set in the
various components of the world class standard.
1 0 1 0 0 1 0 1
Weight
Data*
* Data value could be changed
High byte (upper 8-bit) Low byte (lower 8-bit)
word
bit
0110111 1
211 210 29 28 27 26 25 24 23 22 21 20212213214215
LSBMSB
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
bit-nibble-byte-word is unit of binary data that used in microcontroller data processing.
bit is smallest of unit. It is equal 1 digit of binary number
nibble is 4 bit length of bianry number
byte is 8 bit length of bianry number
word is 16 bit length of bianry number or 2 bytes
118IPST-MicroBOX [SE] Lab manual
8.5 Introduction to the LED8 : Serial 8-LED driverboard
LED8 consists of 3mm. LED 8 dots, interface circuit , input port for inerfacing with
microcontroller board and output port that can connect to high current load driver circuit such
as relay driver board witout more additional programming.
LED8 is ocnnected toi any digital port of IPST-SE board. It requires only one pin. Users
can control the LED 8 channels with only one wire. Figure 8-1 shows board layout and schematic
diagram of LED8 board.
Connection between IPST-SE controller board and LED8 board is using serial data
communication and works with programming instructions. Developer or user can create the
program to control LED from 1 to 8 dots to make some applications such as running light LED
in any pattern or simple light effect project and more.
Figure 8-2 shows how to connect the LED8 board with IPST-SE controller board.
Figure 8-3 shows how to use the output port of LED8 board to control the high current
driver board.
8.6 Programming Function for LED8 board
For programming with LED8 board, there is 2 functions that included in the ipst_led8.h
library.
1. pinLED8 : Set port of IPST-SE board to connect with LED8 board.
2. LED8 : Data display function for LED8 board
IPST-MicroBOX [SE] Lab manual119
+5V
47
7
510
7
47
6
510
6
47
5
510
5
47
4
510
4
47
3
510
3
47
2
510
2
47
1
510
1
47
0
510
0
D7
9
D6
8
D5
5
D4
6
D3
7
D2
14
D1
15
D0
16
ZX-LED controllerPIC18F14K50 with firmwareUART 9600 bps. to 8 bit parallel outputs
XT1 XT2
CeramicResonator
(Option)
VDD RST VSS PGD PGC
ICSP
2 3 1 4 20 19 18
RXD
12
VDDU17
+5V
RxD
+5V
GN
D
4k74k7
MSBD7 D6 D5 D4 D3 D2 D1
LSBD0
0.1F63V
0.1F63V
47F6.3V
Fiogure 8-1 : Board layout and schematic diagram of LED8 board
120IPST-MicroBOX [SE] Lab manual
Figure 8-2 : Connection diagram of LED8 board with IPST-SE controller board
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
MSB LSB+
5V
RxD
GN
D
Secondary Education
LED8Serial LED-8UART communication9600 bps. Baud
27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC M
OTO
R
3 TxD1
LOW+5
2 RxD1
UART1
SERVO
00000000
0Row01000000000000000
00Row0200000000000000
000Row030000000000000
0000Row04000000000000
00000Row0500000000000
000000R00060000000000
0000000R0007000000000
00000000Row0800000000
000000000Row090000000
0000000000Row01000000
00000000000Row0110000
000000000000Row012000
0000000000000Row01300
00000000000000Row0140
000000000000000Row015
RESET2019
18
17
16
KNOB
OK
SW1
ON
Rowl00 rld00Wo
Connect with JST3AA-8
Recommended Digital port for LED8 interfacing
Intercing port of IPST-SE forLED8
Optional -1 : pin 2 and 3 (disable I2C bus)
Most suitable : pin 16 to 20
Optional -2 : pin 8 and 9 (disable UART1)
Optional -3 : pin 24 to 30 (stop analog)
IPST-MicroBOX [SE] Lab manual121
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
MSB LSB
+5V
RxD
GN
D
Secondary Education
LED8Serial LED-8UART communication9600 bps. Baud
27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC M
OTO
R
3 TxD1
LOW+5
2 RxD1
UART1
SERVO
00000000
0Row01000000000000000
00Row0200000000000000
000Row030000000000000
0000Row04000000000000
00000Row0500000000000
000000R00060000000000
0000000R0007000000000
00000000Row0800000000
000000000Row090000000
0000000000Row01000000
00000000000Row0110000
000000000000Row012000
0000000000000Row01300
00000000000000Row0140
000000000000000Row015
RESET2019
18
17
16
KNOB
OK
SW1
ON
Rowl00 rld00Wo
Recommended digital port for LED8 interfacing
For example, LED8 gets data 10110001.It drives LED on and off following thedata value.
At the bit is "1", output pin that is sameposition also has +5V to send out.
At pin 7, 5, 4 and 0 will send out +5Vbut for pin 6, 3, 2 and 1 will be 0V.
+5V +5V +5V +5V
IPST-SE board send theserial data to set thedisplay of LED8 board.
Figure 8-3 : The operation of LED on LED8 board that related with its output
port.
122IPST-MicroBOX [SE] Lab manual
Practical 2 : 8-ch. LED controller
Practical 2-1 : Binary LED controller
This practical demonstrates how to control 8-LED on LED8 board with simple binary
number value.
Hardware connection
Connect pin 20 of IPST-SE board with LED8 board by using JST3AA-8 cable
Procedure
2.1.1 Open the Wiring 1.0 IPST-SE software. Create the new sketch file. Type the code following
the Listing L2-1. then save as the sketch to LED8test.
2.1.2 Compile and upload the sketch to IPST-SE board by clicking on the button or
choose at menu File > Upload to Wiring Hardware
Figure L2-1 : Connection diagram for practical 2 and 3
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
MSB LSB
+5V
RxD
GN
D
Secondary Education
LED8Serial LED-8UART communication9600 bps. Baud
27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC M
OTO
R
3 TxD1
LOW+5
2 RxD1
UART1
SERVO
00000000
0Row01000000000000000
00Row0200000000000000
000Row030000000000000
0000Row04000000000000
00000Row0500000000000
000000R00060000000000
0000000R0007000000000
00000000Row0800000000
000000000Row090000000
0000000000Row01000000
00000000000Row0110000
000000000000Row012000
0000000000000Row01300
00000000000000Row0140
000000000000000Row015
RESET2019
18
17
16
KNOB
OK
SW1
ON
Rowl00 rld00Wo
Connect withJST3AA-8 cable
IPST-MicroBOX [SE] Lab manual123
2.1.3 Run the sketch and observe the LED8 board operation.
LED at bit 0 and 7 of LED8 board are turned on following the received data 10000001.
7 6 5 4 3 2 1 0
2.1.4 Edit the code to change the displayed data as LED8(0b11110000); then compile and
upload to IPST-SE board.
The result is as follows :
7 6 5 4 3 2 1 0
2.1.5 Edit the code again to change the data as led8(0b00011000); then compile and upload
to IPST-SE board
The result is as follows :
7 6 5 4 3 2 1 0
#include <ipst.h> // Include main library
void setup()
{
pinLED8(20); // Connect LED8 to pin 20 of IPST-SE board
}
void loop()
{
LED8(0b10000001); // LED at bit 7 and 0 only are on
}
Code description
The operation of this code is binary data 10000001 should be send to LED8 from
executation of LED8(); function. Pin 20 is used to connect from declaration by pinLED8();
fuinction in setup()
8-bit binary data presents all 8-LED position of LED8 board. Each bit gets “1”, LED at same
position will be turned on. In the other hands, any bit that get “0” the LED at same position
also shoud be off.
Listing L2-1 : Led8test.pde ; the sketch file for demonstration controlling LED
8 channels with one pin of IPST-SE board
124IPST-MicroBOX [SE] Lab manual
2.1.6 Create the new sketch file. Type the code following the Listing L2-2. then save as the
sketch to LED8binary.
2.1.7 Compile and upload the sketch to IPST-SE board by clicking on the button or
choose at menu File > Upload to Wiring Hardware
2.1.8 Run the sketch and observe the LED8 board operation.
All 8-LED show the binary data from 00000000 to 11111111 and restart again. The
data exchange rate is 0.3 second
#include <ipst.h> // Include main library
void setup()
{}
void loop()
{
unsigned char i=0;
while(1)
{
LED8(20,i++);
// Set pin 20 to control LED8 board and send 8-bit binary data to show.
// Displayed data is binary counter from 00000000 to 111111111
delay(300);
}
}
Code description
The displayed data is set by i variable. It is char type. Value is counted from 00000000 to
11111111. The data is send to LED8 board via LED8(); function with single line syntax. It is
set pin and follow the displayed data. With this method, the code is short and easier to
understand.
Listing L2-2 : Led8binary.pde; the sketch file for controlling LED 8 channels
to show 8-bit binary counter
IPST-MicroBOX [SE] Lab manual125
Practical 2-2 : 8-blinking LED
This practical demonstrates how to control LED8 board to drives 8-LED for making the
simple blinking LED 8 channels project.
Hardware connection
Connect pin 20 of IPST-SE board with LED8 board by using JST3AA-8 cable
Procedure
2.2.1 Open the Wiring 1.0 IPST-SE software. Create the new sketch file. Type the code following
the Listing L2-3. then save as the sketch to LED8blink.
2.2.2 Compile and upload the sketch to IPST-SE board by clicking on the button or
choose at menu File > Upload to Wiring Hardware
2.2.3 Run the sketch and observe the LED8 board operation.
All LED on the LED8 board are blink every 1 second.
#include <ipst.h> // Include main library
void setup()
{}
void loop()
{
LED8(20,0b11111111); // Set all LED to on
sleep(500); // Delay 0.5 second
LED8(20,0b00000000); // Set all LED to off
sleep(500); // Delay 0.5 second
}
Code description
This code prepare 2 binary data sets for sending to LED8 board with LED8(); function.
First data is 11111111. It causes all LED on the LED8 board turning on. Second data is
00000000. It causes all LED turning off.
Blinking rate is set by sleep(); function. It is equal to 500 millisecond or 0.5 second.
Listing L2-3 : Led8blink.pde; the sketch file for controlling LED 8 channels as
blinking light
126IPST-MicroBOX [SE] Lab manual
Practical 3 : Control LED with special technics
Practiocal 3-1 : 8-bit running light
This practical demonstrates the programming technic for control 8-LED to work as 2-
way running lights.
Hardware connection
Connect pin 20 of IPST-SE board with LED8 board by using JST3AA-8 cable
Procedure
3.1.1 Open the Wiring 1.0 IPST-SE software. Create the new sketch file. Type the code following
the Listing L3-1. then save as the sketch to LED8running.
3.1.2 Compile and upload the sketch to IPST-SE board by clicking on the button or
choose at menu File > Upload to Wiring Hardware
3.1.3 Run the sketch and observe the LED8 board operation.
LED will on only 1 dot start from last right bit (bit 0) to last left (bit 7). Next, shift back
from bit 7 to bit 0 and loop to restart again continuously. The operation will similar 8- running
light.
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
loop to restart
IPST-MicroBOX [SE] Lab manual127
#include <ipst.h> // Include main library
void setup()
{
// Title message on color GLCD screen
glcdClear();
glcd(0,0,"Example: LED8_02");
glcd(2,0,"connect LED8 to (20)");
glcd(4,0,"LED running LEFT");
glcd(5,0," and RIGHT");
pinLED8(20); // Set pin 20 for interfacing
}
void loop()
{
int i;
for (i=0;i<8;i++) // Set loop to shift data
{
LED8(0x01<<i); // Shift left and send data to LED8.
// Default data is 00000001
delay(300); // Delay 0.3 second
}
for (i=6;i>0;i--) // Set loop to shift right
{
LED8(0x01<<i); // Shift right and send data to LED8.
delay(300); // Delay 0.3 second
}
}
Code description
This code operation use sending data via LED8(); function to turn on LED only one dot
from bit 0 to 7 positon in 0.3 second and back from bit 7 to bit 0. Loop to restart continuous.
Important technic is shifting data both left and right direction. There is 0.3 second delay
time between each shifting.
Shift rate is set by delay(); function. If set less than 300, it causes shfit rate is faster. It means
running LED run faster.
Listing L3-1 : Led8running.pde; the sketch file for making 8-running light
project
128IPST-MicroBOX [SE] Lab manual
Practical 3-2 : Driving LED with look-up table technic
This practical demonstrates how to control 8-bit LED by sending the data from look-up
table programming technic and array.
Hardware connection
Connect pin 20 of IPST-SE board with LED8 board by using JST3AA-8 cable
Procedure
3.2.1 Open the Wiring 1.0 IPST-SE software. Create the new sketch file. Type the code following
the Listing L3-1. then save as the sketch to LED8pattern.
3.2.2 Compile and upload the sketch to IPST-SE board by clicking on the button or
choose at menu File > Upload to Wiring Hardware
3.2.3 Run the sketch and observe the LED8 board operation.
LEDs are turning on follows the data 4 patterns. It starts from pattern 1 to 4 and back
from pattern 4 to 1. Next, restart again continuously
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
Loop to restart
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
Pattern 1
Pattern 2
Pattern 3
Pattern 4
Pattern 4
Pattern 3
Pattern 2
Pattern 1
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
IPST-MicroBOX [SE] Lab manual129
#include <ipst.h> // Include main library
int pattern[]= { // Set pattern display
0b00011000, // Pattern #1
0b00111100, // Pattern #2
0b01111110, // Pattern #3
0b11111111}; // Pattern #4
void setup()
{
// Title message on color GLCD screen
glcdClear();
glcd(0,0,"Example: LED8_pattern");
glcd(2,0,"connect LED8 to (20)");
glcd(4,0,"Pattern LED demo");
pinLED8(20); // Set pin 20 to interface
}
void loop()
{
int i;
for (i=0;i<4;i++) // Set pattern sequence
{
LED8(pattern[i]); // Show LED pattern 1 to 4
delay(300);
}
for (i=2;i>0;i--) // Change pattern sequence
{
LED8(pattern[i]); // Show LED pattern from 4 to 1
delay(300);
}
}
Code description
The displayed data of this code is different from previoius practical. This code use look-
up table technic. The data table contains 4 of array variables. It uses i variable as index to get
the data from table and send to display with LED8(); function. All data pattern will show 0.3
second each.
Listing L3-2 : Led8pattern.pde; the sketch file for driving 8-bit LED with look-up
table technic and array
130IPST-MicroBOX [SE] Lab manual
Practical 3-3 : Bar graph display
This practical demonstrates how to control 8-bit LED to display in bar graph pattern.
Hardware connection
Connect pin 20 of IPST-SE board with LED8 board by using JST3AA-8 cable
Procedure
3.3.1 Open the Wiring 1.0 IPST-SE software. Create the new sketch file. Type the code following
the Listing L3-1. then save as the sketch to LED8bargraph.
3.3.2 Compile and upload the sketch to IPST-SE board by clicking on the button or
choose at menu File > Upload to Wiring Hardware
3.3.3 Run the sketch and observe the LED8 board operation.
LED is turning on from last left bit (bit 0) following bit 1 (bit 0 still on). Then LED in next
bit will on until complete 8 bits. Next round, LED will be turnning off each bit. Begin from bit
7 until bit 1. After that, it will loop to restart again continuously. The display operation looks
like bar graph that increase and decrease values alltime.
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
Loop to restart7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
Next step
Experimenter can use this technic to develop the code for showing the signal value
from analog sensors in bar graph pattern. The minimum value is presented by one LED and
maimum value is presented by all LED turning on.
IPST-MicroBOX [SE] Lab manual131
#include <ipst.h> // Include main library
void setup()
{
// Title message on color GLCD screen
glcdClear();
glcd(0,0,"Example: LED8_bar");
glcd(2,0,"connect LED8 to (20)");
glcd(4,0,"Solid bargraph demo");
pinLED8(20); // Set pin 20 to interface
}
void loop()
{
int i,n;
n=0;
for (i=0;i<8;i++)
{
n|=(0x01<<i); // Create the displayed data by OR operation
LED8(n);
delay(300);
}
for (i=7;i>0;i--)
{
n&=0xff^(0x01<<i); // Create the displayed data by AND operation
LED8(n);
delay(300);
}
}
Code description
The displayed data of this code is created by logic operator both OR (|) and AND (&).
OR operation will keep the bit data “1”. Use this operator for increasing LED turning on.
About AND operation use to clear the MSB bit each bit to decrease the LED turning on.
Listing L3-3 : Led8bargraph.pde; the sketch file for driving 8-bit LED as bar
graph display
132IPST-MicroBOX [SE] Lab manual
IPST-MicroBOX [SE] Lab manual133
This chapter is an introduction to using the switch input board with microcontroller of
IPST-SE board. Learn about how to read the input signal to process and control the output
devices following the setting condition.
About practicals are presented in this chapter, experimenters can use the knowledge
to make a simple control system project that detects input from the switch. Then set the
program is designed to respond to something. For example, when the switch is pressed the
system responds with turn on or off the lights, drives the motor, send temperature information
to display on a computer that is connected.
9.1 Introduction of switch
The most familiar form of switch is a manually operated electromechanical device
with one or more sets of electrical contacts, which are connected to external circuits. Each set
of contacts can be in one of two states: either "closed" meaning the contacts are touching and
electricity can flow between them, or "open", meaning the contacts are separated and the
switch is nonconducting. The mechanism actuating the transition between these two states
(open or closed) can be either a "toggle" (flip switch for continuous "on" or "off") or "momentary"
(push-for "on" or push-for "off") type. (http://en.wikipedia.org/wiki/Switch)
9.1.1 Push-button switch/Tactile switch
Push-button switch or Tactile switches are commonly used in many consumer electronic
devices. They have a small footprint and come in many sizes and gram forces. A push-button
switch has only two states ON and OFF.
Push-button switch have many package with solder tag type, PCB type, panel mounted
type, etc. Some type includes the built-in LED. Normally, the push-button or tactile switch has
at least 2 pins for connection. In micrcocontroller applications, this switch is used to generate
the digital input signal. Almost connect one pin with the pull-up resistor to set the logic state
as “HIGH” or “1” when open circuit and connect this point to microcontroller input port.
Microcontroller will read the status from this point. Other pin of switch normally connect to
ground. When the switch is pressed, the connection point is connected to ground. The logic
is changed to “0”. Microcontroller detects it and activate following the condition that defined
in the opertion program.
Figure 9-1 shows some technical information about push-button switch or tactile switch
that used in microcontroller applications.
Chapter 9
Reading switch
134IPST-MicroBOX [SE] Lab manual
9.1.2 How to connect switch to use in digital circuit
One of the most common means of entering information into a digital system is the
use of switches or a keyboard. Examples might be the switches on a digital clock, the keys on
a calculator, or the large keyboard on a microcomputer. This section will detail several methods
of using a switch to enter data into either TTL or CMOS digital circuits.
There is 3 simple switch interface circuits are depicted in figure 9-2 to 9-4. Pressing the
push-button switch in figure 9-2 will drop the input of the TTL inverter to ground level or LOW.
Releasing the push-button switch to opens the switch. The input to the TTL inverter now is
allowed to “float.” In TTL, inputs usually float at a HIGH logic level.
Rubber button
(c) symbol
(a) one kind of tactile switch
Figure 9-1 : Summary technical information of push-button switch/tactile switch
for microcontroller practical in this chapter
R14k7
+5V
S1
R14k7
+5V
S1
Press buttonto close circuit Current flow
direction
No current flowbecause open circuit
Output = +5Vas logic "1"
Output = 0Vas logic "0"
No press button
(d) basic circuit for microcontrollerapplication
(b) equivalent circuit
OutputS1
Figure 9-2 : Simple active-low switch
interface
IPST-MicroBOX [SE] Lab manual135
S1
+5V
R110k
Connect todigital input pinof microcontroller
S1
R1100k
+5V
Connect todigital input pinof microcontroller
Floating inputs for digital port of microcontroller are not dependable. Figure 9-3 is a
slight refinement of the switch input circuit in Figure 9-2. The 10k resistor has been added to
make sure the microcontroller input pin goes HIGH when the switch is open. The10k
resistor is called a pull-up resistor. Its purpose is to pull the input voltage up to +5 V. Both
circuits in Figure 9-2 and 9-3 illustrate active LOW switches. They are called active LOW
switches because the inputs go LOW only when the switch is activated.
An active HIGH input switch is sketched in Figure 9-4. When the input switch is activated,
the +5 V is connected directly to the digital input of microcontroller. When the switch is
released (opened) the input is pulled LOW by the pull-down resistor.
9.1.3 Contact bounce of switches
Contact bounce (also called chatter) is a common problem with mechanical
switches. Switch contacts are usually made of springy metals that are forced into contact
by an actuator. When the contacts strike together, their momentum and elasticity act
together to cause bounce. The result is a rapidly pulsed electrical current instead of a
clean transition from zero to full current.
Figure 9-3 : Simple active-low switch
interface using pull-up resistor. The idle
state is logic “1”
Figure 9-4 : Simple active-high switch
interface using pull-down resistor. The
idle state is logic “0”
S1
+5V
OUTPUT
R110k
+5V
0V
S1
+5V
OUTPUT
R110k
+5V
0V
S1
+5V
R110k
+5V
0V
Glitch from switch pressingGlitch from switch releasing
Figure 9-5 : The switch bouncing in digital circuit
136IPST-MicroBOX [SE] Lab manual
The digital logic circuits are particularly vulnerable to contact bounce. The voltage
waveform produced by switch bounce usually violates the amplitude and timing
specifications of the logic circuit. The result is that the circuit may fail, due to problems
such as metastability, race conditions, runt pulses and glitches. Figure 9-5 shows the switch's
bouncing in digital circuit.
The switch interface circuits in figure 9-2 to 9-4 work well for some applications.
However, none of the switches in all figures were debounced. The lack of a debouncing
circuit can be demonstrated by operating the counter. Each press of the input switch
should cause the decade (0-9) counter to increase by 1. However, in practice each press
of the switch increases the count by 1, 2, 3, or sometimes more. This means that several
pulses are being fed into the clock (CLK) input of the counter each time the switch is
pressed. This is caused by switch bounce.
9.1.4 Debounce switch with Timing based
Timing based techniques rely on adding sufficient delays to prevent bounce being
detected. Their big advantage is they do not require any special design on the switch side and
so are generally cheaper. However for good performance they must be designed to suit the
switch (too much delay and the response will be needlessly sluggish, too little and bounce
will not be eliminated).
There are 2 methods for solving the bounced switch or call “Debouncing”. One is
hardware method by using RC circuit and solve by software technic.
Figure 9-6 is one example RC integrator circuit that co-working with inverter gate. If an
on/off switch is used with a pull up (or pull down) resistor and a single capacitor is placed
over the switch (you can also place it across the resistor but this can cause nasty spikes of
current on the power supply lines) then when the switch is closed (generally pressed) the
S1
+5V
OUTPUT
R110k
R2 R3
C1
RC integrator
Figure 9-6 : Add RC integrator circuit to debouce the switch.
IPST-MicroBOX [SE] Lab manual137
capacitor will almost instantly discharge through the switch. But when the switch is opened
(generally released) the capacitor takes some time to recharge. Therefore contact bounce will
have negligible effect on the output. The slow edges can be cleaned up with a schmitt trigger
if necessary. This method has the advantage of fast response to the initial press but the current
surges through the switch may be undesirable. Other RC based systems are also possible with
various responses and such systems are probably the easiest method when constructing with
simple logic gates and discrete components.
The second method is software technic. There are summarized procedure as follows :
(1) Read the first pressing of switch.
(2) Delay 0.1 to 1 second
(3) Read the switch status again
If status or data is same, it means the switch is pressed
If not, it means data that read may be noise from switch bouncing.
9.2 Digital input function of C/C++ programmingfor ipst.h library
All functions of C/C++ that use in practical of this chapter are located to library
ipst_in_out.h. Includes in, sw_OK and sw1 function. This library must be included at the top
of the program with the command #include as follows :
#include <ipst_in_out.h> or #include <ipst.h>
9.2.1 in
Read data from the specific digital port
Syntax
char in(x)
Parameter
x - Digital pin of IPST-SE board. It is 0 to 30. Pin 19 or 20 is NOT recommended.
Return value
0 or 1
Example 9-1
char x; // Declare x variable for keeping reading input data
x = in(16); // Read pin 16 and store data to x variable.
138IPST-MicroBOX [SE] Lab manual
9.2.2 sw_OK()
Read status of the OK switch on the IPST-SE board.
Syntax
unsigned char sw_ok()
Retun value
1 (true) when the switch is pressed
0 (false) no press the switch
Note : Pressing the OK switch effects to KNOB value as 0 (zero)
Example 9-2
#include <ipst.h> // Include main library
void setup()
{
glcdClear();
}
void loop()
{
if (sw_OK()) // Check OK switch pressing
{
glcdFillScreen(GLCD_YELLOW); // Change background to yellow
delay(3000); // Show time 3 seconds
}
glcdClear(); // Clare screen and set backgoround color to black
}
9.2.3 sw_OK_press()
Loop to check the OK switch pressing function
Example 9-3
............
sw_OK_press(); // Wait until the OK switch is pressed
.............
IPST-MicroBOX [SE] Lab manual139
9.2.4 sw1_press
This function loops to check the SW1 pressing. It returns value after switch is released.
Syntax
void sw1_press()
Example 9-4
................
sw1_press(); // Wait until the SW1 is pressed and released
................
9.2.5 sw1
This function check the SW1 pressing in any time.
Syntax
char sw1()
Return value
“0” - SW1 is pressed
“1” - SW1 is not pressed
Example 9-5
char x; // Declare x variable for keeping the value
x = sw1(); // Get SW1 status and store to x variable
140IPST-MicroBOX [SE] Lab manual
Practical 4 : LED controlled switch
Practical 4-1 : LED controlled switch #1 (Using OK switch)
Hardware connection
Connect ZX-LED to pin 17 of IPST-SE board
Procedure
4.1.1 Open the Wiring 1.0 IPST-SE software. Create the new sketch file. Type the code following
the Listing L4-1. then save as the sketch to swOK_LED.
4.1.2 Compile and upload the sketch to IPST-SE board by clicking on the button or
choose at menu File > Upload to Wiring Hardware
27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC M
OTO
R
3 TxD1
LOW+5
2 RxD1
UART1
SERVO
00000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
RESET2019
18
17
16
KNOB
OK
SW1
ON
Hello0 rld00Wo
Press OK
ZX
-LE
D+ S
+
S
O
Use both theOK and SW1switch toinput devicesfor setting theoperation.
Figure L4-1 : Connection diagram for practical 4
IPST-MicroBOX [SE] Lab manual141
#include <ipst.h> // Include main library
void setup()
{
setTextSize(2); // Set text size as 2x
glcd(1,1,"Press OK"); // Show message
sw_OK_press(); // Wait until OK switch is pressed
glcdClear(); // Clear screen and set background to black
}
void loop()
{
if (sw_OK()) // Check the OK switch pressing
{
out(17,0); // Turn off LED at pin 17 with 2 seconds
delay(2000);
}
out(17,1); // Turn on LED at pin 17
}
Code description
This code starts with showing the title message that let to press the OK switch for
starting After pressing, enter to main operation in loop(). Check the pressing of OK switch
again. If no pressing, IPST-SE board will turn on LED at pin 17. Keep this operation until OK
switch is pressed.
When the OK switch is pressed, the condition is true. IPST-SE board send data "0" to
turn off LED at pin 17 about 2 seconds following delay(); function executation. Next, exit
from if condition to executes out(); function to turn on LED at pin 17 again and back to
check the OK switch pressing.
4.1.4 Run the sketch and see operation.
IPST-SE monitor shows title message and wait for OK switch pressing. After press, LED
at pin 17 is on.
4.15 Press the OK switch again and release.
LED of ZX-LED at pin 17 will off about 2 seconds and back to on again. It operates with
this condition continuously.
Listing L4-1 : swOK_LED.pde; the sketch file for demonstration the LED
controlled switch
142IPST-MicroBOX [SE] Lab manual
Practical 4-2 : LED controlled switch #2 (Using SW1 switch)
This practical add a switch. It is SW1 switch. It also located in IPST-SE board. This practical setSW1 to control LED with toggle operation. Press to turn on LED and press again to turn off.
Hardware connection
Connect ZX-LED to pin 17 of IPST-SE board
Procedure
4.2.1 Open the Wiring 1.0 IPST-SE software. Create the new sketch file. Type the code following
the Listing L4-2. then save as the sketch to sw1_LED.
4.2.2 Compile and upload the sketch to IPST-SE board by clicking on the button or
choose at menu File > Upload to Wiring Hardware
4.2.3 Run the sketch and see operation.
IPST-SE monitor shows title message and wait for OK switch pressing.
4.2.4 Press the OK switch and release.
4.2.5 Press and release the SW1 switch 3 times. Observe the ZX-LED operation.
LED of ZX-LED at pin 17 will on, off and on following the pressing of SW1 switch. That
is the SW1 is a LED controlled toggle switch.
4.2.6 Press SW1 and hold a moment. Observe the ZX-LED operation.
LED of ZX-LED at pin 17 will keep its status during the SW1 is preesed and toggle
immediately after released.
IPST-MicroBOX [SE] Lab manual143
#include <ipst.h> // Include main library
int i=0;
void setup()
{
setTextSize(2); // Set text size as 2x
glcd(1,1,"Press OK"); // Show message
sw_OK_press(); // Wait until OK switch is pressed
glcdClear(); // Clear screen and set background to black
}
void loop()
{
if (sw1()) // Check SW1 pressing
{
out(17,i^=1); // Toggle LED at pin 17
while(sw1())
delay(5);
}
}
Code description
This code has some function for detecting two switches. They are sw_OK_press();
function for OK switch and sw1(); function for SW1 switch. The first function is located in
setup() for waiting the OK switch pressing to begin.
After enter the main loop, microcontroller waits for SW1 is pressed. When done, it will
send data to pin 17 by using exclusive-OR operator with i variable value. It is i^=1 command.
It cause the data invert or toggle. Possible to use i=~i command. It can work same.
Thus, everytime that press a SW1 switch. It cause toggle operation at pin 17 of IPST-SE
board. LED is connected will on and off for every pressing.
About while(sw1()) loop and delay(5); function are used to debouncing switch. It helps
each pressing switch as more stable.
Listing L4-2 : sw1_LED.pde; the sketch file for demonstration the LED controlled
switch by using SW1 of IPST-SE board in toggle mode
144IPST-MicroBOX [SE] Lab manual
Practical 5 : Counter switch
Hardware connection
Connect the ZX-SWITCH01 to pin 16 of IPST-SE board
Procedure
5.1 Open the Wiring 1.0 IPST-SE software. Create the new sketch file. Type the code following
the Listing L5-1. then save as the sketch to CounterSwitch.
5.2 Compile and upload the sketch to IPST-SE board by clicking on the button or choose
at menu File > Upload to Wiring Hardware
5.3 Run the sketch and see operation.
IPST-SE monitor shows title message and wait for OK switch pressing.
5.4 Press the OK switch and release.
At the monitor, it shows COUNTER message and wait for pressing switch at pin 16.
5.5 Press the ZX-SWITCH01 board that connect with pin 16 to start counting.
IPST-SE will show the counting value following the ZX-SWITCH01 pressing. Counter is
start fron 0 and incresed every pressing. Counter will count continue after release and press
the switch again. If hold the switch, counter operation is also hold.
27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC M
OTO
R
3 TxD1
LOW+5
2 RxD1
UART1
SERVO
00000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
RESET2019
18
17
16
KNOB
OK
SW1
ON
Hello0 rld00Wo
COUNTER
27
ZX-Switch01
+ S
+
S
D
Use OK switchfor starting theoperation
Count switch
Figure L5-1 : Connection diagram for practical 5
IPST-MicroBOX [SE] Lab manual145
#include <ipst.h> // Include main library
int i=0; // Declare counter variable
void setup()
{
setTextSize(2); // Set rtext size as 2x
glcd(1,3,"Start"); // Show Start message
sw_OK_press(); // Wait until OK switch is pressed
glcdClear(); // Clear screen and set background to black
glcd(1,2,"COUNTER"); // Show message COUNTER
setTextSize(3); // Ste text size as 3x
glcd(3,3,"0"); // Set zero
}
void loop()
{
if (in(16)==0) // Check the switch pressing at pin 16
{
i=i++; // Increase counter
glcd(3,3,"%d",i); // Show count value
while(in(16)==0) // Check switch released
delay(5);
}
}
Code description
This code use in(); function to detect the switch pressing at pin 16. When done, it
increases counter and shows on the screen.
About while(in(16)==0) loop and delay(5); function are used to debouncing switch. It
helps each pressing switch as more stable.
Listing L5-1 : CounterSwitch.pde; the sketch file for demonstration about getting
input from switch to increase value. It is idea for making the simple digital
counter.
146IPST-MicroBOX [SE] Lab manual
IPST-MicroBOX [SE] Lab manual147
Electrical signal has 2 kinds; analog and digital signal. Analog signal is correlated with
the time and amplitude change. Digital signal is changed only two states; high and low. Usually
has a voltage of + 5V for logic high or "1" and 0V for logic low or "0". However the logic “1”
voltage level for modern digital devices is down to + 3.3V or 1.8V depending on the digital
device technology . For basic learning still desbribes the logic “1” voltrage as + 5V level.
Figure 10-1 shows the difference between analog and digital signals.
This chapter presents the basic knowledge about analog signal, how to use
microcontroller with analog signal, introduce the analog sensor and some practical of analog
sensor intrerfacing with IPST-SE controller board.
V
t
t1 0 1 0 1 0
1
Vp Data
(b) Example of the digital signalThere is only 2 levels : high ("1") andlow ("0")
V
t
Vp
V
t
Vp
t1 0 1 0 0 1
1
Data
1
t0 1 0 1 1 0
1
Data
0
(a) Example of the analog signal.Amplitude changing relate with time.
Figure 10-1 : Example of analog and digital signal
Chapter 10
Analog sensor
148IPST-MicroBOX [SE] Lab manual
10.1 Analog signal
There is 3 types : DC signals, time-domain and frequency-domain
DC signal : This is the measure of the level of the signal. This signal is changing not so
fast. Example of this signal are temperature, level, flow, pressure, flow rate, weight, etc. The
analog-to-digital (ADC: Analog to Digital Converter) low speed is minimum requirement to convert
the voltage signal to digital data.
Time-domain signal : It is signal that measure of what happened to a parameter of the
system versus time. Voltage or current is expressed as a function of time. Most people are
relatively comfortable with time domain representations of signals. Signals measured on an
oscilloscope are displayed in the time domain and digital information is often conveyed by a
voltage as a function of time. For example is ECG signal (Electrocardiogram). It is the electrical
activity of the heart in exquisite detail. This signal type necessary to use the analog to digital
signal converter with high speed sampling rate.
Frequency-domain signal : This signal type can also be represented by a magnitude and
phase as a function of frequency. Signals that repeat periodically in time are represented by a
power spectrum. Signals that are time limited. Example of this signal is the radio frequency (RF)
signal, audio signal, etc. Requires some special hardware to analysis such as the digital signal
processing board (DSP) works with the high speed analog to digital convewrter circiuit.
10.2 Why does microcontroller read analog signal ?
The main reason for the microcontroller to interface and read with analog signal is read
the physical quantities in the form of electrical signals to process and control the system.
In figure 10-2 shows the basic operation diagram of microcontroller’s analog reading. It
consists of 4 parts as follows :
1. Sensor unit
2. Signal conditioning circuit
3. Analog to Digital Converter (ADC)
4. Microcontroller
10.2.1 Sensor unit
Sensor is devices that convert the physical quantities to electrical signal. There are many
kinds of sensor in the world such as thermocouple, thermistor, flow sensor, light sensor, distance
sensor, etc.
IPST-MicroBOX [SE] Lab manual149
10.1.2 Signal condition circuit
The main function of the signal condition circuit is improve the quality of the electrical
signals from any sensors before send to microcontroller. It may be necessary to adjust the scale,
amplitude, converts tolinear, filters and splits the signal ground (common-mode rejection).
The m ain function of the signal condition ciurcuit is amplification. Because the sensor’
s normally is very low in millivolts (mV) or 1 / 1000V unit and often with noise from the power
supply. The signal condition circuit will amplify and reject noise to as good as signal befroe
send to the analog bto digital converter circuit.
10.1.3 Analog to digital converter circuit (ADC)
An analog-to-digital converter (abbreviated ADC, A/D or A to D) is an electronic integrated
circuit, which converts continuous signals to discrete digital numbers.
Typically, an ADC is an electronic device that converts an input analog voltage (or
current) to a digital number. The digital output may be using different coding schemes, such as
binary, Gray code or two’s complement binary. Analog signal is converted to digital valuse by
sampling method.
Figure 10-2 : Analog reading diagram of microcontroller
Physicalquantities
temperature,light, pressure,
sound, etc.Sensor
Signal conditioncircuit
Analog to digitalconverter
Result is DC voltage.Maximum level is not
more than the rating ofADC input voltage.
Normally, it is 0 to +5V
10001000
01110110
00011101
11100110
Digital data is send tomicrocontroller. Size of data is
depended on resolution ofconversion.
Normally, it is 8-bit or higher
11111010
oC
Microcontroller
electrical signal(volt/current/resistance)
150IPST-MicroBOX [SE] Lab manual
The main feature of ADC ciurcuit is the resolution of conversion. Most ADC circuit formicrocontroller and instrument application has the resolution at least 8-bit. It gives data 256 values; 0to 255. The higher the resolution is better. It will provide a more accurate conversion. But there willbe a higher cost of the system as well.
10.1.4 Microcontroller
Microcontroller is a digital device. To read the analog signal directly, it need an analog
to digital converter circuit. The old style microcontroller are no converter module within the
chip. Must use the external ADC integrated circuit. The resolution of ADC ICs starts at 8, 10,
12, 16-bit or higher.
The modern microcontroller incorporates an ADC module inside the chip. To reduce
the size of the overall system. The signal processing is faster and the total cost of the system
down with it.
Digital data derived from analog-to-digital converter will be sent to the data bus to be
processed and used to make decisions to control the operation of the system.
For the IPST-MicroBOX [SE] uses the ATmega644P a microcontroller with integrated 8-
ch. ADC moducle and 10-bit resolution. It helps to read any analog sensor easier and fast.
10.2 Analog to digital conversion
To convert analog signal to digital. Signal will be converted into digital by sampling as
shown in Figure 10-3, if the analog-to-digital converter has 8-bit resolution. The conversion data
are 28 or 256 values. If 10-bit resolution, the result of binary data values as high as 210 or 1,024.
Figure 10-3 : Sampling the analog singal for assigning the digital data
000101101111
001101100111
Digital data
Analog input signal
Sampling period
IPST-MicroBOX [SE] Lab manual151
The resolution of the analog-to-digital converter is proportional to the number of bits
output. For ADC 10-bit resolution, the converted data is up to 1,024 values which represents
as a binary code of 0000000000 to 1111111111.
if the input from 0 to +5 V, so the resolution is :
V00501024
5.
If binary data 0000000001 (1 bit) represents 0.005V. Thus, voltage 3V will be equal :
6000050
3
. 10
Convert to binary is equal 10010110002.
10.3 Analog function of C/C++ programmingfor reading analog sensor of IPST-MicroBOX (SE)
To helps all experiments and learners who use the IPST-MicroBOX [SE] in analog sensor
interfacing, in main library provides two functions for reading the analog signal. They are
analog(); and knob(); Reading with analog(); and knob(); function get the result 0 to 1,023 in
decimal or 0x0000 to 0x03FF in hexadecimal. Because the resolution of conversion is 10-bit.
10.3.1 analog
This gets digital data from the analog to digital converter module of any analog port; A0
to A6 of the IPST-SE board.
Syntax
unsigned int analog(unsigned char channel)
Parameter
channel - Analog input port. It is 0 to 6 (means A0 to A6)
Return value
Digital data from analog to digital converter module. The value is 0 to 1023 (in
decimal). It represents 0 to +5Vdc.
10.3..2 knob( )
Read the KNOB button data of the IPST-SE board.
Syntax
unsigned int knob()
Retuen value
Digital data from analog to digital converter module of KNOB button. It is 95
to 1,023
152IPST-MicroBOX [SE] Lab manual
Practical 6 : Simple analog sensor interfacing
This practical demonstrates how to connect the analog sensor with IPST-SE controller
board to read value, process data and apply to make simple aplication or project. The work of
this will vary according to the nature and purpose of each sensor such as temperature sensors
that provide temperature changes associated with voltage output, light sensor also change the
intensity of the light to voltage.
The simpleast analog sensor is ZX-POTV (Potentiometer). It is variable resistor module.
The first practical of reading analog sensor will use it to read value and make simple application.
Practical 6-1 : Reading sensor
This is getting start to interface with analog sensor practical. To read and show the
sensor value from input A1 on the IPST-SE monitor
Hardware connection
Connect output of ZX-POTV module with pin A1 of IPST-SE board.
Procedure
6.1.1 Open the Wiring 1.0 IPST-SE software. Create the new sketch file. Type the code following
the Listing L6-1. then save as the sketch to AnalogTest.
27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC M
OTO
R
3 TxD1
LOW+5
2 RxD1
UART1
SERVO
00000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
RESET2019
18
17
16
KNOB
OK
SW1
ON
0 00
Analog
583
ZX
-PO
TV
A
2.847
Volts
Figure L6-1 : Connection diagram for practical 6-1
IPST-MicroBOX [SE] Lab manual153
#include <ipst.h> // Include main library
void setup()
{
glcdClear();
setTextSize(2); // Set text size as 2x
}
void loop()
{
glcd(0,2,"Analog"); // Show message
val = analog(1); // Read sensor at pin A1 and store to variable
setTextSize(3); // Set text size as 3x
glcd(1,2,"%d ",val); // Show sensor raw data
setTextSize(2); // Set text size as 2x
glcd(5,3,"Volts"); // Show message “Volts”
volts = (float(val)*5)/1024; // Convert to Volt unit
setTextSize(3); //Set text size as 3x
glcd(4,1,"%f",volts); // Show data 3-decimnal point floating number
setTextSize(2); //Set text size as 2x
}
Code description
The value of the DC voltage from the sensor at pin A1 of IPST-SE board is converted to
digital data and formatted as a decimal value between 0 and 1023 from analog (); function.
Then, send to show on the color graphic LCD of IPST-SE board continue with glcd(); function.
In addition, the program also calculate the raw data to voltage unit in Volts by using
equation volts = (val x 5) / 1024. Also shows the result on color GLCD of IPST-SE with 3-
decimnal point resolution.
In displaying all result, set the text size different to separate the message and data for
easier to unbderstanding.
Listing L6-1 : AnalogTest.pde; the sketch file for reading analog sensor of
IPST-SE board
154IPST-MicroBOX [SE] Lab manual
6.1.2 Compile and upload the sketch to IPST-SE board by clicking on the button or
choose at menu File > Upload to Wiring Hardware
6.1.3 Turn the shaft of potentiometer on ZX-POT and see the operation at IPST-SE board.
The graphic display shows the data from sensor at pin A1. It is between 0 and 1023
(compared to a voltage of 0 to +5V. )
At the bottom half of the screen, shows voltage value that related with raw data above.
It is between 0.000 to 4.995. (compared with 0 to 1023).
27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC M
OTO
R
3 TxD1
LOW+5
2 RxD1
UART1
SERVO
00000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
RESET2019
18
17
16
KNOB
OK
SW1
ON
0 00
Analog
0
ZX
-PO
TV
A
0.000
Volts
urn the shaft of
potentiometer tominimum position
27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC M
OTO
R
3 TxD1
LOW+5
2 RxD1
UART1
SERVO
00000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
RESET2019
18
17
16
KNOB
OK
SW1
ON
0 00
Analog
1023
ZX
-PO
TV
A
4.995
Volts
Turn the shaft ofpotentiometer tomaximum position
IPST-MicroBOX [SE] Lab manual155
Practical 6.2 : LED controller with analog signal
This practical demonstrates simple application about using variable resistor to control
turning on and off LED.
Hardware connection
Connect ZX-LED to pin 17 of IPST-SE board
Connect output of ZX-POTV to pin A1 of IPST-SE board
Procedure
6.2.1 Open the Wiring 1.0 IPST-SE software. Create the new sketch file. Type the code following
the Listing L6-1. then save as the sketch to AnalogTest.
6.2.2 Compile and upload the sketch to IPST-SE board by clicking on the button or choose
at menu File > Upload to Wiring Hardware
27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC M
OTO
R
3 TxD1
LOW+5
2 RxD1
UART1
SERVO
00000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
RESET2019
18
17
16
KNOB
OK
SW1
ON
0 00
Analog
ZX
-PO
TV
A
108
ZX
-LE
D
+ S
+
S
O
control
Switch
Turn the shaft of potentiometer
Figure L6-2 : Connection diagram for practical 6-2
156IPST-MicroBOX [SE] Lab manual
#include <ipst.h> // Include main library
int val=0; // Declare variable
void setup()
{
glcdClear();
setTextSize(2); // Set text size as 2x
glcd(1,2,"Analog"); // Show message
glcd(2,2,"control");
glcd(3,2,"Switch");
}
void loop()
{
val = analog(1); // Read sensor at pin A1 to store at the variable
if(val>512) // Data is more than 512 ?
{
setTextSize(4); // Set text size as 4x
setTextColor(GLCD_RED); // Set to red
glcd(3,1,"%d ",val); // Show sensor data from pin A1
out(17,1); // If val value is more than 512, turn on LED at pin 17
}
else
{
setTextSize(4); // Set text size as 4x
setTextColor(GLCD_WHITE); // Set text color as white
glcd(3,1,"%d ",val); // Show sensor data from pin A1
out(17,0); // If val value is less than 512, turn off LED at pin 17
}
setTextSize(2); // Set text size as 2x
}
Code description
Sensor signal from potentiometer sensor is read by analog (); function and stored in the
variable val to check and send it to display. If the value is less than 512, displayed as white and
send data "0" to turn off LED at pin 17.
Until valus is equal or more than 512, displayed text will change to red and turn on LED
at pin 17 of IPST-SE board.
Listing L6-2 : AnalogSwitch.pde; the sketch file for making the programmable
analog switch controller. It controls LED with analog sensor voltage.
IPST-MicroBOX [SE] Lab manual157
6.2.3 Turn the shaft of potentiometer on ZX-POT and see the operation at IPST-SE board and ZX-
LED module.
When adjust the POT value, The GLCD screen will show raw data in range 0 to 1023.
If data is less than 512, text color is white and LED at pin17 is off. Until the data is equal or
more than 512, the text color is changed to red and LED at pin 17 is on.
27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC M
OTO
R
3 TxD1
LOW+5
2 RxD1
UART1
SERVO
00000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
RESET2019
18
17
16
KNOB
OK
SW1
ON
0 00
Analog
ZX
-PO
TV
A
420
ZX
-LE
D
+ S
+
S
O
control
Switch
Turn the shaft of potentiometer
LED is off27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC M
OTO
R
3 TxD1
LOW+5
2 RxD1
UART1
SERVO
00000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
RESET2019
18
17
16
KNOB
OK
SW1
ON
0 00
Analog
ZX
-PO
TV
A
520
ZX
-LE
D
+ S
+
S
O
control
Switch
Number is changedto red color
Turn the shaft of potentiometer
LED is on
158IPST-MicroBOX [SE] Lab manual
Practical 6.3 : Night switch controller
This practical is extending from previously. Change the simple analog sensor from ZX-
POT to Light sensor; ZX-LDR. The operation also is same. It is showing about how to make the
different project with change only the critria and a kind of sensor.
Hardware connection
Connect ZX-LED to pin 17 of IPST-SE board
Connect output + or positive output of ZX-LDR module with pin A1of IPST-SE board
Procedure
6.3.1 Open the Wiring 1.0 IPST-SE software. Create the new sketch file. Type the code following
the Listing L6-3. then save as the sketch to NightSwitch.
6.3.2 Compile and upload the sketch to IPST-SE board by clicking on the button or choose
at menu File > Upload to Wiring Hardware
27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC M
OTO
R
3 TxD1
LOW+5
2 RxD1
UART1
SERVO
00000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
RESET2019
18
17
16
KNOB
OK
SW1
ON
0 00
Night
98
ZX
-LE
D
+ S
+
S
O
Switch
Potentiometer
ZX-LDR
++
A
Light sensor
Block the light not fall toLDR sensor to change theoutput voltage of ZX-LDRmodule
LED is onif ZX-LDR'sdata is lessthan 100.
Figure L6-3 : Connection diagram for practical 6-3
IPST-MicroBOX [SE] Lab manual159
Listing L6-3 : NightSwitch.pde; the sketch file for Night switch controller
application
#include <ipst.h> // Include main library
int val=0; // Declare variable to store data
void setup()
{
glcdClear();
setTextSize(2); // Set text size as 2x
setTextColor(GLCD_YELLOW);
glcd(1,2,"Night"); // Show message
glcd(2,2,"Switch");
}
void loop()
{
val = analog(1); // Read data at pin A1 and store to variable
if(val<100) // Check raw data less than 100 or not ?
{
setTextSize(4); // If yes, set text size as 4x
setTextColor(GLCD_WHITE); // Set text color as white
glcd(3,1,"%d ",val); // Show raw data of sensor at pin A1
out(17,1); // If val value is less than 100,
// turn on LED at pin 17
}
else
{
setTextSize(4); // If no, set text size as 4x
setTextColor(GLCD_BLUE); // Set text color as blue
glcd(3,1,"%d ",val); // Show raw data of sensor at pin A1
out(17,0); // If val value is equal or more than 100,
// turn off LED at pin 17
}
setTextSize(2); // Set text size as 2x
}
Code description
This code compares value between reference value (100) with the light sensor value that
read by using analog(1); function and store into val variable. If raw data is more than 100,
displayed number is show with blue color and LED at pin 17 is off.
If raw data of sensor is less than 100, displayed number is change to white and LED at
pin 17 is on.
160IPST-MicroBOX [SE] Lab manual
6.3.3 Use hand or diffuse paper sheet block or filter the light that shine to the LDR sensor on
ZX- LDR module. See the operation at IPST-SE board and ZX-LED module.
If ZX-LDR detects more light density, the raw data is more than 100. The displayed
number is blue color. It is assumed this situation as day time. No need to turn on light. LED at
pin 17 is off.
Until ZX-LDR detectd less light density, raw data is equal or lower than 100. The
operation is changed. Displayed number is changed to white. It is night time. Turn on LED at
pin 17 immediately.
From the operation above, could be called this operation as Twilight Switch or Automatic
night switch.
IPST-MicroBOX [SE] Lab manual161
Practical 7 : Micro-thermometer
This practical demonstrates how to use analog temperature sensor and IPST-SE controller
board to make the digtial thermometer project.
7.1 About MCP9701 Temperature sensor IC
MCP9701 is temperature sensor integrated circuit. It can detect and measure the ambient
temperature. Output is Dc voltage in linear. Recognized the change of temperature in less than
2 seconds. Connect this sensor to the analog input A0 to A6 of IPST-SE board.
Technical features of MCP9701 temperature sensor are as follows :
Tiny Analog Temperature Sensor
Wide Temperature Measurement Range: -40oC to +125oC
Accuracy: ±2oC average
Output voltage/Temperature ratio 19.5mV/oC
Wide Operating Voltage Range +3.1V to +5.5V
No external compensated device require
Hardware connection
Connect the MCP9701 temperature sensor to A3 pin of IPST-SE board
Figure L7-1 : Pin assignment, photo and characreristic graph of MCP9701
Temperature sensor IC.
162IPST-MicroBOX [SE] Lab manual
Procedure
7.1 Open the Wiring 1.0 IPST-SE software. Create the new sketch file. Type the code following
the Listing L7-1. then save as the sketch to MCP9701_Thermometer.
7.2 Compile and upload the sketch to IPST-SE board by clicking on the button or choose
at menu File > Upload to Wiring Hardware
7.3 Run the sketch. Touch the body of temperature sensor and put on the ice. See the measured
temperature of each environment on the IPST-SE display.
IPST-SE board shows the operation message and temperature value in Celcius unit
with 3-decimal point floating number. Only temperature value is displayed with bigger size
(3x) and yellow color.27A3 30A6
29A526A2
28A425A1
24
A0
USB
D
9SDA 8SCL
12
13
14
15
SV0
SV1
SV2
SV3
126VG
136VG
146VG
156VG
21
DC M
OTO
R
3 TxD1
LOW+5
2 RxD1
UART1
SERVO
00000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
000000000000000000000
RESET2019
18
17
16
KNOB
OK
SW1
ON
0 00
Digital
26.740
Temperature sensor;MCP9701
THERMO
METER
Celsius
Figure L7-1 : Connection diagram for practical 7
IPST-MicroBOX [SE] Lab manual163
Listing L7-1 : MCP9701_Thermometer.pde; the sketch file of Micro-thermometer
project. It is simple digital thermometer.
#include <ipst.h> // Include main library
int val,i; // Declare variable for temperature data
float Temp; // Declare variable type as floating
void setup()
{
glcdClear(); // Clear screen
setTextSize(2); // Set text size as 2x
}
void loop()
{
glcd(1,2,"Digital"); // Show title message
glcd(2,2,"THERMO");
glcd(3,3,"METER");
val=0;
for (i=0;i<20;i++) // Set loop for reading the temperature sensor as
// 20 times
{
val = val+analog(3); // Read analog sensor at pin A3
}
val = val/20; // Calculate to average reading data
Temp = (float(val)*0.25) - 20.51 ; // Convert to Celcius unit
setTextSize(3); // Set text size as 3x
setTextColor(GLCD_YELLOW); // Set text color as yellow
glcd(3,1,"%f",Temp); // Show temperature value
// with 3-decinal point floating number
setTextColor(GLCD_WHITE); // Change text color to white
setTextSize(2); // Set text size as 2x
glcd(6,2,"Celsius"); // Show Celcius unit
delay(500); // Delay to restart
}
Code description
The heart of this code is conversion of raw data from reading the temperature sensor to
physical temperature value in Celcius unit. Read data from sensor at pin A3 to store into val
variable. Convert with Temp = (val x 0.25) - 20.51 formula. Then, send value to shows on
the IPST-SE display with 3-decimal point number resolution.