Traducido del English por IA ·
Pruebe primero el SPI por sí solo con un loopback, sin chip. Saque el MCP3008, ponga un cable puente desde MOSI (GPIO10, pin 19) a MISO (GPIO9, pin 21) y ejecute:
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"
Si RX muestra los mismos bytes que TX, la parte de la Pi está bien. Si RX es todo 00 o FF, el SPI no está funcionando realmente.Aun así, mi sospecha está en su código: spi.open(0, 1) usa el chip select CE1, que es GPIO7 en el pin 26. La mayoría de los tutoriales del MCP3008 conectan CS a CE0, es decir, GPIO8 en el pin 24. Si su CS va al pin 24, el chip nunca se selecciona, su salida queda flotando y obtiene 0 con algún 1023 cuando lo toca. O bien mueva el cable al pin 26, o cambie el código a spi.open(0, 0). Yo mismo cometí exactamente esta confusión en un banco de pruebas en el trabajo.Que el canal 1 dé el mismo valor es la pista: un chip no seleccionado devuelve la misma basura en todos los canales.
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.

