Csc 560 Project 5

Embed Size (px)

Citation preview

  • 8/11/2019 Csc 560 Project 5

    1/35

    CSC 560 Project 5 ReportJunnan LuKai Hung

    1

  • 8/11/2019 Csc 560 Project 5

    2/35

    Contents

    IntroductionPyroelectric Infrared SensorsUltrasonic Ranging Module HC-SR04 (Sonar Sensor)RTOSReal TermRadio Communication Section

    NRF24L01 Radio HardWareNRF24L01 introductionNRF24L01 Power Management

    NRF24L01 and Atmega1284P Wiring Diagram ATmega1284P/NRF24L01 Radio Serial Peripheral Interface

    IntroductionSteps for reading data on SPI interface

    Steps for writing data on SPI interfaceThe SPI Clock Polarity and PhaseThe NRF24L01 Registers and Commands

    The NRF24L01 RegistersThe NRF24L01 CommandsThe NRF24L01 Enhanced Shock-Burst Data Packet Format

    NRF24L01 Radio Driver The SS Pin On Atmega1284P Controller The SPCR Register The SPDR Register

    The SPSR Register The SPI ProgrammingThe SPI Interface Configuration Steps

    The NRF24L01 Radio Configuration Steps in SPIThe NRF24L01 Driver Functions

    The NRF24L01 Timing Diagram Atmega1284P/Roomba UART CommunicationPut Everything Together

    The Base Station Unit CheckoutThe Roomba Explore Unit Checkout

    The Whole System DiagramProject 5 C codeThe Video Demo

    2

  • 8/11/2019 Csc 560 Project 5

    3/35

    Introduction

    In the last project report, we outline the overall design of the Roomba Explorer system. Thesystem consisted of a Roomba and a radio base station. Two PIR sensors and a sonar sensor were mounted on the Roomba facing forwards. Once the Roomba detected amoving heat emitting object, it would follow it at a fixed distance. Otherwise, it would spinon the spot until it finds another target. This is what happens when the robot is in Automode.

    The Roomba can be directly controlled remotely through radio in manual mode. TheRoomba can turn into auto mode or manual mode at any time.

    The actual implementation is not much different from the project 4 design.

    Pyroelectric Infrared SensorsThe PIR sensor that we use is a very simple one that has three pins. Two pins are groundand power input. The last one is the output pin. Upon being active, the output pin goes high(5V), otherwise it goes low(0V). This is equivalent to digital output 0 or 1.

    Figure 1. Infrared Sensor.

    3

  • 8/11/2019 Csc 560 Project 5

    4/35

    Figure 2. PIR Sensor.

    The PIR sensor was pretty straight forward to use. When it detected heat motion, the outputwent high (digital 1). The output went low (digital 0) otherwise.

    However, we observed that the output would stay high for a long period, ranging from 1 to 7seconds. This was not very ideal since it would output high voltage even when the movingobject is out of sight. Inspite of the delay time, the whole system seemed to work fine. Itwould be an interesting compare if we replace the PIR we have with the ones that haveshorter delay time.

    Here is the link to the data sheet of the PIR sensor:(http://www.parallax.com/sites/default/files/downloads/910-28027-PIR-Sensor-REV-A-Documentation-v1.4.pdf )

    Figure X below shows how the PIR sensors were sampled. The states of the PIRs (whether or not they are active) are stored in global variables SENSOR0_ACTIVE andSENSOR1_ACTIVE respectively for later use.

    In our implementation, this function was a round-robin task. However, as one can see, the

    sampling operation is so fast ( (PIND & _BV(2))==0) and ((PIND & _BV(4)) ==0), it isprobably logical to take out this function and simply incorporate the sampling operationswith the rest of the code.

    4

    http://www.google.com/url?q=http%3A%2F%2Fwww.parallax.com%2Fsites%2Fdefault%2Ffiles%2Fdownloads%2F910-28027-PIR-Sensor-REV-A-Documentation-v1.4.pdf&sa=D&sntz=1&usg=AFQjCNFWqHVaulf4x8uj19wmMHLhweFH1ghttp://www.google.com/url?q=http%3A%2F%2Fwww.parallax.com%2Fsites%2Fdefault%2Ffiles%2Fdownloads%2F910-28027-PIR-Sensor-REV-A-Documentation-v1.4.pdf&sa=D&sntz=1&usg=AFQjCNFWqHVaulf4x8uj19wmMHLhweFH1g
  • 8/11/2019 Csc 560 Project 5

    5/35

    Figure 3. Code segment of undate_sensor_state().

    Ultrasonic Ranging Module HC-SR04 (Sonar Sensor)

    The sonar sensor that we use has four pins; one for 5V power supply, one for ground, onefor trigger pulse input and one for echo pulse output

    5

  • 8/11/2019 Csc 560 Project 5

    6/35

    Figure 4. Sonar Distance Measurement.

    The following is how it works:

    1. Send a high level signal for at least 10 microseconds to the trigger pin2. The module automatically sends eight 40kHz sound and detect whether there is a soundbounces back. At the mean time, the module raise the echo output to high.3. If the module detects a sound pulse back, it sets the echo output low.4. Distance can be calculated through the time interval between sending trigger signal andreceiving echo signal. range = high level time * velocity (340M/S) / 2

    * It is suggested in the datasheet that there should be 60ms time difference between eachmeasurements.

    6

  • 8/11/2019 Csc 560 Project 5

    7/35

    Figure 5. Sonar Timing Diagram.

    The problem with working with sonar was that it is error prone. For example, if the sonar sensor was facing a wall at an angle, then it was very likely that the pulses the sonar sentout would bounce off and never return to the sonar. In that case, the distance could not bemeasured. We deal with the situations where distance was not measured correctly by thesonar in software.

    The figure below shows how the sonar was activated, sending high signal to the trigger pinof sonar for 1ms. This function was set as a periodic task with allowed execution time

    200ms. Therefore, sonar was triggered periodically.

    Figure 6.

    The output pin of the sonar connects to input capture interrupt 2. The interrupt serviceroutine ISR(INT2_vect) calculate the distance based on the input from sonar. On the risingegde event (when the sonar is triggered), variable time_stamp_s1 captures the time. Onthe falling edge event (sonar receives echo sound pulse), variable time_stamp_s2

    7

  • 8/11/2019 Csc 560 Project 5

    8/35

    captures the time. The time difference can be directly used to calculate the distance.Please read the comments in the code for details.

    Figure 7.

    RTOS

    The RTOS we choose to use was developed by previous students Scott Craig and JustinTanner in fall 2007 who were taking the exact same class. We developed our own RTOS inproject 3, however, we feel more comfortable using this one since it seemed to be robustand extensively tested.

    For details of this RTOS, please refer to the following website.

    http://webhome.csc.uvic.ca/~mcheng/460/summer.2013/handouts/project2/RTOS%20report/index.html

    Here; A, B, C, . G represent the tasks. And the PPP[] array holds all of the periodictasks name and worst time duration. The duration is specified as number of ticks. In our case, one tick is 5ms. If a periodic task reaches Task_Next(), round-robin tasks get to run.

    One has to rename their main() to be r_main(). Because in C, there can only be one main()and it is used by the RTOS. In the r_main(), the tasks are created in the following manner.

    Figure 8.

    8

    http://www.google.com/url?q=http%3A%2F%2Fwebhome.csc.uvic.ca%2F~mcheng%2F460%2Fsummer.2013%2Fhandouts%2Fproject2%2FRTOS%2520report%2Findex.html&sa=D&sntz=1&usg=AFQjCNHXpwSL6NSmQSbA-2L8PGKbZmOvtwhttp://www.google.com/url?q=http%3A%2F%2Fwebhome.csc.uvic.ca%2F~mcheng%2F460%2Fsummer.2013%2Fhandouts%2Fproject2%2FRTOS%2520report%2Findex.html&sa=D&sntz=1&usg=AFQjCNHXpwSL6NSmQSbA-2L8PGKbZmOvtw
  • 8/11/2019 Csc 560 Project 5

    9/35

    Real Term

    We use real term to send data to the microcontroller through UART and the microcontroller will in turn sends data to roomba through radio. In our case, the microcontroller connectedto the computer through COM port 6. For parameters of UART and how to set up UARTconnection, please refer to the following figure.

    Figure 9. The RealTerm, our command control interface.

    We are sending a single ACII character to the microcontroller. The following figure shows

    an example.

    9

  • 8/11/2019 Csc 560 Project 5

    10/35

    Figure 10. RealTerm continued.

    Radio Communication Section

    NRF24L01 Radio HardWare

    NRF24L01 introduction

    The NRF24L01 is a single chip 2.4GHZ transceiver with baseband protocol engine , theEnhanced Shock Burst. The NRF24L01 radio is designed for operation in world wide ISMfrequency band at 2.400-2.4835 GHZ.

    The Nordic nRF24L01 integrates a complete 2.4GHz RF transceiver, RF synthesizer, andbaseband logic including the Enhanced ShockBurst hardware protocol accelerator supporting a high-speed SPI interface for the application controller. The low-power short-range (200 feet or so)Transceiver is available on a board with built-in Antenna.

    10

  • 8/11/2019 Csc 560 Project 5

    11/35

    NRF24L01 Power Management

    The Base Station Atmega1284P Xpld controller is powered via the USB connector from aPC supplying 5V power. The Atmega1284P Xpld supply 5V power to the NRF24L01 by

    connecting the NRF24L01 Vcc pin to Atmega1284P Vcc_5V pin. The power supplied tothe NRF24L01 is regulated by the LDO power regulator, on board of NRF24L01. Therange of input to the NRF24L01 LDO regulator is from 3.3V to 7V.

    NRF24L01 and Atmega1284P Wiring Diagram

    Figure 11. The Base Station NRF24L01/ATmega1284P Wiring Diagram

    In our implementation of the Base Station, the NRF24L01 is directly connected with the ATmega1284P controller, just as the figure shown above. The discussion of the NRF24L01pins are listed as fellow.

    GND Pin

    11

  • 8/11/2019 Csc 560 Project 5

    12/35

    The ground Pin of NRF24L01 is connected to the GND Pin (Pin number needed here) of the Atmega1284P microcontroller.

    VCC

    The VCC pin of NRF24L01 is connected to the VCC_5V pin of the Atmega1284P. Thepower supply to the NRF24L01 is 5V. And as mention before, the LDO power regulator onthe NRF24L01 board regulates the input power to 3.3V to power the NRF24L01 radio.

    IRQ

    The IRQ pin is not connected to any of the pins from the Atmega1284P microcontroller. It isconnected to the Logic Analyzer for testing. The NRF24L01 has an active low interrupt pin.

    The purpose of the connecting IRQ pin is to check if the radio is sending and receivingsuccessfully. The IRQ is activated when any of the transmitting, receiving, or reachingmaximum retransmission limits of the data packets occurring. The result will be resulted inthe corresponding bits of the STATUS register of the NRF24L01 radio. The logic analyzer timing diagram of the NRF24L01 will be shown later.

    MISO

    This pin is connected to the MISO pin of the Atmega1284P microcontroller. The

    NRF24L01 is the slave device. Thus, the serial out pin for NRF24L01 is the MISO. Whenthe NRF24L01 will shift 8 bit value of STATUS register to the Atmega1284P Xpldmicrocontroller by using this pin.

    MOSI

    The Atmega1284P Xpld controller is the master device. The Atmega1284P places thedata ,in byte format, in the shift register and shift the data to NRF24L01 radio.

    SCK

    The SCK pin of the NRF24L01 is connected to the SPI sck pin. In SPI interface, the shiftregister is 8 bits long. After 8 pulses, the content in both of the MOSI and MISO are shifted.When ATmega1284P Xpld, the master device, sends data to the NRF24L01,

    ATmega1284P Xpld controller places data on the MOSI register and generates 8 clockpulses. And when Atmega1284P controller wants to receive data, the NRF24L01 will place

    12

  • 8/11/2019 Csc 560 Project 5

    13/35

    the data on the MISO register. After 8 clock pulses generated by the ATmega1284P Xpld,the data will be received by the microcontroller.

    CSN

    The CSN pin of the NRF24L01 is connected to the PB2 pin on Atmega1284P. After thehigh to low transition of this pin, Atmega1284P can shift the command or data to theNRF24L01 radio.

    CE

    The CE pin is connected to PB1 pin on Atmega1284P. The NRF24L01 radio will be instandby mode I after about 13.8 milliseconds after setting the PWR_UP bit of the CONFIGregister. The operation mode of the NRF24L01 radio will be changed by setting transitions

    of the CE pin. The NRF24L01 operation state diagram is fellow.

    13

  • 8/11/2019 Csc 560 Project 5

    14/35

  • 8/11/2019 Csc 560 Project 5

    15/35

  • 8/11/2019 Csc 560 Project 5

    16/35

    The CSN pin is used to control the SPI bus. We need to keep this pin low when we sendcommands to or read value from the NRF24L01 radio device.

    Steps for reading data on SPI interface

    1. High to low transition on CE pin to change operation mode to radio operationmode.

    2. High to low transition on CSN pin to start reading cycle .3. With each pulse of the SCK, the 8 bit command data is shifted at 1 bit at a pulse.4. After all 8 bit command is shifted from Atmega1284P controller to NRF24L01 radio

    via MOSI pin, the data from NRF24L01 is shifted at 1 bit at a SCK pulse fromNRF24L01 to Atmega1284P controller via MISO pin.

    5. Low to High transition on CSN pin to end the reading cycle.6. Low to High transition on CE pin to change back to standby mode.

    Figure 14. The SPI read operation.

    Steps for writing data on SPI interface

    1. High to low transition on CE pin to change operation mode to radio operation

    mode.2. High to low transition on CSN pin to start reading cycle .3. With each pulse of the SCK, the 8 bit command data is shifted at 1 bit at a pulse.4. After all 8 bit command is shifted from Atmega1284P controller to NRF24L01 radio

    via MOSI pin, the data from NRF24L01 is shifted at 1 bit at a SCK pulse fromNRF24L01 to Atmega1284P controller via MISO pin.

    16

  • 8/11/2019 Csc 560 Project 5

    17/35

    5. Low to High transition on CSN pin to end the reading cycle.6. Low to High transition on CE pin to change back to standby mode.

    Figure 15. The SPI write operation.

    The SPI Clock Polarity and Phase

    There are four modes of SPI phase and polarity with respect to serial data, which aredetermined by control bits CPHA and CPOL of the SPCR register on ATmega1284P. Thefour SPI modes are shown as the figure below.

    Figure 16. SPI modes.

    In our implementation, the SPI mode is setted to mode 0. The CPHA and CPOL bits aredefaulted when we set the SPCR register. The programming detail is shown in NRF24L01driver section. The figure below shows the SPI data transfer format between

    Atmega1284P Xpld and the NRF24L01 radio. Again, the mode 0 is our SPI mode.

    17

  • 8/11/2019 Csc 560 Project 5

    18/35

    Figure 17. SPI data transfer mode 0.

    The NRF24L01 Registers and Commands

    The NRF24L01 Registers

    The following NRF24L01 registers are used to set up and configure the NRF24L01 radio. And each of the registers are 5 bits that is masked by W_REGISTER and R_REGISTERinstruction. For the detail of the registers, please check the NRF24L01 datasheet.

    1. CONFIG, the configuration register.2. EN_AA, Enable Auto Acknowledgment Function Disable this functionality to be

    compatible with nRF2401.3. EN_RXADDR, Enabled RX Addresses.

    4. RX_PW_P0, Number of bytes in RX payload in data pipe 0 (1 to 32 bytes). In thisimplementation, the number of bytes is 32 bytes.5. SETUP_AW, Setup of Address Widths, in our case, it is 5 bytes address width.6. RF_CH, set the frequency channel that NRF24L01 operates on. In this project we

    set the frequency channel to 5.7. RF_SETUP, sets the air data rate. We sets the air data rate to 2Mbps.8. RX_ADDR_P0, sets the 5 bytes long receiving data pipe 0 address. The 5 bytes

    18

  • 8/11/2019 Csc 560 Project 5

    19/35

    address will be assembled to the NRF24L01 data packet which will be discussedlater.

    9. TX_ADDR, Transmit address. Used for a PTX device only.Set RX_ADDR_P0equal to this address to handle automatic acknowledge if this is a PTX device withEnhanced ShockBurst enabled.

    10. SETUP_RETR, Setup of Automatic Retransmission, Auto Retransmit Delay and Auto Retransmit Count. In this project, we set the auto retransmit delay andretransmit count to 4000S and 15 Re-Transmit respectively.

    11. STATUS, Status Register In parallel to the SPI command word applied on the MOSIpin, the STATUS register is shifted serially out on the MISO pin. We read the valuefrom the STATUS register to check the status of NRF24L01.

    The NRF24L01 Commands

    The following NRF24L01 commands are used in our radio driver implementation.

    1. R_REGISTER, masks 3 most significant bits and reads 5 bit width commands andvalue of the status registers from the NRF24L01.

    2. W_REGISTER,masks 3 most significant bits and writes 5 bit width commands andvalue of the status registers from the NRF24L01.

    3. R_RX_PAYLOAD, reads the 32 bytes data payload. The payload is deleted fromFIFO after it is read. This commands is used for radio in receiving mode. TheNRF24L01 on Roomba explore unit executes this command.

    4. W_TX_PAYLOAD, writes the 32 bytes data to transmission payload.5. FLUSH_TX, flushes transmission FIFO.6. FLUSH_RX, flushes receiving FIFO.

    The NRF24L01 Enhanced Shock-Burst Data Packet Format

    The Enhanced Shock-Burst packet contains a preamble field, address field, packetcontrol field, payload field and a CRC field.

    Figure 18. The Enhanced Shock-Burst packet with Payload from 0 to 32 byte.

    19

  • 8/11/2019 Csc 560 Project 5

    20/35

    In our implementation, we set the packet payload to 32 bytes, address to 5 bytes and cyclicredundancy check (CRC) to 2 bytes. The data packet configuration will be shown in thecode section.

    NRF24L01 Radio Driver

    In this section, we will discuss the Radio Driver programming. The Radio Driver isconsisted of 2 parts. They are SPI programming in Atmega1284P and the shiftingNRF24L01 commands using SPI interface.

    The following three SPI registers are used to configure the SPI interface in radio driver.

    1. SPCR, SPI control register.2. SPSR, SPI status register.3. SPDR, SPI data register.

    The SS Pin On Atmega1284P Controller

    It is also important to mention here. In our implementation, the Atmega1284P controller isconfigured as the master device. The SPI interface has no automatic control of the SS pinwhen the Atmega1284P controller is configured as the master device. Thus, we must setthe value to SS pin before the communication can start. The SS pin on Atmega1284P isassociated to the 8th bit of PORTB. The programming detail will be discussed in the SPIprogramming section.

    The SPCR Register

    The SPI control register, SPCR, controls the operation of the SPI interface. The SPCRdefinition is shown in following figure.

    20

  • 8/11/2019 Csc 560 Project 5

    21/35

    Figure 19. The SPCR register.

    First of all, we must enable the SPI interface. This can be done by setting the SPE bit of theSPCR register to 1. Next, as mentioned before, we configured the Atmega1284Pcontroller as the master device. Thus, we must set the MSTR bit to 1 as well. Finally, wemust make sure that the Atmega1284P and NRF24L01 agree on the SCK frequency. Wedo this by setting the SPR0 bit of the SPCR to 1. The programming detail will be discussedin the SPI programming section.

    21

  • 8/11/2019 Csc 560 Project 5

    22/35

    The SPDR Register

    The SPDR register is the read/write register of the SPI interface. Caution for using the

    SPDR register. To avoid data collision, we can only write to SPDR after the last byte of transmission is completed. However, we can read from SPDR before data is completelytransmitted. The following figure shows the SPDR definition.

    Figure 20. The SPDR register.

    The SPSR Register

    The SPSR register is used to detect when the SPI data transfer is completed. The detail of SPSR is shown as the figure below. The programming detail will be discussed in the SPI

    programming section.

    22

  • 8/11/2019 Csc 560 Project 5

    23/35

    Figure 21. The SPSR register.

    An interrupt is generated if SPIE bit in SPCR is set and global interrupts are enabled. If thenegative of the SS is an input and is driven low when the SPI is in Master mode, this willalso set the SPIF Flag. In our case the SS pin is set high and the Atmega1284P isconfigured as the master device. Thus, the SPIF flag will be setted.

    The SPI Programming

    Now we can program the Atmega1284P SPI interface to achieve data communicationback and forth between the NRF24L01 radio. As mentioned before, the Atmega1284P

    23

  • 8/11/2019 Csc 560 Project 5

    24/35

    Xpld controller is configured as the master device. The SPI configuration code is shownbelow.

    Figure 22. The Atmega1284P SPI configuration.

    The SPI Interface Configuration Steps

    The C code above shows the steps of how we configure the SPI interface between the ATmega1284P controller and the NRF24L01 radio.

    1. The DDRB register is setted as code above. As shown in the ATmega1284P/NRF24L01 wiring diagram, we configured that the output pin on Atmega1284P as fellow, MOSI, SCK, CSN and CE. The CE, CSN, MOSI and SCKare PORTB pin 1, 3, 5 and 7 respectively. And because the Atmega1284P

    controller is operating in master mode, we need to set the SS pin high as well. TheSS pin is the PORTB pin 4. The MISO, PORTB pin 6, is used to read input SPI datafrom the NRF24L01.

    2. Set the SPCR register to enable SPI interface, master mode and SCK frequency.The SPE, MSTR and SPR0 bits are discussed in the SPI registers section.

    3. After configured the SPI interface, we can send commands and data to configurethe NRF24L01 radio. The NRF24L01 configuration commands is defined in the

    24

  • 8/11/2019 Csc 560 Project 5

    25/35

    RX_setup() function. The function will be discussed in the next section.4. After configured the NRF24L01 settings, we can set the operation mode of the

    NRF24L01 radio. The RX_mode() and TX_mode() functions are used to configureNRF24L01 radio as either receiving mode or transmission mode.

    The NRF24L01 Radio Configuration Steps in SPI

    Figure 22. The NRF24L01 setup.

    After configured the SPI interface between Atmega1284P controller and the NRF24L01radio, now we can send commands to NRF24L01 to configure its settings. This is done byfollowing steps.

    1. By setting high to low transition of the CE pin, the NRF24L01 is in the standbymode.

    2. Enable auto acknowledgement. The transmitter gets ACK back from the receiver.

    25

  • 8/11/2019 Csc 560 Project 5

    26/35

    3. Enable data pipe 0 as the RX address.4. Set the payload width to 32 bytes. In our implementation, the NRF24L01 data

    packet payload size is 32 bytes. That is we send 32 bytes for every outbound datapacket.

    5. Set the receiver address width to 5 bytes.6. Set the RF channel to 5.7. Set the power mode and air data rate. In our implementation the power mode is

    0dBm. And the air data rate is 2 Mbps.8. Set the receiver data pipe 0 address. In our implementation, the receiving address

    for receiver is 0x2424242424.9. For receiver, the transmission address should be the same as the receiving

    address, if the auto ACK is enabled.10. Finally, we have to setup the retransmission settings. In our implementation, we set

    the auto retransmission delay to 750us. And the number of retry is 15. Again thedetail of the SETUP_RETR register is listed in the NRF24L01 data sheet.

    The NRF24L01 Driver Functions

    spi_command(unsigned char v)

    Both of the spi_Wreg_command and spi_buf_command functions call the spi_commandfunction to pass the data to the destination NRF24L01 registers. The spi_command is the

    basic function to send and receive data to and from the NRF24L01 device. It has only oneparameter v. The variable v is used to define both the NRF24L01 register and as well asthe value to that register. For example, in spi_Wreg_command function, the spi_commandwill be called twice. The first time call of the spi_command is to enter the address of theNRF24L01 register. After entering the register address, the spi_command will be called toenter the value for that register. The coding detail will be shown in the code section.

    spi_Rreg_command(unsigned char reg)

    This function is used to send NRF24L01 commands to the NRF24L01 device. User needto put the NRF24L01 command such as TX_FLUSH or RX_FLUSH as the parameter.

    spi_Wreg_command(unsigned char reg, unsigned char v)

    This function is used to write a single data to the NRF24L01 registers through the SPIinterface. They are two parameters in this function. The first parameter is the name of the

    26

  • 8/11/2019 Csc 560 Project 5

    27/35

    register that we want to write the data to. The second parameter is the value of the datathat the register will get.

    spi_buf_command(unsigned char reg, unsigned char v[], int length)

    This function is used to write an array of data to the NRF24L01 registers. For example, if we want to enter the 5 bytes address for the transmitter, we could use this function asspi_buf_command(TX_ADDR, Address, 5). The reg parameter here again is the name of the NRF24L01 register that we want to write to. The v[] character array contains the 5 bytesaddress, such as 0x2424242424. And the length, of course, is the length of the addressarray. In this case, it is 5 bytes long.

    TX_send(void)

    The TX_send is used for transmission device to transmit the data packet to the receivingdevice. In our design and implementation, the Base Station is the transmitter. And theRoomba Explore is the receiver, The Base Station calls TX_send to send Roombacommands data packets to the Roomba Explore.

    RX_Rece(void)

    The RX_Rece is used for receiving device to receive the data packet from the

    transmission device. As mention above, the Roomba Explore is the receiver. And theRoomba Explore calls the RX_Rece to receive Roomba commands data packets from theBase Station.

    TX_mode(void)

    This function is used to define the NRF24L01 operation mode. As mentioned above, theBase Station is the transmission device. Thus the Base Station calls TX_mode to set itsNRF24L01 to transmission mode.

    RX_mode(void)

    Similar to the TX_mode, the Roomba Explore is the receiver. Thus the system on theRoomba Explore must call RX_mode to set the NRF24L01 on the Roomba Explore toreceiving mode.

    27

  • 8/11/2019 Csc 560 Project 5

    28/35

    The NRF24L01 Timing Diagram

    Figure 23. Entering commands to NRF24L01 radio.

    Figure above shows the command data being transmitted from the Atmega1284Pcontroller to the NRF24L01 radio. The CE pin must be kept low for entering command tothe NRF24L01 radio. Each pulse of the CSN pin signals the start and finish of eachcommand. The command data is represented by the MOSI. As the command binary bits is

    being shifted at each SCK clock pulse. The NRF24L01 status is shifted from theNRF24L01 radio to the Atmega1284P controller via MISO pin.

    28

  • 8/11/2019 Csc 560 Project 5

    29/35

    Figure 24. The NRF24L01 receiving data packets from the air.

    Figure Above shows that the NRF24L01 radio is in receiving mode. The CE pin is kepthigh as the NRF24L01 radio is monitoring the air. The value of the CONFIG register isshifted from the NRF24L01 register to the ATmega1284P controller via MISO. Once theNRF24L01 radio receives the data packet from the transmitter device. The second mostsignificant bit of the CONFIG register, MASK_RX_DR, is set high. And once theNRF24L01 radio receive data packet, the CE pin will be held low. All of the RX_DR,TX_DS and MAX_RT will be reflected on the IRQ pin. In this case, the IRQ pin is reflectedby the interrupt on RX_DR.

    Atmega1284P/Roomba UART Communication

    The detail of Atmega1284P/Roomba UART Communication is mentioned in our Project 2.In this project, the NRF24L01 radio, installed on the Roomba Explore unit, is the receiver device. And it receives Roomba command packet from the base station. We can sendRoomba commands such as F (forward), B(backward), R(right turn), L(left turn) andS(stop) from the base station.

    radio_receiving(void)

    The radio_receiving() function is used on the Roomba Explore unit. This function is used toreceive the Roomba command data packets from the base station. Once the Roombacommand data packets are received by the Roomba Explore unit, the radio_receiving()function will extract the payload of the packet and send command to the Roomba robot viaUART connection.

    29

  • 8/11/2019 Csc 560 Project 5

    30/35

    Figure 25. State diagram of the radio_receiving() function.

    As figure X shows above, in order to control the Roomba remotely, there are four stepsimplemented in the radio_receiving() function. In this project, we are not reading any datafrom the Roomba. Thus the data communication between the Atmega1284P controller andthe Roomba is one way.

    Step 1, receiving the data packets from the base station.Step 2, extracting the payload message from the data packet and selecting the commandby using switch statement.Step 3, creating UART data packet base on the switch statement.Step 4, sending UART data packet to Roomba.

    30

  • 8/11/2019 Csc 560 Project 5

    31/35

    The implementation of the radio_receiving() function is in the coding section.

    Put Everything Together

    The Base Station Unit Checkout

    1. Connecting the SparkFun NRF24L01 radio with Atmega1284P board via SPIinterface connections. The power supply to NRF24L01 is 5V from the

    Atmega1284P microcontroller. Our NRF24L01 radio includes an on board LDOpower regulator. The allowed power supply range is 3.3V to 7V. Thus 5V power is inthe range. At this moment, our Base Station microcontroller is not connected to anycomputer with power supply. Thus, there is no power supply to the NRF24L01 radioyet.

    2. The Atmega1284P Xpld controller is connected to a running computer via USBcable. Thus our Base Station microcontroller is powered via USB cable. The power supplied from the PC is regulated to 3.3V with the LDO power regulator on the

    Atmega1284P Xpld board to supply power to the entire board.

    3. The Base Station microcontroller reads user input from the USART interfaceconnected to the on board AT32UC3B1256 chip. The on board AT32UC3B1256chip is connected to a PC via USB cable. The data transmitted from the PC ispassed to a virtual COM port then to the Atmega1284P Xpld controller.

    31

  • 8/11/2019 Csc 560 Project 5

    32/35

    The Roomba Explore Unit Checkout

    1. Connecting PIR sensors to port D 2 and 4 on Atmega1284P controller.2. Connecting Sonar distance measurement to Atmega1284P controller. The sonar

    echo pin is connected to Atmega1284P port c 0. The trigger pin is connected to Atmega1284P port b 2.

    3. Connecting NRF24L01 radio to Atmega1284P controller. The wiring detail is shownin the figure 27.

    4. Connecting Atmega1284P controller to Roomba via UART communication channel.The wiring detail is shown in the figure 27.

    5. The power supply is 14.4 V from the Roomba battery. The 14.4 V power isregulated to 5V by using the 7805 power regulator. The regulated 5V power issupplied to all the devices on the Roomba Explore unit.

    32

  • 8/11/2019 Csc 560 Project 5

    33/35

    Figure 26. Roomba Robot Unit Wiring Diagram.

    33

  • 8/11/2019 Csc 560 Project 5

    34/35

    The Whole System Diagram

    Figure 27. Our system diagram.

    Project 5 C code

    The Base Station source code can be downloaded at

    http://web.uvic.ca/~byzantin/base_station.zip

    The Roomba Explore Unit source code can be downloaded athttp://web.uvic.ca/~byzantin/Project2_RTOS.zip

    34

    http://www.google.com/url?q=http%3A%2F%2Fweb.uvic.ca%2F~byzantin%2FProject2_RTOS.zip&sa=D&sntz=1&usg=AFQjCNFZnP9LFbrhBvEs-hAZdJpWihogoQhttp://www.google.com/url?q=http%3A%2F%2Fweb.uvic.ca%2F~byzantin%2Fbase_station.zip&sa=D&sntz=1&usg=AFQjCNH_vBWp0Rp4kfyuXFrK-FXlJne1aQ
  • 8/11/2019 Csc 560 Project 5

    35/35

    The Video Demo

    Our project video demo can be found here :

    http://www.youtube.com/watch?v=VeZTy8s4KSU

    http://www.youtube.com/watch?v=VeZTy8s4KSU