Page 1 of 1

NXT IRReceiver Sensor (NIR1032)

Posted: 15 Dec 2010, 14:44
by nikzagvit
What I2C address at a sensor NXT IRReceiver Sensor (NIR1032)?

Re: NXT IRReceiver Sensor (NIR1032)

Posted: 15 Dec 2010, 16:01
by mightor
Have a look at the NXC and/or ROBOTC programs on the product page: http://www.hitechnic.com/cgi-bin/commer ... ey=NIR1032

The info is all there :)

- Xander "Seek and ye shall find!" Soldaat

Re: NXT IRReceiver Sensor (NIR1032)

Posted: 15 Dec 2010, 18:13
by nikzagvit
Thanks has found. I apologize for a carelessness.

Re: NXT IRReceiver Sensor (NIR1032)

Posted: 15 Dec 2010, 19:22
by nikzagvit
I have written the following code.


#define HTIRR_I2C_ADDR 0x02 // HTIRReceiver I2C device address
#define SensorPort IN_4

// Values contained by registers in active mode
#define HTIRR_MOTOR_1A 0x42 // Motor 1A control
#define HTIRR_MOTOR_1B 0x43 // Motor 1B control
#define HTIRR_MOTOR_2A 0x44 // Motor 2A control
#define HTIRR_MOTOR_2B 0x45 // Motor 2B control
#define HTIRR_MOTOR_3A 0x46 // Motor 3A control
#define HTIRR_MOTOR_3B 0x47 // Motor 3B control
#define HTIRR_MOTOR_4A 0x48 // Motor 4A control
#define HTIRR_MOTOR_4B 0x49 // Motor 4B control

task main ()
{
byte message[];
byte nByteReady = 0;
long count;
int buf[10];
string x;

TextOut(0, LCD_LINE1, "Motor 1A", false);

SetSensorLowspeed(SensorPort);
count = 1;
while (true)
{
ArrayBuild(message, HTIRR_I2C_ADDR, HTIRR_MOTOR_1A);
while (I2CStatus(SensorPort, nByteReady) == STAT_COMM_PENDING);
if(I2CBytes(SensorPort, message, count, buf))
{
x = NumToStr(buf[0]);
TextOut(0, LCD_LINE8, x, false);
}
}
}

I read out from the channel Motor 1A control and I display. I test, at me values 100 and 156, why are displayed?

Re: NXT IRReceiver Sensor (NIR1032)

Posted: 15 Dec 2010, 20:48
by nikzagvit
Has understood, here that has turned out

#define HTIRR_I2C_ADDR 0x02 // HTIRReceiver I2C device address
#define SensorPort IN_4

// Values contained by registers in active mode
#define HTIRR_MOTOR_1A 0x42 // Motor 1A control
#define HTIRR_MOTOR_1B 0x43 // Motor 1B control
#define HTIRR_MOTOR_2A 0x44 // Motor 2A control
#define HTIRR_MOTOR_2B 0x45 // Motor 2B control
#define HTIRR_MOTOR_3A 0x46 // Motor 3A control
#define HTIRR_MOTOR_3B 0x47 // Motor 3B control
#define HTIRR_MOTOR_4A 0x48 // Motor 4A control
#define HTIRR_MOTOR_4B 0x49 // Motor 4B control

task main ()
{
byte message[];
byte nByteReady = 0;
long count;
char buf[8];

TextOut(0, LCD_LINE1, "Motor 1A", false);

SetSensorLowspeed(SensorPort);
count = 1;
while (true)
{
ArrayBuild(message, HTIRR_I2C_ADDR, HTIRR_MOTOR_1A);
while (I2CStatus(SensorPort, nByteReady) == STAT_COMM_PENDING);
if(I2CBytes(SensorPort, message, count, buf))
{
TextOut(0, LCD_LINE5, "1: ");
NumOut(6*3, LCD_LINE5, buf[0]);
}
}
}

Re: NXT IRReceiver Sensor (NIR1032)

Posted: 08 Jan 2011, 21:11
by nikzagvit
Hello everyone!
I have written small library on operation with a sensor control on i2c protocol. Has written to understand logic of operation of the protocol, the logician of operation API NXC. Many thanks Xander Soldaat.
It is useful such as I to beginners.

Re: NXT IRReceiver Sensor (NIR1032)

Posted: 08 Jan 2011, 22:17
by mightor
Very tidy code. Thank you for sharing :) Do you think you could upload a .zip file instead? Not everyone can open .rar files.

Thanks!

- Xander

Re: NXT IRReceiver Sensor (NIR1032)

Posted: 08 Jan 2011, 22:30
by nikzagvit
Yes I can upload a .zip file

Re: NXT IRReceiver Sensor (NIR1032)

Posted: 09 Jan 2011, 06:26
by mightor
Much obliged, sir :)

- Xander