nxtprograms.com

Fun Projects for your LEGO® MINDSTORMS® NXT!

Home     Projects     Help     Contacts

Checkout Scanner
Building: Intermediate
Program: Advanced

Building Instructions


1


2


3


4


5


6


7

Note: You can use the NXT with either the rechargeable battery pack or AA batteries.


8


9


10


11


12


13


14


15


16


17

This step builds the Calibration Plate, which is used at the beginning of the program to calibrate the brightness of the white beams as seen by the color sensor.


Checkout Scanner Programming
 
Download Programs (help)

Use the CheckoutScan program for the checkout scanner.  At the beginning of the program, you are instructed to cover the sensor with the Calibration Plate, as shown below, and then press the Enter button, so that the program can measure the brightness of the white beams.

Covering the sensor with the Calibration Plate.

When scanning items, you need to complete a scan in less than a second, and also make sure that the white bars of the bar code are perpendicular to the swipe direction, so that they can be counted as they pass over it.  If the scanner counts only one white bar during the scan time, it assumes an item was scanned incorrectly and gives an error tone. 

Important: If you have problems scanning items (an error tone, or the item is not recognized at all, or recognized incorrectly), a likely problem is interference from overhead lights.  See the solutions below.

 

Avoiding Interference from Overhead Lights

The CheckoutScan program works by detecting and counting the white beams in the "bar codes" of the objects, and it does this with a simple brightness test, using the color sensor in "Light Sensor" mode.  Therefore, it needs the brightness of the white beams to be significantly more than an empty background reading.  If there are overhead lights in the room directly over or near the scanner, the background reading may be too bright, leading to objects not being scanned, or an invalid scan (error sound).  If this happens, there are two things you can do:

  1. Move the scanner to a location that is not near any overhead lights.  To help you locate a good location, you can use the LightMeter program, which continuously displays brightness readings, and try to find a location where the empty background reading is no more than about 75% of the reading with the Calibration Plate in place.  Or,

  2. Convert the Checkout Scanner to the sideways orientation, where the color sensor points to the side, using the instructions below.  With the sensor pointing to the side, it is very unlikely to pick up any interference from ambient room light.

 

Graphing the Sensor Readings on your Computer

When working with a sensor that returns continuous readings, and when you are rapidly taking different data samples, it can be helpful to see a graph of the readings as received by the sensor, to help you understand how fast the sensor is responding and what kinds of values are being returned in different situations.  The DataLogLight program is a "data logging" utility program that you can use to record readings from the color sensor in light sensor mode in a data file on the NXT.  This may help you when writing your own programs that use sensors.  The instructions that follow describe how you can upload this data file to your computer and graph it using a spreadsheet program.
 

Note: The DataLogLight program does not require or use the "Data Logging" feature of the NXT-G 2.X software by LEGO Education.  It will work with any NXT software with color sensor support (and could be easily modified for other sensor types).

An example graph drawn using Microsoft Excel on a PC, from data collected while scanning the "Motor" item (5 white bars) is shown below.
 

To use the DataLogLight program and create a graph, you can do the following:

  1. Get an item ready to scan with the Checkout Scanner, then run the DataLogLight progam.  About a half second after starting, the program will beep when it starts collecting data.  When you hear the beep, scan the item.  The program will beep again 1 second later when it stops collecting data.  The program will take readings as fast as it can for 1 second and record them in a data file on the NXT.

  2. Connect the NXT to your computer via USB or Bluetooth, then open the Memory Tab of the NXT control window in the NXT software, as shown below. 

  1. Click the "Other" category in the bar graph at the left.  You should now see a file named "ScanData.txt" on the NXT, as shown above.  This file contains the data readings.

  2. Select the ScanData.txt file, then press the Upload button to upload the file to your computer.  You will be prompted to select a location to store the file (Desktop is fine).

  3. Open the ScanData.txt file that was uploaded to see what the data looks like (it will probably open in Notepad or another text editor).  Note that there are two numbers per line, the first number is a time in milliseconds, and the second number is a sensor reading taken at that time.  Note that the NXT can take and record light readings about 300 times per second!

  4. If you have a spreadsheet program such as Microsoft Excel, you can either import the data into it, or to make it easy to open directly, close the ScanData.txt file then rename it "ScanData.csv".  Double clicking on the csv ("Comma Separated Values") file should then open it directly in Excel (or another spreadsheet).

  5. Select the two columns of data in the spreadsheet, or just a subset of the data that you want to graph, then insert a "Scatter" chart.  This kind of chart interprets the first column as "x" values, and the second column as the corresponding "y" values, which is what we want here.

  6. Format the graph as desired.  For example, the sample graph above adds axis and graph labels, and data markers.

 

Challenges
  • Design some of your own items to scan, with a bar codes alternating white beams and dark gray beams or empty space.  The light gray beams (e.g. 5M beam) don't work well because they are too close to white.  Then modify the program to use a different text and price for your items.  You should only have to make changes in the tabbed Number Switch near the end of the program.

  • Try designing a handheld scanner that you pass over the bar code of an item, instead of passing the items over the stationary sensor.

  • With more careful calibration or measurement, could you modify the bar code reader to distinguish different color beams (white, light gray, dark gray, black) and invent a bar code scheme with more information in it?

  • Try modifying the scanner to expect printed paper bar codes.  Start with large black stripes on a white background and just count them as the original program does (but reversing black vs. white).  If you scanned the item at a consistent speed (with a motor?) could you modify the scanner to recognize different line widths, like a real product bar code (but larger)?

 


Alternate Instructions for Sideways Scanner


If you have problems with overhead room lights preventing the Checkout Scanner from working, or if you prefer a sideways scanning orientation, here are instructions to convert the scanner to a sideways orientation.
 

1-5

Follow steps 1-5 from the main instructions above, or take apart steps 6-9 of the upward-facing scanner to get the base scanner table as shown below.


6a

Note: You can use the NXT with either the rechargeable battery pack or AA batteries.


7a

 

 

Home     Projects     Help     Contacts

 

Copyright © 2007-2011 by Dave Parker.  All rights reserved. 
All project designs, images, and programs are protected by copyright.  Please see the usage policy.