comparing hex code.

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
sim222
Posts: 20
Joined: Wed Nov 27, 2019 12:04 am

comparing hex code.

Post by sim222 » Tue Mar 23, 2021 1:50 am

Thanks guys,

My purpose is to convert the library corded by Python to MicroPython.
And found the article about it in this forum.
It worked well!!



Hi guys,
Allway thanks for your valuable comment on this forum!!

I am a newbie for this embedded system instead am a hardware guy.
Am trying to develop a pressure system using a pyboard and BMP388 connected through i2c.

Have being struggled to code.

1. can't compare the value getting from BMP388(at this time 0x50 for ID, for example) with 0x50 Constance.
tried to convert binascii class for it..
I think I missed some thing for it since my sample code working well with this cord:

chip_id=self.bmp3_get_regs(0x00,1)[0] # call other method which is just read i2c.

if (chip_id !=0x50):
print('chip id error!')

2. What's the difference between .readfrom and readfrom_mem?
for the resister 0x00, only readfrom_mem is working.
However, other resisters are working well with readfrom and readfrom_mem as well.


>>>
>>> from machine import I2C
>>> i2c=I2C(2)
>>> i2c.readfrom_mem(118,0x00,1)
b'P'
>>> i2c.readfrom_mem(118,0x00,1)==0x50
False
>>> i2c.readfrom(118,0x00,1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 22] EINVAL
>>> i2c.readfrom(118,0x00)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 22] EINVAL
>>> i2c.readfrom(118,0x01)
b'\x10'
>>> i2c.readfrom(118,0x02)
b'\x00\x00'
>>>

Post Reply