Cerebot Sensors Tutorial

From RoboCup

Jump to: navigation, search

Objectives

In this tutorial, you will learn how to connect different types of sensors to Cerebot and how to read the sensor values from a C-program. The following sensors are covered:

  • Analog sensors - the sensors that provide an analog value (varying voltage) on single data line, an example is Fly Eye sensor.
  • I2C sensors - these are sensors that communicate over I2C (also called TWI) bus. It is an type of connection, where many (up to 127) sensors can be connected to the same two wires (TWI = two wire interface), each of them has its own address, and the master (Cerebot board in our case) communicates with them using a special protocol (protocol = formal agreement on how the data are sent up and down the line).
  • LEGO active sensors - these are analog sensors, but they use only two wires - one wire is GND (ground), and the other wire is shared for both powering the sensor and reading the data - this function is switched very fast many times per second
  • LEGO passive sensors - these are similar to analog sensors, but do not require power: instead of indicating the value by changing voltage level, they indicate value by changing resistance, thus we need to apply power on them to be able to read the value.

Tools

We will use the following tools:

  • Hardware
    • PC with Windows
    • Cerebot board
    • Fly Eye sensor
    • SRF02 ultrasonic sensor
    • Light sensor
    • Touch sensor
    • BlueSmirf module for sending information from Cerebot to terminal application running on PC
    • USB BlueTooth dongle connected to USB port of the PC
    • Cerebot-LEGO sensors adapter
    • Voltage divider for LEGO passive sensor
    • JTAG3 programming cable for programming Cerebot
    • Cables for connecting sensors
    • Power source for Cerebot board (either an 9V/5V adapter or 9V batery)
  • Software
    • WinAVR compiler installed on PC
    • Programmers Notepad editor (included in WinAVR)
    • Proycon AVRLib
    • Digilent AVR programmer
    • Hyperterminal application (included in Windows)
    • An internet browser

Before continuing, make sure you have all these tools with you.


Analog sensors: Fly Eye

Instructions:

  • Download Cerebot WinAVR project for Fly Eye: fly_eye.zip, and uncompress it to some folder on your computer
  • Open the file fly_eye.c Programmers Notepad
  • Compile the program (from menu, choose Tools-[WinAVR] Make All), you should get a message saying "Process Exit Code: 0" at the end, and no errors should be printed. This produces file fly_eye.hex, which is a binary code of the program.
  • Power up the Cerebot board with 9V by connecting the power adapter cable or 9V battery
  • Connect the JTAG3 programming cable to PC's printer port (LPT), and to Cerebot board at port J3 (the one marked with white stripe) - make sure the orientation is correct - the VDD mark on the cable should match the VCC mark on the board! If you plug it opposite, you can ruin the board.
  • Connect the BlueSmirf module to Cerebot board at port JE (where you also see TxD1, RxD1 - this is serial port 1 on Cerebot board - there are two serial ports: numbered 0 and 1, but we use serial port 1, because serial port 0 is shared with the JTAG3 programming cable and cannot be used simultaneously). All four pins of BlueSmirf: GND, PWR, TxD, RxD need to be connected. Before connecting, leave the setting of JPE on VCC (this means that BlueSmirf will get 3.3V instead of 9V, it is sufficient). TxD pin of BlueSmirf need to be connected to RxD1 pin of Cerebot, and RxD pin of Cerebot needs to be connected to TxD1 pin of Cerebot - therfore we need to use cable, the BlueSmirf's pins are ordered so that it cannot be plugged to Cerebot directly. The BlueSmirf should start flashing with green light, indicating that it is powered, but not connected from PC yet.
  • Connect PC with BlueSmirf: Open HyperTerminal (in menu Start-Accessories-Communication) application. Create new connection with some (any) name, and choose the serial port, that is mapped to BlueTooth virtual serial port on PC. Use the settings required by the BlueSmirf (our BlueSmirf is 2400-odd-1 stop bit). After you connected, the BlueSmirf will start showing red light instead of flashing green. There might be some program in the Cerebot running, so you may see something printed on the terminal, just ignore that for now).
  • Download the program: open the Digilent AVR Programmer application and download, make sure the settings are correct (Cerebot board, 8MHz onboard crystal), verify the connection by switching to the Fuses tab, and click Read. Do you see the fuses read correctly? If yes, proceed to the Program tab, and click on the three dots, to locate the compiled .hex file (fly_eye.hex). Finally, download the program by clicking on the Program button. You should see message 'Flash contents match programming file' if everything went fine.
  • The downloaded program starts automatically, and will start printing values on the terminal.
  • Connect the Fly Eye sensor: the black wire should be connected to any GND connection on Cerebot, the red wire should be connected to any VU connection (choose one of the unused ports, and set it jumper JPn to VU instead of VCC), and finally, connect the white (data) wire to ADC0 pin on port JF.
  • Test the sensor with the IR Ball, you may get some extra 1023 readings, which need to be ignored by the program.

I2C sensors: SRF02

Instructions:

  • Download Cerebot WinAVR project Cerebot_srf02.zip, uncompress, and compile the file ultrasonic.c
  • In this case we will use 5V power supply, so make sure you change the adapter to 5V, do not use 9V battery in this project (alternately, you can use the 5V power regulator with 9V batery to power the SRF02 sensor, and have Cerebot running on 9V).

Cerebot can be powered with any voltage from 3.6V to 12V.

  • Have the BlueSmirf connected the same way as above.
  • Download the hex-file to Cerebot.
  • Connect the SRF02 sensor to VU power, GND, and to the SDA and SCL pins of one of the TWI-1 or TWI-2 connectors (it is the same TWI bus), according to SRF02 datasheet
  • The readings from the sensor should be now printed on the terminal, experiment with the sensor.

LEGO active sensors: LEGO light sensor

  • Download Cerebot WinAVR project for LEGO active sensors cerebot_sample_ADCs_LEGO.zip, uncompress, and compile (active_sensors.c).
  • Here we are going to use 9V power source again.
  • Download the hex-file to Cerebot.
  • Connect the Cerebot-LEGO active sensor module to port JF (with ADC0-ADC3) so that the mark is close to the corner of cerebot (the PWR pin - next to GND pin). Connect the remaining wire of the module to SERVO HEADER S4 - the red wire to the middle, and the black wire to pin marked SIG (on the very right of all heads).
  • try connecting LEGO sensors to the four different connectors.

LEGO passive sensors: LEGO touch sensor

  • Follow the instructions in our Wiki to test the touch sensor. Now you are experienced, so you should be able to do it all on your own.

Exercises

  • Modify the program for LEGO active sensors to give you only valid values - not the raw values (the valid values are somewhere between 350 and 860, find out yourself).

See Also


Personal tools