Interfacing

Spi and MCP3008

5 3610
Hello everyone, I am looking for a working example using a MCP3008 to read ADC value. How should it set the BananaPi and if possible a sample code? thank you in advanced

Alexis
Found something at least to start... (maybe is nothing)
http://forum.lemaker.org/1572-1-1-spi_really_working_.html

Reply 1# Alexis81


    wiringpiBP lib for wiringPi,the example of mcp3004 may help you.

You can try my code. It works very well.
SPICLK = 11
SPIMISO = 9
SPICS = 5

# set up the SPI interface pins
#GPIO.setup(SPIMOSI, GPIO.OUT)
GPIO.setup(SPIMISO, GPIO.IN)
GPIO.setup(SPICLK, GPIO.OUT)
GPIO.setup(SPICS, GPIO.OUT)
globtemp = 0


def readadc(clockpin, misopin, cspin):
        # if (adcnum != 0):
                # return -1
    GPIO.output(cspin, True)
    GPIO.output(clockpin, False)  # start clock low
    GPIO.output(cspin, False)     # bring CS low

    adcout = 0
        # read in two empty bits, one null bit and 12 ADC bits
    for i in range(15):
        GPIO.output(clockpin, True)
        #time.sleep(0.000001)
        GPIO.output(clockpin, False)
        adcout <<= 1
        if (GPIO.input(misopin)):
           # print(GPIO.input(misopin))
            adcout |= 0x1
            #print"j"

    GPIO.output(cspin, True)

    adcout >>= 1       # first bit is 'null' so drop it
    print (adcout)
    return adcout
value = readadc(SPICLK, SPIMISO, SPICS)
voltage = round(((value*5.25)/4096),3)

I'm using the MCP3002 to read analog Voltage from the Input Battery. I used the spidev python module.

I'm using PyQt signal and Thread to update GUI every 10 seconds.

Hi guys, anyone can tell me how to hack instagram if i search this keyword in any search engine I got the fake website they cheat us

You have to log in before you can reply Login | Sign Up

Points Rules