home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.sys.raspberry-pi      Raspberry Pi computers & related hardwar      26,127 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 25,426 of 26,127   
   The Natural Philosopher to All   
   Anyone gotta clue? TMP36 Pi PICO.   
   29 Mar 25 13:34:51   
   
   From: tnp@invalid.invalid   
      
   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.   
      
   --- SoupGate-DOS v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca