I found another I2C library written by Peter Fleury called i2cmaster (
http://homepage.hispeed.ch/peterfleury/avr-software.html). I can successfully read from the sensor, but the data is corrupt, because the write command still not works. My code look like this:
#include <i2cmaster.h>
int cmd = 0x08;//Read Product ID
int adr = 0x02;//Ultrasonic Sensor
int clockPin = 10;
int buf[8];
void setup()
{
Serial.begin(9600);
i2c_init();//I2C frequency = 9,524KHz
}
void loop()
{
pinMode(clockPin, INPUT);//Needed for receiving to work
digitalWrite(clockPin, HIGH);
i2c_start_wait(adr+I2C_WRITE);
i2c_write(cmd);
delayMicroseconds(50);//Needed for receiving to work
pinMode(clockPin, OUTPUT);
digitalWrite(clockPin, LOW);
delayMicroseconds(50);
pinMode(clockPin, INPUT);
digitalWrite(clockPin, HIGH);
delayMicroseconds(50);
i2c_rep_start(adr+I2C_READ);//Read 5 bytes
buf[0] = i2c_readAck();
buf[1] = i2c_readAck();
buf[2] = i2c_readAck();
buf[3] = i2c_readAck();
buf[4] = i2c_readNak();
i2c_stop();
delay(100);
}
Notice that I do not have to drop the bits, because it takes care of that in the code. If have also modified the library so the frequency is aproximatly 9,6 KHz (See attachment bellow).
The problem with the normal wire.h library was that it did not support repeated start, so I had to use a different one or modify it.
Below you can see the command sent by the Arduino:

It is almost the same as the commands sent by the NXT:

I know it does not send the same command, but I just wanted to see if it could read more bytes.
Bottom of line is that it does not receives ACK when writing or sending the reading command. Does anybody have any ideas how to fix the send command?