temp: First version of adc readout
This commit is contained in:
		
							parent
							
								
									faf0e5421f
								
							
						
					
					
						commit
						df8ae2263d
					
				
					 1 changed files with 38 additions and 0 deletions
				
			
		
							
								
								
									
										38
									
								
								Misc/Temp-Monitor/firmware.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								Misc/Temp-Monitor/firmware.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,38 @@
 | 
			
		|||
import time
 | 
			
		||||
from machine import Pin
 | 
			
		||||
 | 
			
		||||
clock = Pin(2)
 | 
			
		||||
data = Pin(4)
 | 
			
		||||
 | 
			
		||||
SLEEP_TIME = 1
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def read_adc():
 | 
			
		||||
    # Wait for DRDY
 | 
			
		||||
    while data.high():
 | 
			
		||||
        pass
 | 
			
		||||
 | 
			
		||||
    value = 0
 | 
			
		||||
    for i in range(24):
 | 
			
		||||
        clock.high()
 | 
			
		||||
        time.sleep_us(SLEEP_TIME)
 | 
			
		||||
 | 
			
		||||
        value |= data.value() << (23 - i)
 | 
			
		||||
 | 
			
		||||
        clock.low()
 | 
			
		||||
        time.sleep_us(SLEEP_TIME)
 | 
			
		||||
 | 
			
		||||
    # Shift 3 more bits
 | 
			
		||||
    for i in range(3):
 | 
			
		||||
        clock.high()
 | 
			
		||||
        time.sleep_us(SLEEP_TIME)
 | 
			
		||||
        clock.low()
 | 
			
		||||
        time.sleep_us(SLEEP_TIME)
 | 
			
		||||
 | 
			
		||||
    return value
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
while True:
 | 
			
		||||
    value = float(read_adc()) / (2**24-1)
 | 
			
		||||
    print(f"{value:f}")
 | 
			
		||||
    time.sleep(0.1)
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue