Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: The Natural Philosopher Newsgroups: comp.sys.raspberry-pi Subject: Anyone gotta clue? TMP36 Pi PICO. Date: Sat, 29 Mar 2025 13:34:51 +0000 Organization: A little, after lunch Lines: 99 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sat, 29 Mar 2025 14:34:52 +0100 (CET) Injection-Info: dont-email.me; posting-host="6476e7bc124fad99fadd6db7fba78296"; logging-data="1542343"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/rYQ3rD6HUxaM7dNeecusXcSwPF6UOEXU=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:EG+m8fgyhowpK33FAB2Lqj4yFYQ= Content-Language: en-GB Bytes: 3253 I have a PI PICO W which I am developing code for amongst which is a TMP36 temperature sensor The code I have reused form other thermostat projects but its suddenly giving the odd false reading. #define CHIP_TEMP_IO 28 #define CHIP_ADC 2 #define RELAY_IO 21 #define IN 0 #define OUT 1 #define ON 1 #define OFF 0 void initialise_hardware() { adc_init(); adc_gpio_init(CHIP_TEMP_IO); gpio_init(RELAY_IO); gpio_set_dir(RELAY_IO,OUT); } void set_relay(int flag) { cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, flag); // set the lamp gpio_put(RELAY_IO,flag); //set the relay } float read_temperature() { static int index; static int flag; //initialised to zero at startup static uint32_t rawbuf[32]; const float conversion_factor = 3.3f / (1<<12); float result; float last; int i; uint32_t raw; adc_select_input(CHIP_ADC); raw = adc_read(); //wtf? printf ("Raw=%0X\n",raw); result=((float)raw)*conversion_factor; return (100*result-54); // the pcb warms them up by about 4 degrees } I am reading the temperature every two seconds as in while (1) { sleep_ms(2000); flag=(flag? OFF:ON); set_relay(flag); temperature = read_temperature(); printf("Temperature is %.1f C\n",temperature); } about one time in ten the output jumps to about 20°C less than expected e.g. Raw=3BE Temperature is 23.2 C Raw=3BE Temperature is 23.2 C Raw=3BE Temperature is 23.2 C Raw=29B Temperature is -0.3 C /************************ Raw=3C0 Temperature is 23.3 C Raw=3C0 Temperature is 23.3 C Raw=3BF Temperature is 23.3 C Raw=3BF Temperature is 23.3 C Raw=3BF Temperature is 23.3 C Raw=3C1 I have added decoupling to the TMP36 supply which is fed from the ADC 3.3v supply which seems to be a steady 3.29V according to my DVM. Do I have a bad PICO W? TMP 36 or what? Other PICOs with the same chip don't do this... The only difference is that this PICO is running different and a lot more wifi/server code Is it possible that some interrupt is - er - interrupting the ADC read with dire results? I cannot but think this is a hardware issue. -- The lifetime of any political organisation is about three years before its been subverted by the people it tried to warn you about. Anon.