Home > Robots > Make:it Robotics Starter Kit – Capture Sensor Data

Make:it Robotics Starter Kit – Capture Sensor Data

Last blog entry 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)

FTDI

Once you have your cable we can modify our linefollow.ino program to send our personal computer messages on what the sensors are doing.

First we will modify our lineFollow.ino program to enable the software serial port.

Looking at the Schematic drawing that came with the software download, we notice that pins 4 and 5 on
header J4 are available so we will make these our transmit and receive pins for out software serial port.

pins

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.h>
#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.

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.

Jumper_Wires

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.

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.

IMAG0173

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 FTDIUSB 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.

output

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.

IMAG0174

IMAG0175

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 Blog post will be to take our sensor readings and run them through our ReadOptical.py program.

Stay Tuned.

About these ads
Categories: Robots
  1. Brad Bartik
    July 23, 2014 at 6:30 am

    Your R/S_Make robotic articles have been very helpful. Thanks.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 56 other followers

%d bloggers like this: