Replies: 1 comment 1 reply
-
If you print a bytearray, values that represent an Ascii character are printed as such so '`' is the single byte with the value 96 or 0x60, which is the right value of the chip id. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
MicroPython v1.22.0 on 2023-12-27; ESP module with ESP8266
Hardware is a wemos D1 mini connected via I2C to a Bosch BME280 dev board from Adafruit.
I didn't post a picture of the connections because I'm certain they are correct, and the I2C.scan() function works correctly. I have also gotten reasonable temperature, humidity, and pressure data from this hardware by using a BME280.py module and a python code sample I downloaded from https://RandomNerdTutorials.com, so the hardware works if the code is correct.
I'm trying to learn how to do i2c bus transactions on Micropython by just trying to read the chip id of the BME280. The Device address is 0x77 and the ID register is 0xD0. The chip id is supposed to be 0x60. My code is
'''py
from machine import Pin, I2C
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000)
i2c.writeto(0x77, bytearray([0xD0]))
chip_id = i2c.readfrom(0x77, 1)
print(chip_id)
'''
The result is
'''py
b'`'
'''
which is clearly wrong.
I have also tried
'''py
from machine import Pin, I2C
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000)
i2c.writeto(0x77, bytearray([0xD0]))
chip_id = i2c.readfrom_mem(0x77, 0xD0, 8)
print(chip_id)
'''
The result is
'''py
b'`\x00\x00\x00\x00\x00\x00\x00',
'''
which is also clearly wrong.
Questions are:
Beta Was this translation helpful? Give feedback.
All reactions