Sensiron SHT31 on PICAXE

Eclectica

Member
Hi all,

I was just wondering if anyone had managed to get a PICAXE I2C working with this part, since there is no point in re-inventing the wheel so to speak?

Currently here:
Code:
symbol addr = $44
symbol readcmdMSB = $2C
symbol readcmdLSB = $00

hi2csetup i2cmaster, addr, i2cslow, i2cbyte

hi2cout addr,(readcmdMSB) 
  
hi2cin addr,(rhlow, rhhigh)
Any suggestions greatly appreciated. :D
E.
 

hippy

Technical Support
Staff member
We do have some example code though looking at it it needs knocking into shape. The three things are ...

Initialising I2C ...

Code:
HI2cSetup I2CMASTER, $88, I2CFAST, I2CBYTE ; $88 or $8A
Initialising the SHT31, auto-updating here ...

Code:
HI2cOut ( $2B, $32 ) ; Accelerated response
Reading the data ...

Code:
HI2cIn ( temperature.msb, temperature.lsb, temperature.crc, humidity.msb, humidity.lsb, humidity.crc )
temperature = temperature ** 17500 - 4500 
humidity    = humidity    ** 10000
That should work. At least did for me during initial testing, but it is better to reset the device and poll for a result every reading or one can get 255 ($FF) results always turning up. It is also best to check the CRC values to avoid any incorrect data. That's what needs to be updated in our current code.

The temperature and humidity readings are five digit numbers 'ABCDE' representing 'ABC.DE'. Temperature is held as two's complement when negative, msb set.
 

Eclectica

Member
Hi Hippy,

Oh wow - that's amazing! I see where I was going wrong now and how to get it working rather than returning $FF all the time. I've only recently ventured into the realms of I2C, so not surprising that I'm still falling into the many holes! :eek: However, the PICAXE does provide a neat way of solving so many problems in an uncomplicated fashion, and great that it can work with I2C.

Thank you so much for replying to this thread and providing a documented working solution - seriously brilliant - Kudos to you. :D

Many thanks and have a great day.
E.
 

hippy

Technical Support
Staff member
You are welcome. As always with datasheets there can be a degree of trying to figure out what something means beyond what the datasheet may actually say.

In the case of the SHT31 what "repeatability" means isn't at all well defined. That can be best thought of as resolution, the higher the repeatability the more bits of sensor data determined, the more accurate a reading. There is an increase of current the better the repeatability used but as it's micro-amps it will not matter for most PICAXE projects.

And then there's the 'making it work for everyone', going beyond 'well, it works for me'. That can always be a bit tricky as one needs to see a not working case to discover there can be issues. And then comes the analysing of why 'the hardware appears to be broken', and determining how one resolves that.
 

Pongo

Senior Member
Wow, thanks for posting this code Hippy :) I've wanted to start using the very nice SHT31 temp/hum sensor for a while but never got around to making it work.

Just a note for any other weather station enthusiasts who may land here: The SHT31 sensor is now used in the popular Davis weather stations, but for backward compatibility they use the legacy sensibus interface SHT31-LSS version. Sensibus is not I2C so a Davis temp/hum sensor assembly will not work with a picaxe using this code.
 

westaust55

Moderator
@bougnat,
What is the purpose/intent in copying the three earlier posts from 2017 without any further comment from yourself?

If you wished to bring to the fore/front then a simple “bump” post would suffice.
 
Top