CPU temperature of Raspberry Pi in C#

不羁的心 提交于 2021-02-07 05:12:16

问题


I have read a lot of articles and forum posts about this topic, but almost everything is quite complicated and all from over 2+ years ago.

So I was wondering, What is the best way tot get the CPU temperature of the Raspberry Pi in C#?

I have the newest version of Windows 10 IoT Core.

Update

I dont want to reduce the CPU temperature. I am using the Sense HAT. The temperature sensor of that thing is located near the CPU so the reading is inaccurate. I have found a python script what makes the reading accurate, but it needs the CPU temperature.

NOTE:

I am using Windows 10 IoT Core! I DO NOT have this file: /sys/class/thermal/thermal_zone0/temp

Update 2:

If the only way is to write your own driver, please guide me how to do that. I don't know anything about writing drivers or anything so low-level...


回答1:


As far as i know, there is no IoT SDK or powershell client could access to low-level BCM2836 peripherals.You need to write your own drivers. You can follow the code samples from https://github.com/ms-iot/bsp/tree/master/drivers, it's written under WDK framework so you'll need to get yourself familiar with that in order to get started.

Another option is, measure temperature using DS18B20 thermal sensors. This thermal sensor connects the raspberry pi via I2C. And you need to install Rinsen.OneWire package via nuget in your solution, this library is written in C# and it has built-in support for DS18B20 and DS18S20 sensors.

I'm not 100 percent sure this is the right way to go, but if someone could correct me or point out a better solution, I would be more than happy to learn from it.




回答2:


You can achieve this using MCP9808 chip.

There is an article by Jeremy Lindsay which walks you through the process of how to make it work using C# on Window 10 IoT Core.

https://jeremylindsayni.wordpress.com/2016/06/09/how-to-measure-temperature-using-c-raspberry-pi-windows-10-iot-core-and-the-adafruit-mcp9808-sensor/

Some excerpts from the article:

How does the MCP9808 work?

This sensor uses the I2C protocol, which is supported by Windows 10 IoT Core on the Pi 3. As there’s already extensive integration of this protocol in the framework, this makes coding significantly easier. The MCP9808 can be initialised using the slave address of 0x18, and the ambient temperature can be read back from two bytes of data after writing 0x05 to the device.

Connecting the MCP9808 to the Raspberry Pi

There are 4 pins on the MCP9808 temperature sensor that we need to use to get a basic temperature reading. I connected mine to the Pi using the pins specified below.

• Supply Voltage – Pin 2
• Ground – Pin 6
• Serial Clock – Pin 5 • Serial Data – Pin 3

Jeremy has also shared the code on GitHub: https://github.com/jeremylindsayni/Magellanic.Sensors.MCP9808

Hope this help!




回答3:


I think you could try to calculate the current CPU temperature by reading the current consumption and then using this formula to calculate the temperature.

I don't know how current cellphone manufacturers measure the device's temperature today. But this is not much different than how Nokia used to measure temperature based on IBATT (battery current) and VBATT (battery voltage) readings back in the day (when I worked there).



来源:https://stackoverflow.com/questions/52067742/cpu-temperature-of-raspberry-pi-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!