Home > Aaron's Interests > BS2 to MATLAB

Aaron Klapheck's Website

   Home | CSUS | Classes | Experience | Projects | Site Map | Websites   
site search by freefind

BS2 to MATLAB

Contents

General

This page is designed to help people get an understanding of how to download sensor information from the Parallax Basic Stamp 2 (BS2) microcontroller to MATLAB. This can be thought of as an enhancement of the DAQ of the BS2. I hope this information will be particularly beneficial to professor Eke's students taking her Computer Applications course.

Supplies needed:

Note: The older version of PLX-DAQ is called StampDAQ, they are identical. Throughout the rest of this page it is assumed that the user is familiar with the MATLAB programming environment and basic commands, is familiar with the Basic Stamp Editor, and has gone through some of the example programs that teach the user how to use PLX-DAQ (if Indirect Communication is chosen). Chances are for those interested in transferring information from the BS2 to MATLAB a knowledge of these programs has already be established, so the only thing that will seam new will be the PLX-DAQ which is very simple to understand. There are only 10 commands in PLX-DAQ, so if you know those commands then you have mastered PLX-DAQ!

The Process

Below are shown the steps to take in order for the data transmission from the BS2 to MATLAB to take place.

Method 1: Indirect Communication

  • 1. Have the following programs installed: Basic Stamp Editor, MATLAB, PLX-DAQ.
  • 2. Have the sensors and BS2 connected, tested, and up and running.
  • 3. Transfer information from the BS2 to PLX-DAQ (either through a data dump or real-time transfer).
  • 4. Copy the information in PLX-DAQ and paste it into a new Excel document (optional*)
  • 5. Transfer the information from PLX-DAQ to MATLAB.
  • 6. Use MATLAB's advanced programming language to analyze and interpret the sensor information.
*Step 4 is optional because MATLAB usually reads the data in PLX-DAQ just fine but I use this step just in case.
Because there are numerous examples and forums available to help people connect the Basic Stamp Editor to PLX-DAQ, I will be focusing on how to connect PLX-DAQ to MATLAB. Just as the connection from the BS2 to the PLX-DAQ is setup almost entirely in the Basic Stamp Editor so the data transfer from the PLX-DAQ to MATLAB is done almost entirely in the MATLAB environment.

Method 2: Direct Communication

  • 1. Have the following programs installed: Basic Stamp Editor, MATLAB.
  • 2. Have the sensor(s) and BS2 connected, tested, and up and running.
  • 3. Transfer information from the BS2 directly to MATLAB.
  • 6. Use MATLAB's advanced programming language to analyze and interpret the information.
The following sections consist of specific examples of how I transferred data from the BS2 to MATLAB.

Method 1: #1 Photo Sensors

This section contains information about how to take data from two photo sensor, log this information into an Excel file using PLX-DAQ, then read the Excel file into MATLAB which will analyze the information.

Hardware
I am using a two Photoresister (sold by Parallax or found at any electronics store) to acquire light level readings. I am using the photo resistors that came with the Boe-Bot kit which I already own. The circuit diagrams for this hook up can be found in the Robotics with the Boe-Bot text on page 206.

Step-by-Step
See software section below to download specific programs.
1. Setup and test the hardware.
2. Download the program Photo Measure (in .bs2 format) and run it.
3. Connect the BS2 to PLX-DAQ and run it.
4. Upon completion, save the PLX-DAQ as PhotoSensor.xls.
5. Copy the information in PhotoSensor.xls and past it into a new xls document, save as PhotoSensor.xls (see TempProbe1.xls example).
6. Download the program Read Photo DAQ (in .m format) and run it using MATLAB.

Software
Adobe Acrobat icon Photo Measure - The Basic Stamp code (PDF format). Also available in .bs2 format.
PhotoSensor1.xls example - This is example of what the PhotoSensor.xls file should look like.
Read Photo DAQ - The MATLAB code. Also available in .m format.

Results
After running Communicate.m MATLAB will plot two graphs of light intensity vs. time.

Method 1: #2 Temperature Probe

This section contains information about how to take data from a temperature sensor, log this information into an Excel file using PLX-DAQ, then read the Excel file into MATLAB which will analyze the information.

Hardware
I am using a Parallax AD592 Temperature Probe to acquire temperature readings, although any temperature sensor will work. I am using the AD592 because this temperature probe came with the Applied Sensors kit which I already own. The circuit diagrams for this hook up can be found in the Applied Sensors text on page 66. Make sure that whatever temperature sensor is used is also properly calibrated before beginning this procedure to ensure accurate temperature readings.

Step-by-Step
See software section below to download specific programs.
1. Setup and test the hardware.
2. Download the program AD592 Temp Probe (in .bs2 format) and run it in the Basic Stamp Editor.
3. Connect the BS2 to PLX-DAQ and run it.
4. Upon completion, save the PLX-DAQ as TempProbe.xls.
5. Copy the information in TempProbe.xls and past it into a new xls document, save as TempProbe1.xls (see TempProbe1.xls example).
6. Download the program Read Temp DAQ (in .m format) and run it using MATLAB.

Software
Adobe Acrobat icon AD592 Temp Probe - The Basic Stamp code (PDF format). Also available in .bs2 format.
TempProbe1.xls example - This is example of what the TempProbe1.xls file should look like.
Read Temp DAQ - The MATLAB code. Also available in .m format.

Results
After running ReadDAQ_xls_file.m MATLAB will plot a graph of temperature vs. time.

Method 1: #3 Boe-Bot with Photo and Temp Sensor

This section contains information about how to take data from a photo and temperature sensor, dump this information into an Excel file using PLX-DAQ, then read the Excel file into MATLAB which will analyze the information.

Hardware
I am using a Photoresister (sold by Parallax or found at any electronics store) to acquire light level readings. I am using the photo resistors that came with the Boe-Bot kit which I already own. The circuit diagrams for this hook up can be found in the Robotics with the Boe-Bot text on page 206. I am also using a Parallax AD592 Temperature Probe to acquire temperature readings, although any temperature sensor will work. I am using the AD592 because this temperature probe came with the Applied Sensors kit which I already own. The circuit diagrams for this hook up can be found in the Applied Sensors text on page 66. Make sure that whatever temperature sensor is used is also properly calibrated before beginning this procedure to ensure accurate temperature readings. In addition to the sensors I am also using the Boe-Bot setup as shown on page 100 of the Robotics with the Boe-Bot text. Navigation is done with two IR pairs who's setup is shown on page 237 of the "Robotics with the Boe-Bot" text.
Boe-Bot Photo Temp - Electrical schematics, best viewed using IE browser (also available as a downloadable Adobe Acrobat icon document)

Step-by-Step
See software section below to download specific programs.
1. Setup and test the hardware.
2. Download the two programs Boe-Bot Photo Temp and Dump Data (in .bs2 format).
3. Run the two programs in this order: Boe-BotPhotoTemp.bs2 then DumpData.bs2.
4. Connect the BS2 to PLX-DAQ and perform a data dump.
5. Save the PLX-DAQ as Boe-BotPhotoTemp.xls.
6. Copy the information in Boe-BotPhotoTemp.xls and past it into a new xls document, save as Boe-BotPhotoTemp.xls (see Boe-BotPhotoTemp1.xls example).
7. Download the program Read DAQ Photo Temp (in .m format) and run it using MATLAB.

Software
Adobe Acrobat icon Boe-Bot Photo Temp and Adobe Acrobat icon Dump Data - The Basic Stamp code (PDF format). Also available in .bs2 format.
Boe-Bot Photo Temp - Basic Stamp code flowcharts, best viewed using IE browser (also in Adobe Acrobat icon PDF Format)
Boe-BotPhotoTemp1.xls example - This is example of what the PhotoSensor1.xls file should look like.
Read DAQ Photo Temp - The MATLAB code. Also available in .m format.

Results
After running ReadDAQPhotoTemp.m MATLAB will plot two graphs. One graph will plot light light vs. time for three locations. The other graph will plot temperature vs. time for three locations.

Method 2: #1 Simple Message

This section contains information about how to send a simple message from the BS2 to MATLAB.

Hardware
None

Step-by-Step
See software section below to download specific programs.
1. Download the two program Hello from Boe-Bot (in .bs2 format) and run it.
2. Download the program Simple Message (in .m format) and run it using MATLAB.

Software
Adobe Acrobat icon Hello from Boe-Bot - The Basic Stamp code (PDF format). Also available in .bs2 format.
Simple Message - The MATLAB code. Also available in .m format.

Results
After running Simple_message.m MATLAB will display the properties of the COM port it is connected to along with a message the Boe-Bot sent to it.

Method 2: #2 Photo and Temp Sensor

This section contains information about how to take data from a photo and temperature sensor and have MATLAB read this information directly from the BS2 when the BS2 dumps all its data to it. Repeat of #3 but use direct communications.

Hardware
I am using a Photoresister (sold by Parallax or found at any electronics store) to acquire light level readings. I am using the photo resistors that came with the Boe-Bot kit which I already own. The circuit diagrams for this hook up can be found in the Robotics with the Boe-Bot text on page 206. I am also using a Parallax AD592 Temperature Probe to acquire temperature readings, although any temperature sensor will work. I am using the AD592 because this temperature probe came with the Applied Sensors kit which I already own. The circuit diagrams for this hook up can be found in the Applied Sensors text on page 66. Make sure that whatever temperature sensor is used is also properly calibrated before beginning this procedure to ensure accurate temperature readings. In addition to the sensors I am also using the Boe-Bot setup as shown on page 100 of the Robotics with the Boe-Bot text. Navigation is done with two IR pairs who's setup is shown on page 237 of the "Robotics with the Boe-Bot" text.
Boe-Bot Photo Temp - Electrical schematics, best viewed using IE browser (also avalable as a downloadable document)

Step-by-Step
See software section below to download specific programs.
1. Setup and test the hardware.
2. Download the two programs Photo Temp 2 and Dump Data 2 (in .bs2 format).
3. Run the two programs in this order: Boe-BotPhotoTemp2.bs2 then DumpData2.bs2.
4. Download the program Read DAQ Photo Temp 2 (in .m format) and run it using MATLAB.

Software
Adobe Acrobat icon Photo Temp 2 and Adobe Acrobat icon Dump Data 2 - The Basic Stamp code (PDF format). Also available in .bs2 format.
Read DAQ Photo Temp 2 - The MATLAB code. Also available in .m format.

Results
After running Communicate.m MATLAB will display the properties of the COM port it is connected to along with two graphs. One graph will plot light light vs. time for three locations. The other graph will plot temperature vs. time for three locations.

Method 2: #3 Two-Way Communication

This section contains information about how to send and receive data using both MATLAB and the BS2 simultaneously.

Hardware
None

Step-by-Step
See software section below to download specific programs.
1. Download the two programs Send and Receive and Read Data (in .bs2 format).
2. Run SendAndRecieve.bs2
3. Download the program Two Way Communication (in .m format) and run it using MATLAB.
4. Run ReadData.bs2

Software
Adobe Acrobat icon Send and Receive and Adobe Acrobat icon Read Data - The Basic Stamp code (PDF format). Also available in .bs2 format.
Two Way Communication - The MATLAB code. Also available in .m format.

Results
After running ReadData.bs2 a debug terminal will open and display values. These values should be the same as those that were seen in MATLAB after running the program TwoWayCommunication.m.

Method 2: #4 Display PS2 Controller

This section contains information about how to take the PS2 controller readings acquired from the BS2 and transfer them to MATLAB to be displayed.

Hardware
I am using the PS2 controller set-up as described on Aaron's Interest page (Only the circuit diagram is needed).

Step-by-Step
See software section below to download specific programs.
1. Setup and test the hardware.
2. Download the two programs Display Values and PS2 Controller Values (in .bs2 format).
3. Run DisplayValuesOfButtonsAndJoysticks.bs2 to find button values for the controller used, then run PS2ControllerConnectToMATLAB.bs2.
4. Download the program Display Values in MATLAB (in .m format) and run it using MATLAB.


Software
Adobe Acrobat icon Display Values and Adobe Acrobat icon PS2 Controller Values - The Basic Stamp code (PDF format). Also available in .bs2 format.
Display Values in MATLAB - The MATLAB code. Also available in .m format.

Results
After running ReadData.bs2 a debug terminal will open and display values. These values should be the same as those that were seen in MATLAB after running the program TwoWayCommunication.m.

Method 2: #5 PS2 Virtual/Real World Control

This section contains information about how to use the PS2 controller to control the movements of the Boe-Bot. In addition to Boe-Bot control, the information from the PS2 controller will also be used to direct the movements of a virtual car in MATLAB at the same time.

Hardware
I am using the Boe-Bot setup as shown on page 100 of the Robotics with the Boe-Bot text. I am also using the PS2 controller set-up as described on Aaron's Interest page (Only the circuit diagram is needed).

Step-by-Step
See software section below to download specific programs.
1. Setup and test the hardware.
2. Download the program Virtual Car to test the virtual environment in MATLAB*.
3. Download and run Boe-Bot/Virtual Control (in .bs2 format)
4. Download the program Virtual/Real Control (in .m format) and run it using MATLAB.
*vrmount.wrl will not work if the demo version of the virtual reality toolbox is used; if the demo version is used, then look for the demo: "Car in the Mountains."


Software
Virtual Car - The MATLAB code (.m format).
Adobe Acrobat icon Boe-Bot/Virtual Control - The Basic Stamp code (PDF format). Also available in .bs2 format.
Virtual/Real Control - The MATLAB code. Also available in .m format.


Results
After running PS2_Boe_Bot_and_VW.m a virtual reality simulation will start. By using various buttons on the PS2 controller not only will the Boe-Bot move but so will the virtual car in the simulated environment.

Advantages and Drawbacks

There are some advantages and drawbacks to using my approach, some are listed below.

  • Advantages
    • No expensive DAQ software - MATLAB's DAQ toolbox is about $50 and MathView is $100 plus you have to set up the connection manually because Parallax is not inherently supported by either platform.
    • Besides method one, there is no new software to learn - Method one uses PLX-DAQ which uses a total of 10 commands! MATLAB's DAQ toolbox and MathView have hundreds of new commands to get familiar with.
  • Disadvantages
    • Although real-time data analysis is possible using my method, it is not very reliable. A software tool dedicated to real-time analysis - both MATLAB and LabView offer such tools - would work much better.
    • Support - Parallax is currently working on connecting their hardware to LabView and other related software, so when that occurs they will have much more customer support and examples than I can offer.

Comments

Comments, complaints, suggestions? Please let us know.

You do not need facebook in order to post a comment (although it is preferred). Just write something and hit Post.

Problem with making a comment? This commenting ability may not be accessible to computers on slower networks.