Library for Line sensor

Digital Fiber, Photoelectric, Laser Range, Optical, Temperature, Rotary Encoder, Ultrasonic, Gas, Gyro, Accelerometer, FlexiBend, Flexiforce, Compass......

Library for Line sensor

Postby yewys » Thu Apr 27, 2017 4:55 pm

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.
yewys
Novice
 
Posts: 20
Joined: Sun Apr 09, 2017 10:18 pm

Re: Library for Line sensor

Postby yonghui » Thu Apr 27, 2017 4:58 pm

Hi,

which line sensor did you mean? Cytron has several line sensor: LSS05, LSA08 and also rero line sensor
thanks&regards,
yh
yonghui
Moderator
 
Posts: 732
Joined: Mon Sep 28, 2009 3:27 pm

Re: Library for Line sensor

Postby yewys » Thu Apr 27, 2017 5:08 pm

Hi yonghui,

It's rero line sensor.
yewys
Novice
 
Posts: 20
Joined: Sun Apr 09, 2017 10:18 pm

Re: Library for Line sensor

Postby yonghui » Fri Apr 28, 2017 8:05 am

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]);
 
}
thanks&regards,
yh
yonghui
Moderator
 
Posts: 732
Joined: Mon Sep 28, 2009 3:27 pm

Re: Library for Line sensor

Postby yewys » Fri Apr 28, 2017 6:39 pm

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?
yewys
Novice
 
Posts: 20
Joined: Sun Apr 09, 2017 10:18 pm

Re: Library for Line sensor

Postby yonghui » Wed May 03, 2017 9:20 am

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.
thanks&regards,
yh
yonghui
Moderator
 
Posts: 732
Joined: Mon Sep 28, 2009 3:27 pm


Return to Sensor

Who is online

Users browsing this forum: No registered users and 7 guests

cron