Page 1 of 1

[SOLVED] I2C reliability reading second byte issue

Posted: Fri Sep 01, 2017 2:08 pm
by rpi_nerd
Been learning how to use i2c under Micropython. I've figured most of it out, but I have a frustrating issue with reliably receiving the second temperature data byte from my temperature sensor. I've even lowered the i2c frequency down to 1KHz and I'm still not receiving the second data byte occasionally.

I did a very similar configuration a while back under the Arduino IDE, and everything was rock-solid.

My configuration:
Wemos D1 Mini
DS1631+ i2c temp sensor (https://datasheets.maximintegrated.com/ ... DS1731.pdf)
4.7k pull-ups and a .1uF cap near the sensor

Code: Select all

import time
import machine
from machine import Pin, I2C

i2c = I2C(scl=Pin(5), sda=Pin(4), freq=1000) # pins d1 for clk and D2 for sda
time.sleep(2)
i2c.writeto(76,b'\x51') #set advanced temp sense to startup
	
def read_advanced_temp():
	i2c.writeto(76,b'\xAA')
	temp = i2c.readfrom(76,2)
	print(temp)
	
while True:
	time.sleep(3)
	read_advanced_temp()
		
	
a sample of the output:

Code: Select all

b'\x1a\xd0'
b'\x1b\x80'
b'\x1c0'
b'\x1c\xb0'
b'\x1c\xa0'

Re: I2C reliability reading second byte issue

Posted: Fri Sep 01, 2017 4:14 pm
by deshipu
The example output you showed has 2 bytes in every reading. It's just that one of those bytes happens to be 0x30, which python renders as "0" when you print the string. Maybe that is throwing you off?

Re: I2C reliability reading second byte issue

Posted: Fri Sep 01, 2017 4:21 pm
by rpi_nerd
Thanks for the explanation, I'm seeing it now, WebREPL is formatting those numbers as asii characters, got it.