i2c_bus = busio.I2C(board.SCL, board.SDA)

#low range of the sensor (this will be blue on the screen)
MINTEMP = 26.

#high range of the sensor (this will be red on the screen)
MAXTEMP = 32.

#how many color values we can have
COLORDEPTH = 1024

os.putenv('SDL_FBDEV', '/dev/fb1')
pygame.init()

#initialize the sensor
sensor = adafruit_amg88xx.AMG88XX(i2c_bus, addr=0x68)

# pylint: disable=invalid-slice-index
points = [(math.floor(ix / 8), (ix % 8)) for ix in range(0, 64)]
grid_x, grid_y = np.mgrid[0:7:32j, 0:7:32j]
# pylint: enable=invalid-slice-index

#sensor is an 8x8 grid so lets do a square
height = 240
width = 240

#the list of colors we can choose from
blue = Color("indigo")
colors = list(blue.range_to(Color("red"), COLORDEPTH))

#create the array of colors
import time
import busio
import board
import numpy as np
from scipy.interpolate import griddata
from colour import Color
import adafruit_amg88xx

I2C_BUS = busio.I2C(board.SCL, board.SDA)

# low range of the sensor (this will be blue on the screen)
MINTEMP = 26.0
# high range of the sensor (this will be red on the screen)
MAXTEMP = 32.0
COLORDEPTH = 1024
SENSOR = adafruit_amg88xx.AMG88XX(I2C_BUS)

# pylint: disable=invalid-slice-index
POINTS = [(math.floor(ix / 8), (ix % 8)) for ix in range(0, 64)]
GRID_X, GRID_Y = np.mgrid[0:7:32j, 0:7:32j]
# pylint: enable=invalid-slice-index

# sensor is an 8x8 grid so lets do a square
HEIGHT = 240
WIDTH = 240

# the list of colors we can choose from
BLUE = Color("indigo")
COLORS = list(BLUE.range_to(Color("red"), COLORDEPTH))

# create the array of colors
 def __init__(self):
     import adafruit_amg88xx
     self.i2c = busio.I2C(board.SCL, board.SDA)
     self.amg = adafruit_amg88xx.AMG88XX(self.i2c)
示例#4
0
i2c_bus = busio.I2C(board.SCL, board.SDA)

#low range of the sensor (this will be blue on the screen)
MINTEMP = 21.

#high range of the sensor (this will be red on the screen)
MAXTEMP = 30.

#how many color values we can have
COLORDEPTH = 1024

os.putenv('SDL_FBDEV', '/dev/fb1')
pygame.init()

#initialize the sensor
sensor = adafruit_amg88xx.AMG88XX(i2c_bus)

# pylint: disable=invalid-slice-index
points = [(math.floor(ix / 8), (ix % 8)) for ix in range(0, 64)]
grid_x, grid_y = np.mgrid[0:7:32j, 0:7:32j]
# pylint: enable=invalid-slice-index

#sensor is an 8x8 grid so lets do a square
height = 720
width = 720

#the list of colors we can choose from
blue = Color("indigo")
colors = list(blue.range_to(Color("red"), COLORDEPTH))

#create the array of colors
示例#5
0
# for thermal camera
import busio
import board
import adafruit_amg88xx
import math
import numpy as np
from scipy.interpolate import griddata
from colour import Color

# my classes
from button import button
from thermalcamera import *

# setup thermal camera
i2c = busio.I2C(board.SCL, board.SDA)
tc = adafruit_amg88xx.AMG88XX(i2c)

# colors
GOLD = (255, 199, 38)
LTGREEN = (87, 121, 53)
DKGREEN = (0, 83, 62)

# set the display to pitft and initialize
os.putenv('SDL_FBDEV', '/dev/fb1')
os.putenv('SDL_MOUSEDRV', 'TSLIB')
os.putenv('SDL_MOUSEDEV', '/dev/input/touchscreen')

pygame.init()
pygame.mouse.set_visible(False)

lcdWidth = 480
示例#6
0
 def thermal_sensor_init(self):   
     # I2Cバスの初期化
     i2c_bus = busio.I2C(board.SCL, board.SDA)
     # センサの初期化
     self.thermal_sensor = adafruit_amg88xx.AMG88XX(i2c_bus, addr=0x68)
示例#7
0
def main():
    i2c_bus = busio.I2C(board.SCL, board.SDA)
    #low range of the sensor (this will be blue on the screen)
    MINTEMP = 26.
    #high range of the sensor (this will be red on the screen)
    MAXTEMP = 32.
    #how many color values we can have
    COLORDEPTH = 1024
    os.putenv('SDL_FBDEV', '/dev/fb1')
    pygame.init()
    #initialize the sensor
    sensor = adafruit_amg88xx.AMG88XX(i2c_bus)
    points = [(math.floor(ix / 8), (ix % 8)) for ix in range(0, 64)]
    grid_x, grid_y = np.mgrid[0:7:32j, 0:7:32j]
    #the list of colors we can choose from
    blue = Color("indigo")
    colors = list(blue.range_to(Color("red"), COLORDEPTH))
    #create the array of colors
    colors = [(int(c.red * 255), int(c.green * 255), int(c.blue * 255)) for c in colors]
    displayPixelWidth = math.ceil(width / 32.)
    displayPixelHeight = math.ceil(height / 32.)
    # initial low range of the sensor (this will be blue on the screen)
    #MINTEMP = 26
    MINTEMP = (73 - 32) / 1.8
    # initial high range of the sensor (this will be red on the screen)
    #MAXTEMP = 32
    MAXTEMP = (79 - 32) / 1.8
    # initialize camera
    pygame.camera.init()
    cam = pygame.camera.Camera("/dev/video0",(width, height))
    cam.start()
    
    lcd = pygame.display.set_mode((width,height))
    lcdRect = lcd.get_rect()

    # heat surface
    heat = pygame.surface.Surface((width, height))

    # edge detect surface
    overlay = pygame.surface.Surface((width, height))
    overlay.set_colorkey((0,0,0))

    # menu surface
    menu = pygame.surface.Surface((width, height))
    menu.set_colorkey((0,0,0))
    menuMaxPlus = menuButton('+',(230,30),(60,60) )
    menuMaxMinus = menuButton('-',(230,90),(60,60) )
    menuMinPlus = menuButton('+',(230,150),(60,60) )
    menuMinMinus = menuButton('-',(230,210),(60,60) )

    menuCapture = menuButton('Capture',(60,30),(120,60) )
    menuMode = menuButton('Mode',(60,90),(120,60) )

    menuBack = menuButton('Back',(60,150),(120,60) )
    menuExit = menuButton('Exit',(60,210),(120,60) )

    MAXtext = font.render('MAX', True, WHITE)
    MAXtextPos = MAXtext.get_rect(center=(290,20))

    MINtext = font.render('MIN', True, WHITE)
    MINtextPos = MINtext.get_rect(center=(290,140))


    # streamCapture
    streamCapture = 5
    GPIO.setup(streamCapture, GPIO.OUT)
    GPIO.output(streamCapture, False)
    fileNum = 0
    fileStream = time.strftime("%Y%m%d-%H%M-", time.localtime())

    # flags
    menuDisplay = False 
    heatDisplay = 1
    imageCapture = False

    # Field of View and Scale
    heatFOV = 55
    imageScale = math.tan(math.radians(camFOV/2.))/math.tan(math.radians(heatFOV/2.))

    #let the sensor initialize
    time.sleep(.1)

    # loop...
    running = True
    while(running):
        if heatDisplay :
            # heatDisplay == 0	camera only
            # heatDisplay == 1	heat + camera
            # heatDisplay == 2	heat + edge
            # heatDisplay == 3	heat only

            # read the pixels
            pixels = sensor.readPixels()
            pixels = [map(p, MINTEMP, MAXTEMP, 0, COLORDEPTH - 1) for p in pixels]

            # perform interpolation
            bicubic = griddata(points, pixels, (grid_x, grid_y), method='cubic')

            # create heat layer
            for ix, row in enumerate(bicubic):
                for jx, pixel in enumerate(row):
                    rect = (displayPixelWidth * (31 - ix), displayPixelHeight * jx, displayPixelWidth, displayPixelHeight)
                    color = colors[constrain(int(pixel), 0, COLORDEPTH- 1)]
                    heat.fill(color, rect)

            if imageScale < 1.0 and heatDisplay != 3:
                heatImage = pygame.transform.scale(heat, (int(width/imageScale),int(height/imageScale)))
            else:
                heatImage = heat

            heatRect = heatImage.get_rect(center=lcdRect.center)
            lcd.blit(heatImage,heatRect)

            # add camera
            if heatDisplay == 2 :
                camImage = pygame.transform.laplacian(cam.get_image())
                pygame.transform.threshold(overlay,camImage,(0,0,0),(40,40,40),(1,1,1),1)
                if imageScale > 1.0 :
                    overlay2 = pygame.transform.scale(overlay,(int(width*imageScale),int(height*imageScale)))
                else:
                    overlay2 = overlay

                overlay2Rect = overlay2.get_rect(center=lcdRect.center)
                overlay2.set_colorkey((0,0,0))
                lcd.blit(overlay2,overlay2Rect)

            if heatDisplay == 1 :
                if imageScale > 1.0 :
                    camImage = pygame.transform.scale(cam.get_image(), (int(width*imageScale),int(height*imageScale)))
                else:
                    camImage = cam.get_image()

                camRect = camImage.get_rect(center=lcdRect.center)
                camImage.set_alpha(100)
                lcd.blit(camImage,camRect)

            # display max/min
            lcd.blit(MAXtext,MAXtextPos)
            fahrenheit = MAXTEMP*1.8 + 32
            text = font.render('%d'%fahrenheit, True, WHITE)
            textPos = text.get_rect(center=(290,60))
            lcd.blit(text,textPos)

            lcd.blit(MINtext,MINtextPos)
            fahrenheit = MINTEMP*1.8 + 32
            text = font.render('%d'%fahrenheit, True, WHITE)
            textPos = text.get_rect(center=(290,180))
            lcd.blit(text,textPos)
        else:
            camImage = cam.get_image()
            lcd.blit(camImage,(0,0))

        # capture single frame to file, without menu overlay
        if imageCapture :
            imageCapture = False
            fileDate = time.strftime("%Y%m%d-%H%M%S", time.localtime())
            fileName = "/home/pi/Pictures/heat%s.jpg" % fileDate
            pygame.image.save(lcd, fileName)

        # remote stream capture
        # similar to imageCapture, but invoked by GPIO
        # capture continues until stopped
        # for example,from a shell window: start capture:  gpio -g 5 1
        #                                  stop capture:   gpio -g 5 0
        if GPIO.input(streamCapture) :
            fileNum = fileNum + 1
            fileName = "/home/pi/Pictures/heat%s%04d.jpg" % (fileStream, fileNum)
            pygame.image.save(lcd, fileName)

            # add menu overlay
            if menuDisplay :
                    lcd.blit(menu,(0,0))

        # display
        pygame.display.update()
示例#8
0
 def __init__(self, i2c, threshold=20):
     super(AMG8833Sensor, self).__init__(threshold)
     self._sensor = adafruit_amg88xx.AMG88XX(i2c)