Home / Experiments / Taking I2C to the max on the NXT

Taking I2C to the max on the NXT

I’ve been quite busy the last few days with various performance testing.  A friend of mine is keen to develop a robo-football platform.  Due to the nature of the game, very fast sensor updates and processing is required to track the ball and the opponents.  I’ve offered to work on an extension for the NXT allowing him to hook up to 8 Sharp IR sensors, which will be dotted around the robot’s body.  That made me curious, how fast *can* the NXT go when it comes to I2C?

I wrote a program that made use of two drivers I created earlier.  One for the MAX127 and another for the HiTechnic ProtoBoard (HTPB).  Running both sensors in standard mode, I noticed that I was able to get about 140 readings per second on both.  However, after a conversation with Steve from HiTechnic, I confirmed a suspicion that I had before, that it is possible, with a single request, to query ALL of the ADC channels of the HTPB at once.  I had no function for that so I extended the current driver with a new function:

void HTPBReadAllADC(tSensors _link, tBuffer &_oBuffer, byte _width)

Reads all the analogue channels on the Protoboard at once.

This really pushed up the number of readings I could get per second, going as high as 330.  Mind you, this is not the number of I2C requests made per second, that would be 330/5 or 66. 

Dick Swan probably does not look like this. After speaking with Dick Swan, one of the principal developers of RobotC, the Faster and FastSkipStates for the 9V sensor types were added to both the firmware and the compiler as they only existed for the standard sensor types prior to this.  Officially the HTPB is not supported at these speeds, at least not yet.  It does, however, seem to work without any problems.  At the Faster speed, the MAX127 can be pushed to 330 reads per second, using the HTPBReadAllADC() call, the HTPB can crank out a very respectable 833 readings per second.  For ludicrous speed, the FastSkipStates will allow you to go as fast as 500 reads per second on the MAX127 and 886 on the HTPB.

Speed MAX127 (seq) HTPB (seq) HTPB (all)
Normal 142 142 333
Faster 333 333 833
FastSkipStates 500 500 886

To make sure that the readings were not erroneous, extensive testing was done with the HTPB.  A program was written to write a sequentially increased number to a specific register and read it back a predetermined number of times at various speeds.  If a different value was read back than was written, an error had occurred.  I did 250,000 individual reads at each speed and found no errors.  HiTechnic are currently doing their own tests to confirm this. 

You can download the test programs here: [LINK].

About Xander

Xander Soldaat is a Software Engineer and former Infrastructure Architect. He loves building and programming robots. He recently had the opportunity to turn his robotics hobby into his profession and has started working for Robomatter, the makers of ROBOTC and Robot Virtual Words.