4 digit 7 segment led thermometer and humidity display


New Member
Hello new to this but im just not getting it, im building a digital thermometer and humidity display. im currently using a 28x2 driving many 4511b latch decoders to drive the 4 digit 7 seg displays there are 4,
so i have worked out a nice circuit that displays the value of b1 on the leds, looks nice.
OK so my real issue is the sensor the last project i built used the DS18B20 Digital Temperature sensor, that was nice and easy, but with my new project i thought i would try and use the HTU21D temperature humidity sensor module which uses I2C ,
ive been trying to get some code to work but its just not happening.
SYMBOL SensorRH = W0
SYMBOL Temperature = W1
' Implementation of HTU21D temperature and humidity sensor with Picaxe 18m2. RH and Temp update ~every 2 sec.
Pause 20
hi2csetup i2cmaster,0x80,i2cslow_8,i2cbyte '%10000000 (hex 0x80) is device i2c bus address
hi2cin 0xE5, (b1,b0) '%11100101 to trigger humidity measurement, store in b1, b0 (automatically combined to w0)
hi2cin 0xE3, (b3,b2) '%11100011 to trigger temperature measurement, store in b3, b2 (automatically combined to w1)
pause 20
goto main

of course i nicked the code from this site, sorry, but the irony is of course is i dont really know whats going on.
All i was hoping to do is have say w0 display humidity and w1 to show temp, or at least some numbers i could play with and display,
what does hi2cin 0xE5 actually mean is that making a pin go high ?
is it possible this code is not right for the 28x2???
any help would be great, i try to get as far as i can by myself but sometimes.... regards twimc


Senior Member
Read this short document to understand the I2C protocol: http://www.picaxe.com/docs/axe110_i2c.pdf
Note, that document uses the older commands, i2cslave, writei2c, and readi2c.
i2cslave = hi2csetup
readi2c = hi2cin
writei2c = hi2cout

See page 10 of the HTU21D datasheet: https://www.te.com/commerce/DocumentDelivery/DDEController?Action=showdoc&DocId=Data+SheetHPC199_6A6pdfEnglishENG_DS_HPC199_6_A6.pdfCAT-HSC0004
to understand what reading (hi2cin) register 0xE5 is doing.

Make sure you have the SDA and SCL lines connected to the correct pins on the 28X2 and that you are using 4.7K pullup resistors on these lines.
Last edited:


Senior Member
Also, see page 15 of the datasheet as it has the calculations needed to get humidity and temperature from the values returned from registers 0xE3 and 0xE5.


Senior Member
Ahh, it appears the HTU21D has exactly the same formula (written a different way) to the Si7006 temp and humidity sensor I have used quite a bit.
Here's some code that should get you going:

#picaxe 28x2
#terminal 9600

symbol cHumTemp    = %10000000    'SI7006-A20
symbol cI2cSpd    = i2cfast

symbol bThCheck    = bit1    '0 = temperature, 1 = humidity; which register to read in loop
symbol vSenMsb    = b6    'MSB for sensor readings
symbol vSenLsb    = b7    'LSB for sensor readings
symbol wSen        = w1    'b8,b9: Used for sensor readings
symbol wGenVar0    = w12    'b24,b25:

pause 4000

hi2csetup i2cmaster, cHumTemp, cI2cSpd, i2cbyte
    bThCheck = 0    ;bit to loop through temp and humidity on the Si7006
    for bThCheck = 0 to 1 step 1
        if bThCheck = 0 then
            hi2cin 0xE3,(vSenMsb,vSenLsb)    'read in temperature
            hi2cin 0xE5,(vSenMsb,vSenLsb)    'read in humidty
        end if
          wSen = vSenMsb * 256
          wSen = wSen + vSenLsb
        sertxd ("Raw ",#wSen)
        if bThCheck = 0 then   
            sertxd (" T ")
            wSen = 17572 ** wSen - 4685    'formula for temperature
            if wSen > 13000 then        '0 deg C and below
                wSen = -wSen             ': sertxd (" A- = ",#wSen,13,10)
                wSen = wSen * 9 / 5        'convert from Celsius to Farenheit
                wSen = wSen - 3200         ': sertxd (" -3200=",#wSen,13,10)
                if wSen > 13000 then     'temperature is above 0 deg F but below 32 deg F
                    wSen = - wSen         ': sertxd (" B- =",#wSen,13,10)
                end if
            else    'above freezing
                wSen = wSen * 9 / 5        'convert from Celsius to Farenheit
                wSen = wSen + 3200         ': sertxd (" +3200=",#wSen,13,10)
            end if
            sertxd (" H ")
            wSen = 12500 ** wSen - 600    'formula for humidity
        end if
        vSenMsb = wSen / 100        'integer
        wGenVar0 = vSenMsb * 100
        vSenLsb = wSen - wGenVar0    'fraction
        sertxd (#bThCheck,": ",#vSenMsb,".",#vSenLsb)
        if bThCheck = 0 then
            sertxd (" F",13,10)
            sertxd (" %",13,10,13,10)
        end if
        'inc bThCheck
    next bThCheck
pause 3000


Senior Member
I use Phil Hornby code a lovely piece of work that works straight out of the tin
Are you using the adafruit breakout board if so it has a 3v low dropout regulator fitted
so no problem if using 5v with it


New Member
Just want to thank everyone for the help in this forum, particularly Hemi345 the 28X2 code that you posted works great and i have now a great looking working project, still got to sort out negative"-" display and decimal point moving(easy bit) , As it is i can display 99.99 on both displays , but so far the project is going great , Thanks very much.
i have included a photo for the breadboard junkies out there.