Page 1 of 1

Wireless Controller - 120/240 VAC

Posted: Sun Jan 12, 2014 1:08 pm
by Richard-TX
Here is a weekend project. I tried to make the code as readable and as simple as possible.
Either a MCP23008 or MCP23017 can be used. I had a couple of MCP23008 chips laying around so that is what I used.

The wireless remote fob has 4 buttons and their functions are:

A = On
B = Off
C = On for 10 Minutes then Off
D = On for 20 minutes then Off

Parts list:
315 mhz rcvr - Adafruit http://www.adafruit.com/products/1096
315 fob xmtr - Adafruit http://www.adafruit.com/products/1095
Solid state relay
2 x 10k resistors (optional but recommended)
mcp23008 - Adafruit http://www.adafruit.com/products/593
4x4x2 box
power receptacle
120 VAC plug and cord
Rpi Case - Adafruit

Code: Select all

    #!/usr/bin/python
    import os
    import time
    import sys
    import smbus
    address=0x20
    bus = smbus.SMBus(1)


    #setup chip
    bus.write_byte_data(address,0x00,0xfe)
    TMOUT=0
    GM=0

    while (True):
        # read the inputs, etc.
        GM=int(time.time())
        res=bus.read_byte_data(address,0x09)
        # uncomment next line for debugging 
        #print res
        if res == 128 or res == 129:
           bus.write_byte_data(address,0x09,1)
        if res == 64 or res == 65:
           bus.write_byte_data(address,0x09,0)
        if res == 32 or res == 33:
           bus.write_byte_data(address,0x09,1)
           GM=int(time.time())
           TMOUT=GM+600
        if res == 16 or res == 17:
           bus.write_byte_data(address,0x09,1)
           GM=int(time.time())
           TMOUT=GM+1200

        if TMOUT == GM:
                  bus.write_byte_data(address,0x09,0)
        time.sleep (0.05)


Re: Wireless Controller - 120/240 VAC

Posted: Sun Jan 12, 2014 1:26 pm
by FLYFISH TECHNOLOGIES
Hi,
Richard-TX wrote:I had a couple of MCP23008 chips laying around so that is what I used.
I'm afraid that your design is improper.

Summary:
- you supply this chip with 5V,
- minimum allowed voltage for high level on its serial pins is 4.0V (@ 5V supply),
- actual voltage is max 3.3V (or even less, since schematics states just "3V").

Consequently, this voltage level is out of specification.


Best wishes, Ivan Zilic.

Re: Wireless Controller - 120/240 VAC

Posted: Sun Jan 12, 2014 3:30 pm
by Richard-TX
FLYFISH TECHNOLOGIES wrote:Hi,
Richard-TX wrote:I had a couple of MCP23008 chips laying around so that is what I used.
I'm afraid that your design is improper.

Summary:
- you supply this chip with 5V,
- minimum allowed voltage for high level on its serial pins is 4.0V (@ 5V supply),
- actual voltage is max 3.3V (or even less, since schematics states just "3V").

Consequently, this voltage level is out of specification.
Best wishes, Ivan Zilic.
No it is not out of spec!!!

Check the datasheet The datasheet section 2.2 says 1.8 to 5.5 volts for VDD

Adafruit also says this at http://learn.adafruit.com/mcp230xx-gpio ... -it-all-up

"Since these io expander chips use i2c to communicate, you can power them from 5V while still connecting the i2c data lines to a 3.3V device like the pi. That's because the Pi has two i2c resistors that pull up SDA/SCL to 3.3V. Just make sure not to connect any resistors to SDA/SCL to 5V and you can power the chip from 5V (and have 5V input/output on the MCP chip)."

Now if you want to criticize my rounding of the 3.3 volts spec to 3 volts, then go for it. To me there are only two supplies on the Rpi. +3 and +5. There isn't anything else.
Note that the (optional) 10k pullups are connected to +3 volts.

Re: Wireless Controller - 120/240 VAC

Posted: Sun Jan 12, 2014 4:01 pm
by FLYFISH TECHNOLOGIES
Hi,
Richard-TX wrote:Check the datasheet
MCP23008 is made by Microchip. Therefore, I'm considering their datasheet as the only relevant. It can be found here:
ww1.microchip.com/downloads/en/DeviceDoc/21919e.pdf

On its page 24, take a look at the table row D041. It specifies Input High-Level voltages for pins SCL and SDA (and few others). The allowed range is between 0.8 * Vdd and Vdd. Therefore, for 5V suply voltage, this range is between 4V and 5V.

So, until you give me better explanation, I have to stand by my statement, that your circuit does not work within specifications.


Best wishes, Ivan Zilic.

Re: Wireless Controller - 120/240 VAC

Posted: Mon Jan 13, 2014 9:16 pm
by Richard-TX
It appears that it is outside spec and it works very well..
Having said that, don't complain to me. Complain to Adafruit.
Best of all. it works even at 1.2 Mhz speeds

Re: Wireless Controller - 120/240 VAC

Posted: Mon Jan 13, 2014 10:34 pm
by FLYFISH TECHNOLOGIES
Hi Richard,
Richard-TX wrote:Don't complain to me. Complain to Adafruit.
I'm "complaining" to you because you're spreading here the design, which is improper...
Richard-TX wrote:It works!
I'm glad.
But the important message to be underlined is, that people should not blindly follow this your schematics.


Best wishes, Ivan Zilic.

Re: Wireless Controller - 120/240 VAC

Posted: Sun Jan 19, 2014 4:29 pm
by Richard-TX
FLYFISH TECHNOLOGIES wrote:Hi Richard,
Richard-TX wrote:Don't complain to me. Complain to Adafruit.
I'm "complaining" to you because you're spreading here the design, which is improper...
Richard-TX wrote:It works!
I'm glad.
But the important message to be underlined is, that people should not blindly follow this your schematics.


Best wishes, Ivan Zilic.
Ivan,

Go take it up with Adafruit here: http://forums.adafruit.com/ or with nathan chatrell here: http://nathan.chantrell.net/20120610/ra ... t-voltage/

Also take it up with Richard Pell at EDN http://www.edn.com/design/analog/437129 ... unications. He states that the I2C spec is .7 VDD for HI and .3 VDD for a low. If anything the chip does not meet I2C specs.

My schematics are accurate, they work, the reliability is 100% and it is operating 24x7.

Until you can show that that it does NOT work, or convince Adafruit, Nathan et al to change their documentation, my position remains unchanged.

It does the job for my purposes as is. Don't like it? Tough.

Re: Wireless Controller - 120/240 VAC

Posted: Sun Jan 19, 2014 5:07 pm
by FLYFISH TECHNOLOGIES
Hi Richard,
Richard-TX wrote:My schematics are accurate, they work, the reliability is 100% and it is operating 24x7.
It could be that I haven't explained my statement properly... but... if you carefully take a look at my previous messages, I have never wrote that your circuit doesn't work 24x7, etc.

The point I wrote is that one voltage level is not within specifications.

You can argue that your circuit is working and that several other people propose this circuit or that it work also for them well.
This is all fine with me... but this doesn't change the fact that according to specifications, you should not design the circuit like you (or Adafruit, or Nathan, or anybody else) did.

Our discussion became a bit odd... Don't get this personal, I'm just not a member of Adafruit forum and this is the only forum where I saw this error and I reacted. The relevant specification document for me is a datasheet from the vendor and I pointed to exact problematic item.
I think that it would make sense to continue this discussion only if it is based on the mentioned specification and numbers listed there...


Have a nice day, Ivan Zilic.

Re: Wireless Controller - 120/240 VAC

Posted: Sun Jan 19, 2014 5:22 pm
by Richard-TX
Here is how I see it.

The 5 volt line is almost always a little low.

I usually measure about 4.85 - 4.9 volts.

4.85 *.7 (i2c spec) = 3.36 volts. 3.0 is within ~10% of 3.36.

It is within 10% of I2C spec.


Image

Re: Wireless Controller - 120/240 VAC

Posted: Sun Jan 19, 2014 6:44 pm
by FLYFISH TECHNOLOGIES
Hi,

Ok, and this is how I see it:
- we're discussing about specification, so measurements are not applicable in this context,
- instead of some generic values and levels, the values below are listed for MCP23008 chip:

Allowed I2C high level is between 0.8Vdd and Vdd. For 5V supply, this range is between 4.0V and 5.0V.


Best wishes, Ivan Zilic.

Re: Wireless Controller - 120/240 VAC

Posted: Sun Jan 19, 2014 8:27 pm
by Douglas6
I've been watching this thread in the hopes of adding to my knowledge of electronics. Instead I see the same errors of rhetoric and semantics that have plagued arguments since the time of Aristotle. Richard keeps mentioning what works; Ivan reiterates what is specified (sometimes using 'allowed' which is perhaps unfortunate) . Apples and oranges. Can we agree on the following?
1. Electronic designs should strive to follow specifications.
2. Engineering and manufacture sometimes allow for tolerances outside of the specifications.

And be done with it? And to be clear, context and common sense play a role. I'm not talking about building bridges or national defense systems with the Raspberry Pi and an MCP23008, here.