qmc5883 on esp32

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
sbelin
Posts: 4
Joined: Tue Jun 04, 2019 10:19 am

qmc5883 on esp32

Post by sbelin » Tue Jun 04, 2019 10:28 am

Hello,

I am looking for a micropython module to use the qmc5883 sensor with an esp32 card (M5stack) on the i2c port.
Does anyone use this sensor?
Thank you in advance,
Best regards,

Stéphane

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

Re: qmc5883 on esp32

Post by Roberthh » Tue Jun 04, 2019 11:11 am

I have a simple driver here: https://github.com/robert-hh/QMC5883
It is written for the Pycom variant of MicroPython. So you have to adapt the calls to i2c.writeto_mem(), which require a buffer as third parameter instead optional an integer constant.

sbelin
Posts: 4
Joined: Tue Jun 04, 2019 10:19 am

Re: qmc5883 on esp32

Post by sbelin » Tue Jun 04, 2019 11:33 am

Thank you for your answer.
I have just tested your script.
The error message matches.
But I do not see how to modify your script ...
Thank you in advance,

Stéphane

Traceback (most recent call last):
   File "<stdin>", line 3, in <module>
   File "qmc5883.py", line 86, in __init__
   File "qmc5883.py", line 89, in reset
TypeError: object with required buffer protocol
  >
MicroPython ESP32_LoBo_v3.2.24 - 2018-09-06 on M5Stack with ESP32
Type "help ()" for more information.
>>>

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

Re: qmc5883 on esp32

Post by Roberthh » Tue Jun 04, 2019 11:45 am

try replacing these two methods;

Code: Select all

    
    def reset(self):
        self.i2c.writeto_mem(QMC5883.ADDR, QMC5883.RESET, bytes((0x01,)))
        time.sleep(0.1)
        self.reconfig()

    def reconfig(self):
        self.i2c.writeto_mem(QMC5883.ADDR, QMC5883.CONFIG,
                             bytes((self.oversampling | self.range |
                             self.rate | self.mode,)))
        time.sleep(0.01)
        self.i2c.writeto_mem(QMC5883.ADDR, QMC5883.CONFIG2,
                             bytes((QMC5883.CONFIG2_INT_DISABLE,)))
        time.sleep(0.01)

sbelin
Posts: 4
Joined: Tue Jun 04, 2019 10:19 am

Re: qmc5883 on esp32

Post by sbelin » Tue Jun 04, 2019 12:12 pm

It works!
Thank you.

Post Reply