Code Monkey home page Code Monkey logo

Comments (21)

kizniche avatar kizniche commented on July 24, 2024

I agree. However, a quick search didn't turn up anything related to the AM2302 (DHT22) and I2C. Do you know of any documentation covering this? I have a few DHT22s, so it wouldn't be that difficult to get a multiplexer and begin testing in the near future.

from mycodo.

hephaestoskin avatar hephaestoskin commented on July 24, 2024

Oh dang, I meant the AM2315, sorry for the confusion. Drivers are part of tentacle_pi (github).

Sensor:
https://www.adafruit.com/products/1293

Driver:
https://github.com/lexruee/tentacle_pi

Multiplexer:
https://learn.adafruit.com/adafruit-tca9548a-1-to-8-i2c-multiplexer-breakout/overview

from mycodo.

kizniche avatar kizniche commented on July 24, 2024

Nice! A little pricey, but it has a few percent better accuracy in the extreme ends of the humidity range than the DHT22. I'll see about picking one up and a multiplexer and giving it a shot.

from mycodo.

hephaestoskin avatar hephaestoskin commented on July 24, 2024

Thanks :)

from mycodo.

kizniche avatar kizniche commented on July 24, 2024

Got the sensor today. I should have the multiplexer soon.

from mycodo.

hephaestoskin avatar hephaestoskin commented on July 24, 2024

That's great, thanks!

Benjamin Morrison

On Nov 11, 2015, at 7:09 PM, Kyle Gabriel [email protected] wrote:

Got the sensor today. I should have the multiplexer soon.

β€”
Reply to this email directly or view it on GitHub.

from mycodo.

kizniche avatar kizniche commented on July 24, 2024

Got the multiplexer today. Maybe Saturday I'll have some time to hook them up.

from mycodo.

kizniche avatar kizniche commented on July 24, 2024

@hephaestoskin Do you have experience using this I2C multiplexer, either with i2c-tools or Python?

from mycodo.

kizniche avatar kizniche commented on July 24, 2024

This looks like it includes a class for the TCA9548A: https://pypi.python.org/pypi/pymlab/

from mycodo.

hephaestoskin avatar hephaestoskin commented on July 24, 2024

No I'm afraid I don not have experience in this. I'm still just learning.

from mycodo.

kizniche avatar kizniche commented on July 24, 2024

Well, the easy part of adding sensor support is done (c27e903), now I need to figure out how to use the multiplexer. I spent a good while tonight on it and I think I got to the point where I'm selecting the channel of the multiplexer, but I haven't been able to get a reading through the multiplexer.

from mycodo.

kizniche avatar kizniche commented on July 24, 2024

I'm pretty sure I've figured out how to change the channel of the multiplexer with the following code:

#!/usr/bin/python

# Change channel of TCA9548A
# Example: sudo ./multiplexer_channel.py 0

import smbus
import time
import sys

I2C_address = 0x70
I2C_bus_number = 1
I2C_ch_0 = 0b00000001
I2C_ch_1 = 0b00000010
I2C_ch_2 = 0b00000100
I2C_ch_3 = 0b00001000
I2C_ch_4 = 0b00010000
I2C_ch_5 = 0b00100000
I2C_ch_6 = 0b01000000
I2C_ch_7 = 0b10000000

def I2C_setup(i2c_channel_setup):
    bus = smbus.SMBus(I2C_bus_number)
    bus.write_byte(I2C_address,i2c_channel_setup)
    time.sleep(0.1)
    print "TCA9548A I2C channel status:", bin(bus.read_byte(I2C_address))

I2C_setup(int(sys.argv[1]))

But I still haven't been able to read the AM2315 while connected to the multiplexer. The sensor works when directly connected to the Pi I2C (already integrated into Mycodo with the commit in my last comment), so it doesn't seem to be a hardware issue. I do have an I2C barometric pressure sensor I could try to use with the multiplexer.

from mycodo.

hephaestoskin avatar hephaestoskin commented on July 24, 2024

Hm, perhaps we should add a thread to the Adafruit forums so their staff can respond? It is their multiplexer. I wish I knew enough to help myself.

Benjamin Morrison

On Nov 14, 2015, at 10:41 AM, Kyle Gabriel [email protected] wrote:

I'm pretty sure I've figured out changing the channel of the multiplexer with the following code:

#!/usr/bin/python

Change channel of TCA9548A

Example: sudo ./multiplexer_channel.py 0

import smbus
import time
import sys

I2C_address = 0x70
I2C_bus_number = 1
I2C_ch_0 = 0b00000001
I2C_ch_1 = 0b00000010
I2C_ch_2 = 0b00000100
I2C_ch_3 = 0b00001000
I2C_ch_4 = 0b00010000
I2C_ch_5 = 0b00100000
I2C_ch_6 = 0b01000000
I2C_ch_7 = 0b10000000

def I2C_setup(i2c_channel_setup):
bus = smbus.SMBus(I2C_bus_number)
bus.write_byte(I2C_address,i2c_channel_setup)
time.sleep(0.1)
print "TCA9548A I2C channel status:", bin(bus.read_byte(I2C_address))

I2C_setup(int(sys.argv[1]))
But I still haven't been able to read the AM2315 while connected to the multiplexer.

β€”
Reply to this email directly or view it on GitHub.

from mycodo.

kizniche avatar kizniche commented on July 24, 2024

Okay. Creating a thread on Adafruit forums.

For completeness, here's the code I use to read the AM2315, from tentacle_pi drivers:

#!/usr/bin/python

from tentacle_pi.AM2315 import AM2315
am = AM2315(0x5c,"/dev/i2c-1") # Hardcoded address 0x5c

for x in range(0,10):
    temperature, humidity, crc_check = am.sense()
    print "temperature: %s" % temperature
    print "humidity: %s" % humidity
    print "crc: %s" % crc_check
    time.sleep(2)

When I have the sensor attached to the multiplexer, set the channel using the code previously posted, I change the above code's 0x5c address to 0x70, but it can't get a reading.

from mycodo.

kizniche avatar kizniche commented on July 24, 2024

Posted to the Adafruit Forum: Using the TCA9548A I2C Multiplexer with a Pi & AM2315 Sensor

from mycodo.

kizniche avatar kizniche commented on July 24, 2024

The I2C multiplexer and AM2315 are finally working in harmony! Thanks to adafruit_support_rick on the Adafruit support forum.

from mycodo.

kizniche avatar kizniche commented on July 24, 2024

Support for the multiplexer added with commit 677299e

from mycodo.

kizniche avatar kizniche commented on July 24, 2024

Let me know if you have any problems if you attempt to use the multiplexer with multiple sensors. I only have one sensor, but I've tested it on different channels. It should theoretically work with up to 8 sensors connected to each multiplexer (up to 8 multiplexers), making 64 the maximum number of AM2315s that can be used. Such a great idea, thanks for the suggestion!

from mycodo.

kizniche avatar kizniche commented on July 24, 2024

I haven't added support for multiple multiplexers. Currently only one on address 0x70 is supported. I'll reopen this until I add support for multiple multiplexers. That's not going overboard, is it?

from mycodo.

kizniche avatar kizniche commented on July 24, 2024

Up to 8 simultaneously-connected multiplexers supported with commit cb7c33c

from mycodo.

mdobres avatar mdobres commented on July 24, 2024

Hi, I used your code above to change the channel of the multiplexer. It all seemed to work, However I assume your program just reports the status or number of the channel. How would you get it to report the I2c address of the attached device?

from mycodo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.