Menu

Demo Code for Silabs Si7021 Humidity/Temperature Sensor

2018-08-25
2019-03-06
  • William Roth

    William Roth - 2018-08-25

    The attached demo code works with the Si7021 Humidity/Temerature Sensor Board as provided by Adafruit. The accuracy is excellent and the conversion/acquisition time is less than 1/10 that of either DHT-11/22 or DS18B20.

    Adafruit adds an LDO regulator and level shifting to allow the sensor board to work reliably at 5.0V. The current price is $6.95 as of 08/2018.

    I have used separate I2C peripheral modules for the Display and the Sensor. However this is not necessary. If care is taken only one I2C peripheral is needed.

    Anyone so inclined could create a GCB library using this code as a starting point.

    Si7021 Datasheet

    Adafruit 7021A Sensor Board

    William

     

    Last edit: William Roth 2018-08-25
  • Moto Geek

    Moto Geek - 2018-08-28

    Very nice William. Will have to order one of these now. Thanks!

     
  • Randall Young

    Randall Young - 2018-08-30

    Thank you, very useful!

     
  • William Roth

    William Roth - 2018-08-31

    Why in the world would anyone want purchase a bare SiLabs 7021 chip through FleaBay from a Chinese supplier where the supply chain is not traceble?

    Digikey (UK) has this IC for only a few cents more and you can be assured that it is not a factory reject or a counterfeit.

     
  • stan cartwright

    stan cartwright - 2018-09-15

    I posted this in the wrong place, sorry, The device arrived,2 from different sources for a coffee, both work it seems. Output to a terminal is a usb lead with a uno.

    #chip mega328p,16
    #option explicit
    
    #define hi2c_BAUD_RATE 100
    #define hi2c_DATA PORTC.4
    #define hi2c_CLOCK PORTC.5
    hi2cMode Master
    
    Dim Si7021_HighByte, Si7021_LowByte as byte
    Dim SiRaw Alias Si7021_HighByte, Si7021_LowByte as Word
    
    Dim Humidity,Temperature,TemperatureC,TemperatureF as Word
    DIM Temperature as WORD
    
    Dim Hundredths as Byte
    
    #define USART_BAUD_RATE 9600
    #define USART_TX_BLOCKING
    #define USART_DELAY 10 ms
    
    do
    Read_Humidity
    Read_Temperature
    loop
    
    Sub Read_Humidity
      Hi2CStart
      HI2cSend (0x80)  'Write
      Hi2cSend (0xF5)
      Hi2CReStart
      HI2CSend (0x81)  'read
      wait 50 ms   ' for conversion ( could be less)
      Hi2CReStart
    
      HI2CSend (0x81)  'read
      Hi2CReceive (Si7021_HighByte, ACK)
      Hi2CReceive (Si7021_Lowbyte, NACK)
      Hi2Cstop
      'now do the maths
      Humidity = (([long]SiRaw * 125) / 65536) -6
    
    ;  Locate 1,12
      If Humidity  < 10 then hserPrint "0"
      hserPrint "Humidity="+str(Humidity) : hserPrint "%"
      HSerPrintCRLF
    
    End Sub
    
    Sub Read_Temperature
      Hi2CStart
      HI2CSend (0x80)  'Write
      Hi2cSend (0xE0)
    
      Hi2CReStart
      HI2CSend (0x81)  'read
      Hi2CReceive (Si7021_HighByte, ACK)
      Hi2CReceive (Si7021_Lowbyte, NACK)
      Hi2Cstop
      wait 20 ms
    
      TemperatureC = (([long]SiRaw * 17572) / 65536) - 4685
      TemperatureF =   (([long]TemperatureC * 9) /5) + 3200
    
      Hundredths = TemperatureF % 100  'Modulud Divide
      TemperatureF = TemperatureF / 100
    
    ;  Locate 2,14
      hserPrint "Temp.="+str(TemperatureF) : hserPrint "." : hserPrint str(Hundredths)+" "
    
    End Sub
    

    Humidity = (([long]SiRaw * 125) / 65536) -6 ...seems obvious :)
    results decimal jumps about?

     

    Last edit: stan cartwright 2018-09-16
  • Anobium

    Anobium - 2019-03-06

    I have one of these and the C temp is out by a lot. Is this a simple maths issue?

    Temp.=2709.76 Humidity=53%
    Temp.=2707.72 Humidity=53%

    Is not this hot in the lab!

    Any ideas?

     

Log in to post a comment.