[SOLVED] I2C reliability reading second byte issue

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
rpi_nerd
Posts: 20
Joined: Sat Jul 29, 2017 2:05 pm

[SOLVED] I2C reliability reading second byte issue

Post by rpi_nerd » Fri Sep 01, 2017 2:08 pm

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'
Last edited by rpi_nerd on Fri Sep 01, 2017 4:45 pm, edited 1 time in total.

User avatar
deshipu
Posts: 1348
Joined: Thu May 28, 2015 5:54 pm

Re: I2C reliability reading second byte issue

Post by deshipu » Fri Sep 01, 2017 4:14 pm

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?

rpi_nerd
Posts: 20
Joined: Sat Jul 29, 2017 2:05 pm

Re: I2C reliability reading second byte issue

Post by rpi_nerd » Fri Sep 01, 2017 4:21 pm

Thanks for the explanation, I'm seeing it now, WebREPL is formatting those numbers as asii characters, got it.

Post Reply