Hello,
I am trying to use the TF03 LiDAR module with the Teensy 4.1 board. The TF03 uses UART to communicate, so I was wanting to use SoftwareSerial Serial1. After reading some post on here, I changed the following code which works perfectly on an Arduino UNO board:
And I modified it using the tips found in THIS post. Below is that attempt, but nothing comes out of the serial monitor with this code:
Any help on how to achieve UART communication with the Teensy 4.1 board would be greatly appreciated,
Thank you very much
~RandoRkt
I am trying to use the TF03 LiDAR module with the Teensy 4.1 board. The TF03 uses UART to communicate, so I was wanting to use SoftwareSerial Serial1. After reading some post on here, I changed the following code which works perfectly on an Arduino UNO board:
Code:
//Works with UNO board
#include <SoftwareSerial.h>
SoftwareSerial Serial1(2, 3);
int dist;
int strength;
int check;
int uart[9];
int i;
const int HEADER=0x59;
void setup(){
Serial.begin(115200);
Serial1.begin(115200);
}
void loop(){
if(Serial1.available()){
if(Serial1.read()==HEADER){
uart[0]=HEADER;
if(Serial1.read()==HEADER){
uart[1]=HEADER;
for(i=2;i<9;i++){
uart[i]=Serial1.read();
}
check=uart[0]+uart[1]+uart[2]+uart[3]+uart[4]+uart[5]+uart[6]+uart[7];
if(uart[8]==(check&0xff)){
dist = uart[2]+uart[3]*256;
strength = uart[4]+uart[5]*256;
Serial.print("Distance: ");
Serial.print(dist);
Serial.print('\t');
Serial.print("Strength: ");
Serial.print(strength);
Serial.print('\n');
delay(100);
}
}
}
}
}
And I modified it using the tips found in THIS post. Below is that attempt, but nothing comes out of the serial monitor with this code:
Code:
#include <SoftwareSerial.h>
#define txPin 1
#define rxPin 0
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
int dist;
int strength;
int check;
int uart[9];
int i;
const int HEADER=0x59;
void setup(){
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
Serial.begin(115200);
mySerial.begin(115200);
}
void loop(){
if(mySerial.available()){
if(mySerial.read()==HEADER){
uart[0]=HEADER;
if(mySerial.read()==HEADER){
uart[1]=HEADER;
for(i=2;i<9;i++){
uart[i]=mySerial.read();
}
check=uart[0]+uart[1]+uart[2]+uart[3]+uart[4]+uart[5]+uart[6]+uart[7];
if(uart[8]==(check&0xff)){
dist = uart[2]+uart[3]*256;
strength = uart[4]+uart[5]*256;
Serial.print("Distance: ");
Serial.print(dist);
Serial.print('\t');
Serial.print("Strength: ");
Serial.print(strength);
Serial.print('\n');
delay(100);
}
}
}
}
}
Any help on how to achieve UART communication with the Teensy 4.1 board would be greatly appreciated,
Thank you very much
~RandoRkt