Created
September 14, 2025 17:55
-
-
Save leon-anavi/58cbe2ddf340a4b243455a7c69e6982b to your computer and use it in GitHub Desktop.
Python 3 Reading Capacitive Soil Moisture Sensor Data from MCP3002 ADC on ANAVI Gardening uHAT for Raspberry Pi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import spidev | |
| spi=spidev.SpiDev() | |
| spi.open(0,0) | |
| spi.max_speed_hz=1200000 | |
| adc=spi.xfer2([1,(8+0)<<4,0]) | |
| val=((adc[1]&3)<<8)|adc[2] | |
| print(f"Channel 0: {val} ({val*3.3/1023:.2f} V)") | |
| spi.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment