示例#1
0
    def acceleration(self):
        try:
            mpu = mpu6050.MPU(self.i2c)
            mpu.wake()
            acceleration_resultY = mpu.pitchY()
            print (acceleration_resultY)
            acceleration_resultX = mpu.pitchX()
            print (acceleration_resultX)
            return acceleration_resultX, acceleration_resultY

        except:
            print("Acceleration sensor not connected")
            return "Not connected"
示例#2
0
micropython.alloc_emergency_exception_buf(100)

# Pantalla oled
rst = Pin(16, Pin.OUT)
rst.value(1)
scl = Pin(15, Pin.OUT, Pin.PULL_UP)
sda = Pin(4, Pin.OUT, Pin.PULL_UP)
i2c = I2C(scl=scl, sda=sda, freq=450000)
oled = ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3c)

oled.fill(0)
oled.text('Iniciando', 0, 0)
oled.show()

#objeto MPU
mpu = mpu6050.MPU()


#objeto UART/GPS
gps = UART(2, 115200)
gps.init(9600,bits=8,parity=None,stop=1,tx=17,rx=5)
oled.text('Gps...OK', 0, 10)
oled.show()
#objeto SPI
Pin(18,Pin.OUT,value=1) #para desactivar LoRa
#spi = SPI(sck=Pin(23),miso=Pin(12),mosi=Pin(13))
# trucazo (el pin 12 da problemas)
spi = SPI(sck=Pin(23),miso=Pin(14),mosi=Pin(13))

#objeto SD
sd = sdcard.SDCard(spi, Pin(2,Pin.OUT))
示例#3
0
import machine, time, max7219, mpu6050

spi = machine.SPI(-1,
                  10000000,
                  miso=machine.Pin(2),
                  mosi=machine.Pin(13),
                  sck=machine.Pin(14))
display = max7219.Matrix8x8(spi, machine.Pin(12))
display.fill(0)
display.brightness(1)
display.show()

m = mpu6050.MPU(scl=22, sda=21, intr=16, d=display)
while not m.calibrated:
    m.calibrate()

acx, acy, acz, seq, gx, gy, gz = 0, 0, 0, 0, 0, 0, 0

starttime = int(time.time())

while True:

    try:
        acx, acy, acz, seq, gx, gy, gz = m.read_sensors_scaled()
    except:
        pass
    if sum([abs(x) for x in [acx, acy, acz, gx, gy, gz]]) > 50:
        starttime = int(time.time())

    seconds = int(time.time()) - starttime
    hrs = '%02d' % (seconds / 3600)
示例#4
0
import time
import mpu6050

print("start mpu...")
mpu = mpu6050.MPU(sda=4, scl=5, led=2)

while (True):
    values = mpu.read_position()
    print(
        str(values[1][0]) + "," + str(values[1][1]) + "," + str(values[1][2]))
    time.sleep(0.2)