Hello,
Created a working board a few months back. Returned to it. The board was working but the code had been lost.
Trying to use the given code by the manufacturer of the laser finder (below), I get errors I can't understand.
Any help or suggestions greatly appreciated.
the errors I get are :
C:\Users\admin\AppData\Local\Temp\arduino-sketch-81756FE4643AEBE6A39C8CFA7216334F\sketch\sketch_1.ino.cpp.o: In function `__static_initialization_and_destruction_0':
C:\Users\admin\Documents\Arduino\sketch_1/sketch_1.ino:13: undefined reference to `SoftwareSerial::SoftwareSerial(unsigned char, unsigned char, bool)'
C:\Users\admin\AppData\Local\Temp\arduino-sketch-81756FE4643AEBE6A39C8CFA7216334F\sketch\sketch_1.ino.cpp.o: In function `_GLOBAL__sub_I_mySerial':
C:\Users\admin\Documents\Arduino\sketch_1/sketch_1.ino:62: undefined reference to `SoftwareSerial::~SoftwareSerial()'
C:\Users\admin\AppData\Local\Temp\arduino-sketch-81756FE4643AEBE6A39C8CFA7216334F\sketch\sketch_1.ino.cpp.o: In function `setup':
C:\Users\admin\Documents\Arduino\sketch_1/sketch_1.ino:19: undefined reference to `SoftwareSerial::begin(long)'
C:\Users\admin\AppData\Local\Temp\arduino-sketch-81756FE4643AEBE6A39C8CFA7216334F\sketch\sketch_1.ino.cpp.o: In function `loop':
C:\Users\admin\Documents\Arduino\sketch_1/sketch_1.ino:27: undefined reference to `SoftwareSerial::available()'
C:\Users\admin\Documents\Arduino\sketch_1/sketch_1.ino:32: undefined reference to `SoftwareSerial::read()'
collect2.exe: error: ld returned 1 exit status
exit status 1
Compilation error: exit status 1
Here is the code as given on the website ..I've only changed the library include method because it doesn't find it otherwise.
/*!
* @File DFRobot_Iraser_Sensor.ino
* @brief In this example, the infrared laser ranging sensor is used to measure the distance, and the sensor data is processed to obtain the measured distance
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @licence The MIT License (MIT)
* @author [liunian](nian.liu@dfrobot.com)
* @version V1.0
* @date 2020-08-13
*/
//#include <SoftwareSerial.h> it doesn't find the library with this one
#include"SoftwareSerial.h" //finds the library with this one
SoftwareSerial mySerial(2,3);//Define software serial, 3 is TX, 2 is RX
char buff[4]={0x80,0x06,0x03,0x77};
unsigned char data[11]={0};
void setup()
{
Serial.begin(115200);
mySerial.begin(9600);
}
void loop()
{
mySerial.print(buff);
while(1)
{
if(mySerial.available()>0)//Determine whether there is data to read on the serial
{
delay(50);
for(int i=0;i<11;i++)
{
data[i]=mySerial.read();
}
unsigned char Check=0;
for(int i=0;i<10;i++)
{
Check=Check+data[i];
}
Check=~Check+1;
if(data[10]==Check)
{
if(data[3]=='E'&&data[4]=='R'&&data[5]=='R')
{
Serial.println("Out of range");
}
else
{
float distance=0;
distance=(data[3]-0x30)*100+(data[4]-0x30)*10+(data[5]-0x30)*1+(data[7]-0x30)*0.1+(data[8]-0x30)*0.01+(data[9]-0x30)*0.001;
Serial.print("Distance = ");
Serial.print(distance,3);
Serial.println(" M");
}
}
else
{
Serial.println("Invalid Data!");
}
}
delay(20);
}
}
and here is the library as i found it online on github. I don't even know if it is the right one, but it seems like it is and I can' t find it anywhere else.
#ifndef SoftwareSerial_h
#define SoftwareSerial_h
#include <inttypes.h>
#include <Stream.h>
#include <HardwareSerial.h>
/******************************************************************************
* Definitions
******************************************************************************/
#define _SS_MAX_RX_BUFF 64 // RX buffer size
#ifndef GCC_VERSION
#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#endif
#if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MKL26Z64__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(__IMXRT1052__) || defined(__IMXRT1062__)
class SoftwareSerial : public Stream
{
public:
SoftwareSerial(uint8_t rxPin, uint8_t txPin, bool inverse_logic = false);
~SoftwareSerial() { end(); }
void begin(unsigned long speed);
void end();
bool listen() { return true; }
bool isListening() { return true; }
bool overflow() { bool ret = buffer_overflow; buffer_overflow = false; return ret; }
virtual int available();
virtual int read();
int peek();
virtual void flush();
virtual size_t write(uint8_t byte);
operator bool() { return true; }
using Print::write;
private:
HardwareSerial *port;
uint32_t cycles_per_bit;
#if defined(__IMXRT1052__) || defined(__IMXRT1062__)
volatile uint32_t *txreg;
volatile uint32_t *rxreg;
#else
volatile uint8_t *txreg;
volatile uint8_t *rxreg;
#endif
bool buffer_overflow;
uint8_t txpin;
uint8_t rxpin;
};
#else
class SoftwareSerial : public Stream
{
private:
// per object data
uint8_t _receivePin;
uint8_t _receiveBitMask;
volatile uint8_t *_receivePortRegister;
uint8_t _transmitBitMask;
volatile uint8_t *_transmitPortRegister;
uint16_t _rx_delay_centering;
uint16_t _rx_delay_intrabit;
uint16_t _rx_delay_stopbit;
uint16_t _tx_delay;
uint16_t _buffer_overflow:1;
uint16_t _inverse_logic:1;
// static data
static char _receive_buffer[_SS_MAX_RX_BUFF];
static volatile uint8_t _receive_buffer_tail;
static volatile uint8_t _receive_buffer_head;
static SoftwareSerial *active_object;
// private methods
void recv();
uint8_t rx_pin_read();
void tx_pin_write(uint8_t pin_state);
void setTX(uint8_t transmitPin);
void setRX(uint8_t receivePin);
// private static method for timing
static inline void tunedDelay(uint16_t delay);
public:
// public methods
SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic = false);
~SoftwareSerial();
void begin(long speed);
bool listen();
void end();
bool isListening() { return this == active_object; }
bool overflow() { bool ret = _buffer_overflow; _buffer_overflow = false; return ret; }
int peek();
virtual size_t write(uint8_t byte);
virtual int read();
virtual int available();
virtual void flush();
operator bool() { return true; }
using Print::write;
// public only for easy access by interrupt handlers
static inline void handle_interrupt();
};
#endif
#endif