MCP23017 test preparation notes
Now I have extended the 5V0 level I2C and UART signals from the pent level shifter proto board to the half size bread board. I have tested the toggled output of 5V0 IO2 (TxD pin) to be 4.97V high and 0.11 V low.
So far so good. Next step is playing with MCP23017.
.END
Raspberry Pi pent level shifter testing notes
Now I have tidied up the wiring of the 5 channel level shifter board. I found it easy to do the testing, because I can just short either the 3V3 or 5V0 I/O to ground, and see that the opposite side follows. Now I appreciate one more good things about this open drain circuit, it is safe to short the input and/or (need to rigourly verify later) without worrying that some opposite polarity outputs would fight and white smokes come out. I have started playing with MCU things like Arduino and Netduino since 2001 January. So far I have only seen twice white smoke coming out from my circuits, once because wrong polarity of a capacitor, another because misaligned power pins inserted in the wrong place. There were also a couple of devices burnt because of my careless mistakes, but without any smoke.
Next step is to try the new thing MCP23017. I have played with the shorter sistor MCP20338 and solved all the teething problems. So this time the longer MCP23017 should not cause me much trouble, I hope.
.END
Penta level shifter testing notes
Now I am using 2 HC04 hex inverter / buffer to drive red / green LEDs, each HC04 for one side of the level shifter. Offline testing is OK.
.END
Now I that I am confident in using 2N7000 as a level shifter, I have completed all the point to point soldering of the remaining 3 level shifter. So I have all together 5 level shifters for the following 5 signals.
1. SCL
2. SDL
3. INT
4. TxD
5. RxD
So far so good, I am no thinking of use LEDs to show the status of the input and output levels, perhaps for one channel, the INT.
.END
Star Letter: An FET Buffer Stage for GPIO Access - Clive Tombs, MagPi Issue 6, 2012 October
In response to the article from Issue 4, Clive Tombs shares his own example of connecting to GPIO pins.
Introduction
Following on from the issue 4 article on transistors, I would like to describe my use of the 2N7000 Enhancement FET. I used this device only because I had some on hand from previous projects. Other types could be better suited as I will explain later.
Their use provides some interesting behaviours to buffer circuits which may prove beneficial in some applications. The data sheet can be found here:
Now, the FET's Gate is, in simplistic terms, insulated from the Source and Drain connections. Only the voltage relative to the Source (Vgs) is important. Once again I state in simplistic terms. Even if the GPIO pin is configured as an INPUT with the Pi's own Pull Up or Down resistors active, the FET will change state due to the extremely high input impedance of the FET.
From the data-sheet it can been seen that at around Vgs of 2.5v at room temperature the device starts to conduct. By 3.3v it can certainly operate an LED or small relay. As I stated above other FETs may be more suitable in their Vgs characteristics.
Now consider the following application: Test all inputs at start-up. Very simple code can be written to test all used inputs at start-up. By pulling the inputs up then down and testing for the condition in software and visually for an LED flash one can verify both the wiring and the buffer FET. This may seem trivial, but if the LED were replaced with the start circuit for some equipment which must be started in a correct sequence, this code would eliminate the FET as a source of error.
As a maintenance engineer I like diagnostics to make my life easier!
As a maintenance engineer I like diagnostics to make my life easier!
It also has the advantage that one GPIO can be used for both input and output with, in Fig 1's case, a visual indication of button press too.
This is my first ever stab at a Python script. It is bound to be very inelegant, but it just about does what we need. It has been tested in Python 3 only. Try running it with a finger on the button to simulate an input being stuck.
Of course one could arrange the switch to pull the input up. That way the LED would not be on all the time. Script adjustments will be necessary.
With a change in resistor values the FET status can remain unchanged if the button is pressed when the GPIO is set as output.
Eg: if R1 is 330Ω and the switch is connected through about 4k7Ω the Vgs will still be in excess of 3.0v with the button pressed if GPIO pin is output set high.
2N7000s are available for 10p each. Other, superb devices are now available. Some like the2SK4043LS can switch pulses of 80A with as little as 2.5v Vgs. A single transistor could never do that as driven by the PI. And the 2SK3018, a surface mount device designed for small Vgs conditions like here in the PI.
There is a lot to be said for the FET in this application.
Clive Tombs
Editors Note: We love hearing from our readers. If you have a comment on an article or a cool Raspberry Pi related tip to share, please send it to us and
we'll try to get it in an upcoming issue.
we'll try to get it in an upcoming issue.
The "In Control" series in issues 2, 3 and 4 is a great place to start and learn how to use the GPIO. ...
.END
Raspberry Pi and 5V I2C [2N7000] - eLinux
...
the default permissions on /dev/i2c-X are not terribly forgiving, and you'll find yourself having to run everything as root. To alleviate this problem:
sudo chmod 666 /dev/i2c-0
...
The code (i2cTest.py):
import smbus
import time
import smbus
import time
LCD_ADDR = 0x28
def StringToBytes(val):
retVal = []
for c in val:
retVal.append(ord(c))
return retVal
retVal = []
for c in val:
retVal.append(ord(c))
return retVal
def SayHello():
bus = smbus.SMBus(0)
messageInBytes = StringToBytes("Hello World")
bus.write_i2c_block_data(LCD_ADDR, 0, messageInBytes)
bus = smbus.SMBus(0)
messageInBytes = StringToBytes("Hello World")
bus.write_i2c_block_data(LCD_ADDR, 0, messageInBytes)
if __name__ == "__main__":
while True:
SayHello()
time.sleep(1)
while True:
SayHello()
time.sleep(1)
Is it safe to drive a MOSFET from an output pin of a microcontroller?
...
What is a common "hobbyist" MOSFET suitable for various low-power situation? I.E., what's the MOSFET equivalent to a 2N2222 or 2N3904?
...
The BS170 and 2N7000 are roughly equivalent to the BJTs you mentioned. The Zetex ZVN4206ASTZ has a maximum drain current of 600 mA. I don't think that you will find a small MOSFET that can be driven from 3.3V, though.
...
I'd put two resistors into the circuit: one from gate to ground, as Leon has mentioned (actually I'd put it from the MCU output to ground), and another between the MCU output and the gate, to protect the MCU in case the MOSFET has a fault.
...
The resistor from MCU pin to gate is also used to slow down the switching edge, to reduce ringing, overshoot, and EMI. 10 ohms is a typical value. – Mike DeSimone Dec 4 '11 at 15:55
...
It is safe - in general - and it will work if you select a "logic level" MOSFET. Note that "logic level" does not seem to be an exactly standardized term, and it won't necessarily show up as a parameter in the parametric search at the vendor sites, nor will it necessarily show up in the data sheet. However, you will find that logic-level MOSFETs often have an "L" in the part number, ex: IR540 (non logic level) vs. IRL540 (logic level). The big thing is to look in the data sheet and check the VGS(threshold) value and look at the graph that shows current flow vs VGS. If the VGS(threshold) is like 1.8V or 2.1V or so, and the "knee of the curve" on the graph is at around 5 volts, you basically have a logic-level MOSFET.
...
All of that said, I see that a lot of people still recommend using an opto-isolator between the micro-controller and the MOSFET, just to be extra safe.
Homofaciens Raspberry Pi I/O boards
Connecting an Arduino and Raspberry Pi - Fritz-Hut August 27, 2012
Now I am using RPi's TxD pin to test the 2 level shifters. I wrote a new function togglePin() to toggle an output pin. I connected the TxD pin to the 3V3 side of one level shifter and found the 5V0 side toggles as the 3V3 side, except peak to peak is 5V instead of 3V3 on the other side.
I used the TxD pin to test the other level shifter and found the same results.
So both level shifters pass the basic AC test.
Next step is to move on to the IO expander MCP23017.
.END
I am not that confident that my desing is OK, so I only soldered 2 of the 5 level shifter circuits. After checking open short, I did a DC testing making sure the following characteristics.
1. With no inputs on either side, both channels are high (one side 3V3, the other side 5V0.
2. If 3V3 IO1 shorted to ground, 5V0 IO1 also goes low, and vice versa.
3. Same performance for 3V3 IO2 and 5V0 IO2.
So far so good. Next step is a AC test.
.END
Time I went jogging.
.END
So I have tested the 2N7000 based logical level shifter. The circuit is very simple indeed - Gate to 3V3, Source pulled up to 3V3, Drain pulled up to 5V0, and that is all.
I connected Source to ground, and found Drain as output also goes to ground. And when I connected Drain to ground, I found Source also goes to ground.
And this is the end of the test. It is hard to believe that the circuit wiring and testing is so simple. It took me less than 15 minutes to complete everything.
.END
Philips 3V3/5V0 logical level shifter testing notes
No comments:
Post a Comment