python - How to Read FSR Value using Raspberry Pi3 -


i need help. going read value of fsr sensor using raspberry pi3 , cjmcu-1118 adc converter. tried code, , give me output 0 0x 0 0 0 code. import time import os import rpi.gpio gpio import spidev import sys

gpio.setwarnings(false) gpio.setmode(gpio.bcm) debug = 1   spi = spidev.spidev()               # create spi object spi.open(0,1)                   # open spi port 0, device (cs)1 spi.max_speed_hz = (500000) spi.mode = (1)  spiclk = 11 spimiso = 9 spimosi = 10 spics = 8   # set spi interface pins gpio.setup(spimosi, gpio.out) gpio.setup(spimiso, gpio.out) gpio.setup(spiclk, gpio.out) gpio.setup(spics, gpio.out)   def readadc(adcnum):     # read spi data mcp3008, 8 channels in total     if adcnum > 3 or adcnum < 0:         return -1     r = spi.xfer2([1, 4 + adcnum << 4, 0])     data = ((r[1] & 3) << 4) + r[2]     return data   while true:     fsr_value = readadc(spimiso)     buff = [0,0,0,0,0,0,0,0,0];     gpio.output(spimiso, false)     buff = spi.xfer2([0xff,0xff,0xff])     gpio.output(spimiso, true)     print("0x %x %x %x\t"%(buff[0],buff[1],buff[2]))     value = buff[0]<<16 | buff[1]<<8 | buff[2]     print(value) 


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -