Microcontroller in Science experiment kit documentation
Transcription
Microcontroller in Science experiment kit documentation
SCi-B X Microcontroller in Science Experiment kit l 1 SCi-B X Microcontroller in Science experiment kit documentation 2 l SCi-B X Microcontroller in Science Experiment kit SCi-B X Microcontroller in Science Experiment kit l 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-Stamp based on BASIC Stamp2SX OEM version. It is connected with the serial A/D processor to read the alalog data into system. i-Stamp 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-Stamp 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 l SCi-B X Microcontroller in Science Experiment kit 1.1 Technical features of SCi-BOX main board 1.1.1 Main controller l Controlled by i-Stamp (the OEM BASIC Stamp2SX) with PBASIC programming l 16KB EEPROM divide to 8 pages 2KB each and can access all pages in during working. l 10,000 PBASIC instructions per second speed l Connect RS-232 serial port for downloadings and communication 1.1.2 Input/Output l 8-ch. Programmable digial input/output port l 8-ch. Analog input. Maximum voltage input is +5V. The ADC Co-processor functions these inputs and interface i-Stamp with serial. Resolution of conversion is 10 bits. The value is 0 to 1,023. 1.1.3 On-board output components l 4-LEDs indicator (connected to P8 to P11) l 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. l 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. l 2-ch. Stepper motor drivers serially interface with a Stepper motor Co-processor. Support +12V uni-polar stepper motor. l Piezo speaker for sounding. The resonant frequency range is 1kHz to 3kHz. 1.1.4 Power supply l Apply the supply voltage to SCi-BOX via 2 points. One is DC jack adaptor. 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 l Wide range of the supply voltage input 9 to 16V. On-board +5V 500mA regulator circuit. SCi-B X Microcontroller in Science Experiment kit l 5 1.2 Part list l SLCD16x2 l DC adaptor 12V 500mA l Crocodile clip cable l 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 l 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. l Output device (O group) include : Infrared LED board (x 2) Bi-color LED indicator board l DC motor operating voltage 3 to 12V range l 12V Uni-polar Stepper motor l Resistors and Capacitors for experiemnts 10 values and one piece per value. 6 l SCi-B X Microcontroller in Science Experiment kit D5 1N5819 J1 DC INPUT 6-16V. +V S1 POWER ON / OFF D6 1N4001 C5 220/16V K1 BATT. INPUT C2 0.1/63V D1-D4 1N4001 x4 +5V D LED1 POWER C1 470/25V C6 0.1/63V 2 3 C8 0.1/63V C7 0.1/63V K2 DOWNLOAD DB-9 FEMALE S2 RESET +5V K8 SENSOR5 +5V 6 K7 SENSOR4 +5V 7 AN0 5 AN2 GP3 GP5 K6 SENSOR3 +5V 3 K5 SENSOR2 +5V 5 AN2 K4 SENSOR1 +5V 6 K3 SENSOR0 +5V 7 AN0 AN1 IC2 i-Stamp R3 10k 18 20 4 NXP2220S-SMC 1 RST C12 1/50V GND 10 P15 BUSY 7 5 CR1 4MHz SER IN 6 P14 P8 P9 P10 R4 150 P11 17 K21 MOTOR-A C13 10/16V 13 SP1 PIEZO 14 16 MOTOR-A #1 2 MOTOR-A #2 7 2A 11 10 K18 P7 K17 P6 +5V R11 220 K16 P5 +5V R10 220 10 K15 P4 +5V R9 220 9 K14 P3 +5V R8 220 K13 P2 +5V R7 220 7 K12 P1 +5V R6 220 6 R5 220 12 11 8 5 P7 8 9 IC8/4 1 IC8/1 IC8/3 10 3 5 4 6 16 IC8/2 P6 9 IC8/1-IC8/4 : 74HC32 P5 1Y 3 1A 2Y 4Y 3Y 3A 14 RY1 RELAY 12V P1 9 P0 1 3 5 7 D0 Q0 D1 Q1 D2 Q2 D3 Q3 R18 R17 R19 R20 8 R17-R20 510 x4 LED7 LED6 LED5 LED4 P11 P10 P9 P8 Figure 1-2 SCi-B X schematic diagram 16 R24 14 R23 12 R22 10 R21 R21-R24 47 x4 IC9 ULN2003 INVERT + C15 0.1/63V + 13 12 5 K23 P8 RELAY NO C LED2 DIR. #A LED3 DIR. #B R16 2k2 K22 MOTOR-B 4 DIRECT DC MOTOR JP1 DRIVER SELECT P2 + DIRECT 11 34EN P3 + R15 2k2 Vcc1 P4 INVERT 6 12EN 15 4A 1 2 C14 0.1/63V IC7 L293DNE 15 MOTOR-B #1 R12 220 R14 10k 19 12 13 +5V +5V R15 10k 20 MOTOR-B #2 +5V 1D 1C 1B 1A 2D 2C 2B 2A +Vcc IC5 +5V 8 K11 P0 1 P13 GP5 2 GP3 2 19 18 17 16 12 13 14 15 C11 0.1/63V R13 10k Q4 BC557 2 4 3 MCLR IC4 QP410 AN3 4 TxD P12 1 5 RxD IC3 QP410 +5V 6 +5V R2 150 8 7 +5V 4 AN1 A IC6 ULN2803 9 8 C10 0.1/63V AN3 K9 SENSOR6 +5V B RN1 2k2 *8 1 3 K10 SENSOR7 C D 11 12 13 14 15 16 17 18 +5V C9 0.1/63V PHASE A to D COIL A 10 +V 23 1 B K20 STEPPER MOTOR #2 CONNECTOR 4 2 3 4 5 C K19 STEPPER MOTOR #1 CONNECTOR 21 6 7 STEPPER MOTOR #2 PHASE A to D COIL R1 510 C3 47/16V +5V STEPPER MOTOR #1 C4 0.1/63V IC1 LM2940CT -5.0 +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 l 7 Serial port connector DC jack and terminal Piezo speaker POWER switch SENSOR0 to SENSOR7 connector for connect with all analog sensors Connect to stepper motor i-Stamp P0 to P7 connector LED indicators Relay/DC motor driver jumper selection Connect to DC motor Relay contact terminal i-Stamp port assignment on SCi-B X P0-P7 : Programmable general purpose input/output port to interface Serial LCD and Digital sensors (D group) P8-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-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 l 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 SCi-BOX.exe. Double click, the first setup window will appear. Click Next button. 1.3.2 The Select Destination Location window appears. User can select the location in the box. Click Next button. SCi-B X Microcontroller in Science Experiment kit l 9 1.3.3 The Select Start menu Folder window appears to define the folder name. Default is SCi-BOX and click Next button. 1.3.4 The Ready to Install dialogue box appears, click Instyall button to begin instalaltion. 10 l SCi-B X Microcontroller in Science Experiment kit 1.3.5 Installation stauts dialogue box appears to shows the status. 1.3.6 After installation finish, the complete installtion dialogue box appears. Click Finish button to finish installation. 1.3.6 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.7 Install i-Stamp on the main board following the figure 1-5. SCi-B X Microcontroller in Science Experiment kit l 11 Figure 1-4 The main window of SCi-BOX Activity software Install i-Stamp 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 iStamp ready to use. Figure 1-5 Show the fitting i-Stamp on the main board 12 l SCi-B X Microcontroller in Science Experiment kit 1.3.8 At the circle #1, select AT07-Switch. 1.3.9 Connect the Switch input board to P1port on the SCi-BOX. 1.3.10 Select RELAY/MOTOR jumper to RELAY 1.3.11 Connect SCi-BOX to COM1 of computer or another. If computer has only USB, the USB to RS-232 serial port is required 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 R S -232 D O W N LO A D 1 2 3 4 5 D C IN P U T RESET i-Stamp OFF SCi-BOX BASIC Stamp in Science Experiment 6 7 8 9 ON Male DB-9 connector SCi-B X Microcontroller in Science Experiment kit l 13 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. 1.4 Regulations 1.4.1. Turn-off POWER switch before remove and re-connect the serial port cable. 1.4.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 iStamp damaged from electric shock during remove and re-connect any cables. 1.4.3 Do not touch the heatsink at the right side of SCi-BOX board. Because it handle some heat from normal operation. 1.4.4 If any error occur, must turn-off POWER switcxh suddenly. 1.4.5 Do not use DC adaptor that output over +16Vdc witn SCiBOX board. 1.4.6 After all finished, remove all cable from SCi-BOX board include DC adaptor. 14 l SCi-B X Microcontroller in Science Experiment kit SCi-B X Microcontroller in Science Experiment kit l 15 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 E 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 CONTROL P2 P1 MOTOR P14, P15 : STEPPER MOTOR 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 NSOR3 P11 P10 P3 16 l 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 X main board 2.2 12V Relay driver Sci-BOX board provides 4 relay drivers. Their contact rating can support 220Vac 5A 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 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 X main board SCi-B X Microcontroller in Science Experiment kit l 17 E 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 P10 0 1 0 1 B P11 1 0 0 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 18 l 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 motors coil in 1-phase full step driving SCi-B X Microcontroller in Science Experiment kit l 19 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. O 220 Apply logic "0" to this point, LED indicates Green. Apply logic "1" to this point, LED indicates Red. LOW S + 4 LOW LED O HIGH LOW If apply the input signal at this point with logic “0”, LED indicates Green. / 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 motors 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 motors coil in half-step mode 20 l SCi-B X Microcontroller in Science Experiment kit 2.6 Infrared LED board : Infrared LED (connect to P0-P7) l A 3mm. Infrared LED and limit current resistor l Drive with logic HIGH TTL level l 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 l Serial Input RS-232 or Invert/Non-invert TTL/CMOS logic level. l 1/8 or 1/16 Duty can be selected by jumper. l Scott Edwards's LCD Serial Backpack ® command compatible addition with Extended Command that make LCD control easier. l Easy to interface with microcontroller l Operation with +5 to 12 Vdc supply (connect to P0-P7) SCi-B X Microcontroller in Science Experiment kit l 21 LCD Module connector attachment 1x14 or 2x7 pin type 14 CONNECTOR 14 PIN BRIGHTNESS Control 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 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 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 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 ... 22 l 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] , [0] , b] , [4] , b] , [2] , b] , [31] , b] , [2] , b] , [4] , b] , [0] , b] , [0] SCi-B X Microcontroller in Science Experiment kit l 23 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 129 130 131 Instruction / Action Initial LCD Clear Screen Return Home cursor Cursor not move after byte (S=1) ASCII 142 143 144 145 Instruction / Action Write CGRAM 0 ( *See note) Write CGRAM 1 Write CGRAM 2 Write CGRAM 3 132 133 134 135 Cursor increase after byte (I/D=1) Cursor decrease after byte (I/D=0) Display ON (D=1) Display OFF (D=0) 146 147 148 149 Write Write Write Write 136 137 138 139 140 141 Display ON with Cursor on Display ON with Blink Cursor on Shift Cursor to left Shift Cursor to right Shift Display to left Shift Display to right 150 151 152 153 154 155 156 Set DDRAM Set DDRAM Set DDRAM Set DDRAM Set DDRAM Set DDRAM Set DDRAM CGRAM CGRAM CGRAM CGRAM 4 5 6 7 to to to to to to to 00h 10h 14h 20h 40h 50h 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]. 24 l SCi-B X Microcontroller in Science Experiment kit Something to know about LCD module Character LCD modules are available 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 E SCi-B X Microcontroller in Science Experiment kit l 25 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 module board (IRM) and Signal Comparator 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 5 LOW 5 HIGH + , 5916+0 + , 4 / Bi-color LED 26 l SCi-B X Microcontroller in Science Experiment kit , 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 & $ ! !" !& " "$ # #" #& 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 1 S + 6 7 4 S Input 3.5V max. A>B B>A GREEN 5 B 510 A>B * B>A Active Low output , B>A A>B RED A ) S 3 LM393 A S 8 2 + + B COMPARATOR Outs logic "0" when A > B + D Outs logic "0" when B > A SCi-B X Microcontroller in Science Experiment kit l 27 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 28 l SCi-B X Microcontroller in Science Experiment kit 3.3 Instantaneous detection board 3.3.1 Sound event detector (connect P0 to P7) l Detect the sound level changing. l Output is pulse following the sound moment 2 SOUND 10k 0.1/50V 10k 470k S BC547 + MIC. 470k 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, BC547 transisitor. 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 l 29 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. 30 l 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 + + A Output voltage decrease will lights up Reverse variation output LIGHT A Light detected more, voltage decrease Direct variation output S 10k Light detected more, voltage increase + + LDR Light + + 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. Direct variation output Super bright red LED 10k LDR Light reflector sensor LED light sourc DR detects ght reflect Red LED super bright S + REFLECT LDR detects the light reflects from surface Light reflects more, output voltage increase. REFLECT + ) 220 SCi-B X Microcontroller in Science Experiment kit l 31 4.3 Temperature sensor (connect SENSOR0 to SENSOR7) S + + Temperature high Voltage increase 10k + 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 temperature (25ðC) is equal 10kΩ 32 l 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 + ) 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 l 33 UGN3503 N N S The direction of magnetic field density is positive. Output voltage is higher +2.5V. S UGN3503 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 − .# .! ................................................................. (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 ) # × ....................................................... (4.2) ## .! 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. 34 l 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 ) POTENTIOMETER A S Turn couter clockwise, Output voltage increases. + Horizontal type Turn clockwise, Output voltage increases. 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 + 10kB + + the shaft of Slide. Output of this sensor has 2 formats : S This sensor is used to specific 0 to 5V following move 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. ) Move to left, Output voltage increases. SCi-B X Microcontroller in Science Experiment kit l 35 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. ) 2. Read value in digital. Output is logic “0” when PHOTO TRANSISTOR detect infrared light. 10k Usability : recommended to use this sensor with Infrared LED board. E + S Photo transistor Optical spectrum Violet Blue 400 nm X-rays 1nm Green 500 nm Orange 600 nm White light Ultraviolet 10nm Near infrared Yellow 100nm Red 700 nm 800 nm Infrared 1mm Wavelength 10mm 100µm Microwave 1mm 10mm 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. 36 l 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. RESISTANCE 1 LM334 constant current source 100n 2 3 68R 1mA set 5 OUT 8 7 6 S R unknown TLC2272 + ) 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. Input resistance for setting measurement range (R shunt) is equal 0.5Ω and 500mW maximum power rating. OUT 1k OUT 8 7 5 4 TLC2272 10k 1k Input : 1A max. 1.5V Testing point A S 0.5R 6 0.1/50V 0.5 Ohm 10k CURRENT Current flow direction that measurement CURRENT + A Output : 5mV/mA LOAD Example circuit for using this Current sensor board SCi-B X Microcontroller in Science Experiment kit l 37 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. l 1 select attenuator ratio to 1:1. Setting range of input voltage is 0 to 5V l 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 1 1/2 5 6 1M Ratio 1 : Input 0-5V. Ratio 1/2 : Input 0-10V. INNOVATIVE EXPERIMENT 0.1/50V 8 7 4 TLC2272 OUT S VOLT Input + ) Output : 0-5V 38 l SCi-B X Microcontroller in Science Experiment kit SCi-B X Microcontroller in Science Experiment kitl39 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-Stamp 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 40lSCi-B X Microcontroller in Science Experiment kit SCi-BOX contains PBASIC code of BASIC Stamp2SX Experimental activity 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.BSX : Read data from anlog sensor one channel. C_Single.BSX : Read data from Capacitance sensor one channel. Dual.BSX : Read data from analog sensor two channels. All 3 .bsx file will convert to .obj file for download to i-Stamp 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 kitl41 Select number of recording data (100-1,000) 3 1 Select resoultion of Data axis (1,024 or 65,536) 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 42lSCi-B X Microcontroller in Science Experiment kit SCi-B X Microcontroller in Science Experiment kit l 43 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-Stamp. It is OEM version of BASIC Stamp2SX 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. 44 l 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 $ % & ' ! " # DB-9 female side DB-9 male side 9-wires multicore cable R S -232 D O W N LO A D ! " # D C IN P U T RESET i-Stamp OFF SCi-BOX BASIC Stamp in Science Experiment $ % & ' ON Male DB-9 connector SCi-B X Microcontroller in Science Experiment kit l 45 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 à BS2SX. The message ‘{$STAMP BS2SX} 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. 46 l 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. SCi-B X Microcontroller in Science Experiment kit l 47 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. 48 l SCi-B X Microcontroller in Science Experiment kit 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 2SX!”] Send command value to P8 pin of i-Stamp with 9600 bit per second baudrate in direct logic for sending message Hello Stamp 2SX! SCi-B X Microcontroller in Science Experiment kit l 49 Example 6-3 SEROUT 8,240,[154,”Test Line 2 LCD”] Send command value to P8 pin of i-Stamp 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-Stamp 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 50 l SCi-B X Microcontroller in Science Experiment kit 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 PCB3AA-8 cable between Swtich input board with P0 at SCi-BOX main board. 2. Write the PBASIC code below '{$STAMP BS2SX} '{$PBASIC 2.5} '*************************************************** ' File: ACT18.BSX ' Purpose : Sound generation by switch ' Hardware : Connect SWITCH as actived “LOW” at P0 '*************************************************** ' Custom I/O ON this application SWITCHVAR 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 1.5kHz TO 2.5kHz 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 l 51 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 PCB3AA-8 cable between Swtich input board with P0 at SCi-BOX main board. 2. Write the PBASIC code below '{$STAMP BS2SX} '{$PBASIC 2.5} '****************************************************** ' File : ACT19.BSX ' Purpose : Relay selector ' Hardware : Jumper at RELAY position ' Connect SWITCH as actived “LOW” at P0 '****************************************************** SWITCHCON 0 ' Connect SWITCH here! CH VAR Byte ' Channel SELECT SW_VARVAR 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 ' GOTO 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 52 l SCi-B X Microcontroller in Science Experiment kit 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 Procudure 1. Connect PCB3AA-8 cable between Potentiometer board with SENSOR0 at SCi-BOX main board. 2. Write the PBASIC code. SCi-B X Microcontroller in Science Experiment kit l 53 '{$STAMP BS2SX} '{$PBASIC 2.5} '************************************************ ' File : ACT20.BSX ' 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 PAUSE 1000 ' VALUE as SENSOR0 variable ' RESULT FOR calculation purpose ' Delay 1s. for pheripheral initialize 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 Byte TO 1 Word DEBUG HOME,"READ DATA = ",DEC4 VALUE," is " ' Convert 0-1023 DATA TO 000-499 RESULT=(VALUE*/((62*$100)+$80))/128 ' 1024 STEP TO 500 STEP ' Equation (Value * 62.5)/128 ' Represent DATA into 2 point decimal X.XX volt format DEBUG DEC1 RESULT DIG 2,".",DEC1 RESULT DIG 1,DEC1 RESULT DIG 0," volt" PAUSE 100 GOTO LOOP1 ' Delay 100ms. ' 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 54 l 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 PCB3AA-8 cable between 2 of Potentiometer boards with SENSOR0 and SENSOR1 at SCi-BOX main board. 2. Connect DC motor to Motor A connector . 3. Write the PBASIC code. SCi-B X Microcontroller in Science Experiment kit l 55 '{$STAMP BS2sx} '{$PBASIC 2.5} '************************************************************************ ' File : ACT21.BSX ' 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 VALUE SENSOR CH VAR VAR VAR Word Word(2) Byte ' VALUE as SENSOR variable ' SENSOR, 2 Word array ' Channel SELECT PAUSE 1000 ' Delay 1s. FOR pheripheral initialize LOOP1: FOR CH=0 TO 1 GOSUB Get_SENSOR : SENSOR(CH)=VALUE ' GET sensor0 AND 1 DEBUG DEC SENSOR(CH)," " ' View DATA ON DEBUG NEXT DEBUG CR ' Carriage RETURN Check_A: IF SENSOR(0)>=512 THEN A_Forward LOW 8 : HIGH 9 : GOTO Check_B A_Forward: HIGH 8 : LOW 9 ' Rules FOR decision ' Backward IF less than 512 ' 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 ' '***************************** ' GET sensor value subroutine '***************************** Get_SENSOR: LOW SD : PAUSE 1 : HIGH SD ' SEROUT SD,BAUD,[CH] ' SERIN SD,BAUD,[VALUE.LOWBYTE,VALUE.HIGHBYTE] RETURN ' DO again Break signal Request SENSOR0 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 56 l SCi-B X Microcontroller in Science Experiment kit 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] SCi-B X Microcontroller in Science Experiment kit l 57 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. 58 l SCi-B X Microcontroller in Science Experiment kit 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 PCB3AA-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 . 3. Write the PBASIC code below '{$STAMP BS2SX} '{$PBASIC 2.5} '****************************************************************** 'File : ACT23.BSX 'Purpose : Running Stepper motor 1 AND 2 'Hardware : Connect POTENTIOMETER #1 at SENSOR0 (motor 1 control) ' Connect POTENTIOMETER #2 at SENSOR1 (motor 2 control) '****************************************************************** 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 VALUE VAR Word ' VALUE as SENSOR variable SENSOR VAR Word(2) ' SENSOR, 2 Word array CH VAR Byte ' Channel SELECT L VAR Byte R VAR Byte PAUSE 1000 ' Delay 1s. for peripheral initialize ' Set full powered, half STEP, STEP delay 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 sensor 0 AND 1 DEBUG DEC SENSOR(CH)," " ' View DATA ON DEBUG NEXT DEBUG CR SCi-B X Microcontroller in Science Experiment kit l 59 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 ' Call drive GOTO LOOP1 ' DO again '**************************** ' Drive stepper motor routine '**************************** Drive : SEROUT SO,BAUD,[L,R] ' Drive L & R motor -127 TO +127 range Poll_BUSY : IF BUSY=0 THEN Poll_BUSY RETURN ' RETURN TO main '**************************** ' 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 Byte 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. 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. 60 l SCi-B X Microcontroller in Science Experiment kit