1

I've been messing with raspberry pi, and I am learning about interfacing it with analog devices. I am using the MCP3008 for that and following this tutorial here. I wired it up like the pictures below: enter image description here enter image description here

I did all of the required things to set up spi devices such as: 1) enable spi in raspi-config 2) uncommented dtparam=spi=on in config.txt. 3) ls /dev/sp* says /dev/spidev0.0 and /dev/spidev0.1

Everything to me seems correct, but the output from a potentiometer is still 0 no matter what i do with it. can anyone spot the problem?

tlfong01
  • 4,665
  • 3
  • 10
  • 24
  • Hi @Aubrey Champagne, Welcome and nice to meet you. Ah, let me see. (1) You setup looks correct. (2) For newbies, I usually suggest to do SPI "loop back" test first, to make sure SPI software and hardware (hardware wiring correct, no poor electrical connect, broker jumper wires (sometime bent too often and broken inside and not visible outside). – tlfong01 Dec 30 '19 at 04:01
  • If you have a multi-meter, you can try "open, short" tests, ie, all point to point connection are shorted (very low resistance, approaching zero), and neighbour points are open, ie not "stuck" together, therefore very very high resistance, approaching 10Mega ohm. – tlfong01 Dec 30 '19 at 04:01
  • You can google for "UART", "serial", "SPI" loop back test to get a rough idea what is meant by loop back, and the setup (For SPI, MOSI (output) connected/shorted to MSIO (input). then send something out to MSOI, and read back from MISO. If send characters are echoed, loopback to input, then basic steup is OK. WARNING, usually basic out to input short test does NOT check CS pin operation, so not 100% proof. – tlfong01 Dec 30 '19 at 04:05
  • For spi loopback tests in Rpi python 3.5x and 3.7x, you can search this forum using key words "SPI", "loopback". If you add the search word "tlfong01" you might find a couple of my answers with loopback python test programs, colourful waveforms illustrating the CLK, MOIS, MISO, CSn waveforms. You don't need to understand the details of the programs. My programs are "plug and play/run" no library is required. Though you need to "uncomment" to select slight variation of loopback, say one, two, or three characters, or control characters such a etc. Happy testing, cheers! – tlfong01 Dec 30 '19 at 04:12
  • Connect 3V3 to channel 0. Do you get a reading? Drop the speed to 100 kbps and use piscope to check the signals. – joan Dec 30 '19 at 09:31
  • @tlong01 I performed the loopback test, and i got hexadecimal characters, just like the tutorials said I should. – Aubrey Champagne Dec 30 '19 at 21:53
  • @joan I hooked it straight to 3.3V, and still got 0 – Aubrey Champagne Dec 30 '19 at 21:54
  • Hi @Aubrey Champagne. How nice you have made a successful SPI loopback. Congratulations! Let me tell you why this should be congratulated and the significance or implications. (1) SPI or UART loopback filters away many possible/potential problems, include (a) bad power supply (too low), (b) bad wiring, too long wiring, acting as antenna absorbing noise, especially at high frequencies, – tlfong01 Dec 31 '19 at 03:58
  • (b) intermittently poor contact connections (better use cable tie to do strain relief). BTW this loopback test is very useful for trouble shooting later, in case your MCPO3008 breaks down, or when you squeeze more SPI devices and crash things. – tlfong01 Dec 31 '19 at 03:58
  • @tlfong01 I have an extra pi, so tomorrow I am going to use a clean version of Raspian to find the problem. Hopefully it works – Aubrey Champagne Dec 31 '19 at 04:02
  • I read your tutorial and found the critical function read ADC result is bit complicated, with the following two statements: (1) r = spi.xfer2([1, 8 + adcnum << 4, 0]) (2) data = ((r[1] & 3) << 8) + r[2]. This is the most critical part. You need to understand every word, every symbol, =, &, <<, + etc then you can troubleshoot in case you made a typo error. It is unlikely that your Rpi is bad. It is more likely the human newbie makes a stupid mistake somewhere. – tlfong01 Dec 31 '19 at 06:51
  • Anyway, you already passed the SPI loopback test, so you are already a junior ninja. Perhaps I should give you another test called "Ping MCP3008 Test", to help you upgrade to middle level ninja! :) – tlfong01 Dec 31 '19 at 06:52
  • @tlfong01 you can ping the device? I thought there was no way of detecting it through the pi – Aubrey Champagne Dec 31 '19 at 15:23

0 Answers0