I have been trying to connect my HiTechnic LEGO NXT PIR sensor to my Arduino Uno, but I am having some trouble.
I found a picture form Mindsensors that shows the cable layout. The blue is SDA, yellow is SCL, green is 5v, the red and black are ground, and the white is used for analog sensors. I have connected the cables as such, but my first problem is with the code.
From the HiTechnic website I found that the device address is 0x02 and the register I am trying to read from is 0x00.
Does anyone know how I would go about reading this address? I have included my code and I there are several problems with it. It tells me "no matching function for call to 'TwoWire::requestFrom(int)' " and "no matching function for call to 'TwoWire::read(int)' "
master_reader.ino: In function 'void loop()':
master_reader:12: error: no matching function for call to 'TwoWire::requestFrom(int)'
C:\Users\Admin\Documents\Robotics\arduino-1.0.3\libraries\Wire/Wire.h:56: note: candidates are: uint8_t TwoWire::requestFrom(uint8_t, uint8_t)
C:\Users\Admin\Documents\Robotics\arduino-1.0.3\libraries\Wire/Wire.h:57: note: uint8_t TwoWire::requestFrom(uint8_t, uint8_t, uint8_t)
C:\Users\Admin\Documents\Robotics\arduino-1.0.3\libraries\Wire/Wire.h:58: note: uint8_t TwoWire::requestFrom(int, int)
C:\Users\Admin\Documents\Robotics\arduino-1.0.3\libraries\Wire/Wire.h:59: note: uint8_t TwoWire::requestFrom(int, int, int)
master_reader:14: error: no matching function for call to 'TwoWire::read(int)'
C:\Users\Admin\Documents\Robotics\arduino-1.0.3\libraries\Wire/Wire.h:63: note: candidates are: virtual int TwoWire::read()
So, the compiler is telling you that the only overloads of the requestFrom() method take two or three arguments, not 1. Why are you not supplying the required number?
The read() method doesn't take any arguments. Why are you supplying one?
I have removed the extra Wire.read() from my code (I don't know why I put it there).
As for the Wire.requestFrom(), I am not sure what to do with that. I need to specify to read from device 0x02, register 0x00, and I am not sure how many bytes it should be returning. Any ideas on what I should do with that?
As for the Wire.requestFrom(), I am not sure what to do with that. I need to specify to read from device 0x02, register 0x00, and I am not sure how many bytes it should be returning. Any ideas on what I should do with that?
Whatever source told you to read from device 0x02, register 0x00, should have told you how much to expect to be able to read. Typically, a register only holds one byte, so, in the absence of other information, I'd ask for one byte. Being a digital sensor (there is movement or there isn't), one byte is probably right.
Ok, thanks. The data I am trying to read right now is the version number for the sensor, so it probably is one byte (unfortunately the information provided about the sensor does not list this).
The Wire.requestFrom() asks for " Wire.requestFrom(address, quantity) ". How would I specify the device address and the address of the register I am trying to read?
I am starting to think that the NXT sensors do not use standard i2c.
First, when a sensor is plugged into my Raspberry Pi through an i2c safe logic level converter the device does not show up when using the i2cdetect function.
Second, the NXTshield advanced development guide from mindsensors says:
Software I2C: The Software I2C protocol is slower than the
Hardware I2C, however it is tailored to work with NXT Digital
sensors.
Hardware I2C: This I2C protocol provides high speed
communication. But NXT digital sensors (e.g. Ultrasonic) do not work
with this protocol.
What is the difference between the software i2c and the hardware i2c and how do I use the software i2c on the Arduino?