求助:SENO158红外定位探头,将它与UNO 板相连的使用方法
SENO158红外定位探头,将它与UNO 板相连,通过串口助手得回来的数据总是一样的,没有变化。不知道是不是程序的问题,还是探头扫描物体应该有要求不符合?这是以下程序,希望各路大神能帮忙解决问题。
#include <Wire.h>
int IRsensorAddress = 0xB0;
//int IRsensorAddress = 0x58;
int slaveAddress;
int ledPin = 13;
boolean ledState = false;
byte data_buf;
int i;
int Ix;
int Iy;
int s;
void Write_2bytes(byte d1, byte d2)
{
Wire.beginTransmission(slaveAddress);
Wire.write(d1); Wire.write(d2);
Wire.endTransmission();
}
void setup()
{
slaveAddress = IRsensorAddress >> 1; // This results in 0x21 as the address to pass to TWI
Serial.begin(19200);
pinMode(ledPin, OUTPUT); // Set the LED pin as output
Wire.begin();
// IR sensor initialize
Write_2bytes(0x30,0x01); delay(10);
Write_2bytes(0x30,0x08); delay(10);
Write_2bytes(0x06,0x90); delay(10);
Write_2bytes(0x08,0xC0); delay(10);
Write_2bytes(0x1A,0x40); delay(10);
Write_2bytes(0x33,0x33); delay(10);
delay(100);
}
void loop()
{
ledState = !ledState;
if (ledState) { digitalWrite(ledPin,HIGH); } else { digitalWrite(ledPin,LOW); }
//IR sensor read
Wire.beginTransmission(slaveAddress);
Wire.write(0x36);
Wire.endTransmission();
Wire.requestFrom(slaveAddress, 16); // Request the 2 byte heading (MSB comes first)
for (i=0;i<16;i++) { data_buf=0; }
i=0;
while(Wire.available() && i < 16) {
data_buf = Wire.read();
i++;
}
Ix = data_buf;
Iy = data_buf;
s = data_buf;
Ix += (s & 0x30) <<4;
Iy += (s & 0xC0) <<2;
Ix = data_buf;
Iy = data_buf;
s = data_buf;
Ix += (s & 0x30) <<4;
Iy += (s & 0xC0) <<2;
Ix = data_buf;
Iy = data_buf;
s = data_buf;
Ix += (s & 0x30) <<4;
Iy += (s & 0xC0) <<2;
Ix = data_buf;
Iy = data_buf;
s = data_buf;
Ix += (s & 0x30) <<4;
Iy += (s & 0xC0) <<2;
for(i=0; i<4; i++)
{
if (Ix < 1000)
Serial.print("");
if (Ix < 100)
Serial.print("");
if (Ix < 10)
Serial.print("");
Serial.print( int(Ix) );
Serial.print(",");
if (Iy < 1000)
Serial.print("");
if (Iy < 100)
Serial.print("");
if (Iy < 10)
Serial.print("");
Serial.print( int(Iy) );
if (i<3)
Serial.print(",");
}
Serial.println("");
delay(15);
}
你用什么作为被识别目标的?
页:
[1]