Read temperature with MAX31855 Thermocouple Sensor

2019-06-10 17:32发布

问题:

I am working on a Raspberry Pi 2 with Windows IoT. I want to connect the Raspberry Pi with a MAX31855 Thermocouple Sensor which I bought on Adafruit. There's a Python libary available on GitHub to read the current temperature from the sensor. Unfortunately, I am not able to get this libary to work on my Pi because I have no idea how to install the prerequisite RPi.GPIO and the Adafruit_Python_MAX31855 libary on my Pi. I am not sure if it is working at all with Python on Windows IoT. Can somebody confirm this?

I've found the thread Getting SPI temperature data from outside of class on StackOverflow which seems to be what I want to do. First, when I connect my Thermocouple with my Pi, do I need to use Software SPI or Hardware SPI? Is there a important difference when working on Windows IoT?

There's also a C++ libary on GitHub. Is it possible to call the methods from this libary within my C# project?

回答1:

You'll need to do some porting work before using that python driver on raspberry pi with windows IoT core,

  1. Follow this sample https://developer.microsoft.com/en-us/windows/iot/win10/samples/pythonblinky to get started with python programming on windows IoT.
  2. See to Platform.py from https://github.com/adafruit/Adafruit_Python_GPIO , it is intended for board version detect and multiple board support. Add it to your project, you can hard-code it to only support raspberry pi.

  3. Add MAX31855.py to your project, copy the code from https://github.com/adafruit/Adafruit_Python_MAX31855/blob/master/Adafruit_MAX31855/MAX31855.py

  4. Replace

    import Adafruit_GPIO as GPIO with import _wingpio as gpio

and import Adafruit_GPIO.SPI as SPI with import _winspi as SPI

Also, replace every api calls with one from PyWinDevices library.

  1. depending if you're using the Software SPI or Hardware SPI wiring, you may need to port SPI.py driver from https://github.com/adafruit/Adafruit_Python_GPIO/blob/master/Adafruit_GPIO/SPI.py. That SetBang api is the software wrapper for sw/hw spi controller, you can easily write your own following the example.

You shall be good to go after all the driver porting.



回答2:

The MAX31855 uses an SPI interface so you can use the Windows.Devices.Spi.SpiDevice class to read the data in C#.

Here's a Universal Windows Platform (UWP) sample app demonstrating using the SPI bus: https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/IoT-SPI

Be aware that SPI may be broken in the latest Windows 10 IoT Core Insider Preview version 10.0.14366.0. The following thread concerns the MAX31855 and mentions this issue: https://social.msdn.microsoft.com/Forums/en-US/b7a61a59-3238-47a3-9249-a3e00abd1488/trouble-reading-thermocouple-max31855-over-spi?forum=WindowsIoT