Пример #1
0
class Minimu:
    VERSION = 'minimu9v5'

    def __init__(self, buss_id, address):
        self.gyro = Gyroscope(buss_id, address)
        self.gyro_full_scale = 245
        self.acc = Accelerometer(buss_id, address)
        self.acc_full_scale = 2
        self.fifo = Fifo(buss_id, address)
        self.temp = Temperature(buss_id, address)

    def enable(self, odr=104):
        self.gyro.enable(odr)
        self.gyro_full_scale = self.gyro.get_full_scale_selection()
        self.acc.enable(odr)
        self.acc_full_scale = self.acc.get_full_scale_selection()
        self.fifo.enable(odr)

    def disable(self):
        self.gyro.disable()
        self.acc.disable()
        self.fifo.disable()

    def read_fifo_raw(self):
        data = np.array(self.fifo.get_data(), dtype=np.int)
        return data

    def read_fifo(self):
        data = np.array(self.fifo.get_data(), dtype=np.double)
        try:
            data[:, :3] *= 1
        except IndexError:
            sleep(0.1)
            data = np.array(self.fifo.get_data(), dtype=np.double)

        data[:, :3] *= self.gyro_full_scale
        data[:, -3:] *= self.acc_full_scale
        data[data > 0] /= 32767
        data[data < 0] /= 32768
        return data

    def read_temperature(self):
        return self.temp.get_temperature()
 def test_get_temperature(self):
     """Check if the temperature is correct from text into file"""
     obj_temperature = Temp()
     file = "71 01 55 05 7f a5 a5 66 84 : crc=84 YES \n71 01 55 05 7f a5 a5 66 84 t=23062"
     data = obj_temperature.get_temperature(file)
     assert data == 23.062
Пример #3
0
import time, machine
import sys, ssd1306
import numbers
from machine import I2C, Pin
from temperature import Temperature

i2c = I2C(sda=Pin(5), scl=Pin(4))
display = ssd1306.SSD1306_I2C(128, 64, i2c)

temp = Temperature()

while True:
    display.fill(0)
    display.text('TEMPERATURA', 2, 2, 100)
    numbers = get_number(str(temp.get_temperature()) + 'ºC')
    aux_col = 1
    for number in numbers:
        aux_col += 12
        for x, row in enumerate(number):
            for y, col in enumerate(row):
                if col == "1":
                    display.pixel(y + aux_col, x + 20, 200)

    display.show()
    time.sleep_ms(1000)