GithubHelp home page GithubHelp logo

adafruit / adafruit_circuitpython_max31865 Goto Github PK

View Code? Open in Web Editor NEW
23.0 23.0 11.0 133 KB

CircuitPython module for the MAX31865 thermocouple amplifier.

License: MIT License

Python 100.00%
hacktoberfest

adafruit_circuitpython_max31865's Introduction

Introduction

Documentation Status Discord Build Status Code Style: Black

CircuitPython module for the MAX31865 thermocouple amplifier.

Dependencies

This driver depends on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.

Installing from PyPI

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:

pip3 install adafruit-circuitpython-max31865

To install system-wide (this may be required in some cases):

sudo pip3 install adafruit-circuitpython-max31865

To install in a virtual environment in your current project:

mkdir project-name && cd project-name
python3 -m venv .venv
source .venv/bin/activate
pip3 install adafruit-circuitpython-max31865

Usage Example

See examples/max31865_simpletest.py for a demo of the usage.

Documentation

API documentation for this library can be found on Read the Docs.

For information on building library documentation, please check out this guide.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

adafruit_circuitpython_max31865's People

Contributors

ben-lewis avatar brennen avatar brentru-2 avatar dhalbert avatar emmanuelthome avatar evaherrada avatar foamyguy avatar jepler avatar jposada202020 avatar kattni avatar keiththeee avatar ladyada avatar osterwood avatar siddacious avatar sommersoft avatar tannewt avatar tdicola avatar tekktrik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit_circuitpython_max31865's Issues

Is the constant "_MAX31865_CONFIG_FILT60HZ" redundant?

Hi,
I was reading the code, and see that there is a variable called _MAX31865_CONFIG_FILT60HZ, then I search for usage of it and see nothing. As far as I see, there is an if-else statement in line 116-119. The 50Hz variable is using in both if and else blocks(in if block there is an OR(|) operator, in else block there are an AND(&) and a Complementary(~) operators):

    if filter_frequency == 50:
        config |= _MAX31865_CONFIG_FILT50HZ
    else:
        config &= ~_MAX31865_CONFIG_FILT50HZ

I do not have any superior knowledge of this but it seems off. Maybe the else statement is wrong or the variable _MAX31865_CONFIG_FILT60HZ is redundant?

Reduce self-heating

As with the equivalent C++ library https://github.com/adafruit/Adafruit_MAX31865, the bias current seems to be left on permanently, leading to increased self-heating. Adding self.bias = False at line 233 of adafruit_max31865.py should fix this. Also, maybe a note should be made that all improvements to C++ libraries should be duplicated in the equivalent python library and vice versa.

Library uses short argument names

pylint suggests using argument names with at least 3 letters. This library uses argument names of shorter length, and while these warnings have been disabled for now, they should be considered for renaming. This may require the rework of Learn Guides and other references to code snippets.

Getting output "-242.020C"

Hi,
When I run the sample code I always get this as output:
"Temperature: -242.020C
Temperature: -242.020C
Temperature: -242.020C
Temperature: -242.020C
Temperature: -242.020C
Temperature: -242.020C
Temperature: -242.020C
Temperature: -242.020C
Temperature: -242.020C
^CTraceback (most recent call last):
File "/home/pi/tempsensor/Adafruit_CircuitPython_MAX31865/examples/max31865_simpletest.py", line 29, in
time.sleep(1.0)
KeyboardInterrupt"

I'm stuck with this and can't get it fixed.
When I type ls -l /dev/spidev* in the terminal I get this as output:
"crw-rw---- 1 root spi 153, 0 Mar 24 15:01 /dev/spidev0.0
crw-rw---- 1 root spi 153, 1 Mar 24 15:01 /dev/spidev0.1"

Does someone know what's wrong. Is my MAX31865 stuck or something?

Loop

How to loop a scrpit or file? I cant get loop so i must open and open file to check temp. I try loop it by systemd and other stuff like "import os" but its not working and issue with os is "no module called os" (raspberry). The worse thing is i try while true() in script but also not working so any ideas how to do loop ? My idea is: tomorrow i try with lcd to get temp on screen in loop.

Please add __version__ and __repo__ metadata. Thank you!

For this module to work with the upcoming circup utility (see https://github.com/ntoll/circup), there needs to be two bits of metadata expressed as "dunder" objects within the module.

Specifically, circup looks for something like the following:

__version__ = "1.2.3"
__repo__ = "https://github.com/adafruit/SomeLibrary.git"

The __version__ should be a correct semantic-version value (see: https://semver.org/).

The __repo__ should be the HTTPS URL used for cloning this repository.

You can see an example of this behaviour in an existing project here.

Please don't hesitate to ping me if you have any questions. Thank you! ๐Ÿ โค๏ธ ๐Ÿ‘

cc/@ladyada

Temperature calculation ignores rtd_nominal for temperatures below zero

The above-zero calculation uses rtd_nominal but the below-zero calculation doesn't. So if rtd_nominal is set to anything but 100, when the resistance drops below that value the reported temperature will abruptly jump to the uncalibrated value.

It seems like the below-zero formula is more complicated and it might not be feasible to incorporate rtd_nominal in it, but giving the wrong answer seems like a bad failure mode. Either returning None or raising an exception in the case where rtd_nominal is overridden and the initial calculation is negative would seem better to me.

setters not working

Hi, cause I need to test many MAX31865's features on RPI I use your library. I observe that with Python (3.7.3 in my case) I can't use bias and auto_conversion : setters doesn't work at all. After google search I found that the library is not well designed for Python 3.
I changed localy adafruit_max31865.py like that :
replacing "class MAX31865:" by "class MAX31865(object):"
It's work's now.
Best regards

Faster Temperature Measurement

Hello !
I am using 3 Devices (Max31865) with Raspberry pi and in 1 second I get only 6 values from each sensor.
If I use single device I get 14 values from sensor in 1 second. Is it possible to get values from sensors a bit faster say 20 values from each sensor in one second.
Guidance will be highly appericiated

Regards
Danial

Installing the module fresh on a RPi3 / RPi Zero breaks, due to evolving dependencies

Hello,

I've been struggling to make the code work for my RPi 3/ Zero with a fresh install, and I just figured the problem:

Adafruit_CircuitPython_MAX31865 depends on Adafruit_Blinka, which has evolved a great deal since you release these examples.

And either the code in Blinka of Platform Detect has regressed or something, but this is what I have right now:

Using the test.py files as below:

import time
import board
import busio
import digitalio
import adafruit_max31865

spi = busio.SPI(board.SCLK, MOSI=board.MOSI, MISO=board.MISO) # GPIO 11, 10 and 9 on Rpi
cs = digitalio.DigitalInOut(board.CE0)  # CE0 is D8 on Rpi
sensor = adafruit_max31865.MAX31865(spi, cs, wires=4)

while True:
    temp = sensor.temperature
    print("Temperature: {0:0.3f}C".format(temp))
    time.sleep(1.0)

We start on a fresh virtualenv named latest:

pi@rpi(rw):~$ source latest/bin/activate
pi@rpi(rw):~$ pip3 install Adafruit_CircuitPython_MAX31865
[...]
Successfully installed Adafruit-Blinka-5.13.1 Adafruit-CircuitPython-MAX31865-2.2.8 Adafruit-PlatformDetect-2.28.0 Adafruit-PureIO-1.1.8 RPi.GPIO-0.7.0 adafruit-circuitpython-busdevice-5.0.6 aenum-3.0.0 pyftdi-0.52.9 pyserial-3.5 pyusb-1.1.1 rpi-ws281x-4.2.6 sysv-ipc-1.0.1
pythonpi@rpi(rw):~$ python3 test.py
Temperature: -241.553C
Temperature: -241.553C
Temperature: -241.553C
^CTraceback (most recent call last):
  File "test.py", line 15, in <module>
    time.sleep(1.0)
KeyboardInterrupt
pi@rpi(rw):~$ pip3 list
DEPRECATION: Python 3.5 reached the end of its life on September 13th, 2020. Please upgrade your Python as Python 3.5 is no longer maintained. pip 21.0 will drop support for Python 3.5 in January 2021. pip 21.0 will remove support for this functionality.
Package                          Version
-------------------------------- -------
Adafruit-Blinka                  5.13.1
adafruit-circuitpython-busdevice 5.0.6
adafruit-circuitpython-max31865  2.2.8
Adafruit-PlatformDetect          2.28.0
Adafruit-PureIO                  1.1.8
aenum                            3.0.0
pip                              20.3.4
pkg-resources                    0.0.0
pyftdi                           0.52.9
pyserial                         3.5
pyusb                            1.1.1
rpi-ws281x                       4.2.6
RPi.GPIO                         0.7.0
setuptools                       50.3.2
sysv-ipc                         1.0.1
wheel                            0.36.2

If I switch to another fresh virtualenv named works:

pi@rpi(rw):~$ source works/bin/activate
pi@rpi(rw):~$ pip3 install Adafruit-Blinka==2.4.* adafruit-circuitpython-max31865 Adafruit-PlatformDetect==1.* --upgrade
[...]
Successfully installed Adafruit-Blinka-2.4.1 Adafruit-PlatformDetect-1.4.5 Adafruit-PureIO-1.1.8 RPi.GPIO-0.7.0 adafruit-circuitpython-busdevice-5.0.6 adafruit-circuitpython-max31865-2.2.8 rpi-ws281x-4.2.6 spidev-3.5 sysv-ipc-1.0.1
pi@rpi(rw):~$ python3 test.py
Temperature: 20.292C
Temperature: 20.258C
Temperature: 20.292C
^CTraceback (most recent call last):
  File "test.py", line 15, in <module>
    time.sleep(1.0)
KeyboardInterrupt
pi@rpi(rw):~$ pip3 list
DEPRECATION: Python 3.5 reached the end of its life on September 13th, 2020. Please upgrade your Python as Python 3.5 is no longer maintained. pip 21.0 will drop support for Python 3.5 in January 2021. pip 21.0 will remove support for this functionality.
Package                          Version
-------------------------------- -------
Adafruit-Blinka                  2.4.1
adafruit-circuitpython-busdevice 5.0.6
adafruit-circuitpython-max31865  2.2.8
Adafruit-PlatformDetect          1.4.5
Adafruit-PureIO                  1.1.8
pip                              20.3.4
pkg-resources                    0.0.0
rpi-ws281x                       4.2.6
RPi.GPIO                         0.7.0
setuptools                       50.3.2
spidev                           3.5
sysv-ipc                         1.0.1
wheel                            0.36.2

So you see, using recent versions of Blinka breaks the code, the RTD returns temparatures of -241ยฐC.
If I switch to a (older) working version of Blinka and PlatformDetect, all is fine.

Did I write my code badly? (This is directly sourced from your example..)

Or did Blinka/Platform Detect break something in their code?

DisplayIO Example Wanted

Add a Basic DisplayIO Based Example

We would like to have a basic displayio example for this library. The example should be written for microcontrollers with a built-in display. At a minimum it should show a Label on the display and update it with live readings from the sensor.

The example should not be overly complex, it's intended to be a good starting point for displayio based projects that utilize this sensor library. Try to keep all visual content as near to the top left corner as possible in order to best fascilitate devices with small built-in display resolutions.

The new example should follow the naming convention examples/libraryname_displayio_simpletest.py with "libraryname" being replaced by the actual name of this library.

You can find an example of a Pull Request that adds this kind of example here: adafruit/Adafruit_CircuitPython_BME680#72

We have a guide that covers the process of contributing with git and github: https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github

If you're interested in contributing but need additional help, or just want to say hi, feel free to join the Discord server to ask questions: https://adafru.it/discord

Missing Type Annotations

There are missing type annotations for some functions in this library.

The typing module does not exist on CircuitPython devices so the import needs to be wrapped in try/except to catch the error for missing import. There is an example of how that is done here:

try:
    from typing import List, Tuple
except ImportError:
    pass

Once imported the typing annotations for the argument type(s), and return type(s) can be added to the function signature. Here is an example of a function that has had this done already:

def wrap_text_to_pixels(
    string: str, max_width: int, font=None, indent0: str = "", indent1: str = ""
) -> List[str]:

If you are new to Git or Github we have a guide about contributing to our projects here: https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github

There is also a guide that covers our CI utilities and how to run them locally to ensure they will pass in Github Actions here: https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/check-your-code In particular the pages: Sharing docs on ReadTheDocs and Check your code with pre-commit contain the tools to install and commands to run locally to run the checks.

If you are attempting to resolve this issue and need help, you can post a comment on this issue and tag both @FoamyGuy and @kattni or reach out to us on Discord: https://adafru.it/discord in the #circuitpython-dev channel.

The following locations are reported by mypy to be missing type annotations:

  • adafruit_max31865.py:118
  • adafruit_max31865.py:156
  • adafruit_max31865.py:164
  • adafruit_max31865.py:172
  • adafruit_max31865.py:187
  • adafruit_max31865.py:203

OSError: [Errno 12] Cannot allocate memory

Hi! I am using this library on a raspberry pi 3B+ and it works great, except when I try do longer measurements, then I get the error below. The temperature from two sensors and the time are stored in a .txt file. The issue does not seem to come from a lack of space on the raspberry (still got 4.7 Gb free space). The two last times it happened the measurement stopped after 1 hour (.txt file of 80 Kb) and around 2 hours. Any ideas?

Thanks a lot,
Jens

Traceback (most recent call last):
File "pt100_2_sensors.py", line 25, in
file_temp_time.write("{0} {1} {2}\n".format(time.time(), sensor_1.temperature, sensor_2.temperature))
File "/usr/local/lib/python3.5/dist-packages/adafruit_max31865.py", line 238, in temperature
raw_reading = self.resistance
File "/usr/local/lib/python3.5/dist-packages/adafruit_max31865.py", line 223, in resistance
resistance = self.read_rtd()
File "/usr/local/lib/python3.5/dist-packages/adafruit_max31865.py", line 213, in read_rtd
self._write_u8(_MAX31865_CONFIG_REG, config)
File "/usr/local/lib/python3.5/dist-packages/adafruit_max31865.py", line 138, in _write_u8
device.write(self._BUFFER, end=2)
File "/usr/local/lib/python3.5/dist-packages/busio.py", line 129, in write
return self._spi.write(buf, start, end)
File "/usr/local/lib/python3.5/dist-packages/adafruit_blinka/microcontroller/generic_linux/spi.py", line 39, in write
self._spi.open(self._port, 0)
OSError: [Errno 12] Cannot allocate memory

OSError: [Errno 24] Too many open files: '/proc/cpuinfo'

Continuous reading of the module MAX31865 with a PT100 temperature sensors in an infinite loop crashes after a constant number of iterations with the error

OSError: [Errno 24] Too many open files: '/proc/cpuinfo'

Reading before the error occures works fine using the adafruit-supplied python code. The while==True loop does not contain any file opening process. For one module the error occures after 1019 loops, for 5 modules after 203. The max number of open files allowed is (ulimit -n) 1024. The errror only occurs for the system depicted below. For RasPi zero + stretch the essentially identical python code works without problems.

System:

  • Adafruit MAX31865 PT100-board
  • Raspberry Pi 4 Model B Rev 1.4 (8GB)
  • Linux fourB 5.10.17-v8+ #1403 SMP PREEMPT Mon Feb 22 11:37:54 GMT 2021 aarch64 GNU/Linux (Raspbian Buster 10)
  • Python 3.7.3

Relevant package versions:

  • Adafruit-ADS1x15==1.0.2
  • Adafruit-Blinka==6.4.1
  • adafruit-circuitpython-busdevice==5.0.6
  • adafruit-circuitpython-max31865==2.2.8
  • Adafruit-GPIO==1.0.4
  • Adafruit-PlatformDetect==3.4.0
  • Adafruit-PureIO==1.1.8
  • adafruit-python-shell==1.3.1

Code:
PT100.py

import board
import busio
import digitalio
import time
import adafruit_max31865

def read_PT100():
        spi = busio.SPI(board.SCK,MOSI=board.MOSI,MISO=board.MISO)
        cs = digitalio.DigitalInOut(board.D26)
        sensor = adafruit_max31865.MAX31865(spi,cs,rtd_nominal=100.0, ref_resistor=430.0, wires=4)
        T = sensor.temperature
        return T

test.py:

from PT100 import read_PT100
i = 0
while True:
      print(f"{i}   {read_PT100()}")
      i += 1

Full error:
Traceback (most recent call last):
File "test.py", line 4, in
File "/home//Programme/LT_Testbench/PT100.py", line 31, in read_PT100
File "/home//.local/lib/python3.7/site-packages/adafruit_max31865.py", line 98, in init
File "/home//.local/lib/python3.7/site-packages/adafruit_max31865.py", line 120, in _read_u8
File "/home//.local/lib/python3.7/site-packages/adafruit_bus_device/spi_device.py", line 76, in enter
File "/usr/local/lib/python3.7/dist-packages/busio.py", line 198, in configure
File "/home//.local/lib/python3.7/site-packages/adafruit_platformdetect/board.py", line 426, in any_raspberry_pi
File "/home//.local/lib/python3.7/site-packages/adafruit_platformdetect/board.py", line 198, in _pi_rev_code
File "/home//.local/lib/python3.7/site-packages/adafruit_platformdetect/init.py", line 49, in get_cpuinfo_field
OSError: [Errno 24] Too many open files: '/proc/cpuinfo'

issues with using SPI1 on a RapsBerry Pi 4 Module B

Hi all

Today I struggled all day by using SPI1 on the MAX31865 library. I can not use SPI0 as these pins are needed for I2C Communication. I enabled the SPI1 in the /boot/config.txt with dtoverlay=spi1_3cs and by using the test library from rm-hull I was able to send and recieve data on the SPI1. So the SPI connection works. Something seems to be wrong with the MAX31865 library.
With the default library I got the Error: OSError: [Errno 22] Invalid argument by altering the library to accept a phase in the init of MAX31865 I managed to make a connection but now I am reading totally wrong values from the chip. Am I making something totally wrong? Do you need any more information from me?

Thank you very much in advance and best, Alp

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.