sci-box2p_E120704

Page 1

SCi-B X Microcontroller in Science Experiment kit1

SCi-B X Microcontroller in Science experiment kit documentation


2SCi-B X Microcontroller in Science Experiment kit


SCi-B X Microcontroller in Science Experiment kit3

Chapter 1 Introduction to

SCi-B X

SCi-BOX is a universal programmable controller board that contain a small microcontroller and many relate input/output components. The figure 1 shows the operation diagram of SCi-BOX board and system. The heart of operation is i-Stamp2P24 based on BASIC Stamp2P OEM version. It is connected with the serial A/D processor to read the alalog data into system. i-Stamp2P24 will process and analyse to send the data to any actuator such as mechanical relays, DC motors, stepper motors and speaker. SCi-BOX will guide you as you build, program, test, and calibrate a multi-sensor environmental control system with a data logger. With this instrument you will measure ambient temperature, light level, magnetic field, voltage, resistance, current and detect the sound. You will monitor and maintain the temperature level in an area with a relay and temperature sensor. Feedback about the operation of the controller will be conveyed to you audibly with a piezo speaker and collected data will be displayed on your computer screen. Experimenters will be introduced to each subsystem one at a time, and integrate them in small steps.

RS-232 serial port (connected via P16)

Analog input connector SENSOR0 to SENSOR7. Convert to digital data and sent data to the main microcontroller by A/D conversion processor. Interface with serial signal

Programmable Digital Input/Output

P8-P11 P13

2-ch. DC motor drivers 4-ch. Mechanical relay drivers

i-Stamp2P24 BASIC controller rmodule

P0-P7

Figure 1-1 SCi-B X operation diagram

P14 P15 P12

2-ch. Stepper motor drivers. Operate with a serial stepper motor co-processor

Drive sound via Piezo speaker


4SCi-B X Microcontroller in Science Experiment kit

1.1 Technical features of SCi-BOX main board 1.1.1 Main controller  Controlled by i-Stamp2P24 (the OEM BASIC Stamp2P) with PBASIC programming  16KB EEPROM divide to 8 pages 2KB each and can access all pages in during working.

 10,000 PBASIC instructions per second speed  Connect RS-232 serial port for downloadings and communication

1.1.2 Input/Output  8-ch. Programmable digial input/output port  8-ch. Analog input. Maximum voltage input is +5V. The ADC Co-processor functions these inputs and interface i-Stamp2P24 with serial. Resolution of conversion is 10 bits. The value is 0 to 1,023.

1.1.3 On-board output components  4-LEDs indicator (connected to P8 to P11)  4-ch. Relay drivers shared with LED indicator and Motor driver circuit. Relay contact rating can support 220Vac 5A load. The coil voltage is +12V.

 2-ch. DC motor driver shared with LED indicator and Relay driver circuit. Support 6 to 12V DC motor.There are bi-color LED for indicated the operation. Select mode between relay and motor driver circuit by a jumper.

 2-ch. Stepper motor drivers serially interface with a Stepper motor Co-processor. Support +12V uni-polar stepper motor.

 Piezo speaker for sounding. The resonant frequency range is 1kHz to 3kHz.

1.1.4 Power supply  Apply the supply voltage to SCi-BOX via 2 points. One is DC jacl adapter. Another is a 2-pins terminal block. On-board provides the polarity voltage circuit for setting the internal polarity of supply voltage. It causes SCi-BOX board can work with any polarity of DC adaptor

 Wide range of the supply voltage input 9 to 16V. On-board +5V 500mA regulator circuit.


SCi-B X Microcontroller in Science Experiment kit5

1.2 Part list  SLCD16x2  DC adaptor 12V 500mA  Crocodile clip cable  Digital sensors and detectors include : Logic detection group (D group) Switch input board x 3 38kHz Infrared module board x 2 Signal Comparator board x2 RC time contstant measurement group (C group) Capacitance Instantaneous detection group (P group) Sound event detector

 Analog sensors (A group) include : Light detector (x 2) Light reflector (x 2) Temperature sensor (x 2) Magnetic field sensor Variable resistor (x 5) prepare 3 types. Vertical potentiometer (x 2) Horizontal potentiometer (x 2) Slide (x 1) Infrared detection by photo transistor (x 2) Current measurement board Resistance measurement board Voltage attenuator for voltage measurement board ; selectable 2 ratios.

 Output device (O group) include : Infrared LED board (x 2) Bi-color LED indicator board

 DC motor operating voltage 3 to 12V range  12V Uni-polar Stepper motor  Resistors and Capacitors for experiemnts 10 values and one piece per value.


6SCi-B X Microcontroller in Science Experiment kit

D5 1N5819

J1 DC INPUT 6-16V.

+V

S1 POWER ON / OFF

C5 220/16V

D6 1N4001

K1 BATT. INPUT

C2 0.1/63V D1-D4 1N4001 x4

STEPPER MOTOR #1

C4 0.1/63V

IC1 LM2940CT -5.0

+5V

PHASE A to D COIL

R1 510

C3 47/16V

D

C

B

C1 470/25V

C6 0.1/63V

1 2 3

6

5

4

3

2

1

TxD RxD MCLR

S2 RESET

IC2 i-Stamp2P24

K9 SENSOR6

5 AN2

K8 SENSOR5

+5V

6

K7 SENSOR4

+5V

7 AN0

GP3 GP5

Q4 BC557

C12 1/50V

R3 10k

2

18

P15 P14 P12

K5 SENSOR2

+5V

5 AN2

K4 SENSOR1

+5V

6

K3 SENSOR0

+5V

7 AN0

IC4 QP410

AN3

P8 P9

AN1

GP5 2

GP3

4

5

CR1 4MHz

SER IN 6

+5V

+5V 3

BUSY 7

P13

IC3 QP410

1

4

NXP2220S-SMC

GND 10

R2 150

8

+5V

1D 1C 1B 1A 2D 2C 2B 2A +Vcc IC5

+5V

4

AN1

K6 SENSOR3

20

1 RST

C10 0.1/63V

AN3

19 18 17 16 12 13 14 15

C11 0.1/63V

R13 10k

1

+5V

P10 R4 150

P11

17

K21 MOTOR-A C13 10/16V

13

SP1 PIEZO

14 16

MOTOR-A #1

2

MOTOR-A #2

7

11

IC8/4

1

K18 P7 K17 P6

+5V

R11 220

K16 P5

+5V

R10 220

K15 P4

+5V

R9 220

9

K14 P3

+5V

R8 220

8

K13 P2

+5V

R7 220

K12 P1

+5V

R6 220 R5 220

11 10

7 6 5

P7

8

9

10 1 2

IC8/1

IC8/3

5 4

1Y 3

2A

2Y

4Y 3Y

16

14 11

R16 2k2

9

+

13 12 5

P3 K23 P8 RELAY NO C 9

P0 1 3 5 7

D0 Q0 D1 Q1 D2 Q2 D3 Q3

16

R24

14

R23

12

R22

10

R21 R21-R24 47 x4

R17

R18

R19

R20

8

R17-R20 510 x4

LED7 LED6 LED5 LED4 P11 P10 P9 P8

Figure 1-2 SCi-B X schematic diagram

IC9 ULN2003

+

C15 0.1/63V

34EN

K22 MOTOR-B

4

DIRECT

DC MOTOR

JP1 DRIVER SELECT

P1

INVERT

Vcc1

P4

RY1 RELAY 12V

LED2 DIR. #A LED3 DIR. #B

6

IC8/1-IC8/4 : 74HC32

P2

+ DIRECT

6

12EN

3A

INVERT

+

R15 2k2

3

IC8/2

P6 P5

1A

15 4A

MOTOR-B #2 10

12

C14 0.1/63V

IC7 L293DNE

15

MOTOR-B #1

+5V

R14 10k

19

12 13

R12 220

+5V

R15 10k

20

8

K11 P0

7

C8 0.1/63V

C7 0.1/63V

+5V

+5V

IC6 ULN2803

9

+5V

+5V

3

A

RN1 2k2 *8

23

K10 SENSOR7

B

11 12 13 14 15 16 17 18 10

+V

8

C9 0.1/63V

C

K20 STEPPER MOTOR #2 CONNECTOR

4

K2 DOWNLOAD DB-9 FEMALE

D

K19 STEPPER MOTOR #1 CONNECTOR +5V

2 3 4 5

PHASE A to D COIL

A

LED1 POWER

21

6 7

STEPPER MOTOR #2

+V RELAY

K24 P9 RELAY NO C

K25 P10 RELAY NO C

K26 P11 RELAY NO C


SCi-B X Microcontroller in Science Experiment kit7

Serial port connector DC jack and terminal

Piezo speaker

POWER switch

i-Stamp2P24 SENSOR0 to SENSOR7 connector for connect with all analog sensors

Connect to stepper motor

P0 to P7 connector

LED indicators

Relay/DC motor driver jumper selection

i-Stamp2P24 port assignment on

Connect to DC motor Relay contact terminal

SCi-B X

P0 to P7 : Programmable general purpose input/output port to interface Serial LCD and Digital sensors (D group) P8 to P11 : LED indicator, 4channels relay driver circuit and DC motor driver circuit (P8 and P9, P10 and P11) selected by jumper P12 : Connect to Piezo speaker P13 : Connect to ADC co-processor for reading SENSOR0 to SENSOR7 input P14 and P15 : Connect to Stepper motor co-processor for driving stepper motor 2 channels; P14 as Data pin and P15 as Status pin

Figure 1-3 SCi-B X board layout


8SCi-B X Microcontroller in Science Experiment kit

1.3 SCi-BOX testing 1.3.1Install SCi-BOX Activity software. Put SCi-BOX CD-ROM into CD-ROM drive and find SCiBOX2P_Setup.exe. Double click, the first setup window will appear. Click Next button

1.3.2 Click on the Next or OK button in each installation steps until the installation is completed. Click on the Finish button to finish installation.


SCi-B X Microcontroller in Science Experiment kit9

Figure 1-4 The main window of SCi-BOX Activity software 1.3.3 Run the SCi-BOX Activity software by enter Start  Program Sci-BOX  SciBOX Activity. The main window following the figure 1-4 will appear. 1.3.4 Install i-Stamp2P24 on the main board following the figure 1-5.

Install i-Stamp2P24 onto the blank 24-pin socket. Must install in the correct direction. Do not install overlap. However the default setting from manufacturer will fit the i-Stamp2P24 ready to use.

Figure 1-5 Show the fitting i-Stamp2P24 on the main board


10SCi-B X Microcontroller in Science Experiment kit

1.3.5 At the orange circle #1 on the SCi-BOX Activity window, select AT07-Switch.

1.3.6 Connect the Switch input board to P1port on the SCi-BOX. 1.3.7 Select RELAY/MOTOR jumper to RELAY 1.3.8 Connect SCi-BOX to COM1 of computer or another. If computer has only USB, the USB to RS-232 serial port converter is required (UCON-232S is recommended). Connect to computer's COM port

Female DB-9 connector 6 7 8 9 1 2 3 4 5

DB-9 female side

DB-9 male side

9-wires multicore cable RS-232 DOWNLOAD

1 2 3 4 5

DC INPUT RESET

i-Stamp OFF

SCi-BOX

6 7 8 9

ON

BASIC Stamp in Science Experiment

Male DB-9 connector


SCi-B X Microcontroller in Science Experiment kit11 1.3.12 Apply the supply voltage to SCi-BOX. 1.3.13 Click Download button. The download window appears. Siftwarte will find COM port that connected SCi-BOX hardware automatically. After finish, click OK button.

l.3.14 Press knob on the switch. Observe operation of LED indicator at P8 to P11 and listen sound of relay’s contact operation following switch pressing. If all correct, all LED will off. Press switch first time, LED at P8 will be on and P8 relay active. Press switch second time, LED at P9 and relay active. The operation will be sequence from P8, P9, P10, P11 and return to P8 again.

Now, your SCi-BOX ready to works and enter the applied science project creation.


12SCi-B X Microcontroller in Science Experiment kit

1.4 SCi-BOX with USB to RS-232 converter Normally the SCi-BOX operates with COM port of computer. But the modern computer will available only ISB port. Thus, the USB to RS-232 port converter is recommeded device. The converter that is recommended for Sci-BOX board is UCON232S (www.inexglobal.com).

(a) UCON-232S : the USB to RS-232 port converter

(b) Using the UCON-232S with CX-232 serial port cable

Figure 1-6 The UCON-232S USB to RS-232 port converter


SCi-B X Microcontroller in Science Experiment kit13

1.4.1 UCON-232S driver installation (1.4.1.1) Fine the driver installation file; InstallParallaxUSBDriversv2.08.02.exe in SCiBOX CD-ROM then double click to run this file. Click on the Install button to start the driver installation.


14SCi-B X Microcontroller in Science Experiment kit

1.4.2 UCON-232S interfacing with SCi-BOX (1.4.2.1) Plug the UCON-232S with USB port of the computer. Then, connect the CX232 serial cable that bundled with SCi-BOX between DB-9 connector of UCON-232S and SCi-BOX board.

UCON-232S

connect to USB port of the computer

CX-232 : the standard serial cable +12V 500mA adaptor

DB-9 male side RS-232 DOWNLOAD DC INPUT RESET

ON

SCi-BOX i-Stamp2P24

OFF

BASIC Stamp in Science Experiment

(1.4.2.2) Wait a moment. Computer will connect with UCON-232S. Wait until the blue LED of UCON-232S is on. It indicates now computer interface with this device already. (1.4.2.3) Check the USB serial port that occured from driver by clicking the Start button and select to Control Panel > System > Hardware > Device Manager


SCi-B X Microcontroller in Science Experiment kit15 (1.3.2.6) Check the listing at Port. The USB Serial port is appeared. Note the number of COM port of USB serial port. Normally, it is COM3 or higher. This port number is very important. It is used to set in the SCi-BOX software and BASIC Stamp editor software for interfacing and downloading with SCi-BOX board.

However all software that working with SCi-BOX board can find the connected poer automatically. But may need time to scan all ports.

COM1 and COM2 is ordinary serial port of computer. Some computer has not this COM port

COM121 is the USB serial port or Virtual COM port that created by USB to RS-232 port converter driver


16SCi-B X Microcontroller in Science Experiment kit

1.5 Regulations 1.5.1. Turn-off POWER switch before remove and re-connect the serial port cable. 1.5.2 Turn-off POWER switch before remove and re-connect the sensor or actuator with SCi-BOX.

Both regulations are very important. User must do strickly to protect iStamp2P24 damaged from electric shock during remove and re-connect any cables. 1.5.3 Do not touch the heatsink at the right side of SCi-BOX board. Because it handle some heat from normal operation. 1.5.4 If any error occur, must turn-off POWER switcxh suddenly. 1.5.5 Do not use DC adaptor that output over +16Vdc witn SCiBOX board. 1.5.6 After all finished, remove all cable from SCi-BOX board include DC adaptor.


SCi-B X Microcontroller in Science Experiment kit17

Chapter 2 Output device in

SCi-B X

In SCi-BOX kit contains many types of output device to indicate result or monitor the operation. This chapter will describe the summary technical informations.

2.1 LED indicator On main board of SCi-BOX preapre 4 LED indicators. They can active with logic “High” or “1” and are drived with P8 to P11of i-Stamp

i

Introducing the 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. 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.

A

K

(A) LED symbol

Cathode

Anode

(B) LED structure

The suitable current that LED need is 10 to 20mA.

R1

Limit-current resistor (RS)can assgin by formula below :

Vcc  VF RS  IF Vcc is Supply voltage, VF is forward bias voltage cross LED and IF is forward bias current If apply the reverse bias, LED will not work and damage. Because LED can hold the reverse bias voltage in range 3 to 10V only.

Vs

LED1

+

I1

(C) Connect the serial resistor to limit current for LED


P9

P8

P2 P1

MOTOR P14, P15 : STEPPER MOTOR CONTROL

Between relay driver circuit and DC motro driver operaion, user must select only one in a moment by a jumper RELAY/MOTOR.

P0

SENSOR1 SENSOR0

Stepper motor Co-processor

SENSOR2

RELAY

RELAY 12V 5A

RELAY 12V 5A

RELAY 12V 5A

RELAY 12V 5A

STEPPER MOTOR1 STEPPER MOTOR2

P11 RELAY P10 RELAY

P9 RELAY

P8 RELAY

MOTOR A

B

INV-A

INV-B

P8-P9 MotorA P10-P11 MotorB

SENSOR3

P11 P10

P3

18SCi-B X Microcontroller in Science Experiment kit

About LED indicator, can conrtrol directly and active together with the driver circuit.

Figure 2-1 Shows output devices area on SCi-B

d Xmain board

2.2 12V Relay driver

P8 RELAY

MOTOR

P0

Fit jumper at RELAY position to select Relay driver circuit

LED at P8 to P11 will be active following the operation of each relay, such as If P8 RELAY activated P8 LED will on too. P2

P9

P1

P11 P10

P3

Sci-BOX board provides 4 relay drivers. Their contact rating can support 220Vac 5A load. Control with P8 to P11 of i-Stamp shared with DC Motor driver and LED indicator.

RELAY 12V 5A

P11 RELAY P10 RELAY

RELAY 12V 5A

P9 RELAY

RELAY 12V 5A

P8 RELAY

MOTOR A

B

INV-A

INV-B

P8-P9 MotorA P10-P11 MotorB

RELAY 12V 5A

Relay contact works equivalent as switch

Figure 2-2 Shows the selection of Relay driver circuit on SCi-B

d Xmain board


SCi-B X Microcontroller in Science Experiment kit19

i

Relay is a signal-actuated switching device. In most instances, a relatively weak current or voltage is used to make the relay switch a higher current or voltage. A relay can be electromechanical or fully electronic (no moving parts). Relay consist of Coil and Contact. The contact has 2 types; NC (Normally Closed) and NO (Normally Opened). In operation, apply the suitable voltage to relay’s coil. It

contact NC

coil

C NO

will be active and contact will change from NC to NO similar SPDT (single-pole double-throw) switch.

NC

NC

+V

+ -

C

+ -

+V

C NO

NO

Relay does not works

Relay works

2.3 DC motor driver SCi-BOX can drive DC motor 2 channels. The maximum rating is 12V 500mA. Assign P8 and P9 to control DC motor driver circuit channel A, P10 and P11 to control DC motor driver circuit channel B. Bi-color LED are used for indicate the DC motor voltage pole. If Red color on, it means apply the reverse pole voltage to DC motor. But Green LED will indicated the correct pole voltage to DC motor. The voltage pole that applied to DC motor is important to show the motor operation as : Motor A P8 0 1 0 1

P9 1 0 0 1

Motor B P10 P11 0 1 1 0 0 0 1 1

Motor operation Invert (LED indicate Red color) Direct (LED indicate Green color) Free (LED off and motor shaft free. Easy to turn by hand Lock (LED off but motro shaft will lock. Difficult to turn by hand Motor operation Invert (LED indicate Red color) Direct (LED indicate Green color) Free (LED off and motor shaft free. Easy to turn by hand Lock (LED off but motro shaft will lock. Difficult to turn by hand


20SCi-B X Microcontroller in Science Experiment kit

2.4. Stepper motor driver SCi-BOX can drive uni-polar stepper motor 12V 500mA maximum 2 channels by using P14 and P15 of i-Stamp. The heart of this circuit is Stepper motor Co-processor. It receives serial data from P14 of i-Stamp. Thus, call this pin as SERIN. After that this processor will pprocess data and send signal to drive the stepper motor. During the STepper motor Co-processor working in process, it sends signal back to iStamp at P15 for informing in-process not cannot get any data from i-Stamp. Call this pin as BUSY. Baudrate of this interface is 9,600 bit per second. Data is 8 bits and none parity. Everytime i-Stamp send data to porcessor, it will send BUSY siganl in logic “0” back to iStamp. i-Stamp will polling until BUSY line set to high. It can send the new data following.

Stepper motor basic Stepper motors differ from standard DC motors in that they do not spin freely when power is applied. For a stepper motor to rotate, the power source must be continuously pulsed in specific patterns. The step sequence (pattern) determines the direction of the stepper’s rotation. The time between sequence steps determines the rotational speed. Each step causes the stepper motor to rotate a fixed angular increment. The stepper motor supplied with SCi-BOX kit rotates 7.5 degrees per step. This means that one full rotation (360 degrees) of the stepper requires 48 steps. PHASE 4

PHASE 4

+V PHASE 3

PHASE 3

PHASE 2

PHASE 1

PHASE 2 +V PHASE 1

+V

Step

Phase-4

Phase-3

Phase-2

Phase-1

Step

Phase-4

Phase-3

Phase-2

Phase-1

1

0

0

0

1

1

1

0

0

0

2

0

0

1

0

2

0

1

0

0

3

0

1

0

0

3

0

0

1

0

4

1

0

0

0

4

0

0

0

1

(A) Step data in Left rotation

(B) Step data in Right rotation

Table P2-1 Sequence operation of stepper motor’s coil in 1-phase full step driving


SCi-B X Microcontroller in Science Experiment kit21

2.5 Bi-color LED board : LED

(connect to P0-P7)

This output board use bi-color LED for indicator. It can indicate 2 types : HIGH If apply the input signal at this point with logic “1”, LED indicates Red. LOW

If apply the input signal at this point with logic

O

220

Apply logic "0" to this point, LED indicates Green. Apply logic "1" to this point, LED indicates Red.

LOW

S

+

R

LOW

LED

O

HIGH

“0”, LED indicates Green.

G

Bi-color LED

Step

Phase-4

Phase-3

Phase-2

Phase-1

Step

Phase-4

Phase-3

Phase-2

Phase-1

1

1

0

0

1

1

1

1

0

0

2

0

0

1

1

2

0

1

1

0

3

0

1

1

0

3

0

0

1

1

4

1

1

0

0

4

1

0

0

1

S

HIGH

LED

+

(A) Step data in Left rotation

(B) Step data in Right rotation

Table P2-2 Sequnce operation of stepper motor’s coil in 2-phase full step driving Step

Phase-4

Phase-3

Phase-2

Phase-1

Step

Phase-4

Phase-3

Phase-2

Phase-1

1

1

0

0

1

1

1

0

0

0

2

0

0

0

1

2

1

1

0

0

3

0

0

1

1

3

0

1

0

0

4

0

0

1

0

4

0

1

1

0

5

0

1

1

0

5

0

0

1

0

6

-

1

0

0

6

0

0

1

1

7

1

1

0

0

7

0

0

0

1

8

1

0

0

0

8

1

0

0

1

(A) Step data in Left rotation

(B) Step data in Right rotation

Table P3 Sequnce operation of stepper motor’s coil in half-step mode


22SCi-B X Microcontroller in Science Experiment kit

2.6 Infrared LED board : Infrared LED

(connect to P0-P7)

 A 3mm. Infrared LED and limit current resistor  Drive with logic HIGH TTL level  2-mode operations : Continuous drive This mode IR-LED will receive forward bias to drive infrared ray. Works with ZX-117 Photo-transistor sensor board for measuring rthe infrared light density. Frequency drive This mode will modulated 38kHz carrier frequency into IR-LED operation. Work with ZX-106 (or ZX-05) 38kHz IR module to detect infrared signal.

S +

Infrared LED

150

2.7 Serial LCD 16x2 : SLCD16x2 SLCD16x2 is the 16 characters 2 lines LCD module that communication by serial interface. It received data serially and display on the LCD. Accept serial data at 2400 or 9600 baudrate and accept either TTL or RS-232 level, by 2 jumpers select. Support on standard LCD controller HITACHI HD44780 or SEIKO EPSON SED1278 compatible. Both 1/8 Duty and 1/16 Duty of 1x16 LCD Module can be used by jumper selection too.

2.7.1 Features  Serial Input RS-232 or Invert/Non-invert TTL/CMOS logic level.  1/8 or 1/16 Duty can be selected by jumper.  Scott Edwards's LCD Serial Backpack ® com mand com patibl e

addition with Extended

Command that make LCD control easier.  Easy to interface with microcontroller  Operation with +5 to 12 Vdc supply

(connect to P0-P7)


SCi-B X Microcontroller in Science Experiment kit23

LCD Module connector attachment 1x14 or 2x7 pin type

BRIGHTNESS Control

14 CONNECTOR 14 PIN

1

INPUT

GND

+ S G

BRIGHTNESS

DI IN

16 8

24 96

NXP1008S-LCD

ST EX

14

CONNECTOR 2x7 PIN

1

darker

SERIAL INPUT +Vcc

(c) 2000 Innovative Experiment

Extended Mode Command

1/8 Duty LCD Module

Baudrate 9600 bps

Invert TTL/CMOS or RS-232

Standard Mode Command

1/16 Duty LCD Module

Baudrate 2400 bps

Direct Logic TTL/CMOS Level

2.7.2 Data and Command sending Once SLCD16x2 is properly connected and configured. Data and command can be send serially. For data sending, user can send any message such as "Hello" via serial I/ O directly, "Hello" message will be shown on your LCD. For command sending, you can send standard instruction set to LCD (see Figure C) by precede it with the instruction prefix character, ASCII 254 (0FE hex or 11111110 binary). SLCD16x2 treats the byte immediately after prefix as an instruction, then automatically returns to data mode. An example: To clear screen on LCD, clear instruction is 00000001 binary (or ASCII 1), send [254] and [1] to SLCD16x2 (where parentheses in [ ] symbols mean single bytes set to these values) COMMAND\DATA BIT

D7

D6

D5

D4

D3

D2

D1

D0

1. Initial LCD

0

0

0

0

0

0

0

0

2. Clear LCD

0

0

0

0

0

0

0

1

3. Returm Home

0

0

0

0

0

0

1

*

4. Entry Mode Setting

0

0

0

0

0

1

I/D

S

5. Display Setting

0

0

0

0

1

D

C

B

6. Shift Display

0

0

0

1

S/C

R/L

*

*

7. Function Setting

0

0

1

DL *

N

F

*

*

8. Set CGRAM Address

0

1

A5

A4

A3

A2

A1

A0

9. Set DDRAM Address

1

A6

A5

A4

A3

A2

A1

A0

* S

0=Automatic cursor shift after byte 1=Cursor not moved I/D 0=After byte, decrease cursor position 1=After byte, increase cursor position (when S=1, cursor won't be shifted .) D C B

0=Display OFF, 1=Display ON 0=Cursor OFF, 1=Cursor ON 0=Cursor not blink, 1=Cursor blink

S/C R/L

0=Cursor shift, 1=Display Shift 0=Left shift, 1=Right shift

N

0=1/8 Duty, 1=1/16 Duty (not recommend to set this bit, use jumper setting instead) 0=5x7 dot size, 1=5x10 dot size

F

Standard instrction command set summary (except Initial LCD is addition command. Initialize make I/D=1, S=0, D=1, C=0, B=0, N=1, F=0, DDRAM Address=00

Don't care bit

A0 to A7 are CGRAM or DDRAM Address

Serial input timing diagram SERIAL INPUT

Start

D0

D1

D2

D3

D4

D5

D6

D7

Stop

TP (Processing time) TP MIN = 5 ms.

Start

D0

D1

D2

...


24SCi-B X Microcontroller in Science Experiment kit

2.7.3 LCD Characters Most of the LCD characters (Figure E) cannot be changed because they are store in ROM. However, the first eight symbols, corresponding to ASCII 0 through 7, are store in RAM. By Writing new values to the character-generator RAM (CGRAM), you can alter these

*See note

characters as you want in 5x8 dots size.

LCD character set. (Built-in character on HD44780A or SED1278F0A)

Create your symbols by point to the CGRAM location, then write first line whose bits form the desired pattern, and point to next CGRAM address to write bits later. Repeat this procedure until 8 times (one character), your character is ready to use now. CGRAM 0 is located on CGRAM Address 00h-07h, CGRAM 1 on 08h-0Fh, CGRAM 2 on 10h-17h, ...until CGRAM 7 on 38h-3Fh. See figure below Defining custom symbols. Example: Load arrow symbol on CGRAM 3, a program would send the following bytes to the SLCD controller. [254] , [254] , [254] , [254] , [254] , [254] , [254] , [254] ,

[01011000 [01011001 [01011010 [01011011 [01011100 [01011101 [01011110 [01011111

b] b] b] b] b] b] b] b]

, , , , , , , ,

[0] , [4] , [2] , [31] , [2] , [4] , [0] , [0]


SCi-B X Microcontroller in Science Experiment kit25

2.7.4 Extended your command with Extended mode. You can control your LCD easier by using Extended Mode Command (to enable this mode, set first left jumper to " EX " position), In this mode,instruction prefix had no needed. Extended command has shown in text below.

ASCII 128

Instruction / Action Initial LCD

ASCII 142

Instruction / Action Write CGRAM 0 ( *See note)

129

Clear Screen

143

Write CGRAM 1

130

Return Home cursor

144

Write CGRAM 2

131 132

Cursor not move after byte (S=1) Cursor increase after byte (I/D=1)

145 146

Write CGRAM 3 Write CGRAM 4

133

Cursor decrease after byte (I/D=0)

147

Write CGRAM 5

134 135

Display ON (D=1) Display OFF (D=0)

148 149

Write CGRAM 6 Write CGRAM 7

136

Display ON with Cursor on

150

Set DDRAM to 00h

137

Display ON with Blink Cursor on

151

Set DDRAM to 10h

138 139

Shift Cursor to left Shift Cursor to right

152 153

Set DDRAM to 14h Set DDRAM to 20h

140

Shift Display to left

154

Set DDRAM to 40h

141

Shift Display to right

155

Set DDRAM to 50h

156

Set DDRAM to 54h

Note. For CGRAM write command (ASCII 142 - 149) , Program would send 8 bytes whose bits form the desired pattern follow the command. Example: If you want to load arrow symbol as above of this page on CGRAM 3, a program will be to use modified in extended mode as: [145] , [0] , [4] , [2] , [31] , [2] , [4] , [0] , [0].


26SCi-B X Microcontroller in Science Experiment kit

Something to know about LCD module Character LCD m odul es are avail abl e in a wide variety of configurations: one-line, two-line, and four-line are very common. The number of columns (characters) per line is also variable, with 16- and 20- character displays being the most common and popular.

Initialization The character LCD must be initialized before displaying characters on it. The projects that follow initialize the LCD in accordance with the specification for the Hitachi HD44780 controller. The Hitachi controller is the most popular available and many controllers are compatible with it. When it doubt, be sure to download and examine the driver documentation for an LCD that does not work properly with these programs.

Modes of Operation There are two essential modes of operation with character LCDs: writing a character on the LCD, and sending a command to the LCD (to clear the screen, for example). When sending a character, the RS line is high and the data sent is interpreted as a character to be displayed at the current cursor position. The code sent is usually the ASCII code for the character to be displayed. Several non-ASCII characters also are available in the LCD ROM, as well as up to eight user-programmable custom characters (store in an area called CGRAM). Commands are sent to the LCD by taking the RS line low before sending the data. Several standard commands are available to manage and manipulate the LCD display. Clear

$01

Clears the LCD and moves cursor to first position of first line

Home

$02

Moves cursor to first position of first line

Cursor Left

$10

Moves cursor to the left

Cursor Right $14

Moves cursor to the right

Display Left

Shifts entire display to the left

$18

Display Right $1C

Shifts entire display to the right

i


SCi-B X Microcontroller in Science Experiment kit27

Chapter 3 Digital sensors in

SCi-B X

Digital signal will concentrate at voltage level as Logic “High” and “Low”. Logic “High” in TTL level is voltage level over 3.8V to 5V, for CMOS is 2/3 Vcc and upper. Logic “Low” in TTL level is voltage level under 1V and near gorund or 0V, for CMOS is 1/3Vcc and lower. The digital sensors and detectors in SCi-BOX kit give the output in digital logic. SCiBOX kit has 3 groups of digital sensors and detectors as : 1. Logic detection group (D group) includes Swithc intput board (SWITCH), 38kHz Infrared receiver m odul e board (IRM ) and Signal Com parator board (COMPARATOR). 2. RC time constant measurement group (C group) includes Capacitance board. 3. Instantaneous detection group (P group) includes Sound event detector (SOUND)

3.1 Logic detection board 3.1.1 Switch input board : SWITCH

(connect P0 to P7)

It has a push-button switch and bi-color LED indicator. Output 2 types as : HIGH

Output is logic “High” and LED indicates Red color.

LOW

Output is logic “Low” and LED indicates Green color.

Not press

LED off. The logic output will invert.

LOW

Out logic "Low" or "0" LED indicates Green.

HIGH

Out logic "High" or "1" LED indicates Red.

SWITCH

510

10k

S

LOW

S

HIGH

+

D

SWITCH

+

D

R

G

Bi-color LED


28SCi-B X Microcontroller in Science Experiment kit

D

Sensitivity (5dB per box)

3.1.2 38kHz Infrared Receiver module board (connect P0 to P7) INFRARED RECEIVER

38kHz OUT IRM GND

S

+ +V

38kHz Infrared receiver module

0.1/50V 18 22 26 30 34 38 42 46 50 54 58

Frequency (kHz)

This module is used to detect infrared signals carried by the 38kHz carrier frequency.

The heart component is TSOP4838 miniaturized receivers for infrared remote control systems. PIN diode and preamplifier are assembled on lead frame, the epoxy package is designed as IR filter. The demodulated output signal can directly be decoded by a microprocessor. TSOP4838 is the standard IR remote control receiver, supporting all major transmission codes. Outs logic “1”

does not detect the 38kHz frequency with the infrared light.

Outs logic “0”

detects the 38kHz frequency.

3.1.3 Signal Comparator : COMPARATOR (connect P0 to P7) This board compares the voltage level between input A and B. Output is logic “Low” and indicator. It has 2 outputs; A>B and B>A Limitation : Voltage level at both input must not over 3.5V

3

A>B RED

A

S

+

Input 3.5V max.

A>B

S

5

B

510

B>A GREEN

6

7 4

A B

S

1

A>B

LM393

B>A

Active Low output

D

B>A

8

A

S

2

+

+

B

COMPARATOR Outs logic "0" when A > B

+

D

Outs logic "0" when B > A


SCi-B X Microcontroller in Science Experiment kit29

3.2 RC time constant measurement board 3.2.1 Capacitance measurement board : CAPACITANCE (connect P0 to P7) This board use to measure capacitance in Farad unit by RC time constant technique.

+5V.

ST=0 10k

Opeartion of ST=0 point

If connect this point, measure RC time constant from PORT charging voltage 0 to 1.5V means 33.3% charge of voltage

C unknown

Discharge methode : Apply 0V to PORT pin GND

+5V.

C unknown

10k ST=1

Opeartion of ST=1 point

If connect this point, measure RC time constant from PORT charging voltage 5 down to 1.5V means 66.7% charge of voltage GND

Discharge methode : Apply +5V to PORT pin


30SCi-B X Microcontroller in Science Experiment kit

3.3 Instantaneous detection board 3.3.1 Sound event detector

(connect P0 to P7)

 Detect the sound level changing.  Output is pulse following the sound moment

R1 22k

C2 0.1uF/50V

3 R2 2 100k

+ IC1/1

R6 1k

1

R5 68k 6

8

+

5

IC1/2

-

-

4

R7 12R 7 C3 22uF S

+

MIC1

C1 470uF/16V

R4 R3 100k 1k

IC1 : MCP6002

The main transducer of this sensor board is a condenser microphone. If the souund pressure fall to the diaphram of microphone, it will change sound pressure to electric signal. The signal will coupling to simple amplifier circuit. It will amplify and drive the output signal to the output connector. Output signal of this sensor is digital pulse. Output level is 0 and +5V. If cannot detect sound, output will be logic “0”. If detect, output will be logic “1” This sensor cannot give the result in level. It can inform the sound detection event by digital signal only. Suitable for sound detector application, burgar alarm, sound activated switch. User can connect this sensor with any microcontroller into the digital input port. Note : For BASIC Stamp microcontroller family will suggess to use PULSIN command to detect the output of this sensor.


SCi-B X Microcontroller in Science Experiment kit31

Chapter 4 Analog sensors in

SCi-B X

Heart of interfacing microcontroller with Science experiment is the signal conversion processing. It has 2 main process as 1. Sensing or Detection and convert science signal to electrical signal or analog signal. 2. Analog to digital conversion (ADC). First process, the important component is sensor. Its function is convert physical quantities to electrical quantities such as Microphone converts voice or sound to voltage. Thermister detects temperature for changing to electrical resistance. Hall effect sensor detects magnetic field to voltage. LDR detects ambient light and change to electrical resistance. In second process, ADC is electronic circuits that get analog signal normally as voltage to convert to digital data. The important feature is conversion resolution. The suitable resolution for science experiment is 8-bit or higher. In SCi-BOX kit has more analog sensors for coverage all science quantities as : 1. LDR Light sensor 2. Light reflector 3. Temperature sensor 4. Magnetic field sensor 5. Variable resistor : Potentiometer in vertical and horizontal use to angular measurement and Slide for distance measurement 6. Photo-transistor for Infrared light detection 7. Current measurement board 8. Resistance maresurement board 9. Voltage attenuator for voltage measurement board Interfacing of all analog sensor with SCi-BOX main board can connect to SENSOR0 to SENSOR7 points. User can test the operation and learn about sensor’s behavior without programming by SCi-BOX Activity software and with programming by BASIC Stamp Editor software.


32SCi-B X Microcontroller in Science Experiment kit

4.1 LDR Light sensor

(connect SENSOR0 to SENSOR7)

Detect the ambient light density with LDR (Light dependent resistor)

2-output selections :

+

Output voltage increase will lights up Output voltage decrease will lights up

+

A

Reverse variation output

LIGHT

A

Light detected more, voltage decrease

+

Direct variation output

S

10k

+

+

LDR Light

Light detected more, voltage increase

+

LDR

S

+

4.2 Light reflector : REFLECT

(connect SENSOR0 to SENSOR7)

Includes the super bright LED to light source and LDR for light detection. Both install at thew suitable position. Red light will reflect from any sirface back to LDR. Voltage accross LDR is used to output. The output of this sensor is direct variation ratio. If LDR can detect more light, otuput voltage will increase. A

Direct variation output Super bright red LED

Light reflects more, output voltage increase.

REFLECT Red LED super bright

10k S

+ REFLECT

+

LDR detects the light reflects from surface

LDR

Light reflector sensor LED light source LDR detects light reflect

220


SCi-B X Microcontroller in Science Experiment kit33

4.3 Temperature sensor

(connect SENSOR0 to SENSOR7)

S

10k

Temperature high Voltage increase

+

Temperature high Voltage decrease

+ + S

T

+

Detect the air temperature with NTC thermister. 2-output selections :

+

Output voltage increase will temperature increase Output voltage decrease will temperature increase

This sensor is analog type. It can supply the output voltage relate with temperature. User can select 2 output format. The heart of this detector is thermistor NTC type (Negtive Temperature Co-efficient) Normally Thermistor’s resistance will define at 25 C degree (see the characteristic graph below). When the temperature increase, its resistance will be decrease. This detector’s circuit is applied to give 2 outputs.

Thermistor that use in Temperature detector. Its resistance at room te m p e ra ture (25ðC) is equal 10k


34SCi-B X Microcontroller in Science Experiment kit

4.4 Magnetic field sensor

(connect SENSOR0 to SENSOR7)

This sensor board use UGN3503 a 3 A Hall-effect sensors accurately track extremely small changes in magnetic flux density—changes generally too small to operate Hall-effect switches. Output is DC voltage relate magnetic filed density. If no magnetic field or 0 Gauss, output voltage is middle point at 2.5V. In case magnetic field direction is out from the point at

UGN3503

back package of UGN3503, the voltage output from its will increase. In case magnetic field direction is rush to the point at back package of UGN3503, the voltage output from its will decrease. The changing ratio is 1.3V per 1 Gauss. The voltage output can calculate following this formula : Vout = 2.5 + (0.0013 x Magnetic field densitiy in Gauss unit)

+V 0.1/50V GND

S

UGN3503 Hall-effect sensor

Magnetic field

+

A

Vout

This is the reference point for magnetic field density direction. The direction that out from this point causes the output voltage of sensor increase from middle point.

A

Magnetic Field

+Vcc GND Vout


SCi-B X Microcontroller in Science Experiment kit35

U GN3503

N

N S

The direction of magnetic field density is positive. Output voltage is higher +2.5V.

S

U GN3503

The direction of magnetic field density is negative. Output voltage is lower +2.5V.

Figure 4-1 Shows the operation of UGN3503 when detect the different direction of magnetic field density.

4.4.1 Calculation of UGN3503U Refer the output voltage of UGN3503, can calculate to find the magnetic field density. The result is linear approximation. The reference is magnetic field density 0 G (Gauss) equal 2.5Vdc. Every voltage changing at 1.3mV means the magnetic filed density change 1 G. Summary of this relation can show as : BG 

By

Vout  2 . 5 0 . 0013

................................................................. (4.1)

B is Magnetic filed density in Gauss unit Vout is Output voltage from UGN3503U

In data conversion, can calculate magnetic field density in term of digital data as BG 

By

Aout

 Ainit   5    ....................................................... (4.2)  255  0. 0013

Ainit is Digital data from voltage value of UGN3503 when does not effect

from magnetic filed. This value get from testing. Aout is Digital data from voltage value of UGN3503 in anytime. The direction of magnetic filed that UGN3503 detected is important. It is used to specific pole of magnetic filed density. If direction rush to sensor, the value will be positive. If direction out from sensor, the value will be negative. The symbol represents the direction of magnetic filed only not effect to magnetic field density value. If bring a permanent magnet close up to front of UGN3503, read the value from conversion as positive. It means pole of magnet near sensor is north pole. Otherwise, the value is negative. It means pole of magnet near sensor is south pole.


36SCi-B X Microcontroller in Science Experiment kit

4.5 POTENTIOMETER

(connect SENSOR0 to SENSOR7) A

Turn couter clockwise, Output voltage increases.

Vertical type

Turn clockwise, Output voltage increases.

POTENTIOMETER

A

POTENTIOMETER A

S

Turn couter clockwise, Output voltage increases.

+ Turn clockwise, Output voltage increases.

Horizontal type Potentiometer

S +

10kB

This sensor is used to specific 0 to 5V following turn the shaft of potentiometer. This sensor rotates 300 degrees. Maximum resistance of the potentiometer is 10 k. At direct variation output : fully counter clockwise the sensor reads 0 and at fully clockwise the sensor reads 1023. At reverse variation output : fully counter clockwise the sensor reads 1023 and at fully clockwise the sensor reads 0.

4.6 Slide

(connect SENSOR0 to SENSOR7) A

SLIDE + S + S

10kB

+

+

This sensor is used to specific 0 to 5V following move the shaft of Slide. Output of this sensor has 2 formats : Move the shaft to right-hand : Voltage will be increase. Move the shaft to left-hand : Voltage will be increase.

Move to right, Output voltage increases.

A

Move to left, Output voltage increases.


SCi-B X Microcontroller in Science Experiment kit37

4.7 Photo-transistor for Infrared light detection (connect SENSOR0 to SENSOR7) This sensor is used to detect light that has wave length 1mm to 1mm. Usable 2 types as follows : 1. Read value in analog. Output voltage will be decrease when detect infrared more. A

PHOTO TRANSISTOR

2. Read value in digital. Output is logic “0” when detect infrared light. 10k

Usability : recommended to use this sensor with Infrared LED board.

i

+ S

Photo transistor

Optical spectrum Violet

Yellow Blue

400 nm

X-rays 1nm

Green

500 nm

Orange

600 nm

White light

Ultraviolet 10nm

Near infrared

100nm

Red

700 nm

800 nm

Infrared 1mm

10mm

100m

Microwave

1mm 10mm

Wavelength nm is nanometre (10-9 metre), mm is micrometre (10-6 metre) and mm is millimetre (10-3 metre)

Note : All ratio in this figure not linear.


38SCi-B X Microcontroller in Science Experiment kit

4.8 Resistance maresurement board: RESISTANCE (connect SENSOR0 to SENSOR7) This sensor gives the output voltage in 1mV /  ratio and measure resistance 4000 or 4k maximum. It includes 1mA constant current source. Unknown resistor connect with this current source. The voltage drop that resistor occur. We can measure this voltage to calculate the resistance value with direct variation ratio. A

RESISTANCE

1

100n

LM334 constant current source

2 3

68R

1mA set 5

TLC2272

OUT

8 S

7 6

+

R unknown

4

Output 1mV./ Input 4000 Max. (Current source 4V. limited)

4.9 Current measurement board : CURRENT (connect SENSOR0 to SENSOR7) This sensor board is used to measure DC current by connect in serial with measurement point. Output voltage is 5 mV/mA ratio and measure 1,000mA maximum.

A

OUT

1k

0.1/50V

OUT 6

8

0.5R

A

4

TLC2272 1k 10k Input : 1A max.

Testing point

S

7 5

1.5V

0.5 Ohm

10k

CURRENT

Current flow direction that measurement

CURRENT

+

0.5

Input resistance for setting measurement range (R shunt) is equal and 500mW maximum power rating.

Output : 5mV/mA

LOAD Example circuit for using this Current sensor board


SCi-B X Microcontroller in Science Experiment kit39

4.10 Voltage attenuator for voltage measurement board : ATTENUATOR (connect SENSOR0 to SENSOR7) Features of this sensor is measuring voltage by parallel connection to measuring point. This sensor can select 2 ranges by jumper.  1 select attenuator ratio to 1:1. Setting range of input voltage is 0 to 5V  1/2 select attenuator ratio to 2:1. Setting range of inout voltage is 0 to 10V

ATTENUATOR

ATTENUATOR ATT. 1 1/2

A

1M

Input testing point

5

7

6 4 TLC2272

1M 1

0.1/50V 8

1/2

OUT S

VOLT

Input

+

A

Output : 0-5V

Ratio 1 : Input 0-5V. Ratio 1/2 : Input 0-10V.

4.10 Sound detector

(connect SENSOR0 to SENSOR7)

 Detect sound pressure with Condenser Microphone.  Output voltage 0 to +5V varies from sound pressure level that microphone detected. If pressure more, the output voltage goes high and vice versa.

C2 0.1uF/50V

MIC1

3 R2 2 100k

R6 1k

R5 68k 6

8

+

+ IC1/1

1

5

IC1/2

-

-

4

R7 12R 7 C3 22uF +

R1 22k

C1 470uF/16V

R4 R3 100k 1k

S

IC1 : MCP6002

INNOVATIVE EXPERIMENT


40SCi-B X Microcontroller in Science Experiment kit


SCi-B X Microcontroller in Science Experiment kit41

Chapter 5 SCi-BOX activity software 5.1 Introduction In SCi-BOX kit provides 2 softwares for experiment and develop by yourself. One is called User mode. Another is called Developer mode. User mode has SCi-BOX activity software. Experimenters can test and experiment all activities without programming. Figure 5-1 shows the main screen of SCi-BOX activity software. It contains 15 sample activities. Figure 5-2 shows its software structure. SCi-BOX activity software is developed from 2 main softwares. One is BASIC Stamp Editor. Another is customizie software was written by Borland Delphi 7 Personal. BASIC Stamp editor is used to make PBASIC code. You can see all code in .bsx file. All activities sourcecode will start with “AT” and following the name of each activity. After that BASIC Stamp Editor will compile to object file in ATxxx.obj. Prepare for download to i-Stamp2P24 on SCi-BOX main board later. Pull-down menu for activity selections

Box shows how to interface all module in each activity

Step number of each activity

Select display between monitor or Serial LCD

Data Monitor box

Activity description

The SLCD connection and config windows will appear when select display with SLCD

Figure 5-1 Detail of SCi-BOX activity software screen


42SCi-B X Microcontroller in Science Experiment kit

Experimental activity

SCi-BOX contains PBASIC code of BASIC Stamp2SX

Signal cables

Interface

Figure 5-2 The SCi-BOX activity software structure diagram The Developer mode means experimenters can write thier own the code to control or test the custom operaion following their requirements in PBASIC language programming. Detail of this mode will describe in Chpater 6.

5.2 SCi-BOX Data logger software Addition SCi-BOX Activity software, SCi-BOX kit bundle the data logger software tool. It is called Sci-BOX Data logger SCi-BOX Data logger function is collect digital data from any sensor to shows in Graph format and save into text file for import to other spreadsheet software such as Microsfot Excel. SCi-BOX Data logger software can measure data and show in one and two channels. It is installed automatic with SCi-BOX activity software. Thsi siftware has 2 parts. One is PBASIC program. It is written by BASIC Stamp Editor. It includes 3 .bsx file as : Single.BSP : Read data from anlog sensor one channel. C_Single.BSP : Read data from Capacitance sensor one channel. Dual.BSP : Read data from analog sensor two channels. All 3 .bsp file will convert to .obj file for download to i-Stamp2P24 on SCi-BOX. Another, PC software is wiritten by Borland Delphi. It included 2 files too. One for show single channel. Another one is dual channels. This software can show all connection, raw data and behavior of graph operation. Expermenters can enter to Start  Program SCi-BOX

 SCi-BOX SingleData for

selection only singel channel display and select to SCi-BOX DualData if need to see dual channels together. In the figure 5-3 shows all procedure for using and detail of this software.


SCi-B X Microcontroller in Science Experiment kit43

Select number of recording data (100-1,000) Select resoultion of Data axis (1,024 or 65,536)

3 1

Click Connect

Select sample time (0-50,000 millisecond)

Check Run

Must disconnect with SCi-BOX main board before set all parameters in this boxes. After setting, click Connect button and select Run .

Logged data box shows the raw data. First value is index. Real data is following value.

Select to read data

The interface windows will appear. Must select SENSOR or Capacitance

Received data status of Graph display

Select to show the grid line.

Save data to text file (.txt) Clear all displayed data Save the graph image to .bmp file

SENSOR The interfacing image will appear as :

Select the color of graph's line.

2

After connect all cable, click OK button. The Download progress window will appear until finish. Clikc OK button in Downloader dialogue box.

Capacitance The interfacing image will appear as :

Figure 5-3 Show procedure of using SCi-BOX Data Logger software and detail of this software in Single data channel.

INNOVATIVE EXPERIMENT


44SCi-B X Microcontroller in Science Experiment kit


SCi-B X Microcontroller in Science Experiment kit45

Chapter 6

SCi-B X with PBASIC programming From chapter 5,Experimenters can use SCi-BOX kit in User mode with SCi-BOX activity software and SCi-BOX Data logger software without programming. However user an develop their own experiment activity by wrting the PBASIC program. Because SCi-BOX’s main microcontroller is i-Stamp2P24. It is OEM version of BASIC Stamp2P microcontroller from Parallax. The software development can use BASIC Stamp Editor V2 or higher. Experimenters and programmers can see all detail of programming reference at BASIC Stamp Editor manual by download from www.parallax.com.

6.1 SCi-BOX in Developer mode This mode is support for advance user or experimenters. They can make thier own PBASIC program for control the operation of SCi-BOX main board. Users can make the operation in stand alone or interface computer allways. In this mode user must write the code at least for microcontroller side. About computer side that use for monitor or display can use Debug Terminal in BASIC Stamp Editor or make thier own GUI software. The important is port of interface must use RS-232 Serial port. If some PC not support serial port, can use USB to RS-232 serial port for solving this problem. About installation and using BASIC Stamp Editor software, epxerimers can see all detail in BASIC Stamp manual.


46SCi-B X Microcontroller in Science Experiment kit

6.2 Using SCi-BOX with BASIC Stamp Editor software 6.2.1 Install i-Stamp on blank 24-pim female header on SCi-BOX main board. 6.3.2 Connect the serila cable between PC’s RS-232 serial port with SCi-BOX main board.

Install i-Stamp on

SCi-B X mainboard. Must becareful the direction of i-Stamp.

Connect to computer's COM port

Female DB-9 connector 6 7 8

9

1 2 3 4

5

DB-9 female side

DB-9 male side

9-wires multicore cable RS-232 DOWNLOAD

5

1 2 3 4

DC INPUT RESET

OFF

SCi-BOX BASIC Stamp in Science Experiment

9

i-Stamp

6 7 8

ON

Male DB-9 connector


SCi-B X Microcontroller in Science Experiment kit47 6.3.3 Apply the supply voltage to SCi-BOX main board and run BASIC Stamp Editor 2.0 software. 6.3.4 Check the connnection between BASIC Stamp Editor software with i-Stamp on SCi-BOX main board. Press key Ctrl I or click Identify button or enter to Run menu, select Identify. If all correct, the Identification windows will appear and show the correct status below. See COM1 line, message “BASIC Stamp2SX V1.0” appears. It means the connection successfully.

6.3.5 Make the simple code by step as : 6.3.5.1 Select BASIC Stamp directive by enter Directive menu. Select Stamp  BS2P. The message ‘{$STAMP BS2P} will appear on the first line. Press Enter key.

6.3.5.2 Still stay at Directive menu, select the serial port interfacing by select Port  Com1 (or any COM port that connected). The message ‘{$PORT COM1} will appear on second line. Press Enter key.


48SCi-B X Microcontroller in Science Experiment kit

6.3.5.3 Still stay at Directive menu, select version of BASIC Stamp Editor by PBASIC à Version2.5. The message ‘{$PBASIC 2.5} will appear at the third line. Press Enter key.

6.3.5.4 Type command debug “welcome”. This command control i-Stamp to send message “welcome” to display on Debug Terminal window of BASIC Stamp Editor. Press Enter key. 6.3.5.5 Click Run button. The interface and download program window will appear. After download successful, i-Stamp will run suddenly. Debug Terminal will appear and display message welcome.

6.3.5.6 Pree RESET switch on SCi-BOX maain board. THe message will appear at Degug Terminal again. Becasue RESET switch pressing means re-start the operation. 6.3.5.7 If dialogue box of No BASIC Stamps found appear in download progress, It means the interface between software and i-Stamp failed. Must check the connection cable and close all software that use serial port. After that try again.

6.3.6 After develop program complete, experimenters can save the code in .bsx file. Enter File menu and slect Save As.. define the suitable filename.


SCi-B X Microcontroller in Science Experiment kit49

Developer mode Activity - 1 Serial LCD programming 6.3.1.1 Connect SLCD with SCi-BOX main board Connect the 3-wires cable from any P0 to P7 on SCi-BOX main board with SLCD connector.

6.3.2 Write standard command and data to SLCD Start with sending the start code$FE or 254 by SEROUT command. The syntax of sending command of LCD is SEROUT

PIN, baudmode, [$FE, command value]

The syntax of sending data display is SEROUT

PIN, baudmode, [$FE, 1, display value]

Similar command sending, start with the Start code $FE following 1 value to inform SLCD know the data following will be display data.

6.3.3 Write extension command and data to SLCD The syntax is simliar the Standard command but easier. The syntax does not need the start code$FE and 1 value to separate command and data. This method use “ ” symbol to define the display data. The syntax of this technique is SEROUT

PIN, baudmode, [command value]

SEROUT

PIN, baudmode, [“display value”]

Example 6-1 SEROUT 8,240,[129] Send command value to P8 pin of i-Stamp with 9600 bit per second baudrate in direct logic for clearing LCD display.

Example 6-2 SEROUT 8,240,[“Hello Stamp 2P!”] Send command value to P8 pin of i-Stamp2P24 with 9600 bit per second baudrate in direct logic for sending message Hello Stamp 2P!


50SCi-B X Microcontroller in Science Experiment kit

Example 6-3 SEROUT 8,240,[154,”Test Line 2 LCD”] Send command value to P8 pin of i-Stamp2P24 with 9600 bit per second baudrate in direct logic to select address of DDRAM at $40. It is first address of upper line of LCD. Show message Test Line 2 LCD

Example 6-4 SEROUT 8,240,[150,137] Send command value to P8 pin of i-Stamp2P24 with 9600 bit per second baudrate in direct logic to select address of DDRAM at $00. It is first address of lower line of LCD. Open the display and blank the LCD cursor. However SLCD need time for processing, after sending command or data must delay 250 to 500 millisecond with PAUSE command. In case show many letters of message, the delay time need more.

SCi-B X

Microcontroller in Science experiment


SCi-B X Microcontroller in Science Experiment kit51

Developer mode Activity - 2 Switch & sound This activity demonstrate the reading switch at P0 to drive sound to piezo speaker in SCi-BOX main board.

Procudure 1. Connect the JST3AA-8 cable between Swtich input board with P0 at SCi-BOX main board.

HEAT SINK

POWER DC. IN 6-16V

Don't Touch !! High temperature

#1

SENSOR5

RESET

P7

Co-processor

BASIC Stamp in Science Experiment

HIGH

P5

SENSOR6

i-Stamp2P24

ADC

SCi-BOX

P13 : A/D

SENSOR4

P4

ADC Co-processor

P12 SOUND

SENSOR3

P11 P10

P9

P3

#2

P8

P2 P1

MOTOR P14, P15 : STEPPER MOTOR

P0

SENSOR1 SENSOR0

Stepper motor Co-processor

SENSOR2

RELAY

CONTROL

D

SENSOR7

ON

P6

SERIAL PORT

RELAY 12V 5A

RELAY 12V 5A

RELAY 12V 5A

RELAY 12V 5A

STEPPER MOTOR1 STEPPER MOTOR2

P11 RELAY P10 RELAY

P9 RELAY

P8 RELAY

MOTOR A

B

INV-A

INV-B

P8-P9 MotorA P10-P11 MotorB

ON

LOW


52SCi-B X Microcontroller in Science Experiment kit

2. Write the PBASIC code below '{$STAMP BS2p} '{$PBASIC 2.5} '*************************************************** ' File : ACT18.BSP ' Purpose : Sound generation by switch ' Hardware : Connect SWITCH as actived “LOW” at P0 '*************************************************** ' Custom I/O ON this application SWITCH VAR IN0 ' Connect switch here! SOUND CON 12 ' On-board speaker ' Variable defined FREQ VAR Word

' Channel select

LOOP1: IF SWITCH=1 THEN LOOP1 FOR FREQ=600 TO 1000 STEP 100 FREQOUT SOUND,250,FREQ NEXT GOTO LOOP1

' ' ' ' '

Wait switch pressed Sweep 2.26kHz to 3.77kHz Send frequency out Do loop Do again

3. Connect SCi-BOX main board with computer. 4. Download PBASIC code and run this program.

SCi-B X

Microcontroller in Science experiment


SCi-B X Microcontroller in Science Experiment kit53

Developer mode Activity - 3 Relay switcher This activity demontrates the Relay switcher operation. It use only one switch to select 4 relays in sequence operation. Press first time, relay 1 activate. Press second time, relay 2 activate until relay 4 and loop o atrat at relay 1 again.

Procudure 1. Connect JST3AA-8 cable between Swtich input board with P0 at SCi-BOX main board.

HEAT SINK

POWER DC. IN 6-16V

P7

#1

HIGH

SENSOR5

RESET P5

SENSOR6

i-Stamp2P24

ADC Co-processor

SCi-BOX BASIC Stamp in Science Experiment

P13 : A/D

SENSOR4

P4

ADC Co-processor

P12 SOUND

SENSOR3

P11 P10

P9

P3

#2

P8

P2 P1

SENSOR1 SENSOR0

MOTOR P14, P15 : STEPPER MOTOR CONTROL

 

P0

SENSOR2

RELAY Stepper motor Co-processor

D

SENSOR7

ON

P6

SERIAL PORT

RELAY 12V 5A

RELAY 12V 5A

RELAY 12V 5A

RELAY 12V 5A

STEPPER MOTOR1 STEPPER MOTOR2

P11 RELAY P10 RELAY

P9 RELAY

P8 RELAY

MOTOR A

B

INV-A

INV-B

P8-P9 MotorA P10-P11 MotorB

ON

Don't Touch !! High temperature

LOW


54SCi-B X Microcontroller in Science Experiment kit

2. Write the PBASIC code below '{$STAMP BS2p} '{$PBASIC 2.5} '****************************************************** ' File : ACT19.BSP ' Purpose : Relay selector ' Hardware : Jumper at RELAY position ' Connect SWITCH as actived “LOW” at P0 '****************************************************** SWITCH CON 0 ' Connect switch here! CH VAR Byte ' Channel select SW_VAR VAR Byte ' Switch variable PAUSE 1000 ' Delay 1s. for pheripheral initialize DIRC=%1111 ' Force P8-P11 as output LOOP1: BUTTON SWITCH,0,255,0,SW_VAR,0,LOOP1 ' Get switch,one times CH=(CH+1)//5 ' Gotot next step (0-5) LOOKUP CH,[%0000,%0001,%0010,%0100,%1000],OUTC ' Get step output to relays PAUSE 100 ' Delay 100ms. GOTO LOOP1 ' Do again

3. Connect SCi-BOX main board with computer. 4. Select RELAY/MOTOR jumper on SCi-BOX main board to RELAY position. 5. Download PBASIC code and run this program.

SCi-B X

Microcontroller in Science experiment


SCi-B X Microcontroller in Science Experiment kit55

Developer mode Activity - 4 Analog signal activity SCi-BOX can read analog signal via SENSOR0 to SENSOR7 connector. This activity will read analog signal to display on Debug Terminal.

Concept On SCi-BOX main board provides 2 analog to digital converter (ADC) ICs , QP410 for support 8 analog inputs. The resolution of conversion is 10 bit means 0 to 1,023. The interfacing between ADC ICs with i-Stamp is serial in single wire. Syntax of programming start with make Break signal to QP410. The PBASIC code is LOW

SD : PAUSE 1 : HIGH SD

‘ Break signal

After that, send request command to QP410 for reading the concersion data from any analog channel. The code is SEROUT

SD,BAUD,[0]

‘ Request SENSOR0

Number [0] means analog input channel refer SENSOR0. Then this parameter can define 0 to 7 Last step, wait for the conversion data. The result data is 10 bit value. Experimeters must declare a variable for store this data in Word. Result data will start with low byte and following 2-bit in high byte. The PBASIC code is SERIN SD,BAUD,[VALUE.LowByte,VALUE.HighByte] ‘ Received data 2 byte to 1 word


56SCi-B X Microcontroller in Science Experiment kit

Procudure 1. Connect JST3AA-8 cable between Potentiometer board with SENSOR0 at SCi-BOX main board.

   

 

HEAT SINK

POWER DC. IN 6-16V

SENSOR5

RESET

P5

SENSOR6

i-Stamp2P24

ADC Co-processor

#1

SCi-BOX BASIC Stamp in Science Experiment

P13 : A/D

SENSOR4

P4

ADC Co-processor

P12 SOUND

SENSOR3

P11 P10

P9

P3

#2

P8

P2 P1

MOTOR

P0

SENSOR1 SENSOR0

Stepper motor Co-processor

SENSOR2

RELAY

P14, P15 : STEPPER MOTOR CONTROL

P7

ON

SENSOR7

A

SERIAL PORT

P6

ZX-POTV

RELAY 12V 5A

RELAY 12V 5A

RELAY 12V 5A

RELAY 12V 5A

STEPPER MOTOR1 STEPPER MOTOR2

P11 RELAY P10 RELAY

P9 RELAY

P8 RELAY

MOTOR A

B

INV-A

INV-B

P8-P9 MotorA P10-P11 MotorB

ON

Don't Touch !! High temperature


SCi-B X Microcontroller in Science Experiment kit57

2. Write the PBASIC code. '{$STAMP BS2p} '{$PBASIC 2.5} '************************************************ ' File : ACT20.BSP ' Purpose :Show voltage value ON DEBUG terminal ' Hardware : Connect POTENTIOMETER at SENSOR0 '************************************************ ' System I/O AND constant , please DO NOT make change SD CON 13 ' Sci-BOX serial communication port BAUD CON 240 ' 9600bps constant ' Variable defined VALUE VAR Word RESULT VAR Word

' VALUE as SENSOR0 variable ' RESULT for calculation purpose

PAUSE

' Delay 1s. for pheripheral initialize

1000

LOOP1 : LOW SD : PAUSE 1 : HIGH SD ' Break signal SEROUT SD,BAUD,[0] ' Request SENSOR0 SERIN SD,BAUD,[VALUE.LOWBYTE,VALUE.HIGHBYTE] ' Received data 2 bytes to 1 Word DEBUG

HOME,"READ DATA = ",DEC4 VALUE," is "

' Convert 0-1023 data to 000-499 or 1024 steps to 500 steps ' Equation : (Value * 62.5)/128 RESULT=(VALUE*/((62*$100)+$80))/128

' Represent data in 2 decimal points format [X.XX volts] DEBUG DEC1 RESULT DIG 2,".",DEC1 RESULT DIG 1,DEC1 RESULT DIG 0," volt" PAUSE 100

' Delay 100ms.

GOTO LOOP1

' Do again

3. Connect SCi-BOX main board with computer. 4. Download PBASIC code and run this program. 5. Debug Terminal will appear. Turn potentiometer shaft and see the data changing at Debug Terminal The result data will show 2 formats. One is raw data from QP410. Another is voltage value from calculation. This activity is like the Simple PC-baesd Digital voltmeter.

SCi-B X

Microcontroller in Science experiment


58SCi-B X Microcontroller in Science Experiment kit

Developer mode Activity - 5 DC motor activity This activity demonstrates controlling DC motor with 2 of Potentiometers that connect at SENSOR0 and SENSOR1 of SCi-BOX main board. If turn the potentiometer to left direction, motor will turn left too and turn oppposite when turm potentiometer shaft to right direction. P8 and P9 of i-Stamp are used to control DC motor channel A. For channel B use P10 and P11. The condition is Motor A P8

P9

Motor operation

0

1

Invert direction

1

0

Normal direction

0

0

Free shaft

1

1

Lock shaft

Motor B P10

P11

Motor operation

0

1

Invert direction

1

0

Normal direction

0

0

Free shaft

1

1

Lock shaft

Procudure 1. Connect JST3AA-8 cable between 2 of Potentiometer boards with SENSOR0 and SENSOR1 at SCi-BOX main board. 2. Connect DC motor to Motor A connector .


SCi-B X Microcontroller in Science Experiment kit59

ZX-POTV

HEAT SINK

POWER SERIAL PORT ON

SENSOR7 SENSOR5

RESET

P5

SENSOR6

i-Stamp2P24

ADC Co-processor

#1

SCi-BOX BASIC Stamp in Science Experiment

P13 : A/D

SENSOR4

P4

ADC Co-processor

P12 SOUND

SENSOR3

P11 P10

P9

P3

#2

P8

P2

MOTOR P14, P15 : STEPPER MOTOR CONTROL

 

P1

SENSOR1 SENSOR0

Stepper motor Co-processor

SENSOR2

RELAY

P0

A

P7

DC. IN 6-16V

ZX-POTV

Don't Touch !! High temperature

P6

ON

RELAY 12V 5A

RELAY 12V 5A

RELAY 12V 5A

RELAY 12V 5A

STEPPER MOTOR1 STEPPER MOTOR2

P11 RELAY P10 RELAY

P9 RELAY

P8 RELAY

MOTOR A

B

INV-A

INV-B

P8-P9 MotorA P10-P11 MotorB

A

DC MOTOR 6-12V

Result

 ZX-POTV

ZX-POTV

A

A

 

 

      


60SCi-B X Microcontroller in Science Experiment kit

3. Write the PBASIC code. '{$STAMP BS2p} '{$PBASIC 2.5} '************************************************************************ ' File : ACT21.BSP ' Purpose :Running DC motor A and B ' Hardware : Jumper at MOTOR position ' Connect POTENTIOMETER (V) #1 at SENSOR0 (motor A control) ' Connect POTENTIOMETER (V) #2 at SENSOR1 (motor B control) '************************************************************************ ' System I/O and constant , please do not make change SD CON 13 ' Sci-BOX serial communication port BAUD CON 240 ' 9600bps constant ' Variable defined VALUE VAR Word ' VALUE as SENSOR variable SENSOR VAR Word(2) ' SENSOR, 2 Word array CH VAR Byte ' Channel select PAUSE 1000 ' Delay 1s. for pheripheral initialize LOOP1: FOR CH=0 TO 1 GOSUB Get_SENSOR : SENSOR(CH)=VALUE ' Get SENSOR0 and SENSOR1 DEBUG DEC SENSOR(CH)," " ' View data on debug NEXT DEBUG CR ' Carriage return Check_A: IF SENSOR(0)>=512 THEN A_Forward ' Rules for decision LOW 8 : HIGH 9 : GOTO Check_B ' Backward if less than 512 A_Forward: HIGH 8 : LOW 9 ' Forward if others Check_B: IF SENSOR(1)>=512 THEN B_Forward LOW 10 : HIGH 11 : GOTO OK B_Forward: HIGH 10 : LOW 11 OK: GOTO LOOP1 ' Do again '***************************** ' Get sensor value subroutine '***************************** Get_SENSOR: LOW SD : PAUSE 1 : HIGH SD ' Break signal SEROUT SD,BAUD,[CH] ' Request SENSOR0 SERIN SD,BAUD,[VALUE.LOWBYTE,VALUE.HIGHBYTE] ' Received data 2 bytes to 1 word RETURN ' Return to main

4. Connect SCi-BOX main board with computer. 5. Select RELAY/MOTOR jumper on SCi-BOX main board to MOTOR position. 6. Download PBASIC code and run this program. If motor A turn in normal direction, LED indicator will show green color but turn invert direction LED will be red. Experimenter can control direction by potentiometer at SENSOR0. 7. Change motor to Motor B connector and change to control by potentiometer at SENSOR1.

SCi-B X

Microcontroller in Science experiment


SCi-B X Microcontroller in Science Experiment kit61

Developer mode Activity - 6 Stepper motor activity This activity demonstrates controlling a uni-polar stepper motor with 2 of Potentiometers that connect at SENSOR0 and SENSOR1 of SCi-BOX main board. If turn the potentiometer to left direction, motor will turn left too and turn oppposite when turm potentiometer shaft to right direction. The heart of this operation is Stepper motor Co-processor on SCi-BOX main board. It interface with i-Stamp in serial communication by 2 pins. One is SERIN pin connect to P14 of i-Stamp. Another is BUSY pin, connect to P15 of i-Stamp. SERIN pin will receive serial data from i-Stamp to process and drive signal to motor driver circuit. During processor operation, it will hold BUSY pin to 0V. It means busy cannot get new data. Until its operation complete, it will chnge logic at BUSY pin to “1”. User can reset the operation by apply logic “1” at RST pin. Suitable baudrate for Stepper motor Co-processor is 9600 bit per second. Data is 8 bit and none parity. Stepper motor Co-processor has FIFO buffer 28 bytes. Controlling data has 2 groups; Target step and Control command 1. Target step has 2 bytes. First byte is step value of the stepper motor 1. Second byte is step value of the stepper motor 2. Step value is 1 to 127 and –1 to –127 (except 128 because it is command value) If value is positive : Motor will turn normal direction. If value is negative : Motor will turn invert direction. Number is in 2’ complement form. The values are $FF (equal -1) to $81 (equal -127). PBASIC code can write below : SEROUT 14,16624 [step value of stepper motor1, step value of stepper motor 2 ] Example-1 Drive both motors in normal direction 96 steps. PBASIC code is SEROUT 14,240,[96,96] Example -2 Drive both motors opposite direction 48 steps. PBASIC code is SEROUT 14,240,[48,-48]


62SCi-B X Microcontroller in Science Experiment kit

2. Control command for stepper motor driver circuit 2.1 Start with send 128 or $80 value. 2.2 Send command in next byte. The syntax of this command is SEROUT 14,240,[128, “command”, parameter for stepper motor1, parameter for stepper motor 2] The detail of all command and parameter can describe as : Command

Operation

C

Reset all variable value

E

Select to power save mode. Not suggess to use in driving mode 0, 3 and 4. In power save mode the circuit need current not over 100mA when shaft free.

F M [0..4]

Select the motor driver circuit works in power full mode. Select driver mode ( Default=0 ) Mode 0 : Half step Mode 1 : 1-phase full step Mode 2 : 2-phase full step Mode 3 : Half step with quater-step compensation Mode 4 : Half step with micro-step compensation (not support S command)

S [0..255]

Set delay time in each step or speed control in Mode 0 to 3 . The default is 100.

P [0..255]*

Set number of delay loop in Mode 3 operation. ( Default =10 )

R [0..255]*

Set number of delay loop in step dividing of Mode 3 (Default =2 )

I [0..255]*

Set number of delay loop in step dividing in Mode 4. ( Default =75 )

Note : * Not suggess to set this parameter.


SCi-B X Microcontroller in Science Experiment kit63

Example - 3 Drive 2-phase stepper motor with delay time = 150. The PBASIC code is SEROUT 14,240,[128,”F”,128,”M”,2,128,”S”,150] Drive stepper motor in Mode 3 and delay time is 75. The PBASIC code is SEROUT 14,240,[128,”F”,128,”M”,3,128,”S”,75] The PBASIC code for reset the Stepper motor dirver co-processor is SEROUT 14,240,[128,”C”] After that must add PAUSE command for delay 1 second before send anothaer value.

Procudure 1. Connect JST3AA-8 cable between 2 of Potentiometer boards with SENSOR0 and SENSOR1 at SCi-BOX main board. 2. Connect stepper motor to Stepper motor connector #1 . ZX-POTV POWER SERIAL PORT

Co-processor

SENSOR5

RESET

BASIC Stamp in Science Experiment

P5

SENSOR6

i-Stamp2P24

ADC #1

SCi-BOX

P7

SENSOR7

ON

P6

DC. IN 6-16V

ZX-POTV

P13 : A/D

SENSOR4

P4

ADC Co-processor

P12 SOUND

SENSOR3

P11 P10

P9

P3

#2

P8

SENSOR1 SENSOR0

P2 P1

SENSOR2

RELAY

MOTOR P14, P15 : STEPPER MOTOR CONTROL

P0

A

HEAT SINK Don't Touch !! High temperature

RELAY 12V 5A

RELAY 12V 5A

RELAY 12V 5A

RELAY 12V 5A

STEPPER MOTOR1 STEPPER MOTOR2

P11 RELAY P10 RELAY

P9 RELAY

P8 RELAY

MOTOR A

B

INV-A

INV-B





P8-P9 MotorA P10-P11 MotorB

ON

Stepper motor Co-processor

A


64SCi-B X Microcontroller in Science Experiment kit

3. Write the PBASIC code below '{$STAMP BS2p} '{$PBASIC 2.5} '****************************************************************** 'File : ACT23.BSP 'Purpose : Running Stepper motor 1 AND 2 'Hardware :Connect POTENTIOMETER #1 at SENSOR0 (motor 1 control) ' Connect POTENTIOMETER #2 at SENSOR1 (motor 2 control) '****************************************************************** 'System I/O AND constant , please DO NOT make change SD CON 13 ' Sci-BOX serial communication port SO CON 14 ' Sci-BOX stepper controller serial port BUSY VAR IN15 ' Sci-BOX stepper controller busy signal BAUD CON 240 ' 9600bps constant CTRL CON $80 ' Variable defined VALUE VAR Word ' VALUE as SENSOR variable SENSOR VAR Word(2) ' SENSOR, 2 words array CH VAR Byte ' Channel select L VAR Byte R VAR Byte PAUSE 1000 ' Delay 1s. for peripheral initialize ' Set full powered, half step and step delay as 40 SEROUT SO,BAUD,[CTRL,"F",CTRL,"M",0,CTRL,"S",40] GOSUB Poll_BUSY ' Wait BUSY signal LOOP1 : FOR CH=0 TO 1 GOSUB Get_SENSOR : SENSOR(CH)=VALUE ' Get SENSOR0 and SENSOR1 DEBUG DEC SENSOR(CH)," " ' View data on debug NEXT DEBUG CR Check_M1 : IF SENSOR(0)>=512 THEN M1_Forward L=-1 : GOTO Check_M2

' Rules for decision ' Backward if less than 512

M1_Forward : L=1

' Forward if others

Check_M2 : IF SENSOR(1)>=512 THEN M2_Forward R=-1 : GOTO OK M2_Forward : R=1 OK : GOSUB Drive GOTO LOOP1 '**************************** ' Drive stepper motor routine '**************************** Drive : SEROUT SO,BAUD,[L,R] Poll_BUSY : IF BUSY=0 THEN Poll_BUSY RETURN

' Call drive ' Do again

' Drive L & R motor -127 TO +127 range

' Return to main


SCi-B X Microcontroller in Science Experiment kit65 '**************************** ' GET sensor value subroutine '**************************** Get_SENSOR : LOW SD : PAUSE 1 : HIGH SD ' Break signal SEROUT SD,BAUD,[CH] ' Request SENSOR0 SERIN SD,BAUD,[VALUE.LOWBYTE,VALUE.HIGHBYTE] ' Received data 2 bytes to 1 word RETURN ' Return to main

4. Connect SCi-BOX main board with computer. 5. Download PBASIC code and run this program. 6. Turn the shaft of potentiometer that connect at SENSOR0. See the operation of stepper motor #1.

Result

 ZX-POTV

A

   

ZX-POTV

A

      

7. Change motor to connect at Stepper motor #2 connector. Turn the shaft of potentiometer that connect at SENSOR1. See the operation of stepper motor #2. 8. If can find 2 motors, connect all to both connectors. Adjust both potentiometers and test the operation again.



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.