I'm trying to read data from the MMC34160PJ magnetometer using the Raspberry Pi 4. However, I'm pretty stuck as to how I can do it as there's seemingly no example code or library for it. I have been able to use the magnetometer with an Arduino, but I'm struggling when trying to port the code over to the RPi using SMBus2 for Python.
I have tried reading the quick start guide on 2.3 from this manual: https://download.kamami.pl/p566664-pmod_cmps2_rm.pdf but I don't understand what commands to use to follow these instructions. I also tried following the Arduino library/Arduino example code https://www.arduinolibraries.info/libraries/mmc34160-pj with little to no luck as that seems to be using a completely different structure when working with I2C.
I'd appreciate it if someone was able to shed some light on how I can achieve the function described in the I2C pseudo code in the datasheet. I have tried writing some code, but it's really just been a shot in the dark and it seems a bit complex judging by the Arduino code.
To be a bit more precise, I'm wondering how I can do the following (These are steps from the datasheet for the sensor):
- Provide a START condition and call the device ID with a write bit. Ref datasheet pseudo code:
I2CBegin(0xA0); //device ID 0x30 with a write (0) bit)
- Wait to receive an ACK from the Pmod CMPS2.
- Send the Internal Control Register 0 (address 0x07) as the register to communicate with. Ref datasheet pseudo code:
I2CWrite(0x07); //address 0x07 corresponds to Control Register 0
. 4. Cycle the SCL line to receive the data bits from the X, Y, and Z registers in the SDA line, providing an ACK between each data byte. The Pmod CMPS2 address pointer automatically moves to each consecutive byte. End the communication by sending a NACK followed by a STOP command. Ref datasheet pseudo code:
I2CReadMultiple(6); //read six bytes, sending an ACK to the slave device betwe en each byte received and a NACK after the last byte
If i understand how I can do these operations, I think I'm much closer to being able to get data from the sensor.
Thank you for any guidance you may provide.