🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Any updates on the mpu6886?

    Scheduled Pinned Locked Moved M5Stick V
    8 Posts 6 Posters 21.5k Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • X Offline
      Xeon
      last edited by

      Can this be used somehow?
      i haven't found any examples.

      The war of 1 and 0 draws ever closer.
      everyday i work to become a cyborg.

      S 1 Reply Last reply Reply Quote 0
      • S Offline
        staberas @Xeon
        last edited by

        @xeon sorry for resurrecting old post, i had the same problem, i currently close getting data from the IMU

        1 Reply Last reply Reply Quote 0
        • S Offline
          staberas
          last edited by

          done, used party code from anoken who sourced it from the arduino version , i clean up and updated it

          import image
          import lcd
          import sensor
          import sys
          import time
          import utime
          from board import board_info
          import KPU as kpu
          from Maix import GPIO
          from fpioa_manager import *
          from pmu import axp192 
          from machine import I2C
          #pmu = axp192() - breaks IMU data -
          #pmu.enablePMICSleepMode(True) - breaks IMU data -
          
          i2c = I2C(I2C.I2C0, freq=400000, scl=28, sda=29)
          #devices = i2c.scan()
          lcd.init()
          
          # IMU6866 define
          MPU6886_ADDRESS=0x68
          MPU6886_WHOAMI=0x75
          MPU6886_ACCEL_INTEL_CTRL=0x69
          MPU6886_SMPLRT_DIV=0x19
          MPU6886_INT_PIN_CFG=0x37
          MPU6886_INT_ENABLE=0x38
          MPU6886_ACCEL_XOUT_H=0x3B
          MPU6886_TEMP_OUT_H=0x41
          MPU6886_GYRO_XOUT_H=0x43
          MPU6886_USER_CTRL= 0x6A
          MPU6886_PWR_MGMT_1=0x6B
          MPU6886_PWR_MGMT_2=0x6C
          MPU6886_CONFIG=0x1A
          MPU6886_GYRO_CONFIG=0x1B
          MPU6886_ACCEL_CONFIG=0x1C
          MPU6886_ACCEL_CONFIG2=0x1D
          MPU6886_FIFO_EN=0x23
          
          # IMU6866 Initialize
          def write_i2c(address, value):
          	i2c.writeto_mem(MPU6886_ADDRESS, address, bytearray([value]))
          	time.sleep_ms(10)
          
          write_i2c(MPU6886_PWR_MGMT_1, 0x00)
          write_i2c(MPU6886_PWR_MGMT_1, 0x01<<7)
          write_i2c(MPU6886_PWR_MGMT_1,0x01<<0)
          write_i2c(MPU6886_ACCEL_CONFIG,0x10)
          write_i2c(MPU6886_GYRO_CONFIG,0x18)
          write_i2c(MPU6886_CONFIG,0x01)
          write_i2c(MPU6886_SMPLRT_DIV,0x05)
          write_i2c(MPU6886_INT_ENABLE,0x00)
          write_i2c(MPU6886_ACCEL_CONFIG2,0x00)
          write_i2c(MPU6886_USER_CTRL,0x00)
          write_i2c(MPU6886_FIFO_EN,0x00)
          write_i2c(MPU6886_INT_PIN_CFG,0x22)
          write_i2c(MPU6886_INT_ENABLE,0x01)
          
          # Read IMU6866 and Scaling
          def read_imu():
          	aRes=255/4096/2
          	gRes = 2000.0/32768.0
          	offset=128
          	accel = i2c.readfrom_mem(MPU6886_ADDRESS, MPU6886_ACCEL_XOUT_H, 6)
          	accel_x = (accel[0]<<8|accel[1])
          	accel_y = (accel[2]<<8|accel[3])
          	accel_z = (accel[4]<<8|accel[5])
          	if accel_x>32768:
          		accel_x=accel_x-65536
          	if accel_y>32768:
          		accel_y=accel_y-65536
          	if accel_z>32768:
          		accel_z=accel_z-65536
          	ax=int(accel_x*aRes+offset)
          	if ax<0: ax=0
          	if ax>255: ax=255
          	ay=int(accel_y*aRes+offset)
          	if ay<0: ay=0
          	if ay>255: ay=255
          	az=int(accel_z*aRes+offset)
          	if az<0: az=0
          	if az>255: az=255
          	accel_array = [ax,ay,az]
          	gyro = i2c.readfrom_mem(MPU6886_ADDRESS, MPU6886_GYRO_XOUT_H, 6)
          	gyro_x = (gyro[0]<<8|gyro[1])
          	gyro_y = (gyro[2]<<8|gyro[3])
          	gyro_z = (gyro[4]<<8|gyro[5])
          	if gyro_x>32768:
          		gyro_x=gyro_x-65536
          	if gyro_y>32768:
          		gyro_y=gyro_y-65536
          	if gyro_z>32768:
          		gyro_z=gyro_z-65536
          	gx=int(gyro_x*gRes+offset)
          	if gx<0: gx=0
          	if gx>255: gx=255
          	gy=int(gyro_y*gRes+offset)
          	if gy<0: gy=0
          	if gy>255: gy=255
          	gz=int(gyro_x*gRes+offset)
          	if gz<0: gz=0
          	if gz>255: gz=255
          	gyro_array = [gx,gy,gz]
          	return accel_array, gyro_array
          
          
          lcd.rotation(2)
          task = kpu.load("/sd/7118109ae3ea570e_mbnet10_quant.kmodel")#change model
          labels=["seadog","Borbya","mermaid","Villo"] #change names.
          sensor.reset()
          sensor.set_pixformat(sensor.RGB565)
          sensor.set_framesize(sensor.QVGA)
          sensor.set_windowing((224, 224))
          sensor.run(1)
          lcd.clear()
          while(True):
          	accel_array,gyro_array = read_imu()
          	img = sensor.snapshot()
          	fmap = kpu.forward(task,img)
          	plist=fmap[:]
          	pmax=max(plist)
          	#lcd.draw_string(40, 20, str(accel_array))
          	#lcd.draw_string(10, 40, str(gyro_array))
          	max_index=plist.index(pmax)
          	if pmax > 0.95:
          		#lcd.draw_string(40, 60, "Accu:%.2f Type:%s"%(pmax, labels[max_index].strip()))  #20-59,130-136,55-30 [side view] 100-130,130-136,9-20 [top view] 
                  #the values are from 0 to 255 
          		if accel_array[0] > 20 and accel_array[0] < 59 and accel_array[1] > 130 and accel_array[1] < 136 and accel_array[2] > 30 and accel_array[2] < 55:
          			img.draw_image(image.Image("/sd/view2.jpg"), 50, 50,x_scale=0.5,y_scale=0.5,mask=image.Image("/sd/view2t.jpg"))
          		if accel_array[0] > 60  and accel_array[0] < 130 and accel_array[1] > 130  and accel_array[1] < 137 and accel_array[2] > 8 and accel_array[2] < 20:
          			img.draw_image(image.Image("/sd/view1.jpg"), 50, 50,x_scale=0.5,y_scale=0.5,mask=image.Image("/sd/view1t.jpg"))
          	a = lcd.display(img)
          a = kpu.deinit(task)
          sys.exit()
          
          B A P 3 Replies Last reply Reply Quote 1
          • B Offline
            Bryam @staberas
            last edited by

            @staberas Como lo instalas no me reconoce si creo un ide en arduino

            S 1 Reply Last reply Reply Quote 0
            • S Offline
              staberas @Bryam
              last edited by

              @bryam
              The code above is for the maixpy (micropython) not arduino

              1 Reply Last reply Reply Quote 0
              • A Offline
                Alisson Brito @staberas
                last edited by

                @staberas I'm trying to run your example on the M5Stick V but I have a error message when trying to write_i2c for the first time. The error is: "OSError: [Errno 5] EIO". Do you know what does it means?

                1 Reply Last reply Reply Quote 0
                • m5stackM Online
                  m5stack
                  last edited by

                  you could find the MPU6886 example in this page:

                  https://docs.m5stack.com/#/en/related_documents/M5StickV-Maixpy

                  1 Reply Last reply Reply Quote 0
                  • P Offline
                    purpledread @staberas
                    last edited by

                    @staberas

                    This code was very helpful. Thanks!

                    I tried adding temperature as well:

                    tmp = i2c.readfrom_mem(MPU6886_ADDRESS, MPU6886_TEMP_OUT_H, 2)
                    temp = (tmp[0]<<8|tmp[1])
                    temp = (float(temp) / 326.8) + 25.0;
                    

                    I'm getting temps of 40.5C (105F). Am I doing something wrong or is this temperature the CPU temp?

                    Thanks,
                    /Chris

                    1 Reply Last reply Reply Quote 0

                    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                    With your input, this post could be even better 💗

                    Register Login
                    • First post
                      Last post