Raspberry pi: rtc-ds3231 extra feature - temperature measuring

Moderator: BarryK

Post Reply
FeodorF
Posts: 244
Joined: Tue Jul 14, 2020 7:52 pm
Has thanked: 10 times
Been thanked: 34 times

Raspberry pi: rtc-ds3231 extra feature - temperature measuring

Post by FeodorF »

The RTC-ds3231 extra feature.

The real time clock ds3231 comes with an extra feature. It's an internal temperature sensor ranging from -45 °C to +85 °C. Mounting the ds3231 module with a piece of cable outside your pi box will give you the ability to read room or outside temperature while operating the pi. It's temperature value can be read by the following 'code'.

Make this an executable shell script.

#!/bin/bash
echo $(cat /sys/bus/i2c/devices/1-0068/hwmon/hwmon2/temp1_input|awk '{print $0/1000 " °C"}')
echo $(cat /sys/bus/i2c/devices/1-0068/hwmon/hwmon2/temp1_input|awk '{print (($0/1000 * 1.8) + 32) " °F"}')
echo $(cat /sys/bus/i2c/devices/1-0068/rtc/rtc0/date)
echo $(cat /sys/bus/i2c/devices/1-0068/rtc/rtc0/time) "UTC"

The console output will look like this.

# /root/ds3231-TempSensor
24.25 °C
75.65 °F
2022-03-18
15:35:00 UTC

# /root/ds3231-TempSensor
24.5 °C
76.1 °F
2022-03-18
15:37:50 UTC
#

RTC-ds3231-pic_001.jpg
RTC-ds3231-pic_001.jpg (17.08 KiB) Viewed 736 times
Post Reply

Return to “EasyOS”