Page 1 of 1
Library for Line sensor
Posted:
Thu Apr 27, 2017 4:55 pm
by yewys
Hi,
May i have the header file, as well as the source file for line sensor? I see from the manual, it also has EEPROM and RAM, like G15 servo motor. Thanks.
Re: Library for Line sensor
Posted:
Thu Apr 27, 2017 4:58 pm
by yonghui
Hi,
which line sensor did you mean? Cytron has several line sensor: LSS05, LSA08 and also rero line sensor
Re: Library for Line sensor
Posted:
Thu Apr 27, 2017 5:08 pm
by yewys
Hi yonghui,
It's rero line sensor.
Re: Library for Line sensor
Posted:
Fri Apr 28, 2017 8:05 am
by yonghui
Hi Yewys,
Cytron provided the documentation of the internal readable and writeable RAM and ROM area of the sensor in the datasheet they attached on product page. however there is no arduino library available yet, since most user is using rero controller to read from sensor.
This what i can get for you, but you need to further do some amendment to make it work, and also take note of the default baudrate of the sensor.
- CODE: SELECT_ALL_CODE
#define txM() digitalWrite(ctrlPin,LOW)
#define rxM() digitalWrite(ctrlPin,HIGH)
byte pingSensor(void)
{
byte rxbuffer[7];
rxM();
while(mySerial.available())
{
mySerial.read();
}
txM();
delay(100);
mySerial.write (0xFF); //Header
mySerial.write (0xFF); //Header
mySerial.write (0x68); //ID=103
mySerial.write (0x02); //Length
mySerial.write (0x01); //Ping
mySerial.write (0x94); //Checksum
mySerial.flush(); //wait for transmission done
rxM();
int count=0;
while(mySerial.available()<6)
{
count++; //wait for response
if(count>10)
break;
delay(100);
}
byte bytenum= mySerial.readBytes(rxbuffer,6);
txM();
if(bytenum<6)
return (0);
else
return(1);
}
void setLEDval(byte val)
{
rxM();
while(mySerial.available())
{
mySerial.read();
}
txM();
delay(100);
mySerial.write (0xFF); //Header
mySerial.write (0xFF); //Header
mySerial.write (0x68); //ID=104
mySerial.write (0x04); //Length
mySerial.write (0x03); //write
mySerial.write (0x0D); //Address to write
mySerial.write (val); //data
byte checksum=0xFF-(0x68+0x04+0x03+0x0D+val);
mySerial.write (checksum); //Checksum
mySerial.flush(); //wait for transmission done
rxM();
while(mySerial.available())
{
mySerial.read();
}
}
void calibrate(byte val)
{
rxM();
while(mySerial.available())
{
mySerial.read();
}
txM();
delay(100);
mySerial.write (0xFF); //Header
mySerial.write (0xFF); //Header
mySerial.write (0x68); //ID=104
mySerial.write (0x04); //Length
mySerial.write (0x03); //write
mySerial.write (0x14); //Address to write
mySerial.write (val); //data
byte checksum=0xFF-(0x68+0x04+0x03+0x14+val);
mySerial.write (checksum); //Checksum
mySerial.flush(); //wait for transmission done
rxM();
while(mySerial.available())
{
mySerial.read();
}
}
byte readSensorVal(void)
{
byte rxbuffer[8];
rxM();
while(mySerial.available())
{
mySerial.read();
}
txM();
delay(100);
mySerial.write (0xFF); //Header
mySerial.write (0xFF); //Header
mySerial.write (0x68); //ID=104
mySerial.write (0x04); //Length
mySerial.write (0x02); //read
mySerial.write (0x12); //Address to read
mySerial.write (0x01); //number of byte to read
mySerial.write (0x7E); //Checksum
mySerial.flush(); //wait for transmission done
rxM();
int count=0;
while(mySerial.available()<7)
{
count++; //wait for response
if(count>10)
break;
delay(100);
}
byte bytenum= mySerial.readBytes(rxbuffer,7);
txM();
// for(int i=0;i<7;i++)
// {
// Serial.write(rxbuffer[i]);
//
// }
if(bytenum<7)
return (0xFF);
else
return(rxbuffer[5]);
}
Re: Library for Line sensor
Posted:
Fri Apr 28, 2017 6:39 pm
by yewys
Hi yonghui,
can i know a bit on how to use the code you shared? is that a kinda header file for arduino? What exactly do i need to change in the code?
Re: Library for Line sensor
Posted:
Wed May 03, 2017 9:20 am
by yonghui
Hi Yewys,
im sorry i dont have library for you, the code that i posted are c language functions. u can directly use those functions in your code with some proper intialization codes, or u can create library from it.