0

[![enter image description here][1]][1]I use MCP3008 adc to see a potentiometer values on raspberry pi 3. My connection same with the link down here. https://roboticadiy.com/potentiometer-analog-input-for-the-raspberry-pi-4/ I was able to read pot values for a while like a month but then all values became 0. I tested ADCs. They are not faulty. Formatted my raspberry pi sd card. Nothings changed. Tested spi with spidev_test this is the result.

spi mode: 4
bits per word: 8
max speed: 500000 Hz (500 KHz)

FF FF FF FF FF FF
40 00 00 00 00 95
FF FF FF FF FF FF
FF FF FF FF FF FF
FF FF FF FF FF FF
DE AD BE EF BA AD
F0 0D

Tested with a different spidev_test code from https://github.com/rm-hull/spidev-test that link. This is the result.

spi mode: 0x4
bits per word: 8
max speed: 500000 Hz (500 KHz)
TX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D  | ......@....?..................?.
RX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D  | ......@....?..................?.

I didn't find anything such as spi mode: 4 or 0x4 on the internet. I dont know if it is a hardware issue. If it is a hardware issue is anything can be done?

Lastly this is the code i used to get adc values and save on a csv file.

import csv
import time
from gpiozero import PWMLED, MCP3008
from time import sleep

pot = MCP3008(0)
x_value = 0
total_1 = 0

fieldnames = ["x_value", "total_1"]

with open('data.csv', 'w') as csv_file:
    csv_writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
    csv_writer.writeheader()

while True:

    with open('data.csv', 'a') as csv_file:
        csv_writer = csv.DictWriter(csv_file, fieldnames=fieldnames)

        info = {
            "x_value": x_value,
            "total_1": total_1,
        }

        csv_writer.writerow(info)
        print(x_value, total_1)

        x_value += 1
        total_1 = int(pot.value*100)

    time.sleep(0.05)

My analog circuit connection was like this and i feed that circuit with +-9V.[1]: https://i.stack.imgur.com/nVGZN.png

2
  • 1
    Most likely a wiring problem. We need clear close-up photos. The modes are 0-3. The driver reports values 4-7 for modes 0-3.
    – joan
    Mar 25 at 16:37
  • I think i understand what is the problem. I use the same adc-raspberry pi connections for a different analog circuit. That analog circuit was an EEG signal acquisition circuit. My analog circuits gain was approximately 19000. For an EEG signal max output could be 1.9v but i use the same circuit for ECG signal. So with 19000 times gain ECG output was more than 3.3v and i think that was the issue. But i use 3.3v feed for MCP3008 adc. Only channel 0 input was more than 3.3v. Could this be cause the issue? Mar 28 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.