Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5240

MicroPython • Re: I want to use ky-013 for raspberry pi pico.

$
0
0
I wrote a module to help with this: curiously, there wasn't a generic module for MicroPython to work with NTC thermistors.

It needs a bunch of testing on other platforms and with something other than a KY-013, but I've had the thermistor agree with a nearby AHT20 to within 0.2 degrees C.

scruss/micropython-simple-thermistor: read NTC thermistor temperature wired in a potential divider

Sample code:

Code:

# MicroPython, Raspberry Pi Pico# pylint: disable=E0401# -*- coding: utf-8 -*-import machineimport timefrom simple_thermistor import Thermistor# setup for KY-013-alike thermistor on GPIO 26t = Thermistor(    adc=machine.ADC(        26    ),  # ADC object with read_u16() method returning 0–65535    beta=3950,    r0=10000,  # thermistor nominal resistance of 10 kΩ at 25 °C    t0=Thermistor.fromC(25),  # everything is Kelvin internally    resistor=10000,  # high side resistor of 10 kΩ)while True:    print(        "%6.1f °C / %.1f Ω"        % (Thermistor.toC(t.temperature()), t.resistance())    )    time.sleep(5)

Statistics: Posted by scruss — Wed Oct 30, 2024 1:35 am



Viewing all articles
Browse latest Browse all 5240

Trending Articles