Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    GY-87 micropython library

    Scheduled Pinned Locked Moved Discussion
    micropythongy-80lopy4
    32 Posts 4 Posters 5.1k Views 4 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.
    • robert-hhR Offline
      robert-hh @tttadam
      last edited by

      @tttadam 119 is the address of the BMP180. I have a driver for that at https://github.com/robert-hh/BMP085_BMP180. Do not be confused that the file is called bmp085.py. It cintains the classes for both devices. In fact, they behave identical.

      1 Reply Last reply Reply Quote 1
      • robert-hhR Offline
        robert-hh @tttadam
        last edited by

        @tttadam 104 should be the address of the MPU6050 device,
        The hmc5883l device address is told to be 30 decimal. If the SI7021 is also connected, you should get four I2C addresses.
        So when connecting the GY-87, you should see that. By the way, the title of your post says GY-80, but you link to the GY87.

        T 2 Replies Last reply Reply Quote 1
        • T Offline
          tttadam @robert-hh
          last edited by

          @robert-hh I took some picture of the wiring.
          Sorry for the confusion, I will fix the title. The sensor what I have is GY-87. This is where I bought it.

          1 Reply Last reply Reply Quote 0
          • T Offline
            tttadam @robert-hh
            last edited by

            @robert-hh Thank you for the library, it is working fine! :)
            I am checking out something fo MPU6050
            But I am still not sure where is the third sensor. mybe the gy87 is damaged?

            robert-hhR 1 Reply Last reply Reply Quote 0
            • robert-hhR Offline
              robert-hh @tttadam
              last edited by

              @tttadam I looked for MPU6050 libraries. What I found is for RasPi, but it should be easy to adapt them by replacing the calls for I2C send and receive.
              About the third sensor HMC5883L. Acording to the data sheet there is no enable pin. The DRDY signal could come from that chip. You should check whether you init the I2C bust at a baudrate <= 400000, because that is the max rate mentioned in the data sheet.

              T 1 Reply Last reply Reply Quote 0
              • T Offline
                tttadam @robert-hh
                last edited by tttadam

                @robert-hh
                First of all sorry for the long delay.
                I just checked, and seems like no, the last sensor didn't show up on i2c.scan()
                I checked the documentation and the MPU6050 is has some kind of mode/option, where it's connected to other I2c devices, and gather data from them. Maybe the compass is connected to the mpu6050?

                >>> from machine import I2C
                >>> i2c = I2C(0, I2C.MASTER, baudrate=400000)
                >>> i2c.scan()
                [64, 104, 119]
                >>>
                
                robert-hhR 1 Reply Last reply Reply Quote 0
                • robert-hhR Offline
                  robert-hh @tttadam
                  last edited by

                  @tttadam I justz received a sample of the board that you have linked. Three observations:

                  • the HMC5883 does not show up in the i2c.scan(), even if the address is ping'ed.
                  • the bmp180 returns nonsense-values.
                  • the pull-up resistor values on the board are pretty low,
                    effectively 1.1kOhm. I will look tonight into the signals with an oscilloscope to verify the signal quality.

                  So all-in-all, the board might just be crap.

                  T 1 Reply Last reply Reply Quote 1
                  • T Offline
                    tttadam @robert-hh
                    last edited by

                    @robert-hh ohhh, I didn't even thought about that. But could be. Can you recommend some other sensor?
                    pytrack has built-in gyro. what i need pressure, and compass.
                    (The weather ballon will have a camera, and when it took a picture, I would like to know the direction)

                    robert-hhR 1 Reply Last reply Reply Quote 0
                    • robert-hhR Offline
                      robert-hh @tttadam
                      last edited by

                      @tttadam So, looking at the device and the wiring it seems clear why the HMC5883 is not visible in the scan: it is connected to the MBU6050 slave interface. Still, according to the MPU6050 data sheet, it should be visible, because at start-up the MPU6050 connects the main I2C interface to the aux interface.
                      The I2C signals are fine.

                      However, on the board I have the BMP180 is broken. The temperature sensor always returns 229.3°C. At least that helped me to find a signed/unsigned bug in my driver.

                      T 1 Reply Last reply Reply Quote 0
                      • T Offline
                        tttadam @robert-hh
                        last edited by

                        @robert-hh said in GY-87 micropython library:

                        BMP180

                        I just checked the bmp18. It's seems something off with the altitude...
                        (1028 is the current QNH in Budapest)

                        >>> bmp.sealevel = 1028
                        >>> bmp.altitude
                        51.46274
                        >>> bmp.pressure
                        1021.34
                        >>> bmp.temperature
                        24.2
                        >>> si7021.readTemp()
                        22.92749
                        >>> my_gps.altitude
                        120.3
                        

                        So you have any guess how Can I get the compass data?

                        robert-hhR 2 Replies Last reply Reply Quote 0
                        • robert-hhR Offline
                          robert-hh @tttadam
                          last edited by

                          @tttadam The altitude is calculated from the actual pressure and what you enter as sea level pressure, roughly 8.5m/hPa. You can see it in the python script.
                          The compass chip should be available when the I2C-bus is set to pass-through. I'm trying it at the moment.

                          1 Reply Last reply Reply Quote 0
                          • robert-hhR Offline
                            robert-hh @tttadam
                            last edited by

                            @tttadam So I found a way to talk to the compass, with the following sequence:

                            from machine import I2C
                            i2c=I2C()
                            i2c.writeto_mem(104, 107, 128) # reset MPU6050
                            i2c.writeto_mem(104, 107, 0) # disable sleep
                            i2c.writeto_mem(104, 55, 2)   # enable I2C passthru
                            i2c.scan()
                            

                            The scan should show you another I2C address. In my case it is 13, which deviates from the HMV5883 data sheet.

                            T 1 Reply Last reply Reply Quote 0
                            • T Offline
                              tttadam @robert-hh
                              last edited by

                              @robert-hh It's working for me too! :)
                              Awsome! :)
                              Now I just need to find a correct library for it.
                              I will start with this

                              Can you give me some explonation what happend?
                              What your overall expression of the board?

                              robert-hhR 1 Reply Last reply Reply Quote 0
                              • robert-hhR Offline
                                robert-hh @tttadam
                                last edited by

                                @tttadam When you do the i2c.scan(), which address is reported for the HMC5883? It puzzles me that my device reports 13 instead of 30, which is the address in all examples.
                                Besides that, I have the impression that in normal operation the HMC5883 is controlled by the MCU6050 for its own purpose. So you might get the information you need through the MCU6050.
                                If you ask me about what I did to find that way: I looked at the circuit, read the data sheets and looked at some code examples for the MCU6050.

                                T 1 Reply Last reply Reply Quote 0
                                • T Offline
                                  tttadam @robert-hh
                                  last edited by

                                  @robert-hh

                                  This is what I see. So same for me.

                                  >>> from machine import I2C
                                  >>> i2c = I2C(1)
                                  >>> i2c.scan()
                                  [64, 104, 119]
                                  >>> i2c.writeto_mem(104, 107, 128) # reset MPU6050
                                  >>> i2c.writeto_mem(104, 107, 0) # disable sleep
                                  >>> i2c.writeto_mem(104, 55, 2)   # enable I2C passthru
                                  >>> i2c.scan()
                                  [13, 64, 104, 119]
                                  >>>
                                  
                                  
                                  robert-hhR 3 Replies Last reply Reply Quote 0
                                  • robert-hhR Offline
                                    robert-hh @tttadam
                                    last edited by

                                    @tttadam So let's see if that is a bug or an intended address trabslation (but why?)

                                    1 Reply Last reply Reply Quote 0
                                    • robert-hhR Offline
                                      robert-hh @tttadam
                                      last edited by

                                      @tttadam A short google search gave an answer:
                                      The chip in the board is not a HMC5883, but a QMC5883. See https://github.com/nodemcu/nodemcu-firmware/issues/2187
                                      The QMC5883 server for the same purpose, but has different programming interface.

                                      1 Reply Last reply Reply Quote 0
                                      • robert-hhR Offline
                                        robert-hh @tttadam
                                        last edited by robert-hh

                                        @tttadam I found a RasPi driver for the QMC5883 and adapted it to pycom MP:

                                        #
                                        # ported from http://nobytes.blogspot.com/2018/03/qmc5883-magnetic-field-sensor.html
                                        #
                                        
                                        import time
                                        import struct
                                        from machine import idle
                                        
                                        class QMC5883:
                                            #Default I2C address
                                            ADDR = 0x0D
                                        
                                            #QMC5883 = Register = numbers
                                            X_LSB = 0
                                            X_MSB = 1
                                            Y_LSB = 2
                                            Y_MSB = 3
                                            Z_LSB = 4
                                            Z_MSB = 5
                                            STATUS = 6
                                            T_LSB = 7
                                            T_MSB = 8
                                            CONFIG = 9
                                            CONFIG2 = 10
                                            RESET = 11
                                            CHIP_ID = 13
                                        
                                            #Bit values for the STATUS register
                                            STATUS_DRDY = 1
                                            STATUS_OVL = 2
                                            STATUS_DOR = 4
                                        
                                            #Oversampling values for the CONFIG register
                                            MC5883L_CONFIG_OS512 = 0b00000000
                                            CONFIG_OS256 = 0b01000000
                                            CONFIG_OS128 = 0b10000000
                                            CONFIG_OS64  = 0b11000000
                                        
                                            #Range values for the CONFIG register
                                            CONFIG_2GAUSS = 0b00000000
                                            CONFIG_8GAUSS = 0b00010000
                                        
                                            #Rate values for the CONFIG register
                                            CONFIG_10HZ = 0b00000000
                                            CONFIG_50HZ = 0b00000100
                                            CONFIG_100HZ = 0b00001000
                                            CONFIG_200HZ = 0b00001100
                                        
                                            #Mode values for the CONFIG register
                                            CONFIG_STANDBY = 0b00000000
                                            CONFIG_CONT = 0b00000001
                                        
                                        
                                            def __init__(self, i2c):
                                                self.i2c = i2c
                                                self.oversampling = QMC5883.CONFIG_OS64
                                                self.range = QMC5883.CONFIG_2GAUSS
                                                self.rate = QMC5883.CONFIG_100HZ
                                                self.mode = QMC5883.CONFIG_CONT
                                                self.reset()
                                        
                                            def reconfig(self):
                                                print("{0:b}".format(self.oversampling | self.range | self.rate | self.mode))
                                                self.i2c.writeto_mem(QMC5883.ADDR, QMC5883.CONFIG, self.oversampling | self.range | self.rate | self.mode);
                                        
                                            def reset(self):
                                                self.i2c.writeto_mem(QMC5883.ADDR, QMC5883.RESET, 0x01)
                                                time.sleep(0.1)
                                                self.reconfig()
                                                time.sleep(0.01)
                                        
                                            def setOversampling(self, x):
                                                self.oversampling = x
                                                self.reconfig()
                                        
                                            def setRange(x):
                                                self.range = x
                                                self.reconfig()
                                        
                                            def setSamplingRate(self, x):
                                                self.rate = x
                                                self.reconfig()
                                        
                                            def ready(self):
                                                status = self.i2c.readfrom_mem(QMC5883.ADDR, QMC5883.STATUS, 1)[0]
                                        
                                                # prevent hanging up here.
                                                # Happens when reading less bytes then then all 3 axis and will end up in a loop.
                                                # So, return any data but avoid the loop.
                                                if (status == QMC5883.STATUS_DOR):
                                                    print("fail")
                                                    return QMC5883.STATUS_DRDY
                                        
                                                return status & QMC5883.STATUS_DRDY
                                        
                                            def readRaw(self):
                                                while not self.ready():
                                                    idle()
                                                    pass
                                        
                                                # Python performs a wrong casting at read_i2c_block_data.
                                                # The filled buffer has to be onverted afterwards by mpdule Struct
                                                register = self.i2c.readfrom_mem(QMC5883.ADDR, QMC5883.X_LSB, 9);
                                        
                                                # Convert the axis values to signed Short before returning
                                                x, y, z, status, t = struct.unpack('<hhhBh', register)
                                        
                                                return (x, y, z, t)
                                        

                                        and a short test code:

                                        import time
                                        
                                        from qmc5883 import QMC5883
                                        
                                        from machine import I2C
                                        i2c=I2C()
                                        i2c.writeto_mem(104, 107, 128) # reset MPU6050
                                        i2c.writeto_mem(104, 107, 0) # disable sleep
                                        i2c.writeto_mem(104, 55, 2)   # enable I2C passthru
                                        
                                        print(i2c.scan())
                                        time.sleep(1)
                                        
                                        qmc = QMC5883(i2c)
                                        
                                        while True:
                                            print(qmc.readRaw())
                                            time.sleep(1)
                                        
                                        T 2 Replies Last reply Reply Quote 0
                                        • T Offline
                                          tttadam @robert-hh
                                          last edited by

                                          @robert-hh thank you, it's looks useful, but after some time it's produce an OSError. Line 17 in my code is this : print(qmc.readRaw())
                                          and the line 99 is this. register = self.i2c.readfrom_mem(QMC5883.ADDR, QMC5883.X_LSB, 9)
                                          I think there were an ; which is not needed.
                                          But something else is still not alright. I didn't find it yet.

                                          (6967, -4882, -7620, -1943)
                                          (4742, -7337, -7950, -1923)
                                          Traceback (most recent call last):
                                            File "main2.py", line 17, in <module>
                                            File "/flash/lib/qmc5883.py", line 99, in readRaw
                                          OSError: I2C bus error
                                          
                                          robert-hhR 1 Reply Last reply Reply Quote 0
                                          • T Offline
                                            tttadam @robert-hh
                                            last edited by

                                            @robert-hh

                                            This is the error what i get now. Maybe tomorrow with fresh eye I will see something :)

                                            [13, 64, 104, 119]
                                            11001001
                                            Traceback (most recent call last):
                                              File "main2.py", line 17, in <module>
                                              File "/flash/lib/qmc5883.py", line 95, in readRaw
                                              File "/flash/lib/qmc5883.py", line 81, in ready
                                            OSError: I2C bus error
                                            
                                            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
                                            • 1
                                            • 2
                                            • 2 / 2
                                            • First post
                                              Last post

                                            Pycom on Twitter

                                            Pycom