User avatar
rpdom
Posts: 12871
Joined: Sun May 06, 2012 5:17 am
Location: Ankh-Morpork

Re: Relay Module KY-019 5V

Thu Aug 23, 2018 5:41 am

tlfong01 wrote:
Thu Aug 23, 2018 5:04 am
5. OP uses a sensor with I2C address 0x28. I think the sensor is:

Dallas DS18B20 Programmable Resolution 1-Wire Digital Thermometer
https://cdn.sparkfun.com/datasheets/Sen ... S18B20.pdf

This sensor has a one wire system which might not be compatible with smbus. But I know nothing about this 1 wire system, ...
The DS18B20 is a 1-Wire bus device. Completely different to both smbus and i2c.

There is a driver for the w1 (1-wire) in Raspbian. It can be enabled from the configuration utility. After that all you need to do is connect one or more DS18B20 sensors to ground, +3.3V and GPIO4 (Pin 7), and put one 4.7K resistor between +3.3V and GPIO4.

After a reboot, a "file" should magically appear as /sys/bus/w1/devices/<sensorid>/w1_slave (where "<sensorid>" is the sensor's unique serial number starting with 28-

Reading that file will trigger a reading and return the temperature.

Code: Select all

[email protected]:~$ cat /sys/bus/w1/devices/28-0000057b716b/w1_slave 
47 01 4b 46 7f ff 09 10 93 : crc=93 YES
47 01 4b 46 7f ff 09 10 93 t=20437
That sensor is showing 20.437°C

User avatar
tlfong01
Posts: 664
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Thu Aug 23, 2018 7:55 am

rpdom wrote:
Thu Aug 23, 2018 5:41 am
tlfong01 wrote:
Thu Aug 23, 2018 5:04 am
Dallas DS18B20 Programmable Resolution 1-Wire Digital Thermometer
https://cdn.sparkfun.com/datasheets/Sen ... S18B20.pdf
The DS18B20 is a 1-Wire bus device. Completely different to both smbus and i2c.
There is a driver for the w1 (1-wire) in Raspbian. It can be enabled from the configuration utility. After that ...
After a reboot, a "file" should magically appear as ... RReading that file will trigger a Reading and return the temperature.

Dallas DS18B20 1-Wire Digital Thermometer

Wow, that is indeed newbie friendly. Not too long ago I found the DT overlay thing scary. Now I am a middle level linux newbie and know how to edit the config utility to do DT overlay (though I don't know, and don't care what is the meaning of dtoverlay), using the stupid editor nano.

So reading temperature is as easy as reading a file. I should have no problem using python to play with the digital thermometer. Of course I am too lazy to write a python program. Just now I googled and found a good tutorial, with a python example.

Using DS18B20 1-wire Temp Sensors with the Raspberry Pi - Jumpnow Technologies 24 Apr 2017
http://www.jumpnowtek.com/rpi/Using-DS1 ... ry-Pi.html

A simple python script that will read the temp and convert to Fahrenheit.

Code: Select all

#!/usr/bin/env python3

import glob

def celsius_to_fahrenheit(c):
    return (c * 1.8) + 32.0


def find_devices():
    return glob.glob('/sys/bus/w1/devices/28-*')


def read_temp(path):
    lines = []

    with open(path + '/w1_slave') as f:
        lines = f.readlines()

    if len(lines) != 2:
        return False, 0

    if lines[0].find('YES') == -1:
        return False, 0

    d = lines[1].strip().split('=')

    if len(d) != 2:
        return False, 0

    return True, int(d[1])


if __name__ == '__main__':

    devices = find_devices()

    for device in devices:
        valid, raw = read_temp(device)

        if valid:
            c = raw / 1000.0
            f = celsius_to_fahrenheit(c)
            print('%0.2f F' % (f))
I am an electronics, smart phone, and smart home hobbyist.

User avatar
tlfong01
Posts: 664
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Thu Aug 23, 2018 1:39 pm

tlfong01 wrote:
Thu Aug 23, 2018 7:55 am
rpdom wrote:
Thu Aug 23, 2018 5:41 am
It can be enabled from the configuration utility.
Not too long ago I found the DT overlay thing scary.

How to enable (DS18D20) 1-Wire Driver

Ah, I did not read the reply carefully. Actually the driver can be enabled by the Rpi configuration utility using the terminal command:

sudo raspi-config

not by using nano to edit a config.txt file in /boot.

The simplest way is using the Rpi desktop gui (LXPanel)

Preferences > Rpi Configuration > Interfaces > 1-Wire Enable

I also found the WaveShare's 2016 tutorial very good (except a bit outdated).

1-Wire DS18B20 Sensor Tutorial - WaveShare
https://www.waveshare.com/wiki/Raspberr ... B20_Sensor

Using DS18B20 1-wire Temp Sensors with the Raspberry Pi - Jumpnow Technologies
http://www.jumpnowtek.com/rpi/Using-DS1 ... ry-Pi.html
Last edited by tlfong01 on Fri Aug 24, 2018 12:24 am, edited 1 time in total.
I am an electronics, smart phone, and smart home hobbyist.

User avatar
tlfong01
Posts: 664
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Thu Aug 23, 2018 2:44 pm

tlfong01 wrote:
Wed Aug 22, 2018 1:57 pm
tlfong01 wrote:
Wed Aug 22, 2018 12:23 pm
So I am thinking of adding a I2C extender to make sure it is not I2C long wires that causes the trouble.
I am also wiring a couple of GPIO pins for testing input, output, and interrupt.
I will be using
GPIO pins 17, 18, 27, 22 for I2C demux, and
GPIO pins 26, 12, 16, 20 for interrupts.
Now I have wired the 4 I2C demux wires, with their own ground, and 4 interrupt wires, also with their own ground wire. (The I2C wires SCL, SDA, and dedicated ground wire, are all about 30cm to the signal routing board.

Testing I2C Extender

Now I have made a 60cm long I2C cable, consisting of 4 wires of two twisted pairs:

  • 1. SDA and Gnd twisted

  • 2. SCL and Gnd twisted

Both with a pitch of about 2 turns per inch.

I also added a 12V in, 5.5V out, MC2307 based PSU of 3A continuous, 4A peak. This PSU is dedicated to Rpi.
Attachments
wnB8k3K[1].jpg
wnB8k3K[1].jpg (130.04 KiB) Viewed 1485 times
I am an electronics, smart phone, and smart home hobbyist.

User avatar
tlfong01
Posts: 664
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Fri Aug 24, 2018 12:35 am

tlfong01 wrote:
Sun Aug 19, 2018 12:43 pm
Brandon92 wrote:
Sun Aug 19, 2018 9:37 am
1. Okay, that is a large amount of devices.
2. So, you want to different type of humidity and temperature sensor?
2. Well, there are perhaps at least 10 sensors I need to play with, including the following: atmosphere pressure, air quality related (smoke, CO2, pm2.5 etc etc), ambient light sensor, weight sensor (to check if my cat is over weight) etc

Dallas DS18B20 Temperature Sensor

I found this Dallas temperature different from others,

/ to continue, ...
I am an electronics, smart phone, and smart home hobbyist.

User avatar
tlfong01
Posts: 664
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Fri Aug 24, 2018 9:22 am

tlfong01 wrote:
Thu Aug 23, 2018 2:44 pm
tlfong01 wrote:
Wed Aug 22, 2018 1:57 pm
tlfong01 wrote:
Wed Aug 22, 2018 12:23 pm
So I am thinking of adding a I2C extender to make sure it is not I2C long wires that causes the trouble.
Now I have wired the 4 I2C demux wires, with their own ground, and 4 interrupt wires, also with their own ground wire. (The I2C wires SCL, SDA, and dedicated ground wire, are all about 30cm to the signal routing board.
Testing I2C Extender
Now I have made a 60cm long I2C cable, consisting of 4 wires of two twisted pairs:

  • 1. SDA and Gnd twisted
  • 2. SCL and Gnd twisted
Both with a pitch of about 2 turns per inch.

P82B715 I2C Bus Extender Testing Notes

Appendix

P82B715 Datasheet - NXP 2009
https://www.nxp.com/docs/en/data-sheet/P82B715.pdf
Attachments
bGZDT8q[1].jpg
bGZDT8q[1].jpg (42.5 KiB) Viewed 1431 times
I am an electronics, smart phone, and smart home hobbyist.

User avatar
tlfong01
Posts: 664
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Tue Sep 04, 2018 7:08 am

tlfong01 wrote:
Fri Aug 24, 2018 9:22 am
tlfong01 wrote:
Thu Aug 23, 2018 2:44 pm
Testing I2C Extender
Now I have made a 60cm long I2C cable,
  • 1. SDA and Gnd twisted
  • 2. SCL and Gnd twisted
Both with a pitch of about 2 turns per inch.

P82B715 I2C Bus Extender Testing Notes

Now I am preparing a second set of Rpi + demux quad I2C level shifter for swap testing of the P82B715 bus extender.
Attachments
i2c_ext_2018sep0401.jpg
i2c_ext_2018sep0401.jpg (139.48 KiB) Viewed 1328 times
I am an electronics, smart phone, and smart home hobbyist.

User avatar
tlfong01
Posts: 664
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Tue Sep 04, 2018 8:00 am

tlfong01 wrote:
Tue Sep 04, 2018 7:08 am
Now I am preparing a second set of Rpi + demux quad I2C level shifter for swap testing of the P82B715 bus extender.

P82B715 I2C Bus Extender Testing Notes

Quad I2C Level Shifter x 4 is now manually selected all.
Attachments
i2c_ext_2018sep0402.jpg
i2c_ext_2018sep0402.jpg (119.68 KiB) Viewed 1320 times
I am an electronics, smart phone, and smart home hobbyist.

User avatar
tlfong01
Posts: 664
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Tue Sep 04, 2018 8:55 am

tlfong01 wrote:
Tue Sep 04, 2018 8:00 am
Quad I2C Level Shifter x 4 is now manually selected all.

P82B715 I2C Bus Extender Testing Notes

Now I am connecting the following to the four demux 5V I2C channels:

  • IOX MCP23017 x 4

  • RTC DS3231

  • ADCDAC PCF8591

This is where I got stuck last time and stalled my DHT22 Humidity and Temperature Sensor project.

I found MCP23017 had intermittent problems, such as setting High or Low values correctly but at the wrong pins. After a couple of hours troubleshooting, I finally confirmed that the I2C wiring, even no longer than one or two meters, is the problem.

I know how to calculate the I2C pull up resistor values when adding more devices, but I don't know how to check the capacitance of the I2C wires.

That is why I decided to check out the I2C bus extender thing to see if it can help.
Attachments
i2c_ext_2018sep0403.jpg
i2c_ext_2018sep0403.jpg (80.24 KiB) Viewed 1305 times
I am an electronics, smart phone, and smart home hobbyist.

User avatar
tlfong01
Posts: 664
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Tue Sep 04, 2018 2:18 pm

tlfong01 wrote:
Tue Sep 04, 2018 8:00 am
Quad I2C Level Shifter x 4 is now manually selected all.
P82B715 I2C Bus Extender Testing Notes

First test of P82B715 is good. I found 1 of the 4 level shifter (CJMCU 0102 = TXS0102) is not working, and 1 of the 4 MCP23017, the original one, is unstable. I need to swap both to prove that they are indeed bad guys.
Attachments
p82b715_2018sep0401.jpg
p82b715_2018sep0401.jpg (167.38 KiB) Viewed 1294 times
I am an electronics, smart phone, and smart home hobbyist.

User avatar
tlfong01
Posts: 664
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Wed Sep 05, 2018 3:22 am

tlfong01 wrote:
Tue Sep 04, 2018 2:18 pm
First test of P82B715 is good. I found 1 of the 4 level shifter (CJMCU 0102 = TXS0102) is not working, and 1 of the 4 MCP23017, the original one, is unstable. I need to swap both to prove that they are indeed bad guys.

P82B715 I2C Bus Extender Testing Notes

Faulty TXS0102 replaced. All 4 of them OK now.
Attachments
i2c_ext_test_2018sep0501.jpg
i2c_ext_test_2018sep0501.jpg (126.99 KiB) Viewed 1264 times
I am an electronics, smart phone, and smart home hobbyist.

User avatar
tlfong01
Posts: 664
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Wed Sep 05, 2018 2:22 pm

tlfong01 wrote:
Wed Sep 05, 2018 3:22 am
Faulty TXS0102 replaced. All 4 of them OK now.

P82B715 I2C Bus Extender Testing Notes

I have successfully connected 6 MCP23017 to the I2C bus.

Now I am a rich guy with 6 x 16 = 96 gpio pins! :)
Attachments
mcp23017x6_2018sep0501.jpg
mcp23017x6_2018sep0501.jpg (131.74 KiB) Viewed 1230 times
I am an electronics, smart phone, and smart home hobbyist.

User avatar
tlfong01
Posts: 664
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Wed Sep 05, 2018 2:47 pm

tlfong01 wrote:
Wed Sep 05, 2018 2:22 pm
I have successfully connected 6 MCP23017 to the I2C bus.
Now I am a rich guy with 6 x 16 = 96 gpio pins! :)

P82B715 I2C Bus Extender Testing Notes
Attachments
mcp23017x6_2018sep0505.jpg
mcp23017x6_2018sep0505.jpg (78.92 KiB) Viewed 1222 times
I am an electronics, smart phone, and smart home hobbyist.

User avatar
tlfong01
Posts: 664
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Thu Sep 06, 2018 1:17 pm

tlfong01 wrote:
Wed Sep 05, 2018 2:47 pm
Now I am a rich guy with 6 x 16 = 96 gpio pins! :)
[/quote]


P82B715 I2C Bus Extender Testing Notes

Now I have assembled the following and tested OK.

1. Rpi3B+ I2C (SCL, DSA, Gnd) connects to signal routing board (SRB).

2. SRB I2C connects to input of I2C Bus Extender (I2cExt) P82B715.

3. I2cExt P82B715 output connects/fans out to 3 inputs of TSX0102.

4. Each of three TSX0102 connects to one P82B715.

5. The three outputs of P82B715 becomes double extended 5V I2C #1, #2, #3.

6. 5V I2C #1 connects to 4 MCP23017, #2, #3 each connects to 1 MCP23017.
Attachments
i2c_ext_2018sep0602.jpg
i2c_ext_2018sep0602.jpg (102.63 KiB) Viewed 1199 times
I am an electronics, smart phone, and smart home hobbyist.

User avatar
tlfong01
Posts: 664
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Thu Sep 06, 2018 1:34 pm

tlfong01 wrote:
Thu Sep 06, 2018 1:17 pm
5. The three outputs of P82B715 becomes double extended 5V I2C #1, #2, #3.
6. 5V I2C #1 connects to 4 MCP23017, #2, #3 each connects to 1 MCP23017.

P82B715 I2C Bus Extender Testing Notes

Next is to connect more I2C devices to the double extended bus channels and see how many they can entertain.
Attachments
i2c_ext_2018sep0603.jpg
i2c_ext_2018sep0603.jpg (67.95 KiB) Viewed 1194 times
I am an electronics, smart phone, and smart home hobbyist.

User avatar
tlfong01
Posts: 664
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Thu Sep 06, 2018 2:28 pm

tlfong01 wrote:
Thu Sep 06, 2018 1:34 pm
tlfong01 wrote:
Thu Sep 06, 2018 1:17 pm
5. The three outputs of P82B715 becomes double extended 5V I2C #1, #2, #3.
6. 5V I2C #1 connects to 4 MCP23017, #2, #3 each connects to 1 MCP23017.
Next is to connect more I2C devices to the double extended bus channels and see how many they can entertain.

P82B715 I2C Bus Extender Testing Notes

Now I have connected three more I2C devices to I2C Bus Channel 3:

  • MCP23017 Iox # 7
  • PCF8591 ADC/DAC
  • DS3231 RTC + EEPROM
Now the greedy hobbist has 7 MCP23017s or
16 x 7 = 112 GPIO pins!


Greed is Good - Gordon Gekko
https://en.wikipedia.org/wiki/Gordon_Gekko
Attachments
i2c_ext_2018sep0604.jpg
i2c_ext_2018sep0604.jpg (145.07 KiB) Viewed 1181 times
I am an electronics, smart phone, and smart home hobbyist.

User avatar
tlfong01
Posts: 664
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Fri Sep 07, 2018 9:18 am

tlfong01 wrote:
Thu Sep 06, 2018 2:28 pm
Now the greedy hobbist has 7 MCP23017s or
16 x 7 = 112 GPIO pins!

P82B715 I2C Bus Extender Testing Notes

Now the greedy guy has connected 8 MCP23017s to get 16 x 8 = 128 GPIO pins!
Attachments
mcp23017x8_2018sep0703.jpg
mcp23017x8_2018sep0703.jpg (132.45 KiB) Viewed 1122 times
I am an electronics, smart phone, and smart home hobbyist.

User avatar
tlfong01
Posts: 664
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Wed Sep 12, 2018 11:38 am

tlfong01 wrote:
Sun Aug 05, 2018 2:59 pm
I am coming back to the Temperature and Humidity Sensor DHT22.
My plan is to use 4 MCP23017 output signals to control 4 DHT22s.

MCP23017 Controlling DHT22 Humidity and Temperature Sensor

Now I am coming back to the DHT22 result reading problem. Last time the project was stalled because I found MCP23017 had intermittently problems.

I started the DHT project in early August, and it took almost 4 weeks to complete the first part of MCP23017 sending a start signal to DHT22. The second part is to let MCP23017 to read the results sent by DHT22.

I am thinking of using MCP23017's detect interrupt feature to read the 80 data bits.

I have not tried Rpi's interrupt thing, not to mention MCP23017 interrupt. So the first step is to try the basic things of Rpi interrupt.

I googled to find the following tutorial on Rpi interrupt. The 5 year old tutorial is a bit out of date, but I think the basic things are still the same.

How to use interrupts with Python on the Raspberry Pi and RPi.GPIO - raspi.tv 2013mar17
https://raspi.tv/2013/how-to-use-interr ... d-rpi-gpio
https://raspi.tv/2013/how-to-use-interr ... pio-part-2
https://raspi.tv/2013/how-to-use-interr ... pio-part-3

/ to continue, ...
I am an electronics, smart phone, and smart home hobbyist.

Brandon92
Posts: 497
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Relay Module KY-019 5V

Wed Sep 12, 2018 12:48 pm

If I was you, I would start if it theoretical possible what you want to do. Before you start programming.
By this I mean, make a timing diagram. And check if everything is fast enough to detect and save the incoming data from the sensor.

User avatar
tlfong01
Posts: 664
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Thu Sep 13, 2018 6:55 am

Brandon92 wrote:
Wed Sep 12, 2018 12:48 pm
If I was you, I would start if it theoretical possible what you want to do. Before you start programming.
By this I mean, make a timing diagram. And check if everything is fast enough to detect and save the incoming data from the sensor.

DHT22 Results Timing Diagram

Well, the results timing is already specificied in the datasheet, as summarized below.

  • 1. DHT response signal 85uS Low, 85uS High.
  • 2. 40 data pulses, each consists of 50uS Low and either 30 uS High for Zero data bit, or 75uS for One data bits.
So I am thinking of reading the results as below:

  • 1. Read response pulse.
  • 2. Read 40 data bit pulses.
  • 3. Convert 40 data bit pulses to 5 data bytes (2 bytes humidity, 2 bytes temperature, 1 byte parity.
  • 4. Print out data.
Attachments
dht22_result_2018sep1302.jpg
dht22_result_2018sep1302.jpg (172.99 KiB) Viewed 1023 times
I am an electronics, smart phone, and smart home hobbyist.

Brandon92
Posts: 497
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Relay Module KY-019 5V

Thu Sep 13, 2018 9:38 pm

This is not exactly what I meant.
This is more my point, the sensor change his output from a 0 to a 1:
  1. How long will it take for the MCP to change the inta pin from the time that his input is changed
  2. How long does it take before the Rpi know that there is a interupt and start reading the data
  3. How long does it take to read the "change" from the sensor
  4. And process the data
And is this time smaller that the "TH0" time, and the worst case (so the smallest number)?

User avatar
tlfong01
Posts: 664
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Fri Sep 14, 2018 7:51 am

Brandon92 wrote:
Thu Sep 13, 2018 9:38 pm
This is not exactly what I meant.
This is more my point, the sensor change his output from a 0 to a 1:
  1. How long will it take for the MCP to change the inta pin from the time that his input is changed
  2. How long does it take before the Rpi know that there is a interupt and start reading the data
  3. How long does it take to read the "change" from the sensor
  4. And process the data
And is this time smaller that the "TH0" time, and the worst case (so the smallest number)?

Hopeless for Rpi to read DHT22 results using MCP23017

Ah, I see what you meant. Let me summarize what I can I do, but still there is a problem.

1. We need to read DHT22's measurement results, which is 40 pulses, each of which is either 55uS Low + 30uS High representing a Zero data bit, or 55uS Low + 75uS High representing a One bit. In the worst case of all 40 data bits are Zero, then we have to handle 40 pulses each of which is 55 + 30 = 85uS long.

2. As you have concluded in an old post (Appendix below), it takes at least 200uS to write to a MCP23017 register, unless using a block write. I did use the block write trick to overcome this 200uS write problem, when sending the Start Signal.

3. But now the same problem comes back when handling 40 pulses of 85uS long. If I connect the Interrupt pin of MCP23017 to a Rpi GPIO pin assigned to detect interrupt, the least thing the call back function needs to do after each interrupt detected is to clear the interrupt status by writing to a MCP23017 register (IntCap or Gpio). But this write is already 200uS, out of the limit of 85uS pulse. This time I can no longer shorten this 200uS thing by using block write.

3. So, this time I am indeed hopeless. I need to consider either using SPI, or software I2C at a higher speed. But both solutions do not meet my requirement of using long wires for transmission. :(

Appendix Old post for reference
RE: RELAY MODULE KY-019 5V Post by Brandon92 » 2018-Aug-08 Wed 5:45 pm
tlfong01 wrote: ↑
2018-Aug-08 Wed 3:44 pm
Now let us have some brain storming.
(1) If hts couldn't wait longer than 200uS, then I seem to be hopeless,...
The easiest way to solve this issue is to speed up the clock speed of you I2C bus. Or use a other IO expansion that is only 8 bit to speed up some thing.
As I show in my previous figure 7. It's possible to send constant data to the MCP* chip. This will save you some time to change the output faster.
But after you send the pulse, you have 75*2uS the time to change the ouput of the MCP* to become a input.
And after that, you need to read all the data from the DHT22 and is you data bus than fast enough?
I am an electronics, smart phone, and smart home hobbyist.

Brandon92
Posts: 497
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Relay Module KY-019 5V

Fri Sep 14, 2018 3:27 pm

Yup, you are correct. That's why I advised you to use a sensor with a I2C data bus interface. Or does this sensor something that you really need?

User avatar
tlfong01
Posts: 664
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Sat Sep 15, 2018 5:23 am

Brandon92 wrote:
Fri Sep 14, 2018 3:27 pm
Yup, you are correct. That's why I advised you to use a sensor with a I2C data bus interface. Or
does this sensor something that you really need?

DHT22 directly interrupting Rpi, bypassing stupid and slow MCP23017

Well, I actually have bought three other types of sensors to mess around (the most recent one is DHT12 which is similar to DHT22, but also I2C compatible).

But I really need this time wasting, trouble making, DHT22 for two reasons:

  • 1. I need to have 64 sensors for my small, 64 bed room castle (well, in the air) automation project.
  • 2. I need to show off that I can interrupt Rpi with 64 devices. :lol:
Now I am thinking of overcoming the slow and stupid MCP23017 interrupt thing by forgetting it altogether. Instead of using MCP23017 INTA, INTB, I will let DHT22 open drain output (already at the same time, connected to MCPO23017 GPIO pin) to itself directly interrupting RPi.

Appendix - DHT12

DHT12 Datasheet
http://www.robototehnika.ru/file/DHT12.pdf

Castle in the air - Don McLean - 2,295,059 views
https://www.youtube.com/watch?v=TTqi7iEZEWA
Attachments
dht22_interrupt_2018sep1502.jpg
dht22_interrupt_2018sep1502.jpg (170 KiB) Viewed 928 times
I am an electronics, smart phone, and smart home hobbyist.

User avatar
tlfong01
Posts: 664
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Sat Sep 15, 2018 2:37 pm

tlfong01 wrote:
Sat Sep 15, 2018 5:23 am
DHT22 directly interrupting Rpi, bypassing stupid and slow MCP23017
Now I am thinking of overcoming the slow and stupid MCP23017 interrupt thing by forgetting it altogether. Instead of using MCP23017 INTA, INTB, I will let DHT22 open drain output (already at the same time, connected to MCPO23017 GPIO pin) to itself directly interrupting RPi.

Quad Rpi Interrupt Signal Generating, Routing, Evaluation Board

My learning experience of interrupt

I learnt about the idea of interrupt ages ago, when I read the Operating Systems text book by Deitel. But I did not have any practical experience in studying or troubleshooting any realtime systems involved with interrupts. I only read that real time operating systems are very complicated.

Only some 10 years ago (actually, exactly 10 years ago today, 2008 Sep 15, a day to remember for Lehman Brothers and their fans), I suddenly realized that making money is really a very bad hobby.

I decided to quit making money (and losing money) and looked for a new, mentally and physically healthy hobby.

I still remember vividly that I visited the local toy street and did window shopping, and got interested in DIY things such as servos etc. I have never played servos before and found them interesting. I thought perhaps I could make electronics and making robots my new hobby.

I started reading local electronics magazines and was very surprised that, because I have not touched electronics for many years, I did not know what was going on. I never heard of SMD, and PCB tools such as Eagle etc. Everything seemed new to me.

Then I heard about Arduino. I could not find Arduino in local shops, and needed to buy from the shops in the States, NK Electronics and SparkFun.

I was getting serious and actually bought a new edition of Deitel's Operating System book to update my computer knowledge. I read again the ideas of distributed systems, concurrent programming, and interrupts. I was planning to use the Arduino to practise these things.

It was also the first time I heard about SPI and I2C, though I knew UART/RS232 very well. I found I2C a bit scary, because I never knew that a pin can at the same time be input and output. I read the manufacturers' demo code but could not understand it. So I only played with SPI which I thought was not so weird, because there is one line for input, one line for output, not messing up input and output signals in one single line.

It was about 5 years after playing with Arduino that I decided to do the more difficult thing called interrupt. I tried the basic call back thing and found OK. But when I tried more advanced things then I found both Arduino software, hardware, and also documentation were poor. I got stuck often and finally gave up.

Then I heard about something called crowded projects, and the Raspberry Pi. It was almost two years after hearing Rpi that I actually bought one, again from the States, because local shops RS and Farnell were not selling them.

So I started playing with Rpi Linux, found it text terminal commands very unfriendly and actually gave up and switched to Windows CE, Visual Studio C++, C# etc.

It was only when Rpi 3 came along and I found Rpi GUI and Rpi IDLE python fast and friendly, then I started more seriously playing with SPI, and later I2C things.

And that is the end of looking back my Arduino and Raspberry Pi playing history, before I moved on really playing with interrupts.

The Rpi interrupt signal routing and evaluation board

I just finished assembling a quad interrupt signal routing board and will test it tomorrow.

The spec is summarized below.

1. Four cheap, bouncy push buttons with 10K pull up to 5V.

2. Push button outputs are connected to 4 input/output pins at the top edge connector of the board.

3. Input can either from push button, or from another source, such as MCP23017 GPIO pins, DH3231 RTC (32kHz, 8/4/1kHz square wave, real time interupts), DHT22 humidity and temperature measurements, etc.

5. The four 5V interrupt output signals go to the input of CD4050 (or LVC245) which level shifts signal down to 3V3 for four Rpi GPIO pins assigned as interrupt pins.

/ to continue, ...
Attachments
interrupt_signal_router_2018sep1503.jpg
interrupt_signal_router_2018sep1503.jpg (174.24 KiB) Viewed 903 times
I am an electronics, smart phone, and smart home hobbyist.

Return to “Automation, sensing and robotics”