Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

[NP2]Communication with SHT15 through i2c bus doesn't work

I2C SHT1x

  • Please log in to reply
6 replies to this topic

#1 jiwonoh

jiwonoh

    Advanced Member

  • Members
  • PipPipPip
  • 42 posts

Posted 19 April 2013 - 08:15 AM

Dear   I tried to communicate with SHT15 from sensirion through I2C bus. My board is netduino plus 2 including SDA & SCL pin. I tested i2c example code like below:  

static I2CDevice Device;	   public static void Main()	    {		    	byte[] readBuffer = new byte[3];		    	byte[] writeTrans = new byte[1] { 0x03 };					   	I2CDevice.Configuration Configuration = new I2CDevice.Configuration(0x03, 100);		    	I2CDevice.I2CTransaction[] Transactions;					   	Device = new I2CDevice(Configuration);			while(true)		    	{			    		Thread.Sleep(1000);			    		I2CDevice.I2CWriteTransaction WriteTransaction = I2CDevice.CreateWriteTransaction(writeTrans);			    		I2CDevice.I2CReadTransaction ReadTransaction = I2CDevice.CreateReadTransaction(readBuffer);			    		Transactions = new I2CDevice.I2CTransaction[] { WriteTransaction };			    		int value = Device.Execute(Transactions, 100);			    		Debug.Print("ReadTransaction: " + value.ToString());	}	    } 

 

I changed Micro Framework from 4.2 ~ 4.3. Pullup resistor is set as 4.7k.

I also changed the platform to Netduino Plus 1(v4.2.0.1).

 

For checking wiring and sensor, I tested in arduino platform(Arduino Mega), and its connected pins are SDA & SDA. It works and can find signal in OSC.

 

I think SHT1x sensor is little bit different from other i2c based sensor. It use a byte as sum of byte(3bits) & command(5bits).

 

Is there anyone who secceed in communication between NP2 and SHT1x.

 

 

Thanks in advance, from Jiwon.

 



#2 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 19 April 2013 - 12:14 PM

This is because the SHT1x sensor is not I2C but rather an I2C "like" interface. I will post some code in short while.

#3 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 19 April 2013 - 01:35 PM

I have attached a class for the SHT1x series of Temp/Humd sensors.  This has been tested with both the SHT11 and SHT15 sensors.

 

To use this, I am using the following code (see class attached at the bottom of the post):

 

I've defined the following constants in my program class. These represent the Clock and Data pins for this sensor. Again this is not using I2C so you should not use the I2C pins.

// SHT1x Temp Sensor GPIOprivate static Cpu.Pin SHT1x_CLOCK = Pins.GPIO_PIN_D9;private static Cpu.Pin SHT1x_DATA = Pins.GPIO_PIN_D8;

Then I define the following static member (instance of the class)

// Create IO Provider and Interface for the SHT1x Temp Sensorpublic static SHT1x sht1x = new SHT1x(new SHT1x_GPIO_IOProvider(SHT1x_DATA, SHT1x_CLOCK));

Then, in your Main function (not within a loop) you will need to reset the sensor.  This is basically the initialization of the sensor.

// Soft-Reset the SHT1xif (sht1x.SoftReset()){    throw new Exception("Error while resetting SHT1x"); // Soft Reset returns True on error}// Set Temperature and Humidity to more accurate 14/12 bitif (sht1x.WriteStatusRegister((SHT1x.SHT1xSettings.NullFlag))){    throw new Exception("Error while writing status register SHT1x"); // WriteRegister returns True on error}

Then, to read the sensor... I do this within my while loop...

double Temperaturef = sht1x.ReadTemperature(SHT1x.SHT1xVDD_Voltages.VDD_5V, SHT1x.SHT1xTemperatureUnits.Fahrenheit);double Humidity = sht1x.ReadRelativeHumidity(SHT1x.SHT1xVDD_Voltages.VDD_5V);

You will see if you look at the class that I have properties to read both Fahrenheit and Celsius.

 

While I have not added a property for it and probably will in the future, you can also calculate Dew Point if you need to using the Temp and Humidity like so.

double Dewpoint = (((((Temperaturef - 32) / 1.8) - (14.55 + 0.114 * ((Temperaturef - 32) / 1.8)) * (1 - (0.01 * Humidity)) - System.Math.Pow(((2.5 + 0.007 * ((Temperaturef - 32) / 1.8)) * (1 - (0.01 * Humidity))), 3) - (15.9 + 0.117 * ((Temperaturef - 32) / 1.8)) * System.Math.Pow((1 - (0.01 * Humidity)), 14)) * 1.8) + 32);

I hope this gets you up and running.

Attached Files

  • Attached File  SHT1x.cs   16.43KB   31 downloads


#4 jiwonoh

jiwonoh

    Advanced Member

  • Members
  • PipPipPip
  • 42 posts

Posted 21 April 2013 - 04:18 AM

Dear Dave

 

When I reviewed the document of SHT15, it showed the keyword as "I2C" namely, so I confused that.

 

This time is first reviewing i2c protocol, so I could not make sure whether I am right or not.

 

Tomorrow morning I'll test it in my office and report how's it going.

 

Thanks too much

, from Jiwon.



#5 jiwonoh

jiwonoh

    Advanced Member

  • Members
  • PipPipPip
  • 42 posts

Posted 22 April 2013 - 06:09 AM

Dear Dave

 

It works clearly! You are so clever.

I send mail to local distributor about description of protocol in datasheet.

They named the protocol as I2C, it makes me confused.

 

Thank you!

 

from Jiwon.



#6 jiwonoh

jiwonoh

    Advanced Member

  • Members
  • PipPipPip
  • 42 posts

Posted 22 April 2013 - 06:19 AM

They named the protocol as "sensi-bus" 

 

Sensibus is adopted SHT1X, SHT7X Series.

SHT2X is used official I2C protocol.

 

FYI



#7 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 22 April 2013 - 11:45 AM

They named the protocol as "sensi-bus"    Sensibus is adopted SHT1X, SHT7X Series. SHT2X is used official I2C protocol.   FYI

I considered changing to the sht2x series to use true I2C however after a year of using the sht1x it works very well so I'll keep using the 1x.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.