Yapay zekâ tarafından English dilinden çevrildi ·
Önce çip olmadan, loopback ile SPI’yi tek başına test edin. MCP3008’i çıkarın, MOSI (GPIO10, pin 19) ile MISO (GPIO9, pin 21) arasına bir jumper kablo takın ve şunu çalıştırın:
wget https://raw.githubusercontent.com/raspberrypi/linux/rpi-6.6.y/tools/spi/spidev_test.c
gcc -o spidev_test spidev_test.c
./spidev_test -D /dev/spidev0.0 -v -p "HELLO"
RX, TX ile aynı baytları gösteriyorsa Pi tarafı sorunsuz demektir. RX tamamen 00 veya FF ise SPI gerçekten çalışmıyor demektir.Ama bence sorun kodunuzda: spi.open(0, 1) çip seçimi olarak CE1’i kullanır; bu da pin 26’daki GPIO7’dir. Çoğu MCP3008 eğitiminde CS, CE0’a, yani pin 24’teki GPIO8’e bağlanır. CS’iniz pin 24’e gidiyorsa çip hiç seçilmez, çıkışı havada kalır ve ona dokunduğunuzda 0 ile ara sıra 1023 görürsünüz. Ya kabloyu pin 26’ya taşıyın ya da kodu spi.open(0, 0) olarak değiştirin. Bunun tam aynı karışıklığını işte bir test tezgahında yaşadım.Kanal 1’in de aynı değeri vermesi ipucu: seçilmemiş bir çip her kanalda aynı anlamsız değeri üretir.
Test SPI on its own first with a loopback, no chip. Pull the MCP3008 out, put a jumper from MOSI (GPIO10, pin 19) to MISO (GPIO9, pin 21) and run:
wget https://raw.githubusercontent.com/raspberrypi/linux/rpi-6.6.y/tools/spi/spidev_test.c
gcc -o spidev_test spidev_test.c
./spidev_test -D /dev/spidev0.0 -v -p "HELLO"
If RX shows the same bytes as TX, the Pi side is fine. If RX is all 00 or FF, SPI isn’t really running.
My bet though is in your code: spi.open(0, 1) uses chip select CE1, which is GPIO7 on pin 26. Most MCP3008 tutorials wire CS to CE0, GPIO8 on pin 24. If your CS goes to pin 24, the chip is never selected, its output floats, and you get 0 with the odd 1023 when you touch it. Either move the wire to pin 26 or change the code to spi.open(0, 0). I’ve done this exact mixup on a bench at work.
Your channel 1 reading the same is the giveaway: an unselected chip gives the same junk on every channel.

