Search code examples
c#pythonraspberry-pitemperaturewindowsiot

Read temperature with MAX31855 Thermocouple Sensor on Windows IoT


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?


Solution

  • 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.