Skip to content

Commit ebceed6

Browse files
conejoninjadeadprogram
authored andcommitted
AMG88xx thermal camera module
1 parent 08cc84c commit ebceed6

File tree

6 files changed

+269
-0
lines changed

6 files changed

+269
-0
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ smoke-test:
1313
@md5sum ./build/test.hex
1414
tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/adxl345/main.go
1515
@md5sum ./build/test.hex
16+
tinygo build -size short -o ./build/test.hex -target=pybadge ./examples/amg88xx
17+
@md5sum ./build/test.hex
1618
tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/apa102/main.go
1719
@md5sum ./build/test.hex
1820
tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/apa102/itsybitsy-m0/main.go

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ The following 45 devices are supported.
5858
|----------|-------------|
5959
| [ADT7410 I2C Temperature Sensor](https://www.analog.com/media/en/technical-documentation/data-sheets/ADT7410.pdf) | I2C |
6060
| [ADXL345 accelerometer](http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL345.pdf) | I2C |
61+
| [AMG88xx 8x8 Thermal camera sensor](https://cdn-learn.adafruit.com/assets/assets/000/043/261/original/Grid-EYE_SPECIFICATIONS%28Reference%29.pdf) | I2C |
6162
| [APA102 RGB LED](https://cdn-shop.adafruit.com/product-files/2343/APA102C.pdf) | SPI |
6263
| [AT24CX 2-wire serial EEPROM](https://www.openimpulse.com/blog/wp-content/uploads/wpsc/downloadables/24C32-Datasheet.pdf) | I2C |
6364
| [BH1750 ambient light sensor](https://www.mouser.com/ds/2/348/bh1750fvi-e-186247.pdf) | I2C |

amg88xx/amg88xx.go

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
// Package amg88xx provides a driver for the AMG88XX Thermal Camera
2+
//
3+
// Datasheet:
4+
// https://cdn-learn.adafruit.com/assets/assets/000/043/261/original/Grid-EYE_SPECIFICATIONS%28Reference%29.pdf
5+
package amg88xx // import "tinygo.org/x/drivers/amg88xx"
6+
7+
import (
8+
"machine"
9+
"time"
10+
)
11+
12+
// Device wraps an I2C connection to a AMG88xx device.
13+
type Device struct {
14+
bus machine.I2C
15+
Address uint16
16+
data []uint8
17+
interruptMode InterruptMode
18+
interruptEnable uint8
19+
}
20+
21+
type InterruptMode uint8
22+
23+
type Config struct {
24+
}
25+
26+
// New creates a new AMG88xx connection. The I2C bus must already be
27+
// configured.
28+
//
29+
// This function only creates the Device object, it does not touch the device.
30+
func New(bus machine.I2C) Device {
31+
return Device{
32+
bus: bus,
33+
Address: AddressHigh,
34+
}
35+
}
36+
37+
// Configure sets up the device for communication
38+
func (d *Device) Configure(cfg Config) {
39+
d.data = make([]uint8, 128)
40+
41+
d.SetPCTL(NORMAL_MODE)
42+
d.SetReset(INITIAL_RESET)
43+
d.SetFrameRate(FPS_10)
44+
45+
time.Sleep(100 * time.Millisecond)
46+
}
47+
48+
// ReadPixels returns the 64 values (8x8 grid) of the sensor converted to millicelsius
49+
func (d *Device) ReadPixels(buffer *[64]int16) {
50+
d.bus.ReadRegister(uint8(d.Address), PIXEL_OFFSET, d.data)
51+
for i := 0; i < 64; i++ {
52+
buffer[i] = int16((uint16(d.data[2*i+1]) << 8) | uint16(d.data[2*i]))
53+
if (buffer[i] & (1 << 11)) > 0 { // temperature negative
54+
buffer[i] &= ^(1 << 11)
55+
buffer[i] = -buffer[i]
56+
}
57+
buffer[i] *= PIXEL_TEMP_CONVERSION
58+
}
59+
}
60+
61+
// SetPCTL sets the PCTL
62+
func (d *Device) SetPCTL(pctl uint8) {
63+
d.bus.WriteRegister(uint8(d.Address), PCTL, []byte{pctl})
64+
}
65+
66+
// SetReset sets the reset value
67+
func (d *Device) SetReset(rst uint8) {
68+
d.bus.WriteRegister(uint8(d.Address), RST, []byte{rst})
69+
}
70+
71+
// SetFrameRate configures the frame rate
72+
func (d *Device) SetFrameRate(framerate uint8) {
73+
d.bus.WriteRegister(uint8(d.Address), FPSC, []byte{framerate & 0x01})
74+
}
75+
76+
// SetMovingAverageMode sets the moving average mode
77+
func (d *Device) SetMovingAverageMode(mode bool) {
78+
var value uint8
79+
if mode {
80+
value = 1
81+
}
82+
d.bus.WriteRegister(uint8(d.Address), AVE, []byte{value << 5})
83+
}
84+
85+
// SetInterruptLevels sets the interrupt levels
86+
func (d *Device) SetInterruptLevels(high int16, low int16) {
87+
d.SetInterruptLevelsHysteresis(high, low, (high*95)/100)
88+
}
89+
90+
// SetInterruptLevelsHysteresis sets the interrupt levels with hysteresis
91+
func (d *Device) SetInterruptLevelsHysteresis(high int16, low int16, hysteresis int16) {
92+
high = high / PIXEL_TEMP_CONVERSION
93+
if high < -4095 {
94+
high = -4095
95+
}
96+
if high > 4095 {
97+
high = 4095
98+
}
99+
d.bus.WriteRegister(uint8(d.Address), INTHL, []byte{uint8(high & 0xFF)})
100+
d.bus.WriteRegister(uint8(d.Address), INTHL, []byte{uint8((high & 0xFF) >> 4)})
101+
102+
low = low / PIXEL_TEMP_CONVERSION
103+
if low < -4095 {
104+
low = -4095
105+
}
106+
if low > 4095 {
107+
low = 4095
108+
}
109+
d.bus.WriteRegister(uint8(d.Address), INTHL, []byte{uint8(low & 0xFF)})
110+
d.bus.WriteRegister(uint8(d.Address), INTHL, []byte{uint8((low & 0xFF) >> 4)})
111+
112+
hysteresis = hysteresis / PIXEL_TEMP_CONVERSION
113+
if hysteresis < -4095 {
114+
hysteresis = -4095
115+
}
116+
if hysteresis > 4095 {
117+
hysteresis = 4095
118+
}
119+
d.bus.WriteRegister(uint8(d.Address), INTHL, []byte{uint8(hysteresis & 0xFF)})
120+
d.bus.WriteRegister(uint8(d.Address), INTHL, []byte{uint8((hysteresis & 0xFF) >> 4)})
121+
}
122+
123+
// EnableInterrupt enables the interrupt pin on the device
124+
func (d *Device) EnableInterrupt() {
125+
d.interruptEnable = 1
126+
d.bus.WriteRegister(uint8(d.Address), INTC, []byte{((uint8(d.interruptMode) << 1) | d.interruptEnable) & 0x03})
127+
}
128+
129+
// DisableInterrupt disables the interrupt pin on the device
130+
func (d *Device) DisableInterrupt() {
131+
d.interruptEnable = 0
132+
d.bus.WriteRegister(uint8(d.Address), INTC, []byte{((uint8(d.interruptMode) << 1) | d.interruptEnable) & 0x03})
133+
}
134+
135+
// SetInterruptMode sets the interrupt mode
136+
func (d *Device) SetInterruptMode(mode InterruptMode) {
137+
d.interruptMode = mode
138+
d.bus.WriteRegister(uint8(d.Address), INTC, []byte{((uint8(d.interruptMode) << 1) | d.interruptEnable) & 0x03})
139+
}
140+
141+
// GetInterrupt reads the state of the triggered interrupts
142+
func (d *Device) GetInterrupt() []uint8 {
143+
data := make([]uint8, 8)
144+
d.bus.ReadRegister(uint8(d.Address), INT_OFFSET, data)
145+
return data
146+
}
147+
148+
// ClearInterrupt clears any triggered interrupts
149+
func (d *Device) ClearInterrupt() {
150+
d.SetReset(FLAG_RESET)
151+
}
152+
153+
// ReadThermistor reads the onboard thermistor
154+
func (d *Device) ReadThermistor() int16 {
155+
data := make([]uint8, 2)
156+
d.bus.ReadRegister(uint8(d.Address), TTHL, data)
157+
return (int16((uint16(data[1])<<8)|uint16(data[0])) * THERMISTOR_CONVERSION) / 10
158+
}

amg88xx/registers.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package amg88xx
2+
3+
// The I2C address which this device listens to.
4+
const AddressHigh = 0x69
5+
const AddressLow = 0x68
6+
7+
const (
8+
PCTL = 0x00
9+
RST = 0x01
10+
FPSC = 0x02
11+
INTC = 0x03
12+
STAT = 0x04
13+
SCLR = 0x05
14+
AVE = 0x07
15+
INTHL = 0x08
16+
INTHH = 0x09
17+
INTLL = 0x0A
18+
INTLH = 0x0B
19+
IHYSL = 0x0C
20+
IHYSH = 0x0D
21+
TTHL = 0x0E
22+
TTHH = 0x0F
23+
INT_OFFSET = 0x010
24+
PIXEL_OFFSET = 0x80
25+
26+
// power modes
27+
NORMAL_MODE = 0x00
28+
SLEEP_MODE = 0x01
29+
STAND_BY_60 = 0x20
30+
STAND_BY_10 = 0x21
31+
32+
// resets
33+
FLAG_RESET = 0x30
34+
INITIAL_RESET = 0x3F
35+
36+
// frame rates
37+
FPS_10 = 0x00
38+
FPS_1 = 0x01
39+
40+
// interrupt modes
41+
DIFFERENCE InterruptMode = 0x00
42+
ABSOLUTE_VALUE InterruptMode = 0x01
43+
44+
PIXEL_TEMP_CONVERSION = 250
45+
THERMISTOR_CONVERSION = 625
46+
)

examples/amg88xx/colors.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package main
2+
3+
import "image/color"
4+
5+
// palette of colors (iron) taken from http://ramphastosramblings.blogspot.com/2014/03/choosing-appropriate-colour-palette-for.html
6+
var colors = []color.RGBA{{0, 0, 10, 255}, {0, 0, 20, 255}, {0, 0, 30, 255}, {0, 0, 37, 255}, {0, 0, 42, 255}, {0, 0, 46, 255}, {0, 0, 50, 255}, {0, 0, 54, 255}, {0, 0, 58, 255}, {0, 0, 62, 255}, {0, 0, 66, 255}, {0, 0, 70, 255}, {0, 0, 74, 255}, {0, 0, 79, 255}, {0, 0, 82, 255}, {1, 0, 85, 255}, {1, 0, 87, 255}, {2, 0, 89, 255}, {2, 0, 92, 255}, {3, 0, 94, 255}, {4, 0, 97, 255}, {4, 0, 99, 255}, {5, 0, 101, 255}, {6, 0, 103, 255}, {7, 0, 105, 255}, {8, 0, 107, 255}, {9, 0, 110, 255}, {10, 0, 112, 255}, {11, 0, 115, 255}, {12, 0, 116, 255}, {13, 0, 117, 255}, {13, 0, 118, 255}, {14, 0, 119, 255}, {16, 0, 120, 255}, {18, 0, 121, 255}, {19, 0, 123, 255}, {21, 0, 124, 255}, {23, 0, 125, 255}, {25, 0, 126, 255}, {27, 0, 128, 255}, {28, 0, 129, 255}, {30, 0, 131, 255}, {32, 0, 132, 255}, {34, 0, 133, 255}, {36, 0, 134, 255}, {38, 0, 135, 255}, {40, 0, 137, 255}, {42, 0, 137, 255}, {44, 0, 138, 255}, {46, 0, 139, 255}, {48, 0, 140, 255}, {50, 0, 141, 255}, {52, 0, 142, 255}, {54, 0, 142, 255}, {56, 0, 143, 255}, {57, 0, 144, 255}, {59, 0, 145, 255}, {60, 0, 146, 255}, {62, 0, 147, 255}, {63, 0, 147, 255}, {65, 0, 148, 255}, {66, 0, 149, 255}, {68, 0, 149, 255}, {69, 0, 150, 255}, {71, 0, 150, 255}, {73, 0, 150, 255}, {74, 0, 150, 255}, {76, 0, 151, 255}, {78, 0, 151, 255}, {79, 0, 151, 255}, {81, 0, 151, 255}, {82, 0, 152, 255}, {84, 0, 152, 255}, {86, 0, 152, 255}, {88, 0, 153, 255}, {90, 0, 153, 255}, {92, 0, 153, 255}, {93, 0, 154, 255}, {95, 0, 154, 255}, {97, 0, 155, 255}, {99, 0, 155, 255}, {100, 0, 155, 255}, {102, 0, 155, 255}, {104, 0, 155, 255}, {106, 0, 155, 255}, {108, 0, 156, 255}, {109, 0, 156, 255}, {111, 0, 156, 255}, {112, 0, 156, 255}, {113, 0, 157, 255}, {115, 0, 157, 255}, {117, 0, 157, 255}, {119, 0, 157, 255}, {120, 0, 157, 255}, {122, 0, 157, 255}, {124, 0, 157, 255}, {126, 0, 157, 255}, {127, 0, 157, 255}, {129, 0, 157, 255}, {131, 0, 157, 255}, {132, 0, 157, 255}, {134, 0, 157, 255}, {135, 0, 157, 255}, {137, 0, 157, 255}, {138, 0, 157, 255}, {139, 0, 157, 255}, {141, 0, 157, 255}, {143, 0, 156, 255}, {145, 0, 156, 255}, {147, 0, 156, 255}, {149, 0, 156, 255}, {150, 0, 155, 255}, {152, 0, 155, 255}, {153, 0, 155, 255}, {155, 0, 155, 255}, {156, 0, 155, 255}, {157, 0, 155, 255}, {159, 0, 155, 255}, {160, 0, 155, 255}, {162, 0, 155, 255}, {163, 0, 155, 255}, {164, 0, 155, 255}, {166, 0, 154, 255}, {167, 0, 154, 255}, {168, 0, 154, 255}, {169, 0, 153, 255}, {170, 0, 153, 255}, {171, 0, 153, 255}, {173, 0, 153, 255}, {174, 1, 152, 255}, {175, 1, 152, 255}, {176, 1, 152, 255}, {176, 1, 152, 255}, {177, 1, 151, 255}, {178, 1, 151, 255}, {179, 1, 150, 255}, {180, 2, 150, 255}, {181, 2, 149, 255}, {182, 2, 149, 255}, {183, 3, 149, 255}, {184, 3, 149, 255}, {185, 4, 149, 255}, {186, 4, 149, 255}, {186, 4, 148, 255}, {187, 5, 147, 255}, {188, 5, 147, 255}, {189, 5, 147, 255}, {190, 6, 146, 255}, {191, 6, 146, 255}, {191, 6, 146, 255}, {192, 7, 145, 255}, {192, 7, 145, 255}, {193, 8, 144, 255}, {193, 9, 144, 255}, {194, 10, 143, 255}, {195, 10, 142, 255}, {195, 11, 142, 255}, {196, 12, 141, 255}, {197, 12, 140, 255}, {198, 13, 139, 255}, {198, 14, 138, 255}, {199, 15, 137, 255}, {200, 16, 136, 255}, {201, 17, 135, 255}, {202, 18, 134, 255}, {202, 19, 133, 255}, {203, 19, 133, 255}, {203, 20, 132, 255}, {204, 21, 130, 255}, {205, 22, 129, 255}, {206, 23, 128, 255}, {206, 24, 126, 255}, {207, 24, 124, 255}, {207, 25, 123, 255}, {208, 26, 121, 255}, {209, 27, 120, 255}, {209, 28, 118, 255}, {210, 28, 117, 255}, {210, 29, 116, 255}, {211, 30, 114, 255}, {211, 32, 113, 255}, {212, 33, 111, 255}, {212, 34, 110, 255}, {213, 35, 107, 255}, {213, 36, 105, 255}, {214, 37, 103, 255}, {215, 38, 101, 255}, {216, 39, 100, 255}, {216, 40, 98, 255}, {217, 42, 96, 255}, {218, 43, 94, 255}, {218, 44, 92, 255}, {219, 46, 90, 255}, {219, 47, 87, 255}, {220, 47, 84, 255}, {221, 48, 81, 255}, {221, 49, 78, 255}, {222, 50, 74, 255}, {222, 51, 71, 255}, {223, 52, 68, 255}, {223, 53, 65, 255}, {223, 54, 61, 255}, {224, 55, 58, 255}, {224, 56, 55, 255}, {224, 57, 51, 255}, {225, 58, 48, 255}, {226, 59, 45, 255}, {226, 60, 42, 255}, {227, 61, 38, 255}, {227, 62, 35, 255}, {228, 63, 32, 255}, {228, 65, 29, 255}, {228, 66, 28, 255}, {229, 67, 27, 255}, {229, 68, 25, 255}, {229, 69, 24, 255}, {230, 70, 22, 255}, {231, 71, 21, 255}, {231, 72, 20, 255}, {231, 73, 19, 255}, {232, 74, 18, 255}, {232, 76, 16, 255}, {232, 76, 15, 255}, {233, 77, 14, 255}, {233, 77, 13, 255}, {234, 78, 12, 255}, {234, 79, 12, 255}, {235, 80, 11, 255}, {235, 81, 10, 255}, {235, 82, 10, 255}, {235, 83, 9, 255}, {236, 84, 9, 255}, {236, 86, 8, 255}, {236, 87, 8, 255}, {236, 88, 8, 255}, {237, 89, 7, 255}, {237, 90, 7, 255}, {237, 91, 6, 255}, {238, 92, 6, 255}, {238, 92, 5, 255}, {238, 93, 5, 255}, {238, 94, 5, 255}, {239, 95, 4, 255}, {239, 96, 4, 255}, {239, 97, 4, 255}, {239, 98, 4, 255}, {240, 99, 3, 255}, {240, 100, 3, 255}, {240, 101, 3, 255}, {241, 102, 3, 255}, {241, 102, 3, 255}, {241, 103, 3, 255}, {241, 104, 3, 255}, {241, 105, 2, 255}, {241, 106, 2, 255}, {241, 107, 2, 255}, {241, 107, 2, 255}, {242, 108, 1, 255}, {242, 109, 1, 255}, {242, 110, 1, 255}, {243, 111, 1, 255}, {243, 112, 1, 255}, {243, 113, 1, 255}, {243, 114, 1, 255}, {244, 115, 0, 255}, {244, 116, 0, 255}, {244, 117, 0, 255}, {244, 118, 0, 255}, {244, 119, 0, 255}, {244, 120, 0, 255}, {244, 122, 0, 255}, {245, 123, 0, 255}, {245, 124, 0, 255}, {245, 126, 0, 255}, {245, 127, 0, 255}, {246, 128, 0, 255}, {246, 129, 0, 255}, {246, 130, 0, 255}, {247, 131, 0, 255}, {247, 132, 0, 255}, {247, 133, 0, 255}, {247, 134, 0, 255}, {248, 135, 0, 255}, {248, 136, 0, 255}, {248, 136, 0, 255}, {248, 137, 0, 255}, {248, 138, 0, 255}, {248, 139, 0, 255}, {248, 140, 0, 255}, {249, 141, 0, 255}, {249, 141, 0, 255}, {249, 142, 0, 255}, {249, 143, 0, 255}, {249, 144, 0, 255}, {249, 145, 0, 255}, {249, 146, 0, 255}, {249, 147, 0, 255}, {250, 148, 0, 255}, {250, 149, 0, 255}, {250, 150, 0, 255}, {251, 152, 0, 255}, {251, 153, 0, 255}, {251, 154, 0, 255}, {251, 156, 0, 255}, {252, 157, 0, 255}, {252, 159, 0, 255}, {252, 160, 0, 255}, {252, 161, 0, 255}, {253, 162, 0, 255}, {253, 163, 0, 255}, {253, 164, 0, 255}, {253, 166, 0, 255}, {253, 167, 0, 255}, {253, 168, 0, 255}, {253, 170, 0, 255}, {253, 171, 0, 255}, {253, 172, 0, 255}, {253, 173, 0, 255}, {253, 174, 0, 255}, {254, 175, 0, 255}, {254, 176, 0, 255}, {254, 177, 0, 255}, {254, 178, 0, 255}, {254, 179, 0, 255}, {254, 180, 0, 255}, {254, 181, 0, 255}, {254, 182, 0, 255}, {254, 184, 0, 255}, {254, 185, 0, 255}, {254, 185, 0, 255}, {254, 186, 0, 255}, {254, 187, 0, 255}, {254, 188, 0, 255}, {254, 189, 0, 255}, {254, 190, 0, 255}, {254, 192, 0, 255}, {254, 193, 0, 255}, {254, 194, 0, 255}, {254, 195, 0, 255}, {254, 196, 0, 255}, {254, 197, 0, 255}, {254, 198, 0, 255}, {254, 199, 0, 255}, {254, 200, 0, 255}, {254, 201, 1, 255}, {254, 202, 1, 255}, {254, 202, 1, 255}, {254, 203, 1, 255}, {254, 204, 2, 255}, {254, 205, 2, 255}, {254, 206, 3, 255}, {254, 207, 4, 255}, {254, 207, 4, 255}, {254, 208, 5, 255}, {254, 209, 6, 255}, {254, 211, 8, 255}, {254, 212, 9, 255}, {254, 213, 10, 255}, {254, 214, 10, 255}, {254, 215, 11, 255}, {254, 216, 12, 255}, {254, 217, 13, 255}, {255, 218, 14, 255}, {255, 218, 14, 255}, {255, 219, 16, 255}, {255, 220, 18, 255}, {255, 220, 20, 255}, {255, 221, 22, 255}, {255, 222, 25, 255}, {255, 222, 27, 255}, {255, 223, 30, 255}, {255, 224, 32, 255}, {255, 225, 34, 255}, {255, 226, 36, 255}, {255, 226, 38, 255}, {255, 227, 40, 255}, {255, 228, 43, 255}, {255, 228, 46, 255}, {255, 229, 49, 255}, {255, 230, 53, 255}, {255, 230, 56, 255}, {255, 231, 60, 255}, {255, 232, 63, 255}, {255, 233, 67, 255}, {255, 234, 70, 255}, {255, 235, 73, 255}, {255, 235, 77, 255}, {255, 236, 80, 255}, {255, 237, 84, 255}, {255, 238, 87, 255}, {255, 238, 91, 255}, {255, 238, 95, 255}, {255, 239, 99, 255}, {255, 239, 103, 255}, {255, 240, 106, 255}, {255, 240, 110, 255}, {255, 241, 114, 255}, {255, 241, 119, 255}, {255, 241, 123, 255}, {255, 242, 128, 255}, {255, 242, 133, 255}, {255, 242, 138, 255}, {255, 243, 142, 255}, {255, 244, 146, 255}, {255, 244, 150, 255}, {255, 244, 154, 255}, {255, 245, 158, 255}, {255, 245, 162, 255}, {255, 245, 166, 255}, {255, 246, 170, 255}, {255, 246, 175, 255}, {255, 247, 179, 255}, {255, 247, 182, 255}, {255, 248, 186, 255}, {255, 248, 189, 255}, {255, 248, 193, 255}, {255, 248, 196, 255}, {255, 249, 199, 255}, {255, 249, 202, 255}, {255, 249, 205, 255}, {255, 250, 209, 255}, {255, 250, 212, 255}, {255, 251, 216, 255}, {255, 252, 219, 255}, {255, 252, 223, 255}, {255, 253, 226, 255}, {255, 253, 229, 255}, {255, 253, 232, 255}, {255, 254, 235, 255}, {255, 254, 238, 255}, {255, 254, 241, 255}, {255, 254, 244, 255}, {255, 255, 246, 255}}

examples/amg88xx/main.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package main
2+
3+
import (
4+
"image/color"
5+
"machine"
6+
7+
"tinygo.org/x/drivers/st7735"
8+
9+
"tinygo.org/x/drivers/amg88xx"
10+
)
11+
12+
func main() {
13+
14+
machine.SPI1.Configure(machine.SPIConfig{
15+
SCK: machine.SPI1_SCK_PIN,
16+
MOSI: machine.SPI1_MOSI_PIN,
17+
MISO: machine.SPI1_MISO_PIN,
18+
Frequency: 8000000,
19+
})
20+
machine.I2C0.Configure(machine.I2CConfig{SCL: machine.SCL_PIN, SDA: machine.SDA_PIN})
21+
22+
display := st7735.New(machine.SPI1, machine.TFT_RST, machine.TFT_DC, machine.TFT_CS, machine.TFT_LITE)
23+
display.Configure(st7735.Config{
24+
Rotation: st7735.ROTATION_90,
25+
})
26+
display.FillScreen(color.RGBA{0, 0, 0, 255})
27+
28+
camera := amg88xx.New(machine.I2C0)
29+
camera.Configure(amg88xx.Config{})
30+
31+
var data [64]int16
32+
var value int16
33+
for {
34+
// get the values of the sensor in millicelsius
35+
camera.ReadPixels(&data)
36+
37+
for j := int16(0); j < 8; j++ {
38+
for i := int16(0); i < 8; i++ {
39+
value = data[63-(i+j*8)]
40+
// treat anything below 18°C as 18°C
41+
if value < 18000 {
42+
value = 0
43+
} else {
44+
value = (value - 18000) / 36
45+
// our color array only have 433 values, avoid getting a value that doesn't exist
46+
if value > 432 {
47+
value = 432
48+
}
49+
}
50+
// show the image on the PyBadge's display
51+
display.FillRectangle(16+i*16, j*16, 16, 16, colors[value])
52+
}
53+
}
54+
}
55+
56+
}

0 commit comments

Comments
 (0)