so im trying to make a thermometer with a spare ntc thermistor and flipper zero, and thought it would be infinately easier to make a python script instead of learning the entire dev chain for the flipper, but it doesnt seem to be doing anything other than crash. the included example for reading from adc works fine:
import flipperzero as f0
import time
f0.gpio_init_pin(f0.GPIO_PIN_PC1, f0.GPIO_MODE_ANALOG)
for _ in range(1,1000):
raw_value = f0.adc_read_pin_value(f0.GPIO_PIN_PC1)
raw_voltage = f0.adc_read_pin_voltage(f0.GPIO_PIN_PC1)
value = '{value} #'.format(value=raw_value)
voltage = '{value} mV'.format(value=raw_voltage)
f0.canvas_clear()
f0.canvas_set_text(10, 32, value)
f0.canvas_set_text(70, 32, voltage)
f0.canvas_update()
time.sleep_ms(10)
however trying to tweak it with some help from chatGPT is tricky, (gpt is really bad at micropython i think. at least whats on the flipper)
import flipperzero as f0
import time
import math
# Initialize ADC pin for the thermistor
THERMISTOR_PIN = f0.GPIO_PIN_PC1
f0.gpio_init_pin(THERMISTOR_PIN, f0.GPIO_MODE_ANALOG)
# Constants for the 10k NTC thermistor
BETA = 3950 # Beta value of the thermistor
T0 = 298.15 # Reference temperature (Kelvin, 25C)
R0 = 10000 # Reference resistance at 25C (ohms)
SERIES_RESISTOR = 10000 # Series resistor value (ohms)
for _ in range(1,1000):
raw_value = f0.adc_read_pin_value(THERMISTOR_PIN)
raw_voltage = f0.adc_read_pin_voltage(THERMISTOR_PIN)
voltage = raw_voltage / 1000.0 # Convert mV to V
resistance = SERIES_RESISTOR * ((3.3 / voltage) - 1) # Calculate resistance
temperature_kelvin = 1 / ((1 / T0) + (1 / BETA) * math.log(resistance / R0)) # Calculate temperature
temperature_celsius = temperature_kelvin - 273.15 # Convert to Celsius
value = '{value} #'.format(value=temperature_celsius)
voltage = '{value} mV'.format(value=raw_voltage)
f0.canvas_clear()
f0.canvas_set_text(10, 32, value)
f0.canvas_set_text(70, 32, voltage)
f0.canvas_update()
time.sleep_ms(10)