main index Note: my LEGO® bricks index page is here!

Mindsensors NXT sensor does not work! error -35!

No, don't worry: probably you don't have a software problem, but a hardware one and/or a firmware one.

I got my second Mindstorms NXT in November 2007; its firwmare version (verifiable in the NXT menu "Settings / NXT Version") was 1.01; then I bought a few sensors at Mindsensors:

I bought Mindsensors ones because they are cheaper than HiTechnic ones (which come in standard elegant "NXT sensor" packaging); there are other third-party sensors out there, but I did not investigate them because already found what I needed, with a decent pricing (euro/dollar rate was quite high).

These sensors use the I2C standard to exchange data ("low speed", like the NXT ultrasonic sensor).

When I first tested the DIST-Nx bought at Mindsensors, I had at least these problems:

After some investigation and help requests, I finally found that:

  1. hardware problem: Mindsensors flat cables are unreliable for "low speed" data communication (even the 10cm ones); original NXT flat cables (the black thick ones) are absolutely better;
  2. third-party lowspeed sensors cannot operate with original NXT firmware 1.01 (and probably up to 1.04): a firmware upgrade is needed.

How I did solve it

Firmware upgrade: start your Mindstorms NXT application on your Mac or Wind*ws, select "Tools / Firmware upgrade / Check" to see latest firmware releases from LEGO® Mindstorms site and download them. Then connect the NXT via USB cable and upgrade to latest (at least 1.05). A full upgrade requires less than 60 seconds.

After a firmware upgrade to 1.05 the communication problems (the "error -35") disappeared, and the port did not "lock" anymore (don't need anymore to reboot NXT or disconnect/reconnect cable).

Now, when using Mindsensors cables, the NXT reads most of the time a distance of "30" (weird value!) - using the original NXT black cables, distance reads were finally consistent, with very rare "30" or other weird values.

Below, the NXC test program I used to verify that "-35" error before upgrading firmware, and which did not gave any error after some hundreds reads in the DIST-Nx sensor.

#include "NXCDefs.h"

// send a command
void i2command(byte prt, byte adr, byte reg, byte cmd)
  byte cmdbuf[];          // data packet to be sent to sensor
  unsigned int cnt=0;     // counting reads before any error
  int status=NO_ERR+1;    // a default value to start a loop

  ArrayBuild(cmdbuf, adr, reg, cmd);  // prepare packet
  I2CWrite(prt, 0, cmdbuf);           // send command
  while(status > NO_ERR)              // wait completion
    cnt = cnt+1;
    status = I2CCheckStatus(prt);     // update status
  if(status==NO_ERR) return;          // return if no errors

  ClearScreen();                      // detailed info

  TextOut(0, LCD_LINE1, "i2c cmd error:");
  TextOut(0, LCD_LINE2, "cnt:");
  TextOut(0, LCD_LINE3, "prt:");
  TextOut(0, LCD_LINE4, "adr:");
  TextOut(0, LCD_LINE5, "reg:");
  TextOut(0, LCD_LINE6, "cmd:");
  TextOut(0, LCD_LINE8, "err:");

  NumOut(26, LCD_LINE2, cnt, false);
  NumOut(26, LCD_LINE3, prt, false);
  NumOut(26, LCD_LINE4, adr, false);
  NumOut(26, LCD_LINE5, reg, false);
  NumOut(26, LCD_LINE6, cmd, false);
  NumOut(26, LCD_LINE8, status, false);

  Wait(15000);                 // wait 15 seconds before quitting
  Stop(status < NO_ERR);

// read data from sensor register(s)
int i2cread(byte prt, byte adr, byte reg, byte cnt)
  int result = -1;             // default: error value
  byte outbuf[];               // here we will get data
  byte cmdbuf[];               // register number holder

  ArrayBuild(cmdbuf, adr, reg);
  if(I2CBytes(prt, cmdbuf, cnt, outbuf))
    result = outbuf[0];       // read value

      result = result + outbuf[1]*256;
// if 2 registers (16 bit), then add the MSB part 

  return result;              // returns -1 if I2CBytes failed

void i2csetup(byte prt, byte adr, byte reg, byte hwr, byte ene)
  SetSensorLowspeed(prt);         // initialize
  i2command(prt, adr, reg, hwr);  // select hardware
  i2command(prt, adr, reg, ene);  // energize sensor

// setup: hardware is 0x32 (DIST-Nx), energize is 0x45
// read: "1" byte value from register 0x42
// by default ADPA port is always 2 (as of DIST-Nx documentation)

void distnx_setup(byte prt) { i2csetup(prt, 2, 0x41, 0x32, 0x45); }
int  distnx_read(byte prt)  { return i2cread(prt, 2, 0x42, 1);    }
int  distnx_volt(byte prt)  { return i2cread(prt, 2, 0x44, 2);    }
int  distnx_mind(byte prt)  { return i2cread(prt, 2, 0x52, 2);    }
int  distnx_maxd(byte prt)  { return i2cread(prt, 2, 0x54, 2);    }

void dist(byte prt)  // the read-and-show-values loop
  int n;

  for(n=1; n<10000; n++)
    TextOut(0, LCD_LINE1, "read:");
    TextOut(0, LCD_LINE3, "volt:");
    TextOut(0, LCD_LINE5, "min:");
    TextOut(0, LCD_LINE7, "max:");

    NumOut(30, LCD_LINE2, distnx_read(prt));
    NumOut(30, LCD_LINE4, distnx_volt(prt));
    NumOut(30, LCD_LINE6, distnx_mind(prt));
    NumOut(30, LCD_LINE8, distnx_maxd(prt));

    NumOut(0, LCD_LINE6, n);           // how many reads till now

    Wait(1500);                        // 1.5 seconds

task main()           // main task:
  distnx_setup(S1);   // initialization
  dist(S1);           // loop