-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:jamesbowman/i2cdriver
- Loading branch information
Showing
6 changed files
with
128 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
CC=clang | ||
CFLAGS += -I common -Wall -Wpointer-sign -xc++ -std=c++17 # -Werror | ||
|
||
all: build/i2ccl | ||
|
||
install: all | ||
cp build/i2ccl /usr/local/bin | ||
|
||
build/i2ccl: linux/i2c.c common/i2cdriver.c | ||
mkdir -p build/ | ||
$(CC) -o $@ $(CPPFLAGS) $(CFLAGS) $^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import sys | ||
from i2cdriver import I2CDriver, EDS | ||
|
||
# Using a TCA9548A Low-Voltage 8-Channel I2C Switch | ||
# Three LM75B temperature sensors are connected to | ||
# channels 0,1 and 2. All are at address 0x48. | ||
|
||
class Mux: | ||
def __init__(self, i2, a = 0x70): | ||
self.i2 = i2 | ||
self.a = a | ||
|
||
def select(self, n): | ||
assert n in range(8) | ||
self.i2.start(self.a, 0) | ||
self.i2.write([1 << n]) | ||
self.i2.stop() | ||
|
||
if __name__ == '__main__': | ||
i2 = I2CDriver(sys.argv[1]) | ||
|
||
mux = Mux(i2) | ||
sensors = [ | ||
(0, EDS.Temp(i2)), | ||
(1, EDS.Temp(i2)), | ||
(2, EDS.Temp(i2)) | ||
] | ||
|
||
# Reset all 8 channels | ||
for chan in range(8): | ||
mux.select(chan) | ||
i2.reset() | ||
|
||
def read(chan, dev): | ||
mux.select(chan) | ||
celsius = dev.read() | ||
return celsius | ||
|
||
while 1: | ||
print(" ".join(["%.1f" % read(chan, dev) for chan,dev in sensors])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ python -c 'from i2cdriver import I2CDriver' | |
|
||
cd c | ||
make -f linux/Makefile | ||
make -f linux/Makefile.clang |