Arduino Forum

Using Arduino => General Electronics => Topic started by: Netoperz on Mar 09, 2016, 03:16 am

Title: Arduino Pro mini DIgital pins voltage tolerance question
Post by: Netoperz on Mar 09, 2016, 03:16 am
Hello,

I'm working on project where i need to connect some stuff to the arduino.
For example bluetooth module HC-06
The modules are 5v powered, but they have Serial lines 3,3v

My question is:

If the arduino board is 5V 16mgz version is it safe to connect the serial interface from my modules to the digital pins of arduino ?

Everywhere where I was looking for answer, there was no clear answer if the digital pins are "safe" for 3.3 v serial modules ?

the documentation is telling that arduino 5v is 5v tolerant, but what is actual "High" signal ? is it 5v or is it less than 5V and is safe for modules that are using 3,3 v tel serial interface ?


Title: Re: Arduino Pro mini DIgital pins voltage tolerance question
Post by: Koepel on Mar 09, 2016, 03:30 am
It's in the datasheet. The Pro Mini uses the ATmega328P.
http://www.atmel.com/devices/atmega328p.aspx (http://www.atmel.com/devices/atmega328p.aspx)
Complete datasheet, Page 313, for 5V the Vih Min. is 0.6 Vcc
That means that any voltage above 3.0 V is recognized as a high.

However, I had serial modules that gave a signal of around 3.0V and didn't work.
Title: Re: Arduino Pro mini DIgital pins voltage tolerance question
Post by: Netoperz on Mar 09, 2016, 03:51 am
Thank you, i was checking the voltage on ATmega328P 16mhz 5v when pin was set to high, and it was oscillating between 3.7 and 4.1 V

It should be safe for 3,3v tolerant output/input modules connected to the atmega, but i cannot be sure, that's why i'm asking.

In Atmel world things are more complicated sometimes for someone like me working with Microchip till today :)


So can I assume, that connecting directly for example pin 14, or pin 2 of arduino pro mini to be used as TX with Softwareserial library  (version ATmega328P 16mhz 5v)  to the RX input of my bluetooth module HC06 (that is 3,3v level input)  should not burn the module :) ?
Title: Re: Arduino Pro mini DIgital pins voltage tolerance question
Post by: outsider on Mar 09, 2016, 04:06 am
If your HC06 module is 5 volt tolerant, OK.
If your HC06 module is not 5 volt tolerant, not OK.

http://www.mcu-turkey.com/wp-content/uploads/2013/01/HC-Serial-Bluetooth-Products-201104.pdf (http://www.mcu-turkey.com/wp-content/uploads/2013/01/HC-Serial-Bluetooth-Products-201104.pdf)

Page 9.
Title: Re: Arduino Pro mini DIgital pins voltage tolerance question
Post by: Netoperz on Mar 09, 2016, 04:20 am
Most designs on the internet looks like this:

http://www.bitstoc.com/image/data/Products/arduino_bluetooth_serial%20-%20Copy.jpg



And that is why i was asking, because in my opinion it should at least look like this:

http://cdn.instructables.com/FSK/AI30/HMMFE6UO/FSKAI30HMMFE6UO.LARGE.jpg


Right ?
Title: Re: Arduino Pro mini DIgital pins voltage tolerance question
Post by: Netoperz on Mar 09, 2016, 04:45 am
In case if someone would be looking for the same question, here is an answer:

http://fritzing.org/projects/voltage-divider

 The 1.2K Ohms & 2.2K Ohms resistors can be used as voltage dividers to drop the Arduino's 5V to about 3.3V. Also if you have 10K Ohms & 20K Ohms resistors they will do the work.

Exact equation for calculating the dividers is on the frizzing website for example, and well explained.

I know that BT modules do work connected straight on RX(module) <==> TX(Arduino) but it rather depends on luck than physics :)

So better just add two resistors and be safe.

Hope that will help others.
Title: Re: Arduino Pro mini DIgital pins voltage tolerance question
Post by: dlloyd on Mar 09, 2016, 05:04 am
Here, (http://wiki.pinguino.cc/index.php/Interfacing_with_Bluetooth_JY-MCU) it says:

"Warning: the Bluetooth chip is rated for 3.1V to 4.2V - connecting VCC to 5V is only ok if you are using a bluetooth module on a board like the JY-MCU Board which includes a voltage regulation circuit to limit the voltage, otherwise you will fry the Bluetooth chip on your module and be very sad."

Choose voltage divider method, but TxD-1K-2K-GND (in my opinion) would limit the maximum baudrate that can be used.

Here, (http://reprap.org/wiki/Jy-mcu) they use TxD-680Ω-1K-GND. This would provide a stronger signal and have higher baudrate capability.

Note that when loading a 5V Arduino pin with 20mA, its voltage drops to 4.2V.
Here, (http://www.voltagedivider.ca/index.php) I've used 4.6V in the calculation to get TxD-270Ω-680Ω-GND for even better baudrate performance.
Title: Re: Arduino Pro mini DIgital pins voltage tolerance question
Post by: Paul__B on Mar 09, 2016, 06:29 am
There is an important trick to be learned from the Adafruit Huzzah (https://learn.adafruit.com/adafruit-huzzah-esp8266-breakout/overview) ESP8266 breakout.

The level converter is a single diode.  That's it!

(https://learn.adafruit.com/system/assets/assets/000/024/745/original/adafruit_products_schem.png?1429900999) (https://learn.adafruit.com/system/assets/assets/000/024/745/original/adafruit_products_schem.png?1429900999)

Clearly, the ESP8266 contains an internal pull-up, so you might need to add a pull-up to the HC-06.  You are driving it with an Arduino, so pick your value - 1k, 3k3 - whatever.  This will in any case be faster than a resistive divider.
Title: Re: Arduino Pro mini DIgital pins voltage tolerance question
Post by: dmjlambert on Mar 09, 2016, 06:36 am
I have used a 10K-15K voltage divider connecting to the RX pin of HC-05 Bluetooth board and have not had errors at 115200 baud.  It seems extremely reliable.   What kind of speeds are we talking about where a voltage divider becomes a problem?
Title: Re: Arduino Pro mini DIgital pins voltage tolerance question
Post by: dlloyd on Mar 09, 2016, 07:00 am
I really don't have experience with the HC-05 Bluetooth board itself, but a resistive voltage divider will always limit the rise/fall time of a signal. A 10K-15K divider seems rather weak ... its possible 115200 baud is near the upper limit.

With a resistive divider, any capacitive load is the enemy, so the length of connections, type of wire/cable and input capacitance play a role.

A 270Ω/680Ω from 5V to GND will draw about 5mA of current.

Title: Re: Arduino Pro mini DIgital pins voltage tolerance question
Post by: dmjlambert on Mar 09, 2016, 07:07 am
This is great info, thanks!   So if not worried about 5mA, just go for the low resistance voltage divider for max performance.  If it communicates a lot, it is probably less than 5mA on the average, since the moments the TX pin is low it won't be drawing current. 
Title: Re: Arduino Pro mini DIgital pins voltage tolerance question
Post by: dlloyd on Mar 09, 2016, 07:21 am
Oh, I just realized that although 5mA is OK for the Arduino, it might be too much for the IC on the Bluetooth module (I don't have a datasheet).

Therefore, the lowest values to use would be that of the RepRap link ... TxD-680Ω-1K-GND (at least this has been tested and implemented).
Title: Re: Arduino Pro mini DIgital pins voltage tolerance question
Post by: dmjlambert on Mar 09, 2016, 07:30 am
Just about all the current would come from the TX pin on the Arduino, and little or none from the RX pin on the Bluetooth module, right? Because RX is just reading and is set for input.
Title: Re: Arduino Pro mini DIgital pins voltage tolerance question
Post by: dlloyd on Mar 09, 2016, 07:37 am
Yes ... your right.  (I think I need some sleep now)
Title: Re: Arduino Pro mini DIgital pins voltage tolerance question
Post by: Paul__B on Mar 09, 2016, 12:24 pm
Fascinating.

I post the better solution and people just keep on talking about resistive dividers! :smiley-roll:
Title: Re: Arduino Pro mini DIgital pins voltage tolerance question
Post by: dmjlambert on Mar 09, 2016, 02:42 pm
Hi Paul__B, sorry about that.   I did just have some additional questions about the voltage dividers, as I had some past observations that were relevant to the resistor values being discussed.   

The diode idea is also interesting.   Do you think any handy general purpose diode a person happens to have around would be suitable for this purpose?  Or is the 1N4148 particularly attractive for this use because of some characteristic it has?   Are any of the on-board resistors of a typical HC-05 or HC-06 backboard important to have in series with the diode, in case we want to use a bare HC-05 or HC-06 module without a backboard?   Or are there any typical usage tips or other circuitry required when using a diode in this manner?   
Title: Re: Arduino Pro mini DIgital pins voltage tolerance question
Post by: Netoperz on Mar 09, 2016, 03:43 pm
For the exit answer about level shifting:

http://jamesreubenknowles.com/level-shifting-stragety-experments-1741

http://www.daycounter.com/Circuits/Level-Translators/Level-Translators.phtml


http://playground.arduino.cc/Main/I2CBi-directionalLevelShifter


In those articles there is everything You may want to know about digital voltage level shifting.
Title: Re: Arduino Pro mini DIgital pins voltage tolerance question
Post by: Paul__B on Mar 09, 2016, 09:06 pm
The diode idea is also interesting.   Do you think any handy general purpose diode a person happens to have around would be suitable for this purpose?  Or is the 1N4148 particularly attractive for this use because of some characteristic it has?
No, the 1N4148/ 1N914 simply is a handy general purpose - generic - diode.

Are any of the on-board resistors of a typical HC-05 or HC-06 backboard important to have in series with the diode, in case we want to use a bare HC-05 or HC-06 module without a backboard?
Frankly, I am not aware of "on-board resistors of a typical HC-05 or HC-06 backboard".  There would be no reason whatsoever to put any resistor in series with the diode.

In those articles there is everything You may want to know about digital voltage level shifting.
Except that they all omit the simple use of the diode which we may presumably credit to Lady Ada.

It turns out to be a quite brilliant solution!

When the input from the Arduino (or other device) is pulled LOW, the diode pulls the output LOW within 0.7 V.  The diode impedance is very low (tens of Ohms) and 0.7 V will be well within the tolerance of any 3.3 V device as a logic LOW, so delay at this point is negligible.

Correspondingly, when the input from the Arduino (or other device) is pulled HIGH, either the built-in pull-up of the 3.3 V device (as in the ESP8266) will itself pull the input up to its own HIGH level, or in case this is not sufficiently fast, a pull-up to the 3.3 V supply can be added.  Given that it is an Arduino pin driving the circuit, the pull-up can be as low as necessary to achieve the required speed, down to 330 Ohms or so.

The arrangement is both simple, and immediately fills all requirements for level shifting.
Title: Re: Arduino Pro mini DIgital pins voltage tolerance question
Post by: pwillard on Mar 09, 2016, 09:14 pm
This is how Cow Paths are formed...
Title: Re: Arduino Pro mini DIgital pins voltage tolerance question
Post by: dmjlambert on Mar 10, 2016, 12:51 am
Ok, so Lady Ada is presumed to be the first cow that trampled the grass, then Paul__B is following.   If I were to follow along, I think that if the device/pin on the 3V3 side of that diode should  have a pull up.  If it does not have an internal one, add an external one.   The HC-05 has a weak internal pull down on the RX line, so I  need to just add that external pullup to 3V3, probably with a 1K resistor.