Sujet : Re: Anyone gotta clue? TMP36 Pi PICO.
De : jrwalliker (at) *nospam* gmail.com (John R Walliker)
Groupes : comp.sys.raspberry-piDate : 29. Mar 2025, 16:40:48
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vs94a0$t7kp$1@dont-email.me>
References : 1 2
User-Agent : Mozilla Thunderbird
On 29/03/2025 14:51, The Natural Philosopher wrote:
On 29/03/2025 13:34, The Natural Philosopher wrote:
>
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.
I found another TMP36 from an old project and switched it in.
No joy.
Looks like its PI related
“it should be clear by now to everyone that activist environmentalism (or environmental activism) is becoming a general ideology about humans, about their freedom, about the relationship between the individual and the state, and about the manipulation of people under the guise of a 'noble' idea. It is not an honest pursuit of 'sustainable development,' a matter of elementary environmental protection, or a search for rational mechanisms designed to achieve a healthy environment. Yet things do occur that make you shake your head and remind yourself that you live neither in Joseph Stalin’s Communist era, nor in the Orwellian utopia of 1984.”
Vaclav Klaus
I'm sure you have good reasons for using that device, but maybe consider
the TMP1075. It is cheap and reasonably accurate. I2C should not be a
problem on the Pico.
John