Pages

Thursday, February 28, 2013

MCP23017 testing notes

I am reading my old posts to refresh my memory on how did I test the MCP23017 last time.
MCP23017 test preparation notes
2012年12月31日 下午2:34公開累計瀏覽次數 00
 
 

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

MCP23017 pinout diagram
2012年12月31日 下午3:22公開累計瀏覽次數 130
 


Now I am looking at the MCP23017 pinout diagram to remind me how last time I wired the similar thing MCP23008.

.END

MP23017 detection OK
2012年12月31日 下午3:58公開累計瀏覽次數 40
 

Now I have detected MCP23017 OK.  I made two mistakes in the wiring, luckily there is no white smoke appearing.  Finally I detected the thing successfully.  I only made the following connections.

pin 09 Vdd - 5V0

pin 10 Vss - Gnd

pin 12 SCL - RPi SCL

pin 13 SDA - Rpi SDA

pin 15 A0 - Gnd

pin 16 A1 - Gnd

pin 17 A2 - Gnd

pin 18 Reset - 5V0


So far so good.  Next step is to let the Raspberry Pi to talk to the MCP23017.

.END


SN74LVC245AN specification
2012年12月31日 下午4:38公開累計瀏覽次數 70
 


SN74LVC245AN spec

.ENd


MCP23017 proto board assembly notes
2012年12月31日 下午10:57公開累計瀏覽次數 30
 

Now I have started soldering my very first MCP23017 proto board.  I am glad that now the circuit is all 5V only, no more 3V3 blocking the way, and keeping me worrying of shorting 3V3 and 5V0 by mistake and white smoke appears.

.END

MCP23012 proto board asembly notes
2013年1月1日 下午12:45公開累計瀏覽次數 70
 

So I have moved the MCP23017 circuit from breadboard to protoboard.  I used the command "sudo i2cdetect -y 1" to verify that the address jumpers A2 A1 A0 can set the I2C address from 20 to 27 as expected, and that the reset when shorted to ground would disable the MCP23017 and therefore could not be detected anymore.


.END


MCP23017 interrupt LED assembly notes
2013年1月1日 下午9:28公開累計瀏覽次數 20
 
Now I have added two red/green LED pairs to indicate the status of MCP23008's INTA and INTB.  Offline testing good.

.END

Raspberry Pi MCP23017 evaluation board and testing plan
2013年1月2日 上午11:41公開累計瀏覽次數 280
 

Now I have completed all the soldering work of the MCP23017 evaluation board.  Next step is testing.

.END


Raspberry Pi MCP23017 Port Expander Board Kit - HobbyTronics, UK

http://www.hobbytronics.co.uk/mcp23017-port-expander-board

This useful kit contains the MCP23017 Port Expander chip and a breakout board which connects directly to our Raspberry Pi GPIO Breakout Board and plugs into a Breadboard. The Power and I2C connections are automatically made to the GPIO Breakout Board via a 5 way header socket so no breadboard wiring is needed.

Features

Connects directly to GPIO Breakout Board via 5 pin header

Pull up resistor on RESET pin of MCP23017

Pull down resistors on addess pins of MCP23017 to give default address of 0x20

Multiple boards can be linked together

The 16-bit I/O port functionally of the MCP23017 consists of two 8-bit ports (PORTA and PORTB). The MCP23017 can be configured to operate in 8-bit or 16-bit modes

This is a kit and requires soldering.

The kit contains

Port Expander PCB

MCP23017 IC

IC Socket

2 x 14 way header pins

5 way right angle socket

5 way right angle header pins

Documents

MCP23017 Port Expander Board Schematic

http://www.hobbytronics.co.uk/datasheets/rpi_mcp23017_port_expander.pdf

Raspberry Pi Raspbian Distro Installation and GPIO Port

http://www.hobbytronics.co.uk/tutorials-code/raspberry-pi-tutorials/raspberry-pi-raspbian-distro



4-Way Bi-directional Logic Level Converter

http://www.hobbytronics.co.uk/logic-level-4

.END


MCP23017 testing notes
2013年1月2日 下午3:38公開累計瀏覽次數 30
 
Now I have started modifying the MCP23008 functions to do MCP23017.  There are altogether 22 internal registers, double of that of MCP23008.  I have not understood how the banks are working.  So I just blindly make the changes.  The 22 regsters has the following values.

# * MCP23017 Register addresses *
MCP23017_1_REGISTER_BASE_ADDRESS = 0x22
MCP23017_2_REGISTER_BASE_ADDRESS = 0x23

IO_DIRECTION_REGISTER_A_BANK_0 = IODIRA_B0 = 0x00
IO_DIRECTION_REGISTER_B_BANK_0 = IODIRB_B0 = 0x01

INPUT_POLARITY_REGISTER_A_BANK_0 = IPOLA_B0 = 0x02
INPUT_POLARITY_REGISTER_B_BANK_0 = IPOLB_B0 = 0x03

INTERRUPT_ON_CHANGE_REGISTER_A_BANK_0 = GPINTENA_B0 = 0x04
INTERRUPT_ON_CHANGE_REGISTER_B_BANK_0 = GPINTENB_B0 = 0x05

DEFAULT_COMPARE_VALUE_REGISTER_A_BANK_0 = DEFVALA_B0 = 0x06
DEFAULT_COMPARE_VALUE_REGISTER_B_BANK_0 = DEFVALB_B0 = 0x07

INTERRUPT_CONTROL_REGISTER_A_BANK_0 = INTCONA_B0 = 0x08
INTERRUPT_CONTROL_REGISTER_B_BANK_0 = INTCONB_B0 = 0x09

IO_CONTROL_REGISTER_A_BANK_0 = IOCONA_B0 = 0x0a
IO_CONTROL_REGISTER_B_BANK_0 = IOCONB_B0 = 0x0b

PULL_UP_RESISTOR_CONFIG_REGISTER_A_BANK_0 = GPPUA_B0 = 0x0c
PULL_UP_RESISTOR_CONFIG_REGISTER_B_BANK_0 = GPPUB_B0 = 0x0d

INTERRUPT_FLAG_REGISTER_A_BANK_0 = INTFA_B0 = 0x0e
INTERRUPT_FLAG_REGISTER_B_BANK_0 = INTFB_B0 = 0x0f

INTERRUPT_CAPTURE_REGISTER_A_BANK_0 = INTCAPA_B0 = 0x10
INTERRUPT_CAPTURE_REGISTER_B_BANK_0 = INTCAPB_B0 = 0x11

GPIO_REGISTER_A_BANK_0 = GPIOA_B0 = 0x12
GPIO_REGISTER_B_BANK_0 = GPIOB_B0 = 0x13
.END
.END













MCP23017 testing notes



Now that the 2N7000 based 3V3 to 5V0 logical level shifter has been tested OK, I am moving on to the MCP23017 board.  Last time when I played with this MCP23017, I have little confidence, so I only tested 1 bit, and have not using it to interface anything.  This time I will do a more rigourous testing.

.END


MCP23017 test preparation notes

2012年12月31日 下午2:34公開累計瀏覽次數 00
 
 

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
2012年12月30日 下午10:34公開累計瀏覽次數 120
 


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
2012年12月30日 下午5:31公開累計瀏覽次數 30
 


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
Penta level shifter assembly notes
2012年12月30日 下午3:29公開累計瀏覽次數 30
 
penta_level_shifter_2012dec3001



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
An [2N7000] FET Buffer Stage for GPIO Access - Clive Tombs
2012年12月29日 下午4:29公開累計瀏覽次數 70
 



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!
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.

The "In Control" series in issues 2, 3 and 4 is a great place to start and learn how to use the GPIO. ...
.END
I2C and 2N7000 FAQ
2012年12月29日 下午4:03公開累計瀏覽次數 230
 



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
LCD_ADDR = 0x28
def StringToBytes(val):
    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)
if __name__ == "__main__":
    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
Using toggle pin to AC test level selector OK
2012年12月28日 下午10:37公開累計瀏覽次數 00
 

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
Raspberry Pi level shifter basic test OK
2012年12月28日 下午5:32公開累計瀏覽次數 60
 




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
Level shifter board preparation notes
2012年12月28日 下午3:57公開累計瀏覽次數 60
 


Now I am preparing a small proto board 60mm x 80mm for the level shifter circuit.

.END
2N7000 based logical level shifter testing OK
2012年12月27日 下午9:59公開累計瀏覽次數 80
 


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
2012年12月27日 下午5:22公開累計瀏覽次數 70
 


Now I am going to test the Philips' bidirectional 3V3/5V0 logic level shifter, using Fairchild 2N7000.

.END