-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadafruit_amg8833.py
71 lines (55 loc) · 1.66 KB
/
adafruit_amg8833.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
class AMG8833:
normal_mode = 0x00
sleep_mode = 0x00
standby_mode_60 = 0x20
standby_mode_10 = 0x21
def __init__(self, i2c, addr=0x69):
"""
initialization of class, requires 2 parameters
parameters:
i2c (initialized bus eg. with i2c = machine.I2C(sda=.., scl=...))
addr address of AMG88332 (in general 0x69 = 105d)
"""
self._i2c = i2c
self._addr = addr
"""
a = self._i2c.scan()
if not self._addr in a:
print("no device on selected address %02X!" % self._addr)
else:
print("device on address %02X available." % self._addr)
"""
def set_power_mode(self, mode):
b = bytes([mode])
self._i2c.writeto_mem(self._addr, 0x00, b)
return true
def temperature(self):
"""
receive the current temperature in degree celcius
tempearture as float
"""
t = self._i2c.readfrom_mem(self._addr, 0x0E, 2)
return (t[0] + t[1]*256) * 0.0625;
def pixel(self):
"""
read grid data from the chip
(starting address 0x80, )
parameter: none (i2c and address are object properties)
return 8x8 grid of INTEGER Values (no calculation) of real temperature
"""
bin_data = list(self._i2c.readfrom_mem(self._addr, 0x80, 128)) # linear data 128 byte
int_data = [256*hi + lo for lo,hi in zip(bin_data[::2],bin_data[1::2])]; # linear data 64 Integer
int_data = [int((element - 32) / 1.8) for element in int_data]
return int_data
# return [int_data[i:i+8] for i in range(0, 64, 8)] # 8x8 data structure
def print8x8(self, data8x8):
"""
simple support routine to show the 8x8 values
parameter:
data8x8 ... data provided as 8x8 array
return NONE
"""
for row in data8x8:
for item in row:
print(item, end=' ')
print()