I have applied the arduino Mega 5V logic Tx pin to the TFmini 3.3V logic as when i looked at the wiring diagram on tehe Benewake instruction sheet they had it wired this way. they mentioned nothing og arduino Mega's 5V tx pin.
Have i damaged the sensor now? do i need to buy a new one?
Mitchell_Storrie:
I have applied the arduino Mega 5V logic Tx pin to the TFmini 3.3V logic as when i looked at the wiring diagram on tehe Benewake instruction sheet they had it wired this way. they mentioned nothing og arduino Mega's 5V tx pin.
Have i damaged the sensor now? do i need to buy a new one?
The TFMini takes 5V as its V+ but puts out 0ish to 3.3ish volts on tx/rx. I have used the TFMini on the Uno, MiniPro, Mega, Due, STM32 Bluepill, ESP32 supplying it with 5V and hooking it up to 5V and 3.3V devices without issue.
While the sensor can be powered at 5V, the serial UART pins are only 3.3V logic. Make sure to use a logic level converter when reading the sensor with a 5V microcontroller.
Disregarding this warning will damage the TFmini, and possibly also the 5V processor, but both may continue to function for a while.
Thanks Guys! the sensor is working fine. but i will be careful not to use the 5V. I do have logic level converters but found this site which specifies reading the data from the TFmini at 3.3V from the unit and simply displaying it. So i am thinking this might be a work around with the Mega.
I am trying to find some code and good turorials on how to do this with the mega but all I am finding is code for the UNO. I am fairly new to working with arduino. I got two readings working accross the UNO however when i try to do this on the MEGA i have no luck. I think it is something to do with SoftwareSerial not being used on the Mega.
Can someone please guide me onto a tutorial or code for connecting 2 TFmini's to the arduino Mega? Please do not point me towards UNO as these will not work with the Mega.
I have read over one code however I keep getting the error function with HardwareSerial and would rather just do this using the generic library.
This is for my thesis and i would be so greatful for any help. I am trying to learn allot about UART interfacing with arduino Mega at once.
#include <Wire.h>
//Lidar data
int dist;//actual distance measurements of LiDAR
int strength;//signal strength of LiDAR
int check;//save check value
int i;
int uart[9];//save data measured by LiDAR
const int HEADER=0x59;//frame header of data package
void setup() {
Serial.begin(9600);//set bit rate of serial port connecting Arduino with computer
Serial2.begin(115200);//set bit rate of serial port connecting LiDAR with Arduino
}
void loop()
{
if (Serial2.available())//check if serial port has data input
{
if(Serial2.read()==HEADER)//assess data package frame header 0x59
{
uart[0]=HEADER;
if(Serial2.read()==HEADER)//assess data package frame header 0x59
{
uart[1]=HEADER;
for(i=2;i<9;i++)//save data in array
{
uart*=Serial2.read();*
Really struggling here to find any working code for this on the arduino Mega please help guys. I have tried coding it myself but it is just not working.
The code was orginally written to work on a UNO, I have used the code to test the Uno, Mega, Due, STM32, and ESP32. You'll have to change the serial stuff to match your uController.
I, also, have code that will do single trigger but its no use to post that if you cannot get the basic TFMini to work.
Post your well formatted code in code tags so it can be looked over.
Can someone please guide me onto a tutorial or code for connecting 2 TFmini's to the arduino Mega?
What's the problem? The Mega has 4 hardware serial interfaces so it's very easy. You just have to ensure you only connect the TX signal of the TFMini to the RX of the Mega. Do not connect TX of the Mega to the TFMini's RX as that might destroy the sensor. This assumes you use the UART version of the TFMini (you failed to provide a link to the product!), the I2C version is connected differently.
I have done 2 arduino projects before this. My mainstay is C Matlab, Inventor, FEA, very new to this stuff, I am also a SCADA engineer. literally learning this stuff before i interface the sensors in LABview. I have tried the following code. I think i have most of it right I just need to initiate the read which I am struggling to grasp the concept of. If you could help me out i would be most grateful.
Also I am new to the forums. My code compiles I am just missing something to initiate the reads. Code below.
#include <Wire.h>
int dist;//actual distance measurements of LiDAR
int strength;//signal strength of LiDAR
int check;//save check value
int i;
int uart[9];//save data measured by LiDAR
const int HEADER=0x59;//frame header of data package
void lidarData();
void setup() {
Serial.begin(9600);//set bit rate of serial port connecting Arduino with computer
Serial2.begin(115200);//set bit rate of serial port connecting LiDAR with Arduino
}
void loop(){
if (Serial2.available()>0)//check if serial port has data input also greater than 0
{
if(Serial2.read()==HEADER)//assess data package frame header 0x59
{
uart[0]=HEADER;
if(Serial2.read()==HEADER)//assess data package frame header 0x59
{
uart[1]=HEADER;
for(i=2;i<9;i++)//save data in array
{
uart[i]=Serial2.read();
}
check=uart[0]+uart[1]+uart[2]+uart[3]+uart[4]+uart[5]+uart[6]+uart[7];
if(uart[8]==(check&0xff))//verify the received data as per protocol
{
dist=uart[2]+uart[3]*256;//calculate distance value
strength=uart[4]+uart[5]*256;//calculate signal strength value
if(dist>=30 && dist<1200)
{
Serial.print(dist);//output measure distance value of LiDAR, z-coordinate
Serial.print("\n");
Serial.flush();
}
}
}
}
}
}//https://www.youtube.com/watch?v=ts81ZTdY_DQ