Hi,
First of all, I apologize if I’m making a silly mistake here. I purchased the a micro bit, a weatherbit kit, and a few additional Qwiic I2C Sensors to connect to the weatherbit.
I’ve come to understand that I can program the microbit from MakeCode or another coding environment like Arduino IDE. I’d like to stay in MakeCode to avoid having to translate existing MakeCode functions for the weather sensors. However, I can’t seem to find a sample project using the i2c read/write functions in makecode and my code (below) isn’t working. Sample code I’ve found is all written in Arduino IDE with arduino functions. I’ve been able to get the sensor to work by programming the microbit with arduino IDE, so I know the sensor is functioning.
Long story short, my MakeCode is below in python, and here’s a link to the sensor datasheet that explains its I2C communication.
As far as I can tell, to configure the sensor I need to write to 7-bit address 72 (48h), register 0 (00h) with the it’s settings data separated into two 8bit numbers: 19 and 0 (00010011 00000000b). I then need to read two 8-bit numbers back. However, the read function just returns 0 at the moment.
Thank you in advance for any pointers,
James
pins.i2c_write_number(72, 0, NumberFormat.UINT8_LE,True) # Writetoaddress72 (48h) register0
pins.i2c_write_number(72, 0, NumberFormat.UINT8_LE,True) # Write sensor settings (Least Significant Byte) (00000000b)
pins.i2c_write_number(72, 19, NumberFormat.UINT8_LE,False) # Write sensor settings (MSB) (00010011b)
def on_forever():
pins.i2c_write_number(72,4,NumberFormat.INT8_LE) # point to address 72 (48h) register 04h
pause(100)
data = pins.i2c_read_buffer(72,2) # read two bytes
data1 = helpers.buffer_to_array(data, NumberFormat.INT8_LE)
print(data1)
pause(1000)
basic.forever(on_forever)