The sensor is connected to ESP8266 on the I2C interface. ESP8266 polls the sensor and sends this on data collector (RaspberryPi).
It is extremely important to me to achieve the greatest possible number of computation in a second as quality of the obtained data for later processing depends on it.
HMC5983 supports the I2C interface in the Standart, Fast and High-speed mode. But NodeMCU I2C Module support only i2c.SLOW speed
common I²C bus speeds are the 100 kbit/s standard mode and the 10 kbit/s low-speed mode https://en.wikipedia.org/wiki/I%C2%B2C
Then I connected HMC5983 directly to RaspberryPi via I2C I could achieve about 500 measurement per second (by monitoring DRDY interput pin) in single-measurement mode and 200 measurement per second in continuos-measurement mode (with Data Output Rate at 220 Hz - all rigth). The programm was written on Python, her its code:
import smbus #for i2c use
bus = smbus.SMBus(1) #use i2c port 1 on Rasspberry Pi
addr = 0x1e #address HMC5983 0x1E
bus.write_byte_data(addr,0x00,0b00011100) #Write to CRA Speed 220Hz
bus.write_byte_data(addr,0x01,0b00100000) #Write to CRB Gain 660 +-2.5Ga 1.52mG/Lsb
print "Start measuring.....
while True: #if we need infinity cycle
bus.write_byte_data(addr,0x02,0b00000001) #Write to Mode single-measurement mode
while bus.read_byte_data(addr,0x09) == 0b11: #Wait RDY in Status Register
data = bus.read_i2c_block_data(addr,0x03,6)#Take data from data registers
#convert three 16-bit 2`s compliment hex value to dec values and assign x,y,z
x = data*256+data
if x > 32767 :
x -= 65536
y = data*256+data
if y > 32767 :
y -= 65536
z = data*256+data
if z > 32767 :
z -= 65536
print "X=",x, "\tY=",y, "\tZ=",z
When I connected HMC5983 to ESP8266, I could achieve only about 140 computation a second in the mode of single computation...
----------THIS IS FOR SINGLE-MEASUREMENT MODE-------------
i2c.setup(id, sda, scl, i2c.SLOW)
-- reads 6byte from the sensor
i2c.address(id, dev_addr, i2c.RECEIVER)
data = i2c.read(id, 6)
i2c.address(id, dev_addr, i2c.TRANSMITTER)
id = 0
i2c = i2c
dev_addr = 0x1e
set_reg(0x00,0x1c) --set speed 220Hz
set_reg(0x01,0x20) --set gain
while true do
set_reg(0x02,0x01) --single-measurement mode
while(gpio.read(drdyn_pin) == 1) do
data = read_axis()
After that I configured the sensor in the continuos-measurement mode and received the same 200 measurement per second.
Whether operation of the I2C interface in NodeMCU at high speeds is possible? Somebody can offer how to try to accelerate inquiry of the sensor?