IPST-MicroBOX Secondary Education Lab manual

Page 1

IPST-MicroBOX [SE] Lab manual1

Lab manual


2IPST-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 manual3

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


4IPST-MicroBOX [SE] Lab manual


IPST-MicroBOX [SE] Lab manual5

Chapter 1

Getting start with 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.

Software installation - Wiring 1.0 or Arduino IDE 1.0 - USB driver for the IPST-SE board -------------------------------------

Check the interface port of computer

Preparation for programming 1. Open the Wiring or Arduino IDE 1.0 and created the new sketch 2. Choose the hardware by selected menu Tools > Board > IPST-SE > ATmega644@16MHz 3. Choose the serial port at menus Tools > Serial port > COMx

- Connect the miniB-USB cable between computer's USB port and the IPST-SE board - Open Control panel > System > Hardware > Device Manager > Ports. See the USB serial port (COMx)

Create the C/C++ code and save as the sketch file.

Compile the sketch - Record the USB serial port (COMx) and use this port number for interfacing with the IPSTSE board

Upload the sketch

The IPST-SE board starts to run

Figure 1-1 : Programming development diagram of IPST-MicroBOX [SE]


6IPST-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 manual7

(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].


8IPST-MicroBOX [SE] Lab manual

   

   30 A6 27 A3

USB D

 ON

28 A4 25 A1

  

KNOB

OK



UART1

16

18

17

19

+5

20

RESET

LOW

2 RxD1 3 TxD1

1

2

DC MOTOR



SW1

G 6V 12 G 6V 13 G 6V 14 G 6V 15

15 SV0 14 SV1 13 SV2 12 SV3

29 A5 26 A2

000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000



    



8 SCL 9 SDA

24 A0

   



    

SERVO

      

Figure 1-2 : Layout of the IPST-SE board of the IPST-MicroBOX (SE)

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 IPSTMicroBOX [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.


IPST-MicroBOX [SE] Lab manual9

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

2

Plug the adaptor

3 Turn on the POWER switch Connect the USB cable 30 A6 27 A3

D

29 A5 26 A2 28 A4 25 A1

Wait until the USB indicator is on

USB

KNOB

OK

000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000

ON

UART1

16

18

17

19

+5

20

RESET

LOW

2 RxD1 3 TxD1

1

2

DC MOTOR

SW1

G 6V 12 G 6V 13 G 6V 14 G 6V 15 SERVO

Figure1-3 : Preparation the IPST-SE board for getting start

15 SV0 14 SV1 13 SV2 12 SV3

24 A0

4

8 SCL 9 SDA

1


10IPST-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 manual11

(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 :


12IPST-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 manual13

(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.


14IPST-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 manual15

1.4 Troubleshooting of uploading error. 1.4.1 In case that you have clicked the Upload button already 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.


16IPST-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 manual17

Chapter 2

Introduction and part list of

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.


18IPST-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 manual19

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


20IPST-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)




 

  

   

OK

Figure 2-1 : Layout of the IPST-SE board of the IPST-MicroBOX (SE) 19

17

20

RESET

+5

LOW

2 RxD1 3 TxD1

UART1

  



000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000

D

USB

1

2



SERVO

G 6V 12 G 6V 13 G 6V 14 G 6V 15

ON

    







      

18

16

SW1

KNOB

24 A0 DC MOTOR

28 A4 25 A1

29 A5 26 A2

30 A6 27 A3

  

15 SV0 14 SV1 13 SV2 12 SV3

8 SCL 9 SDA

   

IPST-MicroBOX [SE] Lab manual21


22IPST-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

LED1 R1 (Default = 510)

S

+

Q1 KRC102 (DTC114)

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.

Figure 2-3 : The LED8 serial LED output board of the IPST-MicroBOX [SE]


IPST-MicroBOX [SE] Lab manual23

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

K1 SOUND + S

C1 10/16V

SP1 Piezo speaker

Figure 2-4 : Photo and schematic diagram of ZX-SPEAKER


24IPST-MicroBOX [SE] Lab manual

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.

Outs logic "0" when switch is pressed and LED is on.

D

ZX-SWITCH01

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.

Outs logic "1" when switch is released and LED is off.

LED1

Indicator

+V

R2 10k R1 510

R3 220

DATA

Signal output S1 GND Switch

Figure 2-5 : Photo and schematic diagram of ZX-SWITCH01 touch sensor/ switch module

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.

+

LDR Light

+

A

LOW output : Detect more light; output voltage is decreased. HIGH output : Detect more light; output voltage is increased.

ZX-LDR +

10k

S

+

A

+

LDR

S

+

Figure 2-6 : Photo and schematic diagram of ZX-LDR Light sensor


IPST-MicroBOX [SE] Lab manual25

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.

A

ZX-POTV S S

10kB

+

POTENTIOMETER

Output voltage is increased when turn anti-clockwise direction Output voltage is increased when turn clockwise direction

+

A

Figure 2-7 : Photo and schematic diagram of ZX-POT Variable resistor module

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-8 : Pin assignment, photo and characreristic graph of MCP9701 Temperature sensor IC.


26IPST-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. Signal connector

+V TCRT5000

OUT GND

10k

510

Infrared Reflector

Figure 2-9 : Photo and schematic diagram of ZX-03 Infrared reflector sensor


IPST-MicroBOX [SE] Lab manual27

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


28IPST-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 manual29

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


30IPST-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 manual31

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 GND S +5V

2mm. pitch GND 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.


32IPST-MicroBOX [SE] Lab manual


IPST-MicroBOX [SE] Lab manual33

Chapter 3

Wiring IDE Introduction 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.

Figure 3-1 : Main window of Wiring IDE software used in the program development


34IPST-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 manual35

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.


36IPST-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 manual37

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


38IPST-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 Serial monitor window is appeared following the figure below.

button at Toolbar. The


IPST-MicroBOX [SE] Lab manual39

Chapter 4

Hardware experiment of IPST-SE controller board 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.


40IPST-MicroBOX [SE] Lab manual

Activity 1 : Shows message on the display of the IPST-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.

2

Plug the adaptor

3 Turn on the POWER switch Connect the USB cable 30 A6 27 A3

D

29 A5 26 A2 28 A4 25 A1

Wait until the USB indicator is on

USB

KNOB

OK

000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000

ON

UART1

16

18

17

19

+5

20

RESET

LOW

2 RxD1 3 TxD1

1

2

DC MOTOR

SW1

G 6V 12 G 6V 13 G 6V 14 G 6V 15

15 SV0 14 SV1 13 SV2 12 SV3

24 A0

4

8 SCL 9 SDA

1

SERVO

(A1.1.3) Choose the hardware at menu Tools > Board > IPST-SE > ATmega644P @16MHz


IPST-MicroBOX [SE] Lab manual41

#include <ipst.h> void setup() { glcd(1,0,"Hello World"); } void loop() {}

// Incldue IPST-SE library

// Send message to display

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 (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 choose at menu File > Upload to Wiring Hardware At the IPST-SE screen, the message Hello World will be displayed. 30 A6 27 A3

D

29 A5 26 A2 28 A4 25 A1 OK

Hello 0Wo rld00 00000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000

ON

UART1

16

18

17

19

+5

20

RESET

LOW

2 RxD1 3 TxD1

1

2

DC MOTOR

SW1

G 6V 12 G 6V 13 G 6V 14 G 6V 15 SERVO

15 SV0 14 SV1 13 SV2 12 SV3

24 A0 KNOB

8 SCL 9 SDA

USB

button or


42IPST-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 library int i,j; void setup() { glcdFillScreen(GLCD_WHITE); // Set background color as white setTextColor(GLCD_BLACK); // Set text color as black setTextBackgroundColor(GLCD_WHITE); // Set text background as white for (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 manual43

(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.

30 A6 27 A3

D

29 A5 26 A2 28 A4 25 A1 OK

Rowl00 Wo rld00 00000000 0Row01000000000000000 00Row0200000000000000 000Row030000000000000 0000Row04000000000000 00000Row0500000000000 000000R00060000000000 0000000R0007000000000 00000000Row0800000000 000000000Row090000000 0000000000Row01000000 00000000000Row0110000 000000000000Row012000 0000000000000Row01300 00000000000000Row0140 000000000000000Row015

ON

UART1

16

18

17

19

+5

20

RESET

LOW

2 RxD1 3 TxD1

1

2

DC MOTOR

SW1

G 6V 12 G 6V 13 G 6V 14 G 6V 15 SERVO

15 SV0 14 SV1 13 SV2 12 SV3

24 A0 KNOB

8 SCL 9 SDA

USB


44IPST-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(); setTextColor(GLCD_RED); } void loop() { for (x=1;x<6;x++) { setTextSize(x); for(m=0;m<4;m++) { glcdClear(); glcdMode(m); glcd(0,0,"%dX",x); glcd(1,0,"M=%d",m); sleep(500); } } }

// Enable this function if displaying color // of GLCD incorrect // Set text color as red

// Set text size

// // // //

Clear screen Set rotation of display Show text size Show rotation mode number

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 manual45

(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 Text size is 3 times (3X)

M = 2; rotate displaying to 180o Text size is 4 times (4X)

M = 1; rotate displaying to 90o Text size is 4 times (4X)

M = 3; rotate displaying to 270o Text size is 5 times (5X)


46IPST-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 manual47

#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); glcdFillCircle(96,120,31,GLCD_SKY);

// Create the solid margenta circle

// 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


48IPST-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 manual49

(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.


50IPST-MicroBOX [SE] Lab manual

Activity 2 : Reading KNOB button and OK switch of 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. 30 A6 27 A3

USB D

28 A4 25 A1 OK

Hello 0Wo rld00 00000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000

ON

UART1

16

18

17

19

+5

20

RESET

LOW

1

2

2 RxD1 3 TxD1

DC MOTOR

SW1

G 6V 12 G 6V 13 G 6V 14 G 6V 15

15 SV0 14 SV1 13 SV2 12 SV3

29 A5 26 A2

KNOB

8 SCL 9 SDA

24 A0

KNOB button, OK and SW1 switch are the user interface hardware of the IPST-SE board

SERVO

(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 manual51

#include <ipst.h>

// Include the main library

void setup() { //glcdSetColorWordRGB(); glcdClear();

// Enable this function if displaying color // incorrect // 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()) { glcdClear();

// Check the OK switch pressed // 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 backgound glcdFillCircle(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 setTextSize(2);

",knob());

// Show the value of KNOB button // 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


52IPST-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. 30 A6 27 A3

D

29 A5 26 A2 28 A4 25 A1 OK

Hello 0Wo rld00 00000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000

ON

UART1

16

18

17

19

+5

20

RESET

1

LOW

2

DC MOTOR

SW1

G 6V 12 G 6V 13 G 6V 14 G 6V 15

15 SV0 14 SV1 13 SV2 12 SV3

24 A0 KNOB

8 SCL 9 SDA

USB

SERVO

2 RxD1 3 TxD1

ZX-LED LED 510

connect with JST3AA-8 cable

KRC102 S

+

ZX-LED LED 510 KRC102 S

+

connect with JST3AA-8 cable


IPST-MicroBOX [SE] Lab manual53

#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); }

Listing A3-1 : LEDTest.pde; the sketch for demonstration about simple driving the output devices of the IPST-SE board (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.


54IPST-MicroBOX [SE] Lab manual

Activity 4 : Sound activity IPST-MicroBOX [SE] kit provides the sound output device. It is ZXSPEAKER. 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. 30 A6 27 A3

D

29 A5 26 A2 28 A4 25 A1 OK

Hello 0Wo rld00 00000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000

ON

UART1

16

18

17

19

+5

LOW

1

2

DC MOTOR

SW1

G 6V 12 G 6V 13 G 6V 14 G 6V 15

15 SV0 14 SV1 13 SV2 12 SV3

24 A0 KNOB

8 SCL 9 SDA

USB

SPEAKER

O

2 RxD1 3 TxD1

SERVO

S

RESET

+

+ S

20

(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 manual55

#include <ipst.h> void setup() {} void loop() { beep(19); sleep(1000); }

// Include the main library

// Generate the “beep” signal to pin 19

Listing A4-1 : BeepTest.pde; the sketch for demonstration about generate the beep signal of the IPST-SE board #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

}

Listing A4-2 : SoundTest.pde; the sketch for demonstration about generate the sound with any frequency of the IPST-SE board (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.


56IPST-MicroBOX [SE] Lab manual


IPST-MicroBOX [SE] Lab manual57

Chapter 5

library file 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. ipst.h library Color Graphic LCD

Bluetooth

16-ch. Serial servo motor controller

XBEE

              

                                

ZX-SPEAKER

LED8 board

Servo motor

DC motor driver

TB6612FNG

Serial Monitor Wiring/Arduino IDE

                     

M

M

ZX-LED

ZX-SWITCH01

Analog sensors


58IPST-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 manual59

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.


60IPST-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 manual61

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


62IPST-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 manual63

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


64IPST-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>

KNOB button and OK switch on the IPST-SE board are read value or status by knob(), sw_OK() and sw_OK_press() 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.


IPST-MicroBOX [SE] Lab manual65

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

// Show A2 value

",val);

setTextSize(2);

// Set text size back to 2x

A

ZX-POTV

}

8 SCL 9 SDA

30 A6 27 A3 24 A0

USB D

29 A5 26 A2 28 A4 25 A1

00 00000000 0 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000

AnalogTest

ON

KNOB

OK SW1

UART1

16

18

17

19

+5

20

RESET

LOW

2 RxD1 3 TxD1

1

2

G 6V 12 G 6V 13 G 6V 14 G 6V 15 SERVO

15 SV0 14 SV1 13 SV2 12 SV3

543

DC MOTOR

Connect ZX-POT to A2 input of IPST-SE board and test by Example 5-9 code.


66IPST-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

// Show KNOB button value on GLCD

",knob());

setTextSize(2);

// Set text size back to 2x

} 8 SCL 9 SDA

30 A6 27 A3

USB

24 A0

D

29 A5 26 A2

00 00000000 0 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000

KnobTest

ON

28 A4 25 A1 KNOB

OK SW1

UART1

16

18

17

19

+5

20

RESET

LOW

2 RxD1 3 TxD1

1

2

DC MOTOR

Adjust KNOB button

G 6V 12 G 6V 13 G 6V 14 G 6V 15 SERVO

15 SV0 14 SV1 13 SV2 12 SV3

958


IPST-MicroBOX [SE] Lab manual67

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


68IPST-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

Intercing port of IPST-SE for LED8

0

Most suitable : pin 16 to 20 7 MSB

6

5

4

3

2

1

0 LSB

LED8

Optional -2 : pin 8 and 9 (disable UART1) Optional -3 : pin 24 to 30 (stop analog)

+5V RxD GND

Serial LED-8 UART communication 9600 bps. Baud

Optional -1 : pin 2 and 3 (disable I2C bus)

Secondary Education

30 A6 27 A3

D

29 A5 26 A2 28 A4 25 A1 OK

Rowl00 World0000000000 0Row01000000000000000 00Row0200000000000000 000Row030000000000000 0000Row04000000000000 00000Row0500000000000 000000R00060000000000 0000000R0007000000000 00000000Row0800000000 000000000Row090000000 0000000000Row01000000 00000000000Row0110000 000000000000Row012000 0000000000000Row01300 00000000000000Row0140 000000000000000Row015

ON

UART1

Connect with JST3AA-8

16

18

17

19

+5

20

RESET

LOW

1

2

2 RxD1 3 TxD1

DC MOTOR

SW1

G 6V 12 G 6V 13 G 6V 14 G 6V 15

15 SV0 14 SV1 13 SV2 12 SV3

24 A0 KNOB

8 SCL 9 SDA

USB

SERVO

Recommended Digital port for LED8 interfacing

Figure 5-1 : Connection diagram of IPST-SE board and LED8 driver board


IPST-MicroBOX [SE] Lab manual69

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> void setup() { pinLED8(20); } void loop() { unsigned char i=0; while(1) { LED8(i++); delay(500); } }

// Include main library // Set pin 20 to connect with LED8 board

// Show 8-bit binary data (00000000 to 11111111) // Delay 0.5 second


70IPST-MicroBOX [SE] Lab manual

Example 5-15 #include <ipst.h> void setup() {} void loop() { unsigned char i=0; while(1) { LED8(20,i++);

// Include main library

// // // //

delay(500);

Set pin 20 to conect with LED8 board Then, show 8-bit binary data (00000000 to 11111111) Delay 0.5 second

} }

7

6

5

4

3

2

1

0

7 MSB

6

5

4

3

2

1

0 LSB

LED8

Display data = 00000000

+5V RxD GND

Serial LED-8 UART communication 9600 bps. Baud

Secondary Education

7

6

5

4

3

2

1

0

7 MSB

6

5

4

3

2

1

0 LSB

LED8

Display data = 00000001

+5V RxD GND

Serial LED-8 UART communication 9600 bps. Baud

Secondary Education

7

6

5

4

3

2

1

0

7 MSB

6

5

4

3

2

1

0 LSB

LED8

Display data = 00001111

+5V RxD GND

Serial LED-8 UART communication 9600 bps. Baud

Secondary Education

7

6

5

4

3

2

1

0

7 MSB

6

5

4

3

2

1

0 LSB

Serial LED-8 UART communication 9600 bps. Baud

+5V RxD GND

LED8

Display data = 11111111 Secondary Education


IPST-MicroBOX [SE] Lab manual71

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 100 If 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 30 A6 27 A3

USB D

28 A4 25 A1 OK

Rowl00World00 00000000 0Row01000000000000000 00Row0200000000000000 000Row030000000000000 0000Row04000000000000 00000Row0500000000000 000000R00060000000000 0000000R0007000000000 00000000Row0800000000 000000000Row090000000 0000000000Row01000000 00000000000Row0110000 000000000000Row012000 0000000000000Row01300 00000000000000Row0140 000000000000000Row015

ON

UART1

16

18

17

19

+5

20

RESET

LOW

2 RxD1 3 TxD1

DC motor #1

1

2

DC MOTOR

SW1

G 6V 12 G 6V 13 G 6V 14 G 6V 15 SERVO

15 SV0 14 SV1 13 SV2 12 SV3

29 A5 26 A2

KNOB

8 SCL 9 SDA

}

24 A0

#include <ipst.h> void setup() {} void loop() { motor(1,60); // Drive motor 1 with 80% power delay(500); // Driving time 0.5 second motor(1,-60); // Drive mortor 1 backward // with 60% power delay(500); // Driving time 0.5 second


72IPST-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> void setup() { sw_OK_press(); } void loop() { motor(1,60); delay(500); motor(1,-60); delay(500); if (sw1()) { motor_stop(1); while (1); } }

// Include main library // Check the OK switch pressing

// Drive motor1 with 60% power // Driving time 0.5 second // Drive motor1 backward with 60% power // Driving time 0.5 second // Check the SW1 switch pressing // If SW1 switch is pressed, stop motor1


IPST-MicroBOX [SE] Lab manual73

Example 5-18

#include <ipst.h> void setup() {} void loop() { motor(1,50); motor(2,50); sleep(3000); motor(1,-50); motor(2,-50); sleep(3000); motor_stop(ALL); sleep(3000); } 30 A6 27 A3

USB D

Rowl00 Wo rld00 00000000 0Row01000000000000000 00Row0200000000000000 000Row030000000000000 0000Row04000000000000 00000Row0500000000000 000000R00060000000000 0000000R0007000000000 00000000Row0800000000 000000000Row090000000 0000000000Row01000000 00000000000Row0110000 000000000000Row012000 0000000000000Row01300 00000000000000Row0140 000000000000000Row015

ON

28 A4 25 A1

UART1

16

18

17

19

+5

20

RESET

LOW

2 RxD1 3 TxD1

DC motor#1

1

2

DC MOTOR

SW1

G 6V 12 G 6V 13 G 6V 14 G 6V 15

15 SV0 14 SV1 13 SV2 12 SV3

29 A5 26 A2 OK

// Drive motor1 with 50% power // Drive motor2 with 50% power // Driving time 3 วินาที // Drive motor1 backward with 50% power // Drive motor 2 backward with 50% power // Driving time 3 second // Stop both motors // Delay 3 second 8 SCL 9 SDA

24 A0 KNOB

// Include main library

SERVO

DC motor#2


74IPST-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 manual75

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 interfacing with computer via USB port

Using uart1() function for interfacing with any serial devices (such as bluetooth, XBEE or WiFi module) via RxD1 (pin 2) and TxD1 (pin 3)

รูปที่ 5-2 แสดงจุดตอสัญญาณของแผงวงจร IPST-SE เมือมี ่ การใชงานไลบรารี ipst_serial.h


76IPST-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 %C Display 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 manual77

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


78IPST-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() { if(uart_available()) { if(uart_getkey()==’a’) { glcd(3,1,“Key a Active!”); sleep(2000); } else { glcdClear(); } } }

// Main loop // Received data checking // Key a is pressed ? // Show message to response // Delay 2 seconds

// 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 manual79

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.

Connect USB cable alltime 30 A6 27 A3

D

29 A5 26 A2 28 A4 25 A1 OK

00 00000000 0 000000000000000000000 000000000000000000000 000000000000000000000 Key a Active! 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000

ON

UART1

16

18

17

19

+5

20

RESET

LOW

2 RxD1 3 TxD1

1

2

DC MOTOR

SW1

G 6V 12 G 6V 13 G 6V 14 G 6V 15 SERVO

15 SV0 14 SV1 13 SV2 12 SV3

24 A0 KNOB

8 SCL 9 SDA

USB


80IPST-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 manual81

5.4.8.10 When does using UART1 ? 1. Connnect with wirelss devices such as bluetooth, XBEE, WiFi, etc.

TXD1

Computer Laptop Smartphone that support bluetooth (master)

Rx

BlueStick Serial bluetooth (slave) Tx

IPST-SE board RXD1

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

28 A4 25 A1

28 A4 25 A1 18

17

19

+5

20

RESET

LOW

2 RxD1 3 TxD1

1

2

DC MOTOR

UART1

16

SERVO

KNOB

OK

00 00000000 0 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000

ON

SW1

UART1

16

18

17

19

+5

20

RESET

LOW

2 RxD1 3 TxD1

1

2

DC MOTOR

29 A5 26 A2 SW1

15 SV0 14 SV1 13 SV2 12 SV3

ON

G 6V 12 G 6V 13 G 6V 14 G 6V 15

D

29 A5 26 A2

30 A6 27 A3

00 00000000 0 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000

USB

G 6V 12 G 6V 13 G 6V 14 G 6V 15

15 SV0 14 SV1 13 SV2 12 SV3

8 SCL 9 SDA

OK

30 A6 27 A3

KNOB

24 A0

24 A0

D

8 SCL 9 SDA

USB

SERVO

Connect RxD1 to TxD1 and TxD1 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 manual83

Chapter 6

Using the color display of IPST-SE board 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>


84IPST-MicroBOX [SE] Lab manual

  



 

012345 67 89abc defghijk 100000000000000000000 20000 0 0000d 0000000000 300000000000000000000 400000000000000000000 500000000000000000000 600000000000000000000 700000000000000000000 800000000000000000000 900000000000000000000 a00000000000000000000 b00000000000000000000 c00000000000000000000 d00000000000000000000 e00000000000000000000 f00000000000000000000

     

Figure 6-1 : Illustated of details and displayed dot location of the GLCD module that used in IPST-SE board

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)


IPST-MicroBOX [SE] Lab manual85

Example 6-1 glcd(2,0,"Hello World"); // Show message; Hello World at left end position of line 2

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.

Line 0 012345 67 89abc defghijk Line 1 100000000000000000000 Line 2 Hello 0 World 0000000000 300000000000000000000 400000000000000000000 500000000000000000000 Column 0 600000000000000000000 (first digit) 700000000000000000000 800000000000000000000 900000000000000000000 a00000000000000000000 b00000000000000000000 c00000000000000000000 d00000000000000000000 e00000000000000000000 f00000000000000000000

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

D Hello0 Wo rld00 00000000 00 Valu e0=020000000000 Hello 0 World 0000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000

ON

29 A5 26 A2 28 A4 25 A1

DC MOTOR

SW1

G 6V 12 G 6V 13 G 6V 14 G

14 SV1 13 SV2 12 SV3

30 A6 27 A3 OK

8 SCL 9 SDA

24 A0 KNOB

USB


86IPST-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 5bit 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 manual87

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() {}


88IPST-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 manual89

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

29 A5 26 A2 28 A4 25 A1 SW1

D Hello0 Wo rl d 00 00000000 000000000000000000000 Hello 0 World 0000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000

ON

G 6V 12 G 6V 13 G 6V 14

14 SV1 13 SV2 12 SV3

30 A6 27 A3 OK

8 SCL 9 SDA

24 A0 KNOB

USB


90IPST-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

Screen status

Screen status

Before execute

After execute

glcdClear();

glcdClear();

IPST-SE


IPST-MicroBOX [SE] Lab manual91

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

Screen status

Before execute

After execute

glcdFillScreen(GLCD_YELLOW);

glcdFillScreen(GLCD_YELLOW);


92IPST-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.

glcdMode1 orientate 90o

glcdMode3 orientate 270o

IPST-SE

IPST-SE

glcdMode2 orientate 180o

IPST-SE

glcdMode0 0o

IPST-SE

Example 6-12 #include <ipst.h> void setup() { setTextSize(2); } void loop() { glcdClear(); glcdMode(0); glcd(0,0,"IPST-SE"); sw_ok_press(); glcdClear(); glcdMode(1); glcd(0,0,"IPST-SE"); sw_ok_press(); glcdClear(); glcdMode(2); glcd(0,0,"IPST-SE"); sw_ok_press(); glcdClear(); glcdMode(3); glcd(0,0,"IPST-SE"); sw_ok_press(); }

// Set text size as 2x

// // // //

Clear screen Set display orientation mode 0 Show message Wait OK switch pressing

// Set display orientation mode 1

// Set display orientation mode 2

// Set display orientation mode 3


IPST-MicroBOX [SE] Lab manual93

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.

gap 1 dot

pitch 1 dot height 7 dots line space 2 dots

width 5 dots 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.


94IPST-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 manual95

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


96IPST-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,unsigned int 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 } } 30 A6 27 A3

{} 24 A0

29 A5 26 A2

D

28 A4 25 A1 OK SW1

G 6V 12 G 6V 13 G 6V 14

14 SV1 13 SV2 12 SV3

KNOB

ON

000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000

DC MOTOR

6.3.1.17 glcdRect

USB

8 SCL 9 SDA

void loop()


IPST-MicroBOX [SE] Lab manual97

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 dot 0 dot dot dot dot

dot 4

dot 127

0 1 2 3

y-axis

dot 157 dot 158 dot 159

Figure 6-2 : Dot coordinator of IPST-SE board’s color display


98IPST-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() {}

Y1 point (40)

width Start dot of x-axis

X1 point300000000000000000000 (32) 400000000000000000000

height line color

 Start dot of y-axis

500000000000000000000 600000000000000000000 700000000000000000000 800000000000000000000 height 900000000000000000000 a00000000000000000000 b00000000000000000000 c00000000000000000000 d00000000000000000000 e00000000000000000000 width 64 dots f00000000000000000000

80 dots


IPST-MicroBOX [SE] Lab manual99

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() {}

Y1 point (40)

Start dot of x-axis

width height

X1 point 300000000000000000000 (32) 400000000000000000000

target color

 Start dot of y-axis

500000000000000000000 600000000000000000000 700000000000000000000 Height 800000000000000000000 80 dots 900000000000000000000 a00000000000000000000 b00000000000000000000 c00000000000000000000 d00000000000000000000 e00000000000000000000 f00000000000000000000 width 64 dots


100IPST-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() {}

Y1 (0) X1 (0)

3 4

0 0 0000000000000000 0000000000000000 500000000000000000000 600000000000000000000 700000000000000000000 800000000000000000000 900000000000000000000 a00000000000000000000 b00000000000000000000 c00000000000000000000 d00000000000000000000 e00000000000000000000 f00000000000000000000

Y2 (159) X2 (127)3 4

0 0


IPST-MicroBOX [SE] Lab manual101

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 y-coordinator 800000000000000000000 (120) 900000000000 00000000 31 dots a000000000 radius 0000000000 b00000000000000000000 c00000000000000000000 x-coordinator d00000000000000000000 (32) e00000000000000000000 f00000000000000000000


102IPST-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 y-coordinator 800000000000000000000 (120) 900000000000 00000000 31 dots a000000000 radius 0000000000 b00000000000000000000 c00000000000000000000 x-coordinator d00000000000000000000 (32) e00000000000000000000 f00000000000000000000


IPST-MicroBOX [SE] Lab manual103

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() {}


104IPST-MicroBOX [SE] Lab manual


IPST-MicroBOX [SE] Lab manual105

Chapter 7

LED controller 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 :

Vcc  VF IF Vcc is Supply voltage, VF is forward bias voltage cross LED and IF is forward bias current RS 

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.

R1

Cathode

A

Anode Vs

K

(A) LED symbol

(B) LED structure

Figure 7-1 : Symbol and structure of LED

LED1

+

I1

Figure 7-2 : LED circuit application


106IPST-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 IPSTSE 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 IPSTSE 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 manual107

Practical notice for

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.


108IPST-MicroBOX [SE] Lab manual

Practical 1 : Simple LED controller Practical 1-1 : Turning on LED Hardware connection  Connect ZX-LED board to pin 17 of IPST-SE board 30 A6 27 A3 29 A5 26 A2 28 A4 25 A1

S

+

D

O

KNOB

OK

Hello 0Wo rld00 00000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000

ON

#include <ipst.h>

UART1

16

18

17

19

+5

20

RESET

LOW

2 RxD1 3 TxD1

1

2

DC MOTOR

connect with JST3AA-8 cable

SW1

G 6V 12 G 6V 13 G 6V 14 G 6V 15

15 SV0 14 SV1 13 SV2 12 SV3

24 A0

ZX-LED + S

8 SCL 9 SDA

USB

SERVO

// 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


IPST-MicroBOX [SE] Lab manual109

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.

2

Plug the adaptor

3 Turn on the POWER switch Connect the USB cable 30 A6 27 A3

D

29 A5 26 A2 28 A4 25 A1

Wait until the USB indicator is on

USB

KNOB

OK

000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000

ON

UART1

16

18

17

19

+5

20

RESET

LOW

2 RxD1 3 TxD1

1

2

DC MOTOR

SW1

G 6V 12 G 6V 13 G 6V 14 G 6V 15

15 SV0 14 SV1 13 SV2 12 SV3

24 A0

4

8 SCL 9 SDA

1

SERVO

1.1.3 Choose the hardware at menu Tools > Board > IPST-SE > ATmega644P @16MHz


110IPST-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 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.

button or


IPST-MicroBOX [SE] Lab manual111

#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


112IPST-MicroBOX [SE] Lab manual


IPST-MicroBOX [SE] Lab manual113

Chapter 8

Muti-channels LED controller 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, onoff 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 : Binary

Decimal

Binary

Decimal

Binary

Decimal

Binary

Decimal

0 1 10 11

0 1 2 3

100 101 110 111

4 5 6 7

1000 1001 1010 1011

8 9 10 11

1100 1101 1110 1111

12 13 14 15


114IPST-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 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 is to 0 x 20 = 0 x 1= 0 2 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 1 2 3 4 5 6

20 21 22 23 24 25 26

1 2 4 8 16 32 64

7

27

128


IPST-MicroBOX [SE] Lab manualď€ ď Źď€ 115

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


116IPST-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 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

Decimal Signed number 0 1 2 3 4 5 6 7 -8 -7 -6 -5 -4 -3 -2 -1

Unsigned number 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 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 manual117

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.

word High byte (upper 8-bit)

Low byte (lower 8-bit)

MSB bit

LSB

8

7

6

5

4

3

2

1

0

1

0

0

0

1

1

1

0

0

1

Weight 215 214 213 212 211 210 29

28

27

26

25

24

23

22

21

20

Data*

15 14 13 12 11 10 9 1

1

1

0

1

1

* Data value could be changed

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


118IPST-MicroBOX [SE] Lab manual

8.5 Introduction to the LED8 : Serial 8-LED driver board 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 manual119

MSB D7

D6

D5

D4

D3

D2

D1

LSB D0

7

6

5

4

3

2

1

0

+5V

47

47

47

47

47

47

47

47

7

6

5

4

3

2

1

510

510

510

510

510

9

8

5

6

7

D7

D6

D5

D4

D3

510

510

14

15

D2

XT2

2

3

RXD 12

+5V 4k7

VDD

RST

1

4

510

16

D1

D0

ZX-LED controller PIC18F14K50 with firmware UART 9600 bps. to 8 bit parallel outputs XT1

0

VDDU

VSS 20

PGD 19

PGC 18

17

0.1F 63V

4k7

Ceramic Resonator (Option) 47F 6.3V

0.1F 63V

GND RxD +5V

ICSP

Fiogure 8-1 : Board layout and schematic diagram of LED8 board


120IPST-MicroBOX [SE] Lab manual

7

6

5

4

3

2

1

Intercing port of IPST-SE for LED8

0

Most suitable : pin 16 to 20 7 MSB

6

5

4

3

2

1

0 LSB

LED8

Optional -2 : pin 8 and 9 (disable UART1) Optional -3 : pin 24 to 30 (stop analog)

+5V RxD GND

Serial LED-8 UART communication 9600 bps. Baud

Optional -1 : pin 2 and 3 (disable I2C bus)

Secondary Education

30 A6 27 A3

D

29 A5 26 A2 28 A4 25 A1 OK

Rowl00 Wo rld00 00000000 0Row01000000000000000 00Row0200000000000000 000Row030000000000000 0000Row04000000000000 00000Row0500000000000 000000R00060000000000 0000000R0007000000000 00000000Row0800000000 000000000Row090000000 0000000000Row01000000 00000000000Row0110000 000000000000Row012000 0000000000000Row01300 00000000000000Row0140 000000000000000Row015

ON

UART1

Connect with JST3AA-8

16

18

17

19

+5

20

RESET

LOW

1

2

2 RxD1 3 TxD1

DC MOTOR

SW1

G 6V 12 G 6V 13 G 6V 14 G 6V 15

15 SV0 14 SV1 13 SV2 12 SV3

24 A0 KNOB

8 SCL 9 SDA

USB

SERVO

Recommended Digital port for LED8 interfacing

Figure 8-2 : Connection diagram of LED8 board with IPST-SE controller board


IPST-MicroBOX [SE] Lab manual121

+5V

+5V +5V

+5V For example, LED8 gets data 10110001.

7

7 MSB

6

6

5

5

4

3

4

3

2

1

2

It drives LED on and off following the data value.

0

1

0 LSB

Serial LED-8 UART communication 9600 bps. Baud

+5V RxD GND

LED8

At the bit is "1", output pin that is same position also has +5V to send out. At pin 7, 5, 4 and 0 will send out +5V but for pin 6, 3, 2 and 1 will be 0V.

Secondary Education

30 A6 27 A3

D

29 A5 26 A2 28 A4 25 A1

KNOB

OK

Rowl00 Wo rld00 00000000 0Row01000000000000000 00Row0200000000000000 000Row030000000000000 0000Row04000000000000 00000Row0500000000000 000000R00060000000000 0000000R0007000000000 00000000Row0800000000 000000000Row090000000 0000000000Row01000000 00000000000Row0110000 000000000000Row012000 0000000000000Row01300 00000000000000Row0140 000000000000000Row015

ON

UART1

16

18

17

19

+5

20

RESET

LOW

2 RxD1 3 TxD1

1

2

DC MOTOR

SW1

G 6V 12 G 6V 13 G 6V 14 G 6V 15

15 SV0 14 SV1 13 SV2 12 SV3

24 A0

IPST-SE board send the serial data to set the display of LED8 board.

8 SCL 9 SDA

USB

SERVO

Recommended digital port for LED8 interfacing

Figure 8-3 : The operation of LED on LED8 board that related with its output port.


122IPST-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. button or

2.1.2 Compile and upload the sketch to IPST-SE board by clicking on the choose at menu File > Upload to Wiring Hardware

7

6

5

4

3

2

1

0

7 MSB

6

5

4

3

2

1

0 LSB

Serial LED-8 UART communication 9600 bps. Baud

+5V RxD GND

LED8 Secondary Education

30 A6 27 A3

D

29 A5 26 A2 28 A4 25 A1 OK

Rowl00 Wo rld00 00000000 0Row01000000000000000 00Row0200000000000000 000Row030000000000000 0000Row04000000000000 00000Row0500000000000 000000R00060000000000 0000000R0007000000000 00000000Row0800000000 000000000Row090000000 0000000000Row01000000 00000000000Row0110000 000000000000Row012000 0000000000000Row01300 00000000000000Row0140 000000000000000Row015

ON

UART1

16

18

17

19

+5

20

RESET

LOW

2 RxD1 3 TxD1

Connect with JST3AA-8 cable

Figure L2-1 : Connection diagram for practical 2 and 3

1

2

DC MOTOR

SW1

G 6V 12 G 6V 13 G 6V 14 G 6V 15 SERVO

15 SV0 14 SV1 13 SV2 12 SV3

24 A0 KNOB

8 SCL 9 SDA

USB


IPST-MicroBOX [SE] Lab manual123

#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 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


124IPST-MicroBOX [SE] Lab manual

#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 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 choose at menu File > Upload to Wiring Hardware

button or

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


IPST-MicroBOX [SE] Lab manual125

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 choose at menu File > Upload to Wiring Hardware

button or

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


126IPST-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 2way 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 choose at menu File > Upload to Wiring Hardware

button or

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 manual127

#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," pinLED8(20);

and RIGHT"); // 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


128IPST-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 choose at menu File > Upload to Wiring Hardware

button or

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

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

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

2

1

0

Pattern 2 Pattern 3 Pattern 4 Pattern 4 Pattern 3 Pattern 2 Pattern 1 3

Loop to restart


IPST-MicroBOX [SE] Lab manual129

#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 lookup 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


130IPST-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 choose at menu File > Upload to Wiring Hardware

button or

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

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

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 manual131

#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


132IPST-MicroBOX [SE] Lab manual


IPST-MicroBOX [SE] Lab manual133

Chapter 9

Reading switch 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.


134IPST-MicroBOX [SE] Lab manual

Rubber button

+5V R1 4k7 No press button

Output = +5V as logic "1" No current flow because open circuit

S1

(a) one kind of tactile switch +5V R1 4k7

(b) equivalent circuit

Press button to close circuit S1

Output = 0V as logic "0" Current flow direction

(d) basic circuit for microcontroller application

(c) symbol

Figure 9-1 : Summary technical information of push-button switch/tactile switch for microcontroller practical in this chapter

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.

S1

Output

Figure 9-2 : Simple active-low switch interface


IPST-MicroBOX [SE] Lab manual135

+5V

+5V S1

R1 10k

S1

Connect to digital input pin of microcontroller

R1 100k

Connect to digital input pin of microcontroller

Figure 9-3 : Simple active-low switch Figure 9-4 : Simple active-high switch interface using pull-up resistor. The idle interface using pull-down resistor. The state is logic “1” idle state is logic “0” 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. +5V

+5V

R1 10k

S1

+5V

R1 10k

OUTPUT

R1 10k

OUTPUT

S1

S1

+5V

+5V

+5V

0V

0V

0V

Glitch from switch pressing

Figure 9-5 : The switch bouncing in digital circuit

Glitch from switch releasing


136IPST-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

+5V R1 10k S1 R2

R3

OUTPUT

C1

RC integrator Figure 9-6 : Add RC integrator circuit to debouce the switch.


IPST-MicroBOX [SE] Lab manual137

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++ programming for 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.


138IPST-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 manual139

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


140IPST-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 choose at menu File > Upload to Wiring Hardware

30 A6 27 A3

D Hello 0Wo rld00 00000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000

28 A4 25 A1

S

O

KNOB

OK

OK

ON

UART1

16

18

17

19

+5

20

RESET

LOW

2 RxD1 3 TxD1

Figure L4-1 : Connection diagram for practical 4

1

2

DC MOTOR

SW1

Use both the OK and SW1 switch to input devices for setting the operation.

G 6V 12 G 6V 13 G 6V 14 G 6V 15 SERVO

15 SV0 14 SV1 13 SV2 12 SV3

29 A5 26 A2

24 A0

ZX-LED +

8 SCL 9 SDA

USB

Press

+ S

button or


IPST-MicroBOX [SE] Lab manual141

#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.

Listing L4-1 : swOK_LED.pde; the sketch file for demonstration the LED controlled switch 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.


142IPST-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 set SW1 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 choose at menu File > Upload to Wiring Hardware

button or

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 manual143

#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


144IPST-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. button or choose

5.2 Compile and upload the sketch to IPST-SE board by clicking on the 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. 30 A6 27 A3

USB D

Hello 0Wo rld00 00 000000 000000000000000 000000 000000000000000 000000 000000000000000 000000 000000000000000 000000 000000000000000 000000 000000000000000 000000 000000000000000 000000 000000000000000 000000 000000000000000 000000 000000000000000 000000 000000000000000 000000 000000000000000 000000 000000000000000 000000 000000000000000 000000 000000000000000 000000

28 A4 25 A1

COUNTER

27

S

KNOB

OK

Use OK switch for starting the operation

SW1

UART1

16

18

17

19

+5

20

RESET

LOW

2 RxD1 3 TxD1

Figure L5-1 : Connection diagram for practical 5

1

2

DC MOTOR

+

+ S

ON

G 6V 12 G 6V 13 G 6V 14 G 6V 15 SERVO

15 SV0 14 SV1 13 SV2 12 SV3

29 A5 26 A2

D

8 SCL 9 SDA

ZX-Switch01

24 A0

Count switch


IPST-MicroBOX [SE] Lab manual145

#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.


146IPST-MicroBOX [SE] Lab manual


IPST-MicroBOX [SE] Lab manual147

Chapter 10

Analog sensor 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

Data

Vp

1

t

0010110

t

V Data Vp 1

t 1101001

V

t

Data

Vp

t

1

101010

t

(a) Example of the analog signal. (b) Example of the digital signal Amplitude changing relate with time. There is only 2 levels : high ("1") and low ("0")

Figure 10-1 : Example of analog and digital signal


148IPST-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 manual149

Physical quantities temperature, light, pressure, sound, etc.

Sensor

Signal condition circuit

Result is DC voltage. Maximum level is not more than the rating of ADC input voltage. Normally, it is 0 to +5V

oC

electrical signal (volt/current/resistance)

Analog to digital converter

10001000 Digital data is send to microcontroller. Size of data is depended on resolution of conversion. Normally, it is 8-bit or higher

01110110 00011101 11100110 11111010

Microcontroller

Figure 10-2 : Analog reading diagram of microcontroller

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.


150ď€ ď Źď€ IPST-MicroBOX [SE] Lab manual

The main feature of ADC ciurcuit is the resolution of conversion. Most ADC circuit for microcontroller and instrument application has the resolution at least 8-bit. It gives data 256 values; 0 to 255. The higher the resolution is better. It will provide a more accurate conversion. But there will be 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 8ch. 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.

Digital data 001101100111 000101101111

Analog input signal

Sampling period

Figure 10-3 : Sampling the analog singal for assigning the digital data


IPST-MicroBOX [SE] Lab manual151

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 :

5  0.005 V 1024 If binary data 0000000001 (1 bit) represents 0.005V. Thus, voltage 3V will be equal :

3  600 10 0 . 005 Convert to binary is equal 10010110002.

10.3 Analog function of C/C++ programming for 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


152IPST-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

A

ZX-POTV

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.

8 SCL 9 SDA

30 A6 27 A3

USB

29 A5 26 A2

00 00000000 0 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000

Analog

ON

28 A4 25 A1

583 Volts

KNOB

2.847

OK

UART1

16

18

17

19

+5

20

RESET

LOW

2 RxD1 3 TxD1

Figure L6-1 : Connection diagram for practical 6-1

1

2

DC MOTOR

SW1

G 6V 12 G 6V 13 G 6V 14 G 6V 15 SERVO

15 SV0 14 SV1 13 SV2 12 SV3

24 A0

D


IPST-MicroBOX [SE] Lab manual153

#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

// Read sensor at pin A1 and store to variable

= analog(1);

setTextSize(3); glcd(1,2,"%d

// Set text size as 3x ",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 3decimnal 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


154IPST-MicroBOX [SE] Lab manual

6.1.2 Compile and upload the sketch to IPST-SE board by clicking on the choose at menu File > Upload to Wiring Hardware

button or

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. )

A

ZX-POTV

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).

8 SCL 9 SDA

30 A6 27 A3

USB D

29 A5 26 A2

00 00000000 0 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000

Analog

ON

0

Volts

KNOB

0.000

OK

UART1

18

17

19

+5

20

RESET

LOW

1

2

SERVO

2 RxD1 3 TxD1

A

ZX-POTV

16

DC MOTOR

SW1

G 6V 12 G 6V 13 G 6V 14 G 6V 15

15 SV0 14 SV1 13 SV2 12 SV3

28 A4 25 A1

potentiometer to minimum position

24 A0

urn the shaft of

8 SCL 9 SDA

30 A6 27 A3

USB D

29 A5 26 A2

00 00000000 0 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000

Analog

ON

28 A4 25 A1

1023 Volts

KNOB

4.995

OK

UART1

16

18

17

19

+5

20

RESET

LOW

2 RxD1 3 TxD1

1

2

DC MOTOR

SW1

G 6V 12 G 6V 13 G 6V 14 G 6V 15 SERVO

15 SV0 14 SV1 13 SV2 12 SV3

24 A0

Turn the shaft of potentiometer to maximum position


IPST-MicroBOX [SE] Lab manual155

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. button or choose

6.2.2 Compile and upload the sketch to IPST-SE board by clicking on the at menu File > Upload to Wiring Hardware

A

ZX-POTV

Turn the shaft of potentiometer 30 A6 27 A3 29 A5 26 A2

00 00000000 0 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000

Analog control Switch

ON

28 A4 25 A1

108

OK SW1

+ S O

UART1

16

18

17

19

+5

20

RESET

LOW

2 RxD1 3 TxD1

Figure L6-2 : Connection diagram for practical 6-2

1

2

DC MOTOR

S

+

D

G 6V 12 G 6V 13 G 6V 14 G 6V 15 SERVO

15 SV0 14 SV1 13 SV2 12 SV3

24 A0

ZX-LED

KNOB

8 SCL 9 SDA

USB


156IPST-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 out(17,1);

",val);

// Show sensor data from pin A1

// 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

// Show sensor data from pin A1

out(17,0);

",val);

// 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 manual157

6.2.3 Turn the shaft of potentiometer on ZX-POT and see the operation at IPST-SE board and ZXLED 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.

A

ZX-POTV

Turn the shaft of potentiometer 30 A6 27 A3 29 A5 26 A2 28 A4 25 A1 ZX-LED

KNOB

00 00000000 0 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000

Analog control Switch

ON

SW1

+ S

ZX-POTV

18

17

19

+5

20

LOW

2

SERVO

2 RxD1 3 TxD1

RESET

1

DC MOTOR

S

O

UART1

16

G 6V 12 G 6V 13 G 6V 14 G 6V 15



420

OK

+

D

15 SV0 14 SV1 13 SV2 12 SV3

24 A0

LED is off

8 SCL 9 SDA

USB

A

Turn the shaft of potentiometer 30 A6 27 A3

00 00000000 0 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000

Analog control Switch

28 A4 25 A1

520

SW1

+ S S

O

UART1

16

18

17

19

+5

20

RESET

ON

G 6V 12 Number is changed G 6V to red color 13 G 6V 14 G 1 2 6V LOW 15

2 RxD1 3 TxD1

SERVO

15 SV0 14 SV1 13 SV2 12 SV3

29 A5 26 A2

ZX-LED

KNOB

OK

+

D

DC MOTOR

24 A0

LED is on

8 SCL 9 SDA

USB


158IPST-MicroBOX [SE] Lab manual

Practical 6.3 : Night switch controller This practical is extending from previously. Change the simple analog sensor from ZXPOT 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

or positive output of ZX-LDR module with pin A1of IPST-SE board

+

 Connect output

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

ZX-LDR

+

Light sensor

+

30 A6 27 A3

00 00000000 0 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000

Night Switch

ON

98

SW1

+ S S

O

UART1

16

18

17

19

+5

20

RESET

LOW

2 RxD1 3 TxD1

Figure L6-3 : Connection diagram for practical 6-3

1

2

G 6V 12 G 6V 13 G 6V 14 G 6V 15 SERVO

15 SV0 14 SV1 13 SV2 12 SV3

28 A4 25 A1 KNOB

OK

+

D

29 A5 26 A2

ZX-LED

LED is on if ZX-LDR's data is less than 100.

24 A0

Block the light not fall to LDR sensor to change the output voltage of ZX-LDR module

USB

DC MOTOR

Potentiometer

8 SCL 9 SDA

A

at menu File > Upload to Wiring Hardware


IPST-MicroBOX [SE] Lab manual159

#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

// Show raw data of sensor at pin A1

",val);

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

// Show raw data of sensor at pin A1

out(17,0);

",val);

// 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.

Listing L6-3 : NightSwitch.pde; the sketch file for Night switch controller application


160IPST-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 manual161

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.


162IPST-MicroBOX [SE] Lab manual

Temperature sensor; MCP9701 8 SCL 9 SDA

30 A6 27 A3

USB

29 A5 26 A2

00 00000000 0 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000 000000000000000000000

Digital THERMO METER

ON

28 A4 25 A1

26.740

KNOB

Celsius

OK

UART1

16

18

17

19

+5

20

RESET

LOW

1

2 RxD1 3 TxD1

2

DC MOTOR

SW1

G 6V 12 G 6V 13 G 6V 14 G 6V 15

15 SV0 14 SV1 13 SV2 12 SV3

24 A0

D

SERVO

Figure L7-1 : Connection diagram for practical 7 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.


IPST-MicroBOX [SE] Lab manual163

#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.

Listing L7-1 : MCP9701_Thermometer.pde; the sketch file of Micro-thermometer project. It is simple digital thermometer.



Turn static files into dynamic content formats.

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