From time to time, i'm trying to interface 3rd party hardware from arduino using their UART interface. I' m mostly using Arduino Unos, Megas and Micros.
My question could be for any device exposing a UART interface but let's be specific and take a simple example: slamtec rplidar A2. It even has an arduino lib (that by the way only accepts HardwareSerial and not SoftwareSerial)
the A2M4 datasheet in page 12 states a diagram where I eventually much later found out that 3.3v (and not 5v)
I tried it with an Arduino Uno. You just hook up the pints, add a decent 5V power supply. It worked.
But since i'm using the only one hardware interface of the Uno => i cannot use Serial.print(variable) to debug whatever my program is doing. So instead I used an Arduino Mega that has several hardware serial. it did work immediately on Mega, just like on Uno
But both boards are a bit big. I would rather use the compact Arduino Micro that has 2 hardware serial (one for debug over USB, the other to interface with the lidar => perfect). But here it just does not work at all. communication does not happen. It cannot be me not setting the baudrate right, because the lib does it alone.
Besides, with another UART device (VESC. it has an arduino lib and example), that very same arduino micro worked perfectly with the same RX/TX pins.
Someone suggested a 3.3v/5v voltage convention issue. So I tried, a 3.3v/5v pin converter between the lidar and the arduino micro => BANG! it immediately worked.
I am really confused. as why sometimes i need a hardware covnerter for UART and sometimes not.
For a given arduino product (say Uno/Mega/Micro), where is it written in its specs/datasheet if the RX/TX pins work in 3.3v or 5v or both ?
Is there some software way to force the arduino pins to use 3.3v instead of 5v ? or reverse?
And sometimes, the 3rd party UART device does not publish if its UART interface uses 3.3v or 5v => in that case, how do i know what arduino I should use ?
On a 5v “Arduino” 3.3v will trigger the Rx port ( even tho it’s a 5v port) , if you transmit to a 3.3v device use a voltage divider to convert 5v down to 3.3v.
So In practice you can make most combinations work.
Alternatively you can buy level shifter IC’s or little boards off eBay to convert in either direction .
You can’t change the output level of these boards in software .
Look at the Vcc being used for the circuit. If it is 5 volt then the Tx/Rx uses 5 volt. The corresponding applies to the 3.3 volt technology.
Voltage divider migh work for low baudrates but for high baudrates I recommend a level shifter for better margins, better noice immunity.
The reason for the 3.3 volt family is lowering power consumption and power dissipation.
If the specs says 5v, then it's pins may trigger HIGH if they receive both 3.3v or 5v.
If the specs of a device say 3.3v, then be careful how much tension you apply to the pin. here in the case of the Lidar it says max 3.5v (*)
On arduino at least, tt is not possible to change this 3.3v <-> 5v pin settting from software.
now let's see each of those 3 arduino models one by one
Microcontroller ATmega32U4
Operating Voltage 5V
Microcontroller ATmega328P
Operating Voltage 5V
Microcontroller ATmega2560
Operating Voltage 5V
All 3 boards are 5v. None of them are 3.3v
if the devices I want to communicate with are 3.3v (the example of rplidar), then if I just receive data it should be fine with all those 3 arduinos (uno/micro/mega). However, if I need to send them something, then i need voltage conversion (with a level shifter on high baudrates).
In this case, indeed i must first issue a startscan command so that the rplidar sends me data.
==> So far so good?
Assuming yes.. then what can possibly explain that everything worked out-of-the box with uno and mega BUT required a 5v <-> 3.3v conversion on micro ???
and for the (*) above ==> the rplidar specs says it's max 3.5v on its RX/TX pins.... does that mean that even if it seems to work now with my 5v pins from uno/mega => my rpildar could fry any second ?
It may be possible, depending upon the impedance, etc., of your inputs, to use a serial resistor inline from the Arduino TX pin--but you * really * need to pay attention when doing this.