Unable to write to MPU6050 Register 0x1C

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
pmulvey
Posts: 45
Joined: Sun Jul 29, 2018 8:12 am
Location: Athlone, Ireland

Unable to write to MPU6050 Register 0x1C

Post by pmulvey » Sat May 11, 2019 4:41 pm

I am trying to change the range on the accelerometer. This is done by setting bits in 0x1C. I modified the class accel() and added this piece of code. I had the register lines in the __init__ part initially and just moved it here for further debugging. The print statement always returns zero.

Code: Select all

    def get_AcX(self):
        ar = 0x18
        self.iic.writeto_mem(self.addr, 0x1C, bytearray(ar))
        print(self.iic.readfrom_mem(self.addr, 0x1C, 1))
        print ("--------------")
        raw_ints = self.get_raw_values()    
        return self.bytes_toint(raw_ints[0], raw_ints[1])
Paul Mulvey

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Unable to write to MPU6050 Register 0x1C

Post by Roberthh » Sat May 11, 2019 6:35 pm

bytearray(0x1c) creates a bytearray of 28 zero bytes.
You could write for instance:
ar=b'\x1c'
self.iic.writeto_mem(self.addr, 0x1C, bytearray(ar))

pmulvey
Posts: 45
Joined: Sun Jul 29, 2018 8:12 am
Location: Athlone, Ireland

Re: Unable to write to MPU6050 Register 0x1C

Post by pmulvey » Sat May 11, 2019 7:41 pm

Robert,

That works. I'm relatively new to micropython and am inclined to do too much copy and paste rather than being systematic about learning all aspects of the language. This is a good example of that. Thank you for your guidance.
Paul Mulvey

Post Reply