Introduction: Make:it Robotics Starter Kit Capturing Sensor Data

Picture of Make:it Robotics Starter Kit Capturing Sensor Data

Last Instructable we discussed a bit about what the linefollow.ino program is doing. I presented a Python script that will allow us to analyze the bitwise if statements to see how the value that the read_Optical() method returns gets converted to the values of 0, 1, 2 or 3.

Now we are going to put all of this together and see what is really happening on the robot. Sometimes when looking over a program that someone else developed, it is sort of hard to visualize what the program is doing. So one of the things I like to do is actually watch what the program is doing while it is executing. In our below example we are going to take a look at what data the sensors are sending to our lineFollow.ino program through the read_Optical() method.

Well there are several ways of doing this. Some development environments have sophisticated debuggers and hardware debuggers that allow you to watch the program execute on the microprocessor. But if you do not have these tools there is an easier way accomplish this. Most micro-controllers, including the Arduino, include built-in hardware that allows you to send communications to the outside world using a serial port. In fact that is how the Arduino Uno communicates with the Motor driver/sensor board on the Robot.

There is another micro-controller that is on the motor driver/sensor board that is responsible for controlling the motors and capturing the signals from the sensors on the robot. The linefollow.ino program running on the Arduino Uno uses the serial port to send commands to the motor driver/sensor board, to control the motors and requests the outputs from the sensors. In fact there are jumper pins that you must make sure are in place that connect the Serial port to the motor driver/sensor board. As the instructions indicate you must disconnect these jumpers when you want to upload a program to the Arduino. So in this case how can we listen in on the serial port from our own personal computer when the Arduino and motor driver/sensor board is using the serial port all of the time?

The Arduino library comes with some methods that provide a software based serial port. Instead of using the build in hardware based serial port, we can pick any available two pins on the Arduino Uno and use these pins to to act just like a hardware based serial port to also communicate to the outside world. In order for our lineFollow.ino program to send messages to our Personal Computer we need a special USB cable that has an adapter built in. This cable is called an FTDI USB cable: (just google for this cable, many online vendors sell these cables for around $15.00 – $20.00)

My Blog is located at

http://joepitz.wordpress.com/

Step 1: Modify LineFollow.ino Program

Looking at the front of the robot, these are on the right lower set of header pins.

We are going to make pin 4 the receive pin and pin 5 the transmit pin:

Here is our code modifications:

#include <SoftwareSerial>

#include "MakeItRobotics.h" //include library

#define rxPin 4

#define txPin 5

MakeItRobotics line_following; //declare object

SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);

Place this code in the declaration/include section discussed in the last blog post:

We tell our lineFollow.ino program to include the SoftwareSerial.h header file. This gives us the resources we need for Serial Port methods. Then we define two variables rxPin and txPin to have values of 4 and 5 Then we create a new object called mySerial with the following statement:SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);

Lets move on to the setup() function. Add the following lines of code to the bottom of the setup() function (inside of the braces {})

pinMode(rxPin, INPUT);

pinMode(txPin, OUTPUT);

// set the data rate for the SoftwareSerial port

mySerial.begin(9600);

The pinMode() functions setup the rxPin as Input and txPin as output.We then setup the mySerial object to use 9600 baud as the speed that we want to communicate over the software serial port. Now we just have to add one line to our loop() function:

sensor_in=line_following.read_optical();

mySerial.println(sensor_in, HEX);

Right below the sensor_in=line_following.read_Optical(); line add the:mySerial.println(sensor_in, HEX); command

Compile and upload your program to your Robot.

Step 2: Wire Up the FTDI USB Cable

Picture of Wire Up the FTDI USB Cable

There one more physical connection we need to make.

Grab your new FTDI USB cable and focus on the black connector opposite the USB connector.You will see some female pins sockets and some colored wires behind these connectors. We only need to make two connections. Get yourself some male/male jumper wires, if you do not already have some.

Notice the Orange and Yellow wires on the FTDI USB cable. Plug a jumper wire into the orange and yellow sockets on the FTDI USB cable.
Now the tricky part. You have to switch the transmit and receive wires between the connector and the header pins on your motor driver/sensor board. That is the receive pin on the motor driver/sensor board goes to the transmit pin on the USB connector. And the transmit ping on the motor driver/sensor board goes to the receive pin on the USB connector. To make it easy, The orange wire goes to pin 4 and the yellow wire goes to pin 5.

Step 3: Write Down Sensor Data

Picture of Write Down Sensor Data

I have placed my robot on a set of blocks to get the wheels up off of the ground so I can side some paper under the sensors.

Also notice I have photocopied a small section of the black line from the circle. We are going to use this line to measure what the sensors are reading in our tests.

Notice that the right wheel has been removed. The paper is resting on the wheel to get the line close to the sensors. Center the black line between the sensors as we want to get a reading of white on both sensors first.

When running these tests you do not need to turn on the batteries, so the wheels are not going to turn. But the sensors are going to function just fine.

Open your Arduino IDE if it is not opened already. Plug in just the usb cable that you use for programming your robot to the USB port on the Arduino. If you are running Windows,

Open your device manager utility, Control Panel->Systems And Security->Device Manager. Expand the Ports (COM & LPT) icon. Note which COM Port your Arduino is connected to. Write this port down. Now connect the FTDI USB cable to your personal computer.

Open the Device Manager and write down the COM Port of your FTDI USB cable. Open the Tools->Port menu option on your Arduino IDE and select the proper port for your FTDI USB cable.

On my computer is was COM port 3. Now Select the Tools->Serial Monitor Menu option and select a Baud rate of 9600 in the lower right hand corner. If you did everything correct you should see the output in the below image.

Now move the paper so the black line is under the right sensor, write down your measurements and then do the same for the left Sensor.

After taking all of your measurements you should have a total of 6 sensor readings:
Left and Right Measurements are taken looking at the front of the robot.

Center = FF and 100

Right = FF and 1FF

Left = 0 and 100

These number are in hexadecimal, Read my tutorial and the links that it points to. Next Instructble will be to take our sensor readings and run them through our ReadOptical.py program.

Comments

Nice, this is really helpful!

Thanks, Yes this was one of my favorites to write.

About This Instructable

1,755views

17favorites

License:

Bio: Software Developer, like to work with electronics, embedded systems, robots etc.
More by jpitz31:C Library for HD44780 LCD Display ControllerFix your NordicTrack Exercise Bike Make:it Robotics Starter Kit - Sending Sensor Data Wirelessly
Add instructable to: