at-bot e120703 small

Upload: nz225

Post on 08-Jan-2016

216 views

Category:

Documents


0 download

DESCRIPTION

inex

TRANSCRIPT

  • Robo-Creator : AT-BOT ctivity book 1

    AT-BOTThe 4-wheel autonomous robot

    programmed with C/C++ language

    Activity book

  • 2Robo-Creator : AT-BOT activity book

    AT-BOT activity book

    All rights reserved under the Copyrights Act B.E. 2537

    Do not copy any part of this book without our permission

    Who should use this handbook?

    1. Students and other people who are interested in applying to microcontrollers for

    testing working process of automatic system or people who are fascinated in learning

    and examining the microcontrollers in new approaches such as using an autonomous

    robot as a form of an interactive media.

    2. Academic institutes such as schools, colleges and universities, where provide

    electronic subjects or electronic and computing engineering departments.

    3. Lecturers and teachers who would like to study and prepare lesson plans for

    microcontroller courses, including applied science which focuses on integrating

    electronics, microcontrollers, computer programming and scientific examination in high

    school education, vocational education, and bachelors degree.

    Published and distributed by

    Innovative Experiment Co.,Ltd.

    108 Soi Sukumvit 101/2 Sukumvit Road, Bangna, Bangkok 10260 THAILAND

    Details and illustrations used in this handbook are thoroughly and carefully to provide

    the most accurate and comprehensive information under the conditions and time we

    have before publishing. Innovative Experiment Co.,Ltd. shall not be responsible for

    any damages whatsoever resulting from the information of this book as constant

    revisions and updates will be published after this edition.

  • Robo-Creator : AT-BOT ctivity book 3

    All Illustrations and Technical information found in this handbook are in our best

    interest to simplify working processes and equipment principles so that it could be easily

    understood by any user interested in robotics.

    Therefore, The translation from THAI language to English and the usage of technical

    terms may not follow the provision of the Royal Academy where they are many words

    not described officially. Our team would be allowed to produce new technical terms.

    The main reason of this explanation comes from data collection of equipment in

    embedded computer system and robotic technology. Thai language is quite hard to

    translate into English and thus our writer team gathered the required data and

    investigated to make sure that the understanding in working processes has the limited

    error.

    When we compose the information in Thai, many technical terms have

    complicated meanings. Definition of vocabulary occurred from the practice

    coordinated with linguistic meaning. If there are any errors or mistakes shown, the team

    of writer will accept and if we get explanation or suggestion from any expert, we will

    clarify and improve those errors as soon as possible.

    In order to develop the academic media especially with new technological

    knowledge, it will be able to proceed continually under the participation of experts in

    all fields.

    Innovative Experiment Co.,Ltd.

    Clarification from writer/complier team

  • 4Robo-Creator : AT-BOT activity book

    Chapter 1 AT-BOT : The 4-wheel autonomous robot......................................5

    Chapter 2 AT-BOT Development tools...............................................................17

    Chapter 3 Wiring IDE introduction.....................................................................23

    Chapter 4 ATX Library file....................................................................................35

    Chapter 5 The ATX controller board hardware experiment..........49

    Chapter 6 AT-BOT movement........................................................79

    Chapter 7 Object avoiding by contact........93

    Chapter 8 AT-BOT Line tracking..............................................................105

    Chapter 9 AT-BOT with touchless object avoiding............................................147

    Chapter 10 AT-BOT with Servo motor ......................................................155

    Table of contents

  • Robo-Creator : AT-BOT activity book 5

    Chapter 1

    AT-BOT : The 4-wheel autonomous robot

    AT-BOT (All-Terrain mobile robot) is an autonomous robot performed by DC motors

    with the set of 4 DC motor gearboxes come with spiked wheels in order to aid passing

    through rough surface more efficiently. Also, it can move up on the slope in the level of 0

    to 25 degree and if it is necessary to stop immediately to change the direction of motion,

    it can do. The possibility is that AT-BOT is capable of supporting any mission in either a

    smooth competition court with lines appeared for determining directions of motion or

    rough court with barriers or participating with the World RoboCup Junior-Rescue.

    Programming development of AT-BOT robots uses C/C++ language in the open

    source software are named Wiring (www.wiring.org.co).

    AT-BOT controller boad is called ATX board, which is able to drive 6 of DC motors

    and 6 of Servo motors together. It has many ports for interfacing with both digital and

    analog sensors, basic digital outpuit port and using the data communication via 2 lined

    bus system called I2C bus and the standard UART serial bus.

    The main driving system is consisted of 4 DC motor gearboxes with spiked wheels.

    This results the AT-BOT with four-wheel automatic robot has a high driving power and high

    speed. It identifies that this is a presentation of the different robot driving system from the

    old system for studying.

    AT-BOT is one of the robotic activities of Robo-Creator, the robotic kit for creative

    education.

  • 6Robo-Creator : AT-BOT activity book

    1.1 AT-BOT part list1. ATX controller board

    2. USB-miniB cable

    3. Light reflector (ZX-03R) 4 sets

    4. Touch sensor (Switch input boards) 2 sets

    5. BO-1 DC motor gearbox 48:1 ratio with mounting and cable 4 sets

    6. Standard servo motor x 1

    7. Spike wheel sets (diameter 65mm., width 26mm. also include the hub for BO-1

    gearbox) 4 sets

    8. 5-AA battery holder with wire

    9. Plasitc joiner set and Strip joiner set

    10. Right angle metal shaft set

    11. Nuts and screws set

    12. CD-ROM (software, example code and documentations)

    13. Activity manual and construction sheet

    14. Line tracking demonstration paper

    1.2 ATX controller board featuresIn the figure 1-1, it is shown components of the ATX controller board and there are

    significant technical features as follows:

    Main microcontroller is Atmels ATmega128. It features 8-ch 10-bit Analog to

    Digial Converter, 128-KByte Flash memory , 4-KByte EEPROM, 4-KByte RAM. Operated with

    16MHz clock from external crystal

    Define all ports compatible with Wiring I/O standard hardware (www

    .wiring.org.co). The number of port are 0 to 50.

    13 programmable port in JST connector type. Includes Digital I/O port (2 :

    port 14 and 15), A/D port (7 : port 40/ADC0 to port 46/ADC6), Two-wire interface or TWI (2

    : port 0/SDA and port 1/SCL) and UART serial port communication (2 : port 2/RX1 and port

    3/TX1). Both TWI and UART ports can config to digital input/output port for more I/O

    applications.

    Analog input (ADC0 to ADC6) supports 0 to +5Vdc input. The converter

    resolution is 10-bit. The result value is 0 to 1,023 range.

  • Robo-Creator : AT-BOT activity book 7

    One variable resistor is connected with the Analog input ADC7 of main

    microcontroller for simple ADC experiment.

    2 of button switches with resistor pull-up are connected with port 49 and 50 of

    the Wiring I/O controller board for simple digital input experiment.

    One LED with a current limited resistor. It is connected with port 48

    One piezo speaker at port 4

    16x2 characters LCD for monitoring

    On-board digital compass; HMC6352 from Honeywell. It is interfaced by I2C

    bus or TWI

    UART port for interfacing serial module device such as camera module (ZX-

    CCD, CMUCAM1, CMUCAM2, mCAM), servo controller board (Parallax servo controller,

    ZX-SERVO16U), Real-time clock (ZX-17 : serial real-time clock moduel)

    6-ch DC motor driver with indicators. Support 4.5V to 9V DC motor. Maximum

    current output 3A and 1.2A continuous.

    6-RC servo motor output; support 4.8 to 7.2V standard and continuous servo

    motor types.

    Motor driver power indicator; nomally turned on. It will off when motor is short-circuit.

    Figure 1-1 : ATX controller board layout

    ON

    MOTOR

    BATTERY LEVEL1312111098

    SERVO PORT

    7.2

    -9V B

    ATT.

    E2

    RESET

    +

    -S

    14 15PC6 PC7

    C r e

    c o n

    a t o r e > > > >

    t r o l l r b o a

    >

    e r dR

    >

    4850SW249SW1ADC7KNOB

    TWI UART1

    0 SCL 1 SDA 2 RX1 3 TX1

    44 ADC446 ADC640 ADC041 ADC142 ADC2 START

    45 ADC5

    > >

    USB DATA

    43 ADC3

    32

    10

    45

  • 8Robo-Creator : AT-BOT activity book

    5-status battery level monitor circuit :

    - Last left yellow LED displays that the input supply voltage is 6.75V. When the

    battery voltage is lower than 6.75V, this LED will start to blink.

    - Next yellow LED displays the input supply voltage at 7.0V.

    - First green LED displays the input supply voltage at 7.25V.

    - Second green LED displays the input supply voltage 7.5V.

    - Last right green LED displays that the input supply voltage is higher than at 7.75V.

    Download and interface with computer via USB port by using USB to UART

    converter chip; FT232RL. USB connection indicator is available.

    Set the operation by Mode/Reset switch

    Supply voltage range +7.2 to +9V 2400mA for 4 motor loads.

    2 voltage regulator on-board; +5Vdc for microcontroller and all digital circuit,

    +6Vdc for all motor driver circuits. By using voltage regulator; the motor driver circuit can

    drives DC motor with constant speed when battery voltage is full and reduce to 60%. It

    features constant speed without effect by battery voltage until it is lower 60% of full.

  • Robo-Creator : AT-BOT activity book 9

    1.3 Output device features

    1.3.1 DC motor gearbox

    DC motor gearbox of Robo-Creator kit is the BO1 model. The technical features are as

    follows :

    Requires the supply voltage +4.8 to +9Vdc 130mA @6V and no load

    Gear ratio 48:1

    Speed 250 round per minute @6V and no load

    Weight 30 gram

    Torque 0.5kg.-cm.

    Figure1-2 : Details and gear diagram of BO-1 DC motor gearbox

    Follower gear (1)36 teeth

    Driver gear (1) 8 teeth

    Driver gear (2) 9 teeth

    Driver gear (3) 17 teeth

    Driver gear (4) 17 teeth

    Follower gear (2)36 teeth

    Follower gear (3)28 teeth

    Follower gear (4)28 teeth

  • 10Robo-Creator : AT-BOT activity book

    1.3.2 Standard servo motor

    Servo motor has 3 wires; Signal (S), Supply voltage(+V) and Ground (G) The technical

    features is as follows :

    Requires the supply voltage +4.8 to +6Vdc

    Weight 45 gram

    Torque 3.40kg-cm. or 47 oz-inches.

    Size (width x length x height) 40.5 x 20 x 38 mm. or 1.60 x 0.79 x 1.50 inches.

    DATAR3220

    R210k

    R1510

    LED1

    S1

    Switch GND

    +V

    Figure 1-4 : The touch sensor or Switch input board picture andschematic diagram

    1.4 Sensor features

    1.4.1 Touch sensor/Switch input board

    The circuit is shown in the figure 1-4 including a switch with a LED and considered

    output as logic 0 when switch is pressed.

    If the switch is pressed : the logic 0 will be sent and the red LED is on.

    If no press : LED is off and the logic is 1.

    (A)(B) (C)

    Figure 1-3 : Details of standard RC servo motor of Robo-128

    (A) outside body (B) Gear system (C) Electronic circuit board

  • Robo-Creator : AT-BOT activity book 11

    Figure 1-5 : Light reflector sensor layout andshcematic diagram

    10k

    LED1

    220

    +V

    GND

    OUTSFH310

    1.4.2 The light reflection sensor : ZX-03R

    The circuit and layout of this sensor are displayed in the figure 1-5. The circuit is used

    to detect the reflected lights from surface or lines.

    During apply the power supply, the red LED is bright at all the time. Meanwhile, the

    light receptor is SFH310 photo-transistor and it will get red lights from the reflection of objects

    or surface. The amount of the reflected light will be more or less depending whether there is

    an obstacle or not and how well the object can reflect red light. The reflection of red lights

    is based on the surface texture and colour of objects. It is said that the white smooth objects

    are able to reflect light well so the infrared receptor gets a lot of reflected light and the

    output voltage will be high. As black objects reflect less light, the light receptor sends low

    voltage. With such features, the sensor circuit board is often used to trap the reflected light

    on the surface and lines. It is necessary to install the circuit at the lower part of a robot.

    With the use of red light as a main light to detect, this allows the sensor to measure

    the colour difference on the surface printed by IR or UV resistant ink.

    Due to ZX-03R light detection circuit gives the result as DC voltage, applying on AT-

    BOT robot has to connect the signal to 7 channels of analog input on the ATX controller

    board, from ADC0 to ADC6. After reading the analog signal value, use this value to check

    the value on reflected light detection circuit and then apply to detect lines.

    1.4.3 GP2D120 module detecting distance with Infrared

    GP2D120 is a module that detects distance with Infrared and with the packet of 3

    extension parts, including 3 pins; +Vcc, GND and Vout. Reading voltage value from GP2D120

    must do after the preparation period of the module, which takes 32.7 to 52.9 millisecond (1

    millisecond equal 0.001 second). So reading the value should wait for the suitable time as

    mentioned above and shown the basic data in the figure 1-6.

    Output voltage of GP2D120 at the distance of 30 centimetres, the power supply at

    +5V as in the range of 0.25 to 0.55V has the mean as 0.4V and the range of output voltage

    change at the distance of 4 centimetres is 2.25V0.3V.

    Light reflection sensor

    Output port LED

  • 12Robo-Creator : AT-BOT activity book

    How to measure distance

    The infrared light is sent out from a transmitter to the object

    in front, by passing through a condense lens so that the

    light intensity is focused on a certain point. Refraction

    occurs once the light hits the surface of the object. Part of

    the refracted light will be sent back to the receiver end, in

    which another lens will combine these lights and determine

    the point of impact. The light will then be passed on to an

    array of photo-transistors. The position in which the light falls

    can be used to calculate the distance (L) from the

    transmitter to the obstacle using the following formula:

    L F

    A X

    Therefore, L equals

    F AL

    X

    Thus, the distance value from the phototransistors will be

    sent to the Signal Evaluation Module before it is changed

    to voltage, resulting in a change of voltage according to

    the measured distance.

    Figure 1-6 : shown shape, arrangement of pins, diagram of time ofoperation, and graph shown the operation of GP2D120 sensor

    Infrared LED transmitter Infrared Receiver

    GNDVout Vcc

    GP2D120

    4 8 12 16 20 24 28 3200

    0.4

    0.8

    1.2

    1.6

    2.0

    2.4

    2.8

    Output voltage (V)

    Distance (cm)

    1st measure 2nd measure

    Not stable 1st output 2nd output n output

    n measure

    38.39.6 ms

    5 ms

    Measurement

    Vout

    Supply

    * Use Kodak R-27 gray-white paper.

    The white side has a 90%

    reflection rate, made from a

    material that reflects light for range

    measurement.

    L

    A

    F

    X

    Object

    GP2D120

    Transmit LED Photo array

  • Robo-Creator : AT-BOT activity book 13

    1.5 Mechanical compoments

    1.5.1 Plastic wheels for BO-1 DC motor gearbox and rubber tire

    A circular wheel has the diameter of 65 millimeters. It is able to fit with the axis of BO-

    1 gear motor directly without any additional modification and tighten with a 2 mm tapping

    screw. A wheel tire is made up of rubber and its texture has treads in order to enhance in

    sticking over the surface.

    1.5.2 Spike wheel

    The wheels are unique. The wheel surface is rubber and has triangular buttons with

    rounded end and thorn-like protrusions to aid in adhesion and movement across smooth

    surface, rugged surface, slope or zippers with the slope less than 20 degree.

    To install this kind of plastic wheels with the axis of the gear motor of model BO-1 will

    be required to use special joints to help and attach with a screw and 3 mm nuts.

    1.5.3 Track and wheel set

    It is a track set constructed for track with

    wheels or crawler track with wheels in different

    sizes and it is compatible with a plate set. The

    set includes tracks with 30 joints (2 pieces), 10

    joints (4 pieces), 8 joints (4 pieces), driving

    wheels (2 pieces), large support wheels (2

    pieces), medium support wheels (10 pieces),

    poly caps (12 pieces), stainless axis with the

    diameter of 3 mm, length of 110 mm (4 pieces)

    and necessary screw set.

  • 14Robo-Creator : AT-BOT activity book

    1.5.4 Base plate and Plate set

    It is a multi-purpose material set for making the base or the chassis frame. The set

    provides plastic plates produced from 2 types of ABS materials. The first type is called AT-

    plate in black and the other is a plate with the size of 160 x 60 mm. There are holes on the

    plates and each hole is 3 mm in size and they are seperated by 5 mm in distance and the

    total holes are 341. The set also contains brackets for long axis (2 pieces), brackets for

    short axis (2 pieces) and a screw set necessary for fastening.

    1.5.5 Grid plates

    Plates are plastic manufactured from ABS materials in the size of 80 x 60 mm and 80 x

    80 mm each. Each hole has the size of 3 mm and the distance between each hole is 5 mm.

    1.5.6 Plastic joiners

    They are stiffed plastic components and there are three designs, including, straight

    joiners, right angle joiners, and obtuse angle joiners. Each piece can be inserted together

    and they are used to construct a decorated structure (or decoration). A set contains all

    three types, available 5 colors and 4 pieces for each, and 60 pieces in total.

  • Robo-Creator : AT-BOT activity book 15

    1.5.7 Plastic strip joiners

    They are rigid and tough and there are holes in the size of 3 mm for each piece for

    installing or connecting with other structure components by a screw. At the end of each

    rod can insert with plastic joiners. There are three different sizes including 3, 5 and 12 holes

    and each size has 4 pieces in a set.

    1.5.8 Metal angle bar

    Metal angle bars are metal components with the width of 7.5 mm and they are

    cut into the right angle shape. There are holes with the size of 3 mm for using a screw to

    install or construct with other structure parts. Three different sizes are provided in a set,

    including 1x2 holes, 1x2 holes, and 2x5 holes and each size contains 4 pieces.

    1.5.9 Screws and nuts

    Screws and nuts are equipment for fastening many components together. They

    compose of 2 mm-tapping screws (4 pieces), 3x8 mm-tapping screws (4 pieces), 3x10 mm-

    tapping screws (30 pieces), 3x15 mm-tapping screws (4 pieces), 3x40 mm-tapping screws

    (4 pieces), 3x8 mm-flat head screws (4 pieces), 3x5 mm-hand driven screws (4 pieces), 3x20

    mm-hand driven screws (2 pieces), and 3 mm-nuts (30 pieces).

    1.5.10 Metal stands-off

    This kind of materials helps to hold different components together and support

    boards, grid plates and base plates. They are made of rustproof nickle-plated metal and

    have a characteristic of cylinder with the length of 25 mm. Inside of a cylinder, there is a

    spiral hole along its body for a 3 mm-screw to fasten and 3 poles are provided in a set.

  • 16Robo-Creator : AT-BOT activity book

    1.5.11 Plastic stands-off

    Plastic stands-off help fasten different parts and prop up boards, grid plates, and

    base plates. They are made from cohesive ABS plastic but able to be cut. The shape of

    the rod is cylindrical and there is a hole throughout the rod to insert 3 mm-screws. You can

    get different sizes and number of support poles, including, 3 mm. (4 pieces), 10 mm. (4

    pieces), 15 mm. (4 pieces), and 25 mm. (4 pieces) in the set.

    1.5.12 5-AA Battery holder

    It is used to carry 5 AA batteries. There is a wire which connects the anode and the

    cathode to the main controller board immediately.

    1.5.13 JST3AA-8 cable

    This is an INEX standard cable, 3-wires combined with 2mm. The JST connector is at

    each end. 8 inches (20cm.) in length. Used for connecting between controller board and

    all sensor modules in the Robo-Creator kit. The wire assignment is shown in the diagram

    below.

    2mm. pitch

    GNDS

    +5V

    2mm. pitchGND

    S/Data

    +5V

  • Robo-Creator : AT-BOT activity book 17

    Robo-Creator robot kit supports the operation controller program which can be

    developed from Assembly, BASIC or C programming languages. For here, we will use

    C/C++ programming language with the open-source software called Wiring, which is

    the name of a development project of a small control system in order to apply the

    software and hardware together.

    We focus on concrete utilization as well as the connection of devices with

    electronic system so that the system can work according to the statement written

    correctly, collectively, Physical computing or the computer system which concentrates

    on physical signal connection, connecting external sensor devices or controlling display

    of LEDs, light, and sound, etc.

    The official website of Wiring here is www.wiring.org.co. At this website, there is

    data of both hardware and software allowed to download with free of charge. Also, it

    is the open-source project to give an opportunity to developers who will be able to join

    the project and expand the project freely.

    The founder of Wiring is Hernando Barragan (Architecture and Design School,

    Universidad de Los Andes, Comlumbia). Wiring started at the Interaction Design Institute

    Ivrea in Italy and it is currently developed at the Universidad de Los Andes, Architecture

    and Design School in Colombia.

    2.1 Supported operating systemThe software for the program development is Wiring Development Environment

    or sometimes called Wiring IDE and it can work with these operating systems or platforms.

    Mac OS X 10.4 or higher (both models using Powerpc and Intel CPU)

    Windows XP, Windows Vista and 7

    Linux, both Fedora Core and Debian (including Ubuntu as well)

    Other platforms which support the operation of Java 1.4 up

    2.2 Wiring hardware The main hardware of Wiring is Wiring I/O board which is a small circuit board

    with ATmega128 microcontroller. ATmega microcontroller is very important to control

    all kinds of work in which the main controller or microcontroller will be programmed

    Chapter 2

    AT-BOT Development tools

  • 18Robo-Creator : AT-BOT activity book

    through USB port in Wiring IDE software. There is a connection point to recieve signals

    from both analog and digital external sensors that allows the board to acquire information

    from the surrounding environment (temperature, light, distance to an object etc.).

    Moreover, there is another point to send signals out to control external devices, such

    as LEDs, loudspeakers, servo motors, and liquid crystal display or LCD, etc.

    Robo-Creator robot kit provides the hardware of controller board compatible

    with Wiring hardware and the system of Wiring IDE so you will be able to develop the

    program comfortably.

    2.3 Introduction to Wiring 1.0 IDEWiring 1.0 is the software for developing C/C++ programming language in order

    to create a program controlling ATmega1281 microcontroller on Wiring I/O hardware

    and then use the program in AT-BOT robot in Robo-Creator kit as well.

    In the kit, tools used in development of the program are contained completely in

    the format of IDE (Integrated Development Environment), either the text editor for coding

    or C complier. Downloading the program and the window of serial monitor for receiving

    and sending serial information to AT-BOT robot. Wiring is designed to use easily and the

    C/C++ language is for programming which can work on the operating system of

    Windows XP up, Linux and MAC OSX and installation files for each platform are separated.

    2.3.1 Software installation

    (1) Insert the CD Rom, come with Robo-Creator robot kit. Click the file named

    Wiring1000_RoboCreatorR1_Setup.exe (the number of the installation file may be

    changeable) and then the window of welcoming to the Wiring 1.0 setup will appear.

  • Robo-Creator : AT-BOT activity book 19

    (2) Next, click to agree in each step of the setup as installation of other applications

    of Windows until completion.

    (3) Installing the Wiring 1.0 software by using the CD rom is bundled with Robo-

    Creator robotic kit is the setup of both Wiring 1.0 software and USB driver to connect

    with ATX controller board in the same time.

    (4) Test to start the program by select START > All Programs > Wiring. Then for a few

    moment, the window of Wiring IDE will be present.

    After That you can use the Wiring IDE in the program development for AT-BOT

    robots.

  • 20Robo-Creator : AT-BOT activity book

    2.3.2 Checking the USB Serial port for the AT-BOT

    (1) Plug the USB cable connecting ATX control board with the USB port of the

    computer. Turn on and wait for the blue LED at the position of USB on the circuit board

    is on as the figure 2-1.

    (2) Click the START button and go to the Control Panel.

    (3) Then double-click the System

    (4) Go to the tab of Hardware and click on the Device Manager button

    Figure 2-1 : The steps of preparation for checking USB serial portpositions of AT-BOT robot

    MOTOR

    BATTERY LEVEL1312111098

    SERVO PORT

    7.2

    -9V B

    ATT.

    E2

    RESET

    +

    -S

    14 15PC6 PC7

    R o b

    > o R

    o - C r e a o r >

    u n n i n . . o a

    t

    g r d.

    >

    4850SW249SW1ADC7KNOB

    TWI UART1

    0 SCL 1 SDA 2 RX1 3 TX1

    44 ADC446 ADC640 ADC041 ADC142 ADC2 STAR

    T

    45 ADC5

    > >

    USB DATA

    43 ADC3

    32

    10

    45

    Connect with USB port

    Turn on power

    2

    4 Display RUN mode

    1

    Wait until the USB LED is on3

  • Robo-Creator : AT-BOT activity book 21

    (5) Check the hardware listing at Port. You should see USB Serial port . Check the

    position. Normally it is COM3 or higher (for example; COM10). You must use this COM

    port with the Wiring IDE software.

  • 22Robo-Creator : AT-BOT activity book

    2.3.3 AT-BOT with Wiring IDE interface

    (1) Open Wiring IDE. Wait for a while. The main window of Wiring IDE will appear.

    (2) Choose the suitable hardware by select menu Tools > Board > INEX > Robo-

    Creator R1 > ATmega1281 @16MHz

    (3) Select menu Tools > Serial Port to choose the USB serial port of AT-BOT. It is

    COM4 (for example).

    Must do this step for every new connection of the AT-BOT with Wiring IDE

    Now the AT-BOT is ready for interfacing and code development with the Wiring

    IDE.

  • Robo-Creator : AT-BOT activity book 23

    This chapter presents preliminary information of Wiring, which is the software tool

    for developing the operation of AT-BOT robots or one of the activities to build robots in

    Robo-Creator kit. For the details of program structure of C/C++ language Wiring supports,

    you can read in the Wiring IDE help.

    3.1 Components of Wiring IDEWiring IDE consist of two important parts which are text editor and C/C++

    compiler. There are many tools and command buttons to help the program

    development as appeared in the figure 3-1.

    3.1.1 Menu bar

    Including File, Edit, Sketch, Tools and Help menu, will affect work files doing at

    the present only.

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

    Chapter 3

    Wiring IDE introduction

  • 24Robo-Creator : AT-BOT activity book

    3.1.1.1 File

    New (Ctrl+N) : Create new files. This is called sketch in Wiring and given name

    following the recent date in the format sketch_YYMMDDa, such as sketch_080407a or

    click the button on the tool bar.

    Open (Ctrl+O) : Open the exist sketch file or click on the button .

    Close (Ctrl+W) : Choose to close the sketch file.

    Save (Ctrl+S) : Save the open sketch file in the old name and work similarly to

    click the button on the tool bar.

    Save as(Ctrl+Shift+O) : Save the open sketch file in the new name and the old

    file will not disappear.

    Upload to Wiring hardware (Ctrl+U) : Exports the program to the Wiring I/O Board

    (inthis document is the ATX controller board). After the files are exported, the directory

    containing the exported files is opened. There is more information about uploading

    below. It works in the same way as click the button on the tool bar.

    Preference : Customize the operation of Wiring IDE

    Quit (Ctrl+Q) : Quit the Wiring program and close all windows of Wiring program.

  • Robo-Creator : AT-BOT activity book 25

    3.1.1.2 Edit

    The menu contains commands used to edit the sketch file that develops on the

    Wiring IDE.

    Undo (Ctrl+Z) : cancel the previous action of a command or the lastest typing.

    You can cancel Undo command by click Edit > Redo.

    Redo (Ctrl+Y) : To return to make a statement made before the Undo command

    is available only when done Undo already.

    Cut (Ctrl+X) : Delete and copy the selected text to store at the clipboard, which

    functions as the temporary memory unit to preserve information.

    Paste (Ctrl+V) : Place the data in the clipboard on the desired position or replace

    the selected text.

    Select All (Ctrl+A) : Select all letters or text in the open file in the text editor at that

    time.

    Find (Ctrl+F) : Search for any text in the open file in the text editor. In addition, it is

    also able to find and replace another text.

    Find Next (Ctrl+G) : Find text or words we use to search for the next one within

    the open file in the text editor.

  • 26Robo-Creator : AT-BOT activity book

    3.1.1.3 Sketch

    Sketch menu is a command menu relating to compile a sketch file.

    Verify/Compile (Ctrl+R) : It is a command of program compilation and its function

    is similar to pressing the button on the tool bar.

    Import Library : Open the included library of Wiring.

    Show Sketch Folder : Show the folder of the current sketch file.

    Add File: Add the required program file to the sketch file.

    3.1.1.4 Tools

    Tools menu is a command menu relating to selection of tools helped to develop

    a program. Important commands you should know are as follows.

    Auto Format : Try to format program code in the completed form.

    Serial Monitor : Open the serial data terminal.

    Board : Choose the interfaced hardwarere with the Wiring 1.0.

    Serial Port : Choose the interfaced port of the Wiring I/O hardware.

  • Robo-Creator : AT-BOT activity book 27

    3.1.1.5 Help

    Getting Started : Open the window about the using Wiring of the Wiring website.

    Examples : Open a sketch file of an example program.

    Reference : Open Reference window of the Wiring website. It consists of

    language, programming environment, libraries, and language comparison. You have

    to connect with the internet if you would like to see the information.

    Find in Reference (Ctrl+Shift+F) : Choose text in your program code. Here you will

    drag black bar and click on it. The program will take the text you have chosen to find in

    reference and if it cannot find anything, there will be a warning message in the window

    of the program.

    Wiring Hardware : Browse the information of Wiring I/O hardware via internet.

    Troubleshooting : Open the window about solutions in performance of the Wiring

    of the Wiring website.

    Visit wiring.org.co (Ctrl+5) : Open the web browser to visit the homepage of

    Wiring at http://wiring.org.co.

    About Wiring : Show the copyright on the Wiring software

  • 28Robo-Creator : AT-BOT activity book

    3.1.2 Toolbar

    There are six buttons of basic functions and initial operation as follows.

    Run or Compile : This button is used to compile the program code.

    New : This button is used to create a sketch file.

    Open : Open the exist sketch file

    Save : Save the open sketch file in the old name. If would like to

    change filename, use Save As command instead.

    Upload to Wiring hardware : Exports the program to the ATX

    controller board). This procedure is called UPLOAD.

    Serial monitor : opens the serial data communication between the

    Wiring I/O hardware and the monitor of Wiring IDE through serial ports (or COM port) to

    check the information sent back from Wiring I/O hardware (here it is ATX control board,

    which is very useful for the detection of the programs operation).

    3.1.3 Serial monitor

    Wiring IDE has a Serial monitor. It is a serial data communication tool. User can

    transmit, receive and show the serial data via this monitor with USB serial port of computer.

    In the developed sketch code, must put two imporatant commnands as follows :

    1. Serial.begin() : Set the baud rate of serial data communication. Normally the

    baud rate value is 9600 bit per second. Must add this command into Setup() of sketchbook.

    2. Serial.println() : Assign the sending message to Serial monitor on the Wiring IDE.

    Openning the Serial monitor is very easy. Click on the button at Toolbar. The

    Serial monitor window is appeared following the figure below.

  • Robo-Creator : AT-BOT activity book 29

    3.2 How to develop the program(1) Check the installation of the hardware and software of Wiring. Include the

    setting USB serial port that connected with Wiring I/O hardware; the ATX control board

    of AT-BOT robot in Robo-Creator kit.

    (2) Create a new sketch file by a click of the New button on the Tools bar or

    choose from menu File > New

    (3) Type the example code as as follows :

    #include // Include main libraryint ledPin = 48; // LED connected to pin 48 (bootloader)void setup(){

    lcd("Hello Robot!"); // Title message on LCDpinMode(ledPin, OUTPUT); // Sets the digital pin as output

    }void loop(){

    digitalWrite(ledPin, HIGH); // Sets the LED ondelay(1000); // Waits for a seconddigitalWrite(ledPin, LOW); // LED offdelay(1000);

    }

    This program is used to test a basic hardware of AT-BOT robot. At the LCD display

    shows message Hell Robot ! and blink the LED at port 48 of the ATX controller board with

    one second rate.

  • 30Robo-Creator : AT-BOT activity book

    (4) Go to the File menu to choose the Save as command to save the file in the

    name of Test. Now, there is test.pde file happening in the folder called test.

    (5) Verify the sketch by click onthe Run button of choose from menu Sketch >

    Compile/Verify

    If there is any error occurring from compilation, a warning message will

    be appeared in the messsage area. Therefore, you will have to correct the program.

    If all are correct, the message area will display Done compiling message.

  • Robo-Creator : AT-BOT activity book 31

    After the compilation is finished, in the folder of test there will be a new

    folder are in named Build and within this folder it contains the source file of C++

    programming language and a supplementary file.

    (6) Connect the ATX board with USB port. Turn-on power. Wait until USB connection

    is completely ( blue LED at USB is turned-on) .

    (7) Press and hold the START button on the ATX controller board 3 seconds. The

    LCD module shows Entry program mode message following the figure 3-2.

    (8) Click on the Upload to Wiring Hardware. Code uploading is started. Wait

    until uploading complete. The message Done uploading. RESET to start the new program.

    is shown in the status bar of Wiring IDE.

    Figure 3-2 : Illustration of AT-BOT robot controlled to enter theprogram mode

    MOTOR

    BATTERY LEVEL1312111098

    SERVO PORT

    7.2-9

    V B

    ATT

    .

    E2

    RESET

    +

    -S

    14 15PC6 PC7

    R o b

    > o B

    o - C r e a o r >

    o o t l o d r o a

    t

    a r de

    >

    4850SW249SW1ADC7KNOB

    TWI UART1

    0 SCL 1 SDA 2 RX1 3 TX1

    44 ADC446 ADC640 ADC041 ADC142 ADC2 START

    45 ADC5

    > >

    USB DATA

    43 ADC3

    32

    10

    45

    Connect to USB port

    Turn-on power

    2

    5 Display the programming mode

    Press and hold the START button3 seconds.The robot enter to programmingmode

    4

    1

    The blue LED of USB ready is on3

    LED at port 48 is onfor programming mode

  • 32Robo-Creator : AT-BOT activity book

    If there is error occurring from uploading, a warning message will be

    appeared in the messsage area as follows

    This mostly occurs if the serial port is invalid or not selected the board to

    work in the program mode. Correction can be read in the topic of Troubleshooting of

    uploading error.

    (9) Press on the START button on the ATX control board to start the operation of

    the program.

    At the display of ATX board; it shows message Hello Robot! and the LED at

    the port 48 lights up.

  • Robo-Creator : AT-BOT activity book 33

    3.3 Troubleshooting of uploading error.

    3.3.1 In case that you have clicked the Upload buttonalready but no any action

    Cause :

    Wiring software cannot link with ATX control board of AT-BOT robot because it is

    not in the program mode.

    Solution :

    (1) Press the Ctrl, Alt and Delete key simultaneously and then the Window Security

    window will pop up. Next, click on Task Manager to choose. In some computers, the

    program may lead to the Window Task manager window immediately, in this case, you

    can choose the Processes tab and search for the file named avrdude.exe. Finally, click

    on that file and the End Process button respectively.

    (2) Wiring IDE program will resume in a normal status and supply power to the

    board again. Select the correct COM port and then set the ATX board to the

    programming mode in order to upload the program again.

  • 34Robo-Creator : AT-BOT activity book

    3.3.2 In case if you click the Upload button, there is an errormessage that not find any hardware for uploading

    Cause :

    Wiring software cannot connect with ATX control board or AT-BOT robot because

    selecting a COM port is not correct.

    Solution :

    You need to choose an another COM port used for the connection again and

    correctly by doing at the Tools > Serial port.

  • Robo-Creator : AT-BOT activity book 35

    Developing C/C++ programming language with Wiring for AT-BOT robots is managed

    under the support of atx.h library file in order to reduce steps and complexity in programming

    to control parts of the hardware because it is required to give the priority for the program

    development controlling AT-BOT robots to programming to support competitions.

    The structure of atx.h library file shown as the diagram and details of all sub files are

    consisted of as follows.

    atx.h library file

    Chapter 4

    ATX Library file

  • 36Robo-Creator : AT-BOT activity book

    4.1 lcd.h library file of LCD module displayingThis library file supports the instruction set about the display of messages at the LCD

    module. Before activating the function of this library, you should append the library file in

    the first part of the program with the statement.

    #include or #include

    The main function of this library is lcd., which contains the function for message

    display at the LCD module in the type of 16 characters and 2 lines.

    Syntax

    void lcd(char *p,...)

    Parameter

    p - Type of display data. Support the special character for setting display method.

    Command Operation

    %c or %C Display 1 character

    %d or %D Display the decimal value -32,768 to +32,767

    %l or %L Display the decimal value -2,147,483,648 to +2,147,483,647

    %f or %F Display floating point 3 digits

    #c Clear message before next display

    #n Display message on the second line (bottom line)

    Example 4-1

    lcd(Hello LCD); // Displays Hello LCD message at LCD module

    Result :

    Hel

    Wir

    l ooLCD boa

    i ngI/ b obo

    r

    O tdR

    rdr

    Example 4-2

    lcd(abcdefghijklmnopqrstuvwxyz);

    // Display string. If over 16 charactes, the next character will// show on the second line automatically.

    Result :

    abc

    qrs

    d efghi klm

    t uvwx z obo

    j

    y tdR

    nop

  • Robo-Creator : AT-BOT activity book 37

    Example 4-3

    lcd(Value: %d unit ,518);// Display message with number date (518)

    Result :

    Val

    qrs

    u e:g51 kun

    t uvwx z obo

    8

    y tdR

    itp

    Example 4-4

    lcd(Value: %d ,analog(4));

    // Display analog value from analog port 4 (PA4)

    Result :

    Val

    qrs

    u e:gxx kun

    t uvwx z obo

    x

    y tdR

    itp

    therefore xxx as reading value 0 to 1023

    Example 4-5

    char c_test=j;

    lcd(abcd%cxyz,c_test);

    // Display character j with any message

    Result :

    abc

    qrs

    d jxyzx kun

    t uvwx z obo

    x

    y tdR

    itp

    Example 4-6

    lcd(Value: %f ,125.450);

    // Display message with floating number 3 digit

    Result :

    Val

    qrs

    u e:g12 .45

    t uvwx z obo

    5

    y tdR

    0tp

  • 38Robo-Creator : AT-BOT activity book

    Example 4-7

    lcd(count1: %d #ncount2: %d,12,48);// Display message with 2 control code and special key #n

    // for moving all message after #n to line 2 or bottom line of// LCD screen

    Result

    cou

    cou

    nt1:11 .45

    nt2:x 8 obo

    2

    4 t dR

    0t p

    4.2 sleep.h : The delay time libraryThis library file supports all instructions for time delaying. This library must be included

    at the top of the program with the command #include as follows :

    #include or #include

    The important function is sleep . It delay time in millisecond unit.

    Syntax

    void sleep(unsigned int ms)

    Parameter

    ms - Set the delay time in millsecond unit. Range is 0 to 65,535.

    Example 4-8

    sleep(20); // Dealy 20 miliisecond

    sleep(1000); // Delay 1 second

  • Robo-Creator : AT-BOT activity book 39

    4.3 in_out.h : Digital input/output port libraryThis library file supports all instructions for readind and writing data to digital port of

    controller board. This library must be included at the top of the program with the command

    #include as follows :

    #include or #include

    Important functions of this library file are consisted of :

    4.3.1 inRead data from the specific digital port

    Syntax

    char in(x)

    Parameter

    x - Choose digital port number. it is 0 to 50

    Return value

    0 or 1

    Example 4-9

    char x; // Declare x variable for keeping reading input data

    x = in(49); // Read port 49 and store data to x variable.

    Example 4-10

    char x; // Declare x variable for keeping reading input data

    x = in(50); // Read port 50 and store data to x variable.

    4.3.2 outWrite or send the data to the specific digital port

    Syntax

    out(char _bit,char _dat)

    Parameter

    _bit - Choose digital port number. it is 0 to 50

    Example 4-11

    out(43,1); // Write port 43 with logic 1

    out(45,0); // Write port 45 with logic 0

    4.3.3 sw1_pressThis function loops to check the SW1 pressing. It returns value after switch is released.

    Syntax

    void sw1_press()

    Example 4-12

    ................

    sw1_press(); // Wait until the SW1 is pressed and released

    ................

  • 40Robo-Creator : AT-BOT activity book

    4.3.4 sw2_press

    This function loops to check the SW2 pressing. It returns value after switch is released.

    Syntax

    void sw2_press()

    Example 4-13

    ..................

    Sw2_press(); // Wait until the SW2 is pressed and released

    .................

    4.3.5 sw1

    This function check the SW1 pressing in any time.

    Syntax

    char sw1()

    Return value

    0 - SW1 is pressed

    1 - SW1 is not pressed

    Example 4-14

    char x; // Declare x variable for keeping the value

    x = sw1(); // Get SW1 status and store to x variable

    4.3.6 sw2

    This function check the SW2 pressing in any time.Syntax

    char sw2()

    Return value

    0 - SW2 is pressed

    1 - SW2 is not pressed

    Example 4-15

    char x; // Declare x variable for keeping the value

    x = sw2(); // Get SW2 status and store to x variable

  • Robo-Creator : AT-BOT activity book 41

    4.4 analog.h : Analog port libraryThis library file supports all instructions for reading the analog input port of the ATX

    controller board. This library must be included at the top of the program with the command

    #include as follows :

    #include or #include

    4.4.1 analog

    This gets digital data from the analog to digital converter module of any analog

    port; ADC0 to ADC7.

    Syntax

    unsigned int analog(unsigned char channel)

    Parameter

    channel - Analog input (ADC0 to ADC7)

    Return value

    Digital data from analog to digital converter module. The value is 0 to 1023 (in

    decimal)

    4.4.2 knob

    This function gets data from ADC7 port. This port isconnected with variable resistor

    on-board. It is called KNOB.

    Syntax

    unsigned int knob()

    Return value

    Digital data from analog to digital converter module. The value is 0 to 1023 (in

    decimal)

    Example 4-16

    int val=0; // Declare variable to keep the converted data

    val = analog(2); // Get data from analog input ch. 2 (ADC2)// and store data to val variable.

    Example 4-17

    int val=0; // Declare variable to keep the converted data

    val = knob(); // Get data from analog input ch. 7// (ADC7 or KNOB) and store data to val// variable

  • 42Robo-Creator : AT-BOT activity book

    4.5 motor.h : DC motor driving libraryThis library file supports all instructions for driving and controlling 6 DC motor outputs

    of the ATX controller board. This library must be included at the top of the program with

    the command #include as follows :

    #include or #include

    4.5.1 motor

    It is DC motor driving function.

    Syntax

    void motor(char _channel,int _power)

    Parameter

    _channel - DC motor output of ATX board; value is 0 to 5

    _power - Power output value; it is -100 to 100

    If set _power as positive value (1 to 100); motor is driven one direction.

    If set _power as negative value (-1 to -100); motor is driven opposite direction.

    If _power as 0; motor is stop. This value is not recommended. Use motor_stop

    function to stop motor better.

    Example 4-18

    motor(1,60); // Drive motor ch.1with 60% of maximum power

    motor(1,-60); // Drive motor ch.1with 60% of maximum power and turn back

    direction.

    Example 4-19

    motor(2,100); // Drive motor ch.2 with maximum power

    4.5.2 motor_stop

    This function is driving off a motor or stop.

    Syntax

    void motor_stop(char _channel)

    Parameter

    _channel - DC motor output of ATX board; value is 0 to 5 and all (for driving off

    all channels)

    Example 4-20

    motor_stop(1); // Stop motor ch.1

    motor_stop(4); // Stop motor ch.4

    Example 4-21

    motor_stop(ALL); // All motor are stop

  • Robo-Creator : AT-BOT activity book 43

    4.6 servo.h : Servo motor libraryThis library file supports all functions for controlling 6 servo motor outputs of the ATX

    controller board. This library must be included at the top of the program with the command

    #include as follows :

    #include or #inclue

    There is one function. It is servo.

    Syntax

    void servo(unsigned char _ch, int _pos)

    Parameter

    _ch - Servo motor output (8 to 13)

    _pos - Set the sevo motor shaft poistion (0 to 180 and -1)

    If set to -1, disable selected servo motor output

    4.7 sound.h : Sound generating libraryThis library file supports all functions for sound generating of the ATX controller

    board and AT-BOT. This library must be included at the top of the program with the

    command #include as follows :

    #include or #inclue

    4.7.1 beep

    It is beep sound generating function. The beep frequency is 500Hz and 100

    millisecond duration time.

    Syntax

    void beep()

    4.7.2 sound

    This is programmable sound generating function.

    Syntax

    void sound(int freq,int time)

    Parameter

    freq - Set frequency with value 0 to 32,767

    time - Set duration time in millisecond unit from 0 to 32,767

    Example 4-22

    beep(); // Drives beep sound with 100 millisecond duration

    sound(1200,500); // Drives sound with 1200Hz 500 millisecond

  • 44Robo-Creator : AT-BOT activity book

    4.8 serial.h : Serial data communication libraryThis library file supports all functions for sending and receiving the serial data via

    UART port of the ATX controller board and AT-BOT. This library must be included at the top

    of the program with the command #include as follows :

    #include or #include

    4.8.1 Hardware connection

    UART0 port

    UART0 port is connected via USB to Serial converter chip; FT232RL. For connecting

    with computer, must connect via USB port on the ATX controller board. This connector is

    same port for downloading.

    UART1 port

    Connect via RXD1 (port 2 ) and TXD1 (port 3)

    4.8.2 uart

    This is serial data sending function via UART0 port. The default baudrate is 115,200

    bit per second.

    Syntax

    void uart(char *p,...)

    Parameter

    p - Type of data. Support the special character for setting display method.

    Command Operation

    %c or %C Display 1 character

    %d or %D Display the decimal value -32,768 to +32,767

    %l or %L Display the decimal value -2,147,483,648 to +2,147,483,647

    %f or %F Display floating point 3 digits

    \r Set the message left justify of the line

    \n Display message on the new line

    4.8.3 uart_set_baud

    This is baud rate setting function for UART0.

    Syntax

    void uart_set_baud(unsigned int baud)

    Parameter

    baud - Baud rate of UART0 2400 to 115,200

    Example 4-23

    uart_set_baud(4800); // Set baud rate as 4,800 bit per second

  • Robo-Creator : AT-BOT activity book 45

    4.8.3 uart_available

    This is receiveing data testing function of UART0.

    Syntax

    unsigned char uart_available(void)

    Return value

    - 0 : no data received

    - more than 0 : received character

    Example 4-24

    char x =uart_available();

    // Check the recieving data of UART0.

    // If x value is more than 0; it means UART0 get any data.

    // Read it by using uart_getkey function in the order next immediately.

    4.8.4 uart_getkey

    This is data reading function from receivers buffer of UART0

    Syntax

    char uart_getkey(void)

    Return value

    - 0 : no data received

    - data : received character in ASCII code

    Example 4-25

    #include // Get functionvoid setup(){}void loop() // Main loop{

    if(uart_available()) // Check incoming data{

    if(uart_getkey()==a) // Is key a pressed ?{

    lcd(Key a Active!); // Display message when get asleep(1000); // Delay 1 second

    }else{

    lcd(#c); // Clead display}

    }}

    Note : Default baud ratre of UART library is 115,200 bit per second. Data format

    is 8-bit and no parity.

  • 46Robo-Creator : AT-BOT activity book

    4.8.5 uart1

    This is serial data sending function via UART1 port. The default baud rate is 9,600 bit

    per second.

    Syntax

    void uart1(char *p,...)

    Parameter

    p - Type of data. Support the special character for setting display method. See

    details in uart0 function.

    4.8.6 uart1_set_baud

    This is baud rate setting function for UART1.

    Syntax

    void uart1_set_baud(unsigned int baud)

    Parameter

    baud - Baud rate of UART0 2400 to 115,200

    Example 4-26

    uart1_set_baud(19200); // Set baud rate as 19,200 bit per second

    4.8.7 uart1_available

    This is receiving data testing function of UART0.

    Syntax

    unsigned char uart1_available(void)

    Return value

    - 0 : no data received

    - more than 0 : received character

    Example 4-27

    char x =uart1_available(); // Check the receiving data of UART1.

    4.8.8 uart1_getkey

    This is data reading function from receivers buffer of UART1.

    Syntax

    char uart1_getkey(void)

    Return value

    - 0 : no data received

    - data : received character in ASCII code

  • Robo-Creator : AT-BOT activity book 47

    4.9 Digital compass libraryIt is compass.h file. This library file is not included in robot.h library file. Must include

    the specific library file before using.

    This library file supports all functions for interfacing the HMC6352 digital compass of

    the ATX controller board. This library must be included at the top of the program with the

    command #include as follows :

    #include

    4.9.1 compass_read

    This reads the angle of the HMC6352 digital compass.

    Syntax

    int compass_read()

    Return value

    Angle value 0 to 359 defree

    4.9.2 compass_set_heading

    This is reference angle setting function. With this function, the current angle that

    read from digital compass is set to 0 degree reference.

    Syntax

    void compass_set_heading()

    4.9.3 compass_read_heading

    This is reference angle reading function. Use this function after set the new reference

    angle from compass_set_heading function.

    Syntax

    int compass_read_heading()

    Return value

    1 to 180 : positive angle (clock wise direction) of digital compass.

    -1 to -180 : negative angle (Counter-Clockwise direction) of digital compass.

  • 48Robo-Creator : AT-BOT activity book

  • Robo-Creator : AT-BOT activity book 49

    This chapter presents examples of the hardware experiment with the ATX controller

    board of the Robo-Creator robotic kit. There are 7 experiments as follows.

    Experiment 1 Shows message on the display of the ATX board

    Experiment 2 Using SW1 and SW2 switch

    Experiment 3 Reading analog from KNOB button of the ATX board

    Experiment 4 Sound activity

    Experiment 5 DC motors control

    Experiment 6 Servo motor control

    Experiment 7 Serial data communication with computers

    Chapter 5

    The ATX controller board

    hardware experiment

  • 50Robo-Creator : AT-BOT activity book

    Programming and Hardware experiment steps(1) Open Wiring IDE and create a new sketch file.

    (2) Type the code on the test editor of the sketch file

    (3) Compile by click at the button or choose at the menu Compile > Verify.

    (4) Connect the ATX controller board with a USB port. Turn on power and wait until

    the connection between the computer and ATX board is completed. This can be noticed

    from the blue LED at the position of USB power on.

    (5) Set the ATX board to program mode by pressing START switch and hold it for 3

    seconds.

    At the ATX board display, it shows messages

    Robo-Creator

    > Bootloader

    and the red LED at the port 48 is powered on.

    (6) Upload the code by click at the button or click at the menu file > Upload to

    Wiring hardware.

    (7) Wait until the uploading is successful. Then press the START switch again. Finally,

    the ATX controller circuit board will be running the latest uploaded program immediately.

  • Robo-Creator : AT-BOT activity book 51

    Experiment 1

    Shows message on the display of the ATX board

    Experiment 1.1 Simple message displaying on the ATX board

    This experiment demonstrates the simle programming for showing the message at

    the display of the ATX board.

    Procedure

    L1.1.1 Create the new sketch file. Type the Listing L1-1 and save as lcd_01.pde file

    L1.1.2 Compile and upload the sketch to the ATX board.

    L1.1.3 Run the program.

    At the LCD display of the ATX controller board show message Hello Robot! as follows.

    MOTOR

    BATTERY LEVEL1312111098

    SERVO PORT

    7.2

    -9V B

    ATT.

    E2

    RESET

    +

    -S

    14 15PC6 PC7

    Hel

    > o B

    loCRob t!>

    o o t l o d r o a

    o

    a r de

    >

    4850SW249SW1ADC7KNOB

    TWI UART1

    0 SCL 1 SDA 2 RX1 3 TX1

    44 ADC446 ADC640 ADC041 ADC142 ADC2 START

    45 ADC5

    > >

    USB DATA

    43 ADC3

    32

    10

    45

    Listring L1-1 : lcd_01.pde, the sketch file for simple displaying

    message on the ATX board.

    #include // Include the main libraryvoid setup(){ lcd("Hello Robot!"); // Display mesage on the ATX display}void loop(){}

    Code explanation

    This code runs within the setup function. There is one command. Display the message;

    Hello Robot! on the screen. After that the program will jump to run in the loop function. No

    any command in this function. The operation is stop finally.

    Program L1-1

  • 52Robo-Creator : AT-BOT activity book

    Experiment 1.2 Display message 2 lines of the ATX boarddisplay

    This experiment demonstrates the displaying message 2 lines of the ATX board

    display.

    Procedure

    L1.2.1 Create the new sketch file. Type the Listing L1-2 and save as lcd_02.pde file

    L1.2.2 Compile and upload the sketch to the ATX board.

    L1.2.3 Run the program.

    At the LCD display of the ATX controller board show message as follows :

    MOTOR

    BATTERY LEVEL1312111098

    SERVO PORT

    7.2

    -9V B

    ATT.

    E2

    RESET

    +

    -S

    14 15PC6 PC7

    Lin

    Lin

    e1CRob t!>

    e2t l o d r o a

    o

    a r de

    >

    4850SW249SW1ADC7KNOB

    TWI UART1

    0 SCL 1 SDA 2 RX1 3 TX1

    44 ADC446 ADC640 ADC041 ADC142 ADC2 START

    45 ADC5

    > >

    USB DATA

    43 ADC3

    32

    10

    45

    #include // Include the amin libraryvoid setup(){}void loop(){

    lcd(Line1#nLine2); // Display message 2 lines}

    Code explanation

    The program starts running in the setup function then it repeats working in the loop function

    to display message on both lines of the LCD. The result comes from the operation of control

    code #n. The overall results have been shown the display of 2-line text.

    Listring L1-2 : lcd_02.pde, the sketch file for displaying message 2

    lines on the ATX board display.

  • Robo-Creator : AT-BOT activity book 53

    Experiment 1.3 Shows message and number

    This experiment demonstrates showing messages mixed with numbers at the ATX

    board display. It shows the values of counting in every 1 second.

    Procedure

    L1.3.1 Create the new sketch file. Type the Listing L1-3 and save as lcd_03.pde file

    L1.3.2 Compile and upload the sketch to the ATX board.

    L1.3.3 Run the program.

    At the LCD display of the ATX controller board show message as follows :

    Count: xxx

    therefore xxx is counting value that increse every second.

    MOTOR

    BATTERY LEVEL1312111098

    SERVO PORT

    7.2

    -9V B

    ATT.

    E2

    RESET

    +

    -S

    14 15PC6 PC7

    Cou

    Lin

    nt:R20 t!>

    e2t l o d r o a

    0

    a r de

    >

    4850SW249SW1ADC7KNOB

    TWI UART1

    0 SCL 1 SDA 2 RX1 3 TX1

    44 ADC446 ADC640 ADC041 ADC142 ADC2 STA

    RT

    45 ADC5

    > >

    USB DATA

    43 ADC3

    32

    10

    45

    #include // Include the main libraryint i = 0; // Declare the counting variablevoid setup(){}void loop(){ lcd("Count: %d ",i); // Display the counter on the ATX board display sleep(1000); // Delay 1 second i++; // Increase counter}

    Code explanation

    The program starts running in the setup function and then it repeats working in the loop

    function. It shows the counting value that increased every 1 second. The variable i stores the

    count values.

    Listring L1-3 : lcd_03.pde, the sketch file for displaying

    message and number on the ATX board.

  • 54Robo-Creator : AT-BOT activity book

    Experiment 2

    Using SW1 and SW2 switch

    Experiment 2.1 Using SW1 to start the counter

    This expeirment demonstrates how to use the SW1 on the ATX controller board to

    start the counter. The counting values also should be display on the ATX board display.

    Procedure

    L2.1.1 Create the new sketch file. Type the Listing L2-1 and save as switch_01.pde file

    L2.12 Compile and upload the sketch to the ATX board.

    #include // Include the main libraryint i=0; // Declare the counter variablevoid setup(){ lcd("SW1 Press!"); // Display the title message sw1_press(); // Wait the SW1 pressing lcd("#c"); // Clear display before show the next message}void loop(){ lcd("Count: %d ",i); // Display the counting value sleep(1000); // Delay 1 second i++; // Increase counter}

    Code description

    The program starts running in the setup function to wait for the pressing of SW1 and

    there is an alert by the text of SW1 Press! at the display after the switch is pressed. The

    program will repeat working in the loop function to display the count value that is increased

    in every 1 second. The i variable is used to stores the count values.

    Listing L2-1 : switch_01.pde, the sketch file for checking the SW1

    of the ATX board pressing to start the counter

  • Robo-Creator : AT-BOT activity book 55

    L2.1.3 Run the program.

    At the LCD display of the ATX controller board show message as follows :

    SW1 Press!

    L2.1.4 Press the SW1 on the ATX board and release.

    Counting is start. The counter value is displayed on the ATX board display as follows.

    Count: xxx

    therefore xxx is counting value that increase every second.

    MOTOR

    BATTERY LEVEL1312111098

    SERVO PORT

    7.2

    -9V B

    ATT.

    E2

    RESET

    +

    -S

    14 15PC6 PC7

    Cou

    Lin

    nt:R20 t!>

    e2t l o d r o a

    0

    a r de

    >

    4850SW249SW1ADC7KNOB

    TWI UART1

    0 SCL 1 SDA 2 RX1 3 TX1

    44 ADC446 ADC640 ADC041 ADC142 ADC2 STA

    RT

    45 ADC5

    > >

    USB DATA

    43 ADC3

    32

    10

    45

    Press the switchSW1 to start

    Experiment 2.2 Checking the SW1 and SW2 pressing anytime

    This experiment demonstrates the checking of SW1 and SW2 of the ATX board

    pressing. It used to increase and decrease the variable value. Also display the value on

    the LCD module of ATX board.

    Procedure

    L2.2.1 Create the new sketch file. Type the Listing L2-2 and save as switch_02.pde file

    L2.2.2 Compile and upload the sketch to the ATX board.

    L2.2.3 Run the program.

    At the LCD display of the ATX controller board show message as follows :

    Count: xxx

    therefore xxx is the counting value. Start from 10.

  • 56Robo-Creator : AT-BOT activity book

    #include // Include the main library

    int i=10; // Declare the counter variable

    // and set to start from 10

    void setup()

    {}

    void loop()

    {

    lcd("Count: %d ",i); // Display the counting value

    if(sw1()==0) // SW1 is pressed ?

    {

    i++; // If SW1 is pressed, increase counter.

    sleep(200); // Delay for switch debouncing

    }

    if(sw2()==0) // SW2 is pressed ?

    {

    i-- ; // If SW2 is pressed, decrease counter

    sleep(200); // Delay for switch debouncing

    }

    }

    Code description

    The program begins operating in the setup function. Then it repeats in the loop function.

    It loop to check up pressing the switch of SW1 and SW2 all the time and display the count

    values of the variable I at the LCD module as well.

    Conditions of verification in the loop as following these:

    1. If the SW1 is pressed ( sw1 ( ) function returns the value as 0)

    The program responds by increase value of the variable i

    2. If the SW2 is pressed (sw2 ( ) function returns the value as 0 )

    The program responds by decrease value of the variable i.

    Listing L2-2 : switch_02.pde, the sketch file for checking both SW1

    and SW2 of the ATX board pressing anytime

  • Robo-Creator : AT-BOT activity book 57

    L2.2.4 Press the SW1 switch on the ATX board. Observe the operation of the ATX board

    display.

    Each time you press the SW1, the count value is added up one value

    L2.2.5 Press the SW2 switch on the ATX board. Observe the operation of the ATX board

    display.

    Each time you press the SW2, the count value is deduct one value.

    MOTOR

    BATTERY LEVEL1312111098

    SERVO PORT

    7.2

    -9V B

    ATT.

    E2

    RESET

    +

    -S

    14 15PC6 PC7

    Cou

    Lin

    nt:R20 t!>

    e2t l o d r o a

    0

    a r de

    >

    4850SW249SW1ADC7KNOB

    TWI UART1

    0 SCL 1 SDA 2 RX1 3 TX1

    44 ADC446 ADC640 ADC041 ADC142 ADC2 START

    45 ADC5

    > >

    USB DATA

    43 ADC3

    32

    10

    45

    Press SW1 to increase value

    Press SW2 todecrease value

  • 58Robo-Creator : AT-BOT activity book

    Experiment 3

    Reading analog from KNOB button of the ATX board

    Experiment 3.1 Knob value reading

    This experiment demonstrates how to read the analog value from KNOB button of

    the ATX controller board. It is basic example of analog sensor reading. The result is 0 to

    1023.

    Procedure

    L3.1.1 Create the new sketch file. Type the Listing L3-1 and save as knob_01.pde file

    L3.1.2 Compile and upload the sketch to the ATX board.

    L3.1.3 Run the program.

    At the LCD display of the ATX controller board show message as follows :

    KNOB: xxx

    therefore xxx as KNOB position value from 0 to 1023

    - Adjust to last left position. Value is 0.

    - Adjust to last right position. Value is 1023.

    - Adjust to center position. Value is 512.

    MOTOR

    BATTERY LEVEL1312111098

    SERVO PORT

    7.2

    -9V B

    ATT.

    E2

    RESET

    +

    -S

    14 15PC6 PC7

    KNO

    Lin

    B::101 t!>

    e2t l o d r o a

    0

    a r de

    >

    4850SW249SW1ADC7KNOB

    TWI UART1

    0 SCL 1 SDA 2 RX1 3 TX1

    44 ADC446 ADC640 ADC041 ADC142 ADC2 STA

    RT

    45 ADC5

    > >

    USB DATA

    43 ADC3

    32

    10

    45

    Adjust the KNOBshaft to reading

  • Robo-Creator : AT-BOT activity book 59

    #include // Include the main libraryvoid setup(){}void loop(){ lcd("KNOB: %d ",knob()); // Display the KNOB value sleep(100); // Delay 0.1 second for displaying}

    Code explanation

    The program begins operating in the setup function. Then it repeats in the loop function

    to display the readable values from KNOB at the LCD module.

    Knob value is read by using knob function of the atx.h library. It is analog to digital

    converter function.

    Listing L3-1 : knob_01.pde, the sketch file for reading the KNOB

    button of the ATX board value.

    Experiment 3.2 Use KNOB button to Mode selector

    This experiment demonstrates about programming to use KNOB as the directional

    determinant of counting value. If KNOB is adjusted to the left to compare with the middle

    position, this will be the selection to count down values but if it is opposite, it will be the

    selection to count values up. Additionally, the display of the count value is shown at the

    LCD module.

    Procedure

    L3.2.1 Create the new sketch file. Type the Listing L3-2 and save as knob_02.pde file

    L3.2.2 Compile and upload the sketch to the ATX board.

    L3.2.3 Run the program.

    At the LCD display of the ATX controller board show message as follows :

    Count: xxx

    Count Up

    in the Count up mode or

    Count: xxx

    Count Down

    in the Count down mode

    therefore xxx is thge counting value. Start from 100.

  • 60Robo-Creator : AT-BOT activity book

    #include // Include the main libraryint i=100; // Declare the counter variable. Start from 100int k; // Declare the KNOB value variablevoid setup(){}

    void loop(){ lcd("Count: %d ",i); // Display counter k = knob(); // Read the KNOB value to store to the k variable if(k>512) // Check the KNOBs value is through

    // the middle to right or not ? { i++; // Increase the count value lcd("#nCount Up "); // Display the Count up mode message

    // on the lower line of LCD } else { i--; // If the KNOBs value is through

    // the middle to left, count down lcd("#nCount Down "); // Display the Count down mode message

    // on the lower line of LCD } sleep(1000); // Delay 1 second}

    Code explanation

    The program begins operating in the setup function. Then it repeats in the loop function

    to verification of adjustment position of KNOB continually. At the same time, the count value of

    the variable i and the counting mode at the LCD module as well. There are conditions for the

    verification as follows:

    1. If the KNOB value is greater than 512

    The program will respond to adding up the count value of the variable i to one value

    and show the Count up mode message on the display.

    2. If the KNOB value is less than 512 (working in the section of else).

    The program will respond to deducting the count values of the variable i to one value

    and show the Count down mode message on the display.

    Listing L3-2 : knob_02.pde, the sketch file for using the KNOB button

    of the ATX board to Mode selector

  • Robo-Creator : AT-BOT activity book 61

    The program wil count up and down depending on the value of KNOB, which is

    result from the rotation of spindle of the variable resistor at the position of KNOB of ATX

    board.

    MOTOR

    BATTERY LEVEL1312111098

    SERVO PORT

    7.2

    -9V B

    ATT.

    E2

    RESET

    +

    -S

    14 15PC6 PC7

    Cou

    Cou

    nt:120 t!>

    nttUp d r o a

    0

    a r de

    >

    4850SW249SW1ADC7KNOB

    TWI UART1

    0 SCL 1 SDA 2 RX1 3 TX1

    44 ADC446 ADC640 ADC041 ADC142 ADC2 STA

    RT

    45 ADC5

    > >

    USB DATA

    43 ADC3

    32

    10

    45

    Adjust the KNOB shaft tochange the counting mode

    Left direction to countdown mode

    Right direction to countup mode

    L3.2.4 Adjust the KNOB shaft to go through the middle to the left (or may adjust to the left)

    This will be found that the counter is in Count down mode. The count value will be

    deducted 1 value in each second.

    L 3.2.5 Adjust the KNOB shaft to go through the middle to the right (or maybe adjust to the

    far right)

    The counter is in Count up mode. The count value will be added up 1 value in

    each second.

  • 62Robo-Creator : AT-BOT activity book

    Experiment 4

    Sound activity

    Exeperiment 4.1 The signal selector

    This experiment demonstrates about using the SW1 and SW2 on the ATX controller

    board to generate the different sound frequency. If SW1 is pressed, ATX board drives

    500Hz signal with 0.1 second duration. If the SW2 is pressed, it generate 2000Hz (2kHz)

    signal with 0.5 second instead.

    Procedure

    L4.1.1 Create the new sketch file. Type the Listing L4-1 and save as sound_01.pde file

    L4.1.2 Compile and upload the sketch to the ATX board.

    L4.1.3 Run the program. Press the SW1 on the ATX controller board.

    Everytime to press the switch SW1, you will hear the sound with the frequency of

    500 Hz for 0.1 second from the piezo speaker on the ATX board.

    L 4.1.4 Press the switch SW2

    Everytime to press the SW2, you will hear the sound of frequency 2000Hz for 0.5

    second.

    MOTOR

    BATTERY LEVEL1312111098

    SERVO PORT

    7.2

    -9V B

    ATT.

    E2

    RESET

    +

    -S

    14 15PC6 PC7

    Cou

    Lin

    nt:R20 t!>

    e2t l o d r o a

    0

    a r de

    >

    4850SW249SW1ADC7KNOB

    TWI UART1

    0 SCL 1 SDA 2 RX1 3 TX1

    44 ADC446 ADC640 ADC041 ADC142 ADC2 START

    45 ADC5

    > >

    USB DATA

    43 ADC3

    32

    10

    45

    Press SW1 to generate 500Hz signal

    Press SW2 togenerate 2000Hzsignal

  • Robo-Creator : AT-BOT activity book 63

    #include // Include the main libraryvoid setup(){}void loop(){

    if(sw1()==0) // The SW1 is pressed ?{

    beep(); // If SW1 is pressed,// generate the 500Hz signal 0.1 second duration

    sleep(100); // Delay for switch debouncing}if(sw2()==0) // The SW2 is pressed ?{

    sound(2000,500); // If SW2 is pressed,// generate the 2000Hz signal 0.5 second duration

    sleep(100); // Delay for switch debouncing}

    }

    Code explanation

    The program operates in the loop function to check the pressing of the SW1 and SW2

    switches and there are conditions as follows.

    1. If the SW1 is pressed (sw1( ) function returns the value as 0)

    The program will respond to generate the 500Hz signal for 0.1 second.

    1. If the SW2 is pressed (sw2( ) function returns the value as 0)

    The program will respond to generate the 2000Hz signal for 0.5 second.

    Listing L4-1 : sound_01.pde, the sketch file for using the SW1 and

    SW2 on the ATX board to set the condition for signal generating

  • 64Robo-Creator : AT-BOT activity book

    Experiment 4.2 Tuning frequency by KNOB

    This experiment demonstrates about using KNOB button to adjust the sound

    frequency and show the frequency value at the ATX board display

    Procedure

    L4.2.1 Create the new sketch file. Type the Listing L4-2 and save as sound_02.pde file

    L4.2.2 Compile and upload the sketch to the ATX board.

    L4.2.3 Run the program.

    At the LCD display of the ATX controller board show message as follows :

    Freq: xxx Hz

    therefore xxx is the generated signal frequency

    L4.2.4 Asjust the KNOB button slowly from left to right direction. See the display operation

    and listen the sound signal from ATX board.

    The frequency of the sound displaying at the LCD module will increase from 0 to

    2046Hz (as 2 times of the value read from KNOB). The sound you have listen will be

    dramatically sharpened following the adjustment of frequency increasing.

    MOTOR

    BATTERY LEVEL1312111098

    SERVO PORT

    7.2

    -9V B

    ATT.

    E2

    RESET

    +

    -S

    14 15PC6 PC7

    Fre

    Lin

    q::120 tHz

    e2t l o d r o a0a r de

    >

    4850SW249SW1ADC7KNOB

    TWI UART1

    0 SCL 1 SDA 2 RX1 3 TX1

    44 ADC446 ADC640 ADC041 ADC142 ADC2 START

    45 ADC5

    > >

    USB DATA

    43 ADC3

    32

    10

    45

    Adjust the KNOB button to change the sound frequency

  • Robo-Creator : AT-BOT activity book 65

    #include // Include the main library

    int k; // Declare the KNOB value variable

    int f; // Declare the frequency variable

    void setup()

    {

    }

    void loop()

    {

    k = knob(); // Read the KNOB value to store in the k variable

    f = 2*k; // Increase the value 2 times

    lcd("Freq: %d Hz ",f); // Display the sound frequency

    sound(f,200); // Generate the sound signal// from the variable data for 0.2 second

    sleep(1000); // Delay 1 second

    }

    Code explanation

    The program starts working in the setup function and repeats to work in the loop function

    to repeat reading from the KNOB button. Then, the value you have got multiply by 2 to use for

    the frequency value desired so the value will be in the range of 0 to 2046Hz and the frequency

    value will be shown at the LCD module.

    For the sound generation at the Piezo speaker, the program will space in each second

    briefly.

    Listing L4-2 : sound_02.pde, the sketch file for using the KNOB button

    on the ATX board to adjust the sound signal frequency

  • 66Robo-Creator : AT-BOT activity book

    Experiment 5

    DC motors control

    Experiment 5.1 Direction control for DC motor driver

    This experiment demonstrates about direction control for DC motor driver output 0

    and 1 of the ATX board. The motor driver will be drive DC motor forward and backward

    every 3 seconds continually.

    Hardware connection

    Connect the DC motor #1 with Motor-0 output of the ATX board.

    Connect the DC motor #2 with Motor-1 output of the ATX board.

    ON

    MOTOR

    BATTERY LEVEL1312111098

    SERVO PORT

    7.2-9

    V B

    ATT.

    E2

    RESET

    +

    -S

    14 15PC6 PC7

    ATX

    con

    1.0r>> >>>

    troll r boa

    >

    e rdR

    >

    4850SW249SW1ADC7KNOB

    TWI UART1

    0 SCL 1 SDA 2 RX1 3 TX1

    44 ADC446 ADC640 ADC041 ADC142 ADC2 START

    45 ADC5

    >>

    USB DATA

    43 ADC3

    32

    10

    45

    DC motor #2

    DC motor #1

    Procedure

    L5.1.1 Create the new sketch file. Type the Listing L5-1 and save as motor_01.pde file

    L5.1.2 Compile and upload the sketch to the ATX board.

    L5.1.3 Run the program.

    DC motor at output 0 and 1 start and reverse direction every 3 seconds.

  • Robo-Creator : AT-BOT activity book 67

    #include // Include the main library

    void setup()

    {

    }

    void loop()

    {

    motor(0,70); // Drive motor-0 with 70% power

    motor(1,70); // Drive motor-1 with 70% power

    sleep(3000); // Delay 3 seconds before change the direction

    motor(0,-70); // Drive motor-0 backward with 70% power

    motor(1,-70); // Drive motor-1 backward with 70% power

    sleep(3000); // Delay 3 seconds before change the direction

    }

    Code explanation

    The program repeats to work in the loop function to drive the DC motor of the channel 0

    and 1 simultaneously with 70% power equally both. And every 3 seconds reversing direction of

    rotation will be operated continuously.

    Listing L5-1 : motor_01.pde, the sketch file for direction control of

    DC motor driver of the ATX board. DC motor will reverse direction

    every 3 seconds continually

    Experiment 5.2 Timing control motor

    In this experiment demonstrates the programming for driving both DC motor at the

    Motor-0 and 1 output of the ATX board with timing control. Both motors will operate 3

    seconds and then stop 3 seconds alternately and continuously.

    Hardware connection

    Connect the DC motor #1 with Motor-0 output of the ATX board.

    Connect the DC motor #2 with Motor-1 output of the ATX board.

    Procedure

    L5.2.1 Create the new sketch file. Type the Listing L5-2 and save as motor_02.pde file

    L5.2.2 Compile and upload the sketch to the ATX board.

    L5.2.3 Run the program.

    DC motors at output 0 and 1 start and stop 3 seconds alternately and continually.

  • 68Robo-Creator : AT-BOT activity book

    #include // Include the main library

    void setup()

    {

    }

    void loop()

    {

    motor(0,90); // Drive motor-0 with 90% power

    motor(1,90); // Drive motor-1 with 90% power

    sleep(3000); // Delay 3 seconds

    motor_stop(0); // Stop motor-0

    motor_stop(1); // Stop motor-1

    sleep(3000); // Delay 3 seconds

    }

    Code explanation

    The program repeats to work in the loop function to drive the DC motor at channel 0 and

    1 simultaneously with the 90% power driving equally both. After 3 seconds, all motors will stop

    for 3 seconds also and start to rotate again. This will work together seamlessly.

    Listing L5-2 : motor_02.pde, the sketch file for timimg control of DC

    motor driver of the ATX board. DC motor will start and stop every 3

    seconds continually

  • Robo-Creator : AT-BOT activity book 69

    Experiment 6

    Servo motor control

    Experiment 6.1 Control position of the servo motor

    This experiment demonstrates about programming to control the servo motor shaft

    position. The servo motor is driven to move the shaft to 60 degrees position and stop to

    lock at this position for 5 minutes. Next, change to the position to 120 degrees and stop to

    lock at this position for 5 minutes as well. Then, the shaft will be moved to the position of 60

    degrees again so that the positions will be switched back and forth like this constantly.

    Hardware connection

    Connect a standard servo motot to servo motor output port 12 of the ATX board

    ON

    MOTOR

    BATTERY LEVEL1312111098

    SERVO PORT

    7.2

    -9V B

    ATT.

    E2

    RESET

    +

    -S

    14 15PC6 PC7

    ATX

    con

    1.0r >> >>>

    troll r boa

    >

    e rdR

    >

    4850SW249SW1ADC7KNOB

    TWI UART1

    0 SCL 1 SDA 2 RX1 3 TX1

    44 ADC446 ADC640 ADC041 ADC142 ADC2 START

    45 ADC5

    >>

    USB DATA

    43 ADC3

    32

    10

    45

    STANDARDSERVO MOTOR

    Servo motor

    Procedure

    L6.1.1 Create the new sketch file. Type the Listing L6-1 and save as servo_01.pde file

    L6.1.2 Compile and upload the sketch to the ATX board.

    L6.1.3 Run the program.

    The servo motor shaft will move between 60 and 120 degrees position every 5

    seconds

  • 70Robo-Creator : AT-BOT activity book

    #include // Include the main library

    void setup()

    {}

    void loop()

    {

    servo(12,60); // Drive the servo motor at port 12 to move its shaft to// 60 degrees position

    sleep(5000); // Delay 5 seconds

    servo(12,120); // Drive the servo motor at port 12 to move its shaft to// 120 degrees position

    sleep(5000); // Delay 5 seconds

    }

    Code explanation

    The program repeats to work in the loop function to drive a servo motor to move its shaft

    between the position of 60 and 120 degrees in every 5 seconds.

    Experiment 6.2 Switch-controlled the servo motor position

    This experiment demonstrates about control the servo motor shaft position by 2 of

    switch on the ATC board. The SW1 is used to increase the position angle ans SW2 is used to

    decrease the position angle.

    Hardware connection

    Connect a standard servo motot to servo motor output port 12 of the ATX board

    Procedure

    L6.2.1 Create the new sketch file. Type the Listing L6-2 and save as servo_02.pde file

    L6.2.2 Compile and upload the sketch to the ATX board.

    L6.2.3 Run the program.

    At the LCD display of the ATX controller board show message as follows :

    Servo: xxx

    therefore xxx is servo motor shaft position. Start at 90

    Listing L6-1 : servo_01.pde, the sketch file for driving a servo motor

    to control the movement position

  • Robo-Creator : AT-BOT activity book 71

    #include // Include the main libraryint p=90; // Declare the position variable

    // and set the default value as 90void setup(){}void loop(){ servo(12,p); // Drive a servo motor to move the shaft to position

    // that defined by the p variable lcd("Servo: %d ",p); // Show the current position of servo motor shaft if(sw1()==0) // Is the SW1 switch pressed ? { p++; // Increase the position value if(p>180) // Is the position more than 180 ? { p=0; // If the position value more than 180,

    // set the position value back to 0 } sleep(100); // Delay 0.1 second } if(sw2()==0) // Is the SW2 switch pressed ? { p-- ; // Decrease the postion value if(p

  • 72Robo-Creator : AT-BOT activity book

    L6.2.4 Press the SW1 switch

    The shaft position of the servo motor will be increased 1 value. At the same time,

    the servo motor shaft will be moved according to the increasing value. When adding the

    value to 180, the position value will be back to start at the new 0.

    L6.2.5 Press the SW2 switch

    The shaft position of the servo motor will be decreased 1 value. At the same time,

    the servo motor shaft will be moved according to the decreasing value. When the value

    is lower than 0, the position value will be back to start at the new 0.

  • Robo-Creator : AT-BOT activity book 73

    Experiment 7

    Serial data communication with computers

    Experiment 7.1 Transmit the serial data to computer

    This experiment demonstrates about computer interfacing of the ATX controller

    board. Begins with transmitting the serial data to USB port via the USB to serial converter

    circuit on the ATX board. The data will be display on the Serial Monitor of Wiring IDE.

    Connect to USB port

    ON

    MOTOR

    BATTERY LEVEL1312111098

    SERVO PORT

    7.2

    -9V B

    ATT.

    E2

    RESET

    +

    -S

    14 15PC6 PC7

    ATX

    con

    1.0r >> >>>

    troll r boa

    >

    e rdR

    >

    4850SW249SW1ADC7KNOB

    TWI UART1

    0 SCL 1 SDA 2 RX1 3 TX1

    44 ADC446 ADC640 ADC041 ADC142 ADC2 STAR

    T

    45 ADC5

    >>

    USB DATA

    43 ADC3

    32

    10

    45

    Procedure

    L7.1.1