Crickets

From MoDe

Table of contents


Connecting Crickets

Each cricket can be connected to serial port of either the ipaq (using the cradle's serial port) or the serial port of your PC. Note however that you'll need to use the null modem to bridge the two female connectors. Before you start, make sure you put fresh AA batteries in the cricket, as they tend to behave erratically if the batteries begin running low. There are two switches on the right side of the device - one for on/off and one for "test". The "test" switch is only relevant if the cricket is configured to be a beacon. When you flip the switch to "On", you should notice the LED's start flashing. The meaning of each LED is explained in the cricket manual (see below), but usually you just use them to tell if the cricket is on or not.

Programming Crickets

The version of crickets we're using can be configured to either beacons or listeners. In addition, you can program and query the crickets to be either directly over the serial port. Connect the cricket to the serial port of your PC, and start up your favorite terminal program (minicom, hyperterminal, etc.). The settings to use are 115200 8N1 with hardware and software flow control disabled. Once connected, you may start seeing the cricket sending data, or you may see nothing at all.

In either case, enter "g cf" at the terminal, then hit Enter. You should see something like this:

  Cricket configuration:
  Software version: 2.3.1 (Jan 26 2005 17:53:17)
  Mode: Listener
  Unique id: 01:65:ba:28:0a:00:00:e1
  Space id:
  Uptime(hh:mm:ss): 00:00:00
  Ultrasound attenuation time(us): 53000
  Ultrasound circuit gain: 127
  Ultrasound pulse type: 2
  Timer Offset(us): 550
  Minimum beacon interval(ms): 668
  Maximum beacon interval(ms): 1332
  Average beacon interval(ms): 1000
  Compensation value(us): 48
  Distance Units: Metric
  Local temperature value(Celsius): disabled
  Speed of sound value(m/s): not used
  Test switch status: Off
  Event output format: 3
  Output variable(s): VR ID DB DR SP TM TS
  Massachusetts Institute of Technology
  http://cricket.csail.mit.edu

The line "Mode" above tells you the current cricket configuration - either beacon or listener. Please also check that the firmware version is 2.3.1. If not, then the cricket needs to be reprogrammed.

Be default, the crickets are configured as listeners. If you want it to be a beacon, you'll want to also set the space id, which is the name you want to assign to the beacon (usually something short).

   Command>> P MD 1               (sets the mode to 1 - i.e., beacon mode) 
   Command>> P SP <id>            (sets the space id - insert desired name for <id>)
   Command>> G CF                 (tests to make sure the mode and space id have been set correctly)
   Command>> P SV                 (saves configuration - very important, if you don't save, all settings are lost once you turn the cricket off)

To change the cricket back into a listener, change the run mode to "2".

A typical default cricket reading looks something like this by default:

    VR=2.0,ID=01:73:3c:3c:0a:00:00:0f,SP=org,DB=22,DR=689,TM=951,TS=8320

The values we care about are SP (tells us which beacon we heard) and DB, which is distance to beacon, measured in centimers. The cricket manual details what the other values mean, and how additional values can be outputted if desired. While you can directly parse this string using python, it's easier to use the python cricket module (see below) which does the parsing and calculations for you. However, this module expects input in version 1 format, so we need to set the output format. At the terminal, do the following commands:

    Command>> P OU 2               (sets output format to version 1 hexadecimal)
    Command>> P SV                 (saves configuration)

Once the configuration is saved, cricket readings should now look something like this:

    $Cricket2,ver=3.0,space=org,id=45,dist=18,duration=1280

"space" is your space id and dist is the distance to beacon in hexademical.

Using Python with Crickets

To read cricket data in python, we will use the cricketd daemon which allows any application to connect and read the cricket data from a normal TCP port. Install the following packages located in the 6.883 feed.

   root@h3900:~# ipkg install pycricket

This will install cricketd in /usr/bin and the libcricket python module, which is a convenient library used to parse and extract various parts of the cricket data. Look in /usr/lib/python2.4/site-packages/libcricket.py for source code as well as an example of how to use it (it can be executed). In addition, there's a more in-depth example using GTK which you can get here (http://web.mit.edu/6.883/files/cricket_app.tar.gz).

Note that libcricket expects cricket data to be in version 1 format as opposed to the default (which is why we made the configuration change above). You can use libcricket just like any other python module by including "import libcricket" in your code.

To start cricketd, enter:

   root@h3900:~# cricketd -p /dev/tts/0  (enter cricketd -h to see the other options)

You should get the following output:

   cricketd version 2.0
   MIT CRICKET SUPPORT (v2.0)
   command line options:
   device name:    /dev/tts/0
   device speed:   115200 (4098)
   port:           2947

With cricketd up and running, you can telnet from any machine to port 2947 and be able to read the cricket data (libcricket does this). For example:

    root@h3900:~# telnet localhost 2947
    r

    Register (Enable)
    VR=2.0,ID=01:73:3c:3c:0a:00:00:0f,SP=org,DB=26,DR=787,TM=1049,TS=15872
    VR=2.0,ID=01:73:3c:3c:0a:00:00:0f,SP=org,DB=26,DR=781,TM=995,TS=16704
    VR=2.0,ID=01:73:3c:3c:0a:00:00:0f,SP=org,DB=26,DR=784,TM=1238,TS=17440

Note that after entering the telnet command, you need to enter "r" in order to start receiving data. You can also issue cricket commands as well (e.g., g cf will output the current cricket configuration). If you don't get any output or you get error messages, try turning turn off, then on the listener a few times until see the correct output.

Cricket Manual

The cricket website is located at http://cricket.csail.mit.edu. The user manual, which covers most of what was posted above, and more, is located at http://cricket.csail.mit.edu/v2man.html.

Troubleshooting Crickets

Post questions and possible solutions to cricket problems here.

  • For some reason, libcricket.py gives me an "Unexpected EOF Error" on duration=eval('0x'+values_dict.get("duration","0")) (line 311). It worked when I changed that to duration = int(values_dict.get("duration","0"),16). Also, if you run their sample program, you might want to change if line[0] == '$': in line 286 to if len(line) > 0 and line[0] == '$': so you don't die on a string out of bounds error all the time. Is anyone else etting a whole bunch of Err: 1 (Invalid entry) errors? -Vikki
  • We're getting it too, Vikki. We'll let you know if we figure it out. Let us know if you do! --Daniel
  • This error seems to come up very often when I tested the crickets. According to the manual, it means an invalid command was entered. My initial guess was that the telnet program was sending junk over the port, but I saw the same problem whether in windows or linux, on the ipaq or the PC. I have yet to find a good solution to this problem. The error seems to go away if you leave the cricket (listener) on for a few seconds first before trying to read the data, as that seems to help the data values settle. --Ning (mailto:nsong@mit.edu)
  • For us the cricket seems to work for a while and then die sometimes. The solution has been just to reset the cricket, wait a minute, and then open up a new telnet connection. If you have a beacon going, wait to open the telnet until the listener's green LED starts blinking. Sometimes we have to repeat once or twice, but it usually works. We're getting reliable data for a few minutes at a time, but after that it starts spewing Err: 1's again. --Daniel
  • Update: See below for a possible solution to this problem. --Ning (mailto:nsong@mit.edu)
  • I still seem to get Err: 1's when using minicom (anyone else?). There seems to be 2 seperate problems: (1) cricket spews out a bunch of Err: 1's and (2) cricket seems to stop responding to serial port. (1) is pretty annoying but if you close, wait, and open the port enough it might go away. (2) seems a little worse because once it gets into this state it seems stuck unless you turn off then on the cricket. (2) can even happen when you're getting good readings then it suddenly stops. Is this pretty common behavior? --jasperln (mailto:jasperln@mit.edu)
  • Ohh I think I found the problem. Init is starting up a getty process occasionally that listens on /dev/tts/0.. So that Err: 1 (Invalid entry) was the cricket getting confused when getty sends the login prompt to it. Heh sadness. Well testing out this theory and so far so good but never know when this thing is going to fail. Almost a minute of good readings so far which for me is an all-time record=) This is running through cricketd too. --jasperln (mailto:jasperln@mit.edu)
  • Did this fix work for you, jasper? If so, what did you change to make the cricket not confused by the getty prompt? -vikki
  • Jasper - Odd, old familiar versions did that also, but we didn't encounter this problem. But, back then the crickets used a different baud rate on the serial port, so that might've been it. In any case, if that solved the problem for you, then great.
  • Vikki - In the file /etc/inittab, the very last line refers to the process jasper is talking about. Comment out that line, then restart, and hopefully that'll do the trick for you also. --Ning (mailto:nsong@mit.edu)
  • Yea I disabled getty and that fixed everything. I was a little surprised as well but it actually makes a lot of sense now. The reason why it was so hard to track down is getty is usually dormant and things run fine. So it doesn't show up in ps -eaf most of the time but every now and then it wakes up and starts spewing out the login prompt which pisses off the cricket so we get a bunch of Err 1's. Also when it appears the cricket stops outputting it's probably because the output of the cricket is getting sucked in as login and passwd instead or getty/cricket finally gets pissed enough and closes things. I checked and when I start getting the Err 1's corresponds to exactly when a getty process starts up. --jasperln (mailto:jasperln@mit.edu)

Old Version

The crickets on the singapore side are currently falshed with the old software version. So here are some tips to avoid running into problems.

  • While connecting to the cricket use baud rate 38400 and not 115200 as specified above
  • Remember the crickets are fixed as beacons or listeners and are not configurable

Identifying listeners and beacons

  * Put fresh new batteries and switch on the cricket. Most likely you will see green led flash
    once for some milliseconds. 
  * If the green led then starts blinking continuously then that cricket is a beacon! 
  * If the green led doesn’t blink it’s a listener. But when a beacon is near then the green led on
    the listener will blink. 

So to identify a listener from a beacon just by observing the led’s, first switch off all crickets near you and then switch on the cricket of your choice. If the green led blinks continuously it’s a beacon if not it’s a listener!!

Another way to identify is as follows:

Download and run cricketd

root@h3900:~# cricketd -s 38400 -p /dev/tts/0
cricketd version 2.0  
MIT CRICKET SUPPORT (v2.0)  
command line options:
 device name:    /dev/tts/0
 device speed:   38400 (15)
 port:           2947

root@h3900:~# telnet localhost 2947 r Register (Enable) $Cricket2,ver=3.0,space=LR001,id=45,dist=16,duration=1042 $Cricket2,ver=3.0,space=LR001,id=45,dist=15,duration=1383 $Cricket2,ver=3.0,space=LR001,id=45,dist=15,duration=1336 &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;. &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;. &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;.

You will see the lines "$Cricket2, ..." if the cricket that you have connected to is a listener and there is a beacon around which is switched on. If there is no beacon you wont see this. Also if the cricket itself is a beacon you won't see those lines. Supposedly you should be able to type 'G CF' and obtain the configuration information of the cricket but this doesn't seem to work here (i.e cricketd + telnet).

Another alternative is to connect to the cricket using hyperterminal on Windows or minicom for Linux/iPAQ. For connecting to hyperterminal you can follow the instructions in the cricket manual (baud rate 38400, flow control=Xon/Xoff). It makes more sense to use minicom on the iPAQ because the cricket is going to be connected to the iPAQ and not your PC. Soon you will also realise that later when you are coding for the Boggle game all you need is the cricketd daemon running and a TCP socket from your python code to send and receive to/from the daemon. Nevertheless here is how you can use minicom.

Download minicom for the iPAQ here minicom (http://familiar.handhelds.org/releases/v0.8.3/feed/base/minicom_2.1-r0_arm.ipk). Install it the usual way. Make sure you stop cricketd before using minicom to connect to the cricket. This is because the the serial device file /dev/tts/0 will be locked. Then you can use minicom as follows:

root@h3900:~# minicom -o -s

Image:serial.gifImage:Settings.gifImage:Exit.gif
After this should see the following for a listener
Welcome to minicom 2.1 OPTIONS: History Buffer, F-key Macros, Search History Buffer, I18n Compiled on Feb 18 2006, 23:39:10. Press CTRL-A Z for help on special keys $Cricket2,ver=3.0,space=LR001,id=45,dist=19,duration=1435 $Cricket2,ver=3.0,space=LR001,id=45,dist=20,duration=1145 $Cricket2,ver=3.0,space=LR001,id=45,dist=20,duration=1158

Type 'G CF' and you'll see the following for a listener, for a beacon there doesn't seem to be any output

Cricket Listener:                                                         
Version: 3.0                                                                    
Space id: 3.0                                                                   
Max US travel time: 45000                                                       
Timer Offset: 910                                                               
Minimum beacon interval: 668                                                    
Maximum beacon interval: 1332                                                   
Compensation value: 53                                                          
Event output format: 1                                                          
                                                                                
Massachusetts Institute of Technology                                           
http://nms.lcs.mit.edu/cricket

To see what you are typing you can set echo ON. Press CTRL-A Z and you'll see this

Image:echo.gif

Then Press E, from now on you will be able to see what you type on the screen. All this will be helpul once the new software is flashed. And once we configure the crickets correctly and put them into action all that needs to be run is cricketd.

Zahoor Zafrulla (mailto:zahoor.zafrulla@nus.edu.sg)