python - Using int containers with two x MCP3008 ADC Rpi -


the following code uses 2 mcp3008 chips attached rpi , home alarm panel. these 16 analog values fluctuate between 600 , 715 out of 1023 depending on pirs etc.

the int value prints out:

  chip - 1023       chip b -  242   chip - 1023       chip b - 1023   chip -    0       chip b -   68   chip - 1023       chip b -  599   chip - 1023       chip b - 1023   chip -   16       chip b - 1023   chip - 1023       chip b - 1023   chip - 1023       chip b - 1023 

i need:

value 1 = chip 1 readvalue 1 value 2 = chip 1 readvalue 2  etc... 

i tried strings, lists, io, wrappers first value.

could please go more detail want? currently, unclear. – sildoreth 35 mins ago

mcp3008_a , mcp3008_b print out analog values chip.i want assign each of values specific name, eg.value1 = 1023, value2 = 654 etc.. want able write ( if value 2 >=653 ) , (value10 <= 702) something. hope explains bit better – maurice1 19 mins ago

maybe clearer, @ bottom of code have #v1 = input.readline() , #v2= etc. need know should put in thereto read output mcp3008_a – maurice1 1 min ago edit

could please add information original post? – sildoreth 38 secs ago

#!/usr/bin/env python # -*- coding: utf-8 -*- #  https://github.com/adafruit/adafruit-raspberry-pi-python-code/blob/master/adafruit_mcp3008/mcp3008.py # bitbang code testing 8 channels  import rpi.gpio gpio, time, os import time      # import time sleep function import os import sys import cstringio cstringio import stringio import io debug = 1 gpio.setmode(gpio.bcm)  # read spi data mcp3008 chip, 8 possible adc's (0 thru 7) def readadc(adcnum, clockpin, mosipin, misopin, cspin):     if ((adcnum > 16) or (adcnum < 0)):         return -1     gpio.output(cspin, true)      gpio.output(clockpin, false)  # start clock low     gpio.output(cspin, false)     # bring cs low      commandout = adcnum     commandout |= 0x18  # start bit + single-ended bit     commandout <<= 3    # need send 5 bits here     in range(5):         if (commandout & 0x80):             gpio.output(mosipin, true)         else:             gpio.output(mosipin, false)                 commandout <<= 1                 gpio.output(clockpin, true)                 gpio.output(clockpin, false)      adcout = 0     # read in 1 empty bit, 1 null bit , 10 adc bits     in range(12):         gpio.output(clockpin, true)         gpio.output(clockpin, false)         adcout <<= 1         if (gpio.input(misopin)):             adcout |= 0x1      gpio.output(cspin, true)      adcout /= 2       # first bit 'null' drop     return adcout    if __name__=='__main__':     try:         # change these desired         spiclk = 11     #mcp3008_13         spimiso = 9     #mcp3008_12         spimosi = 10    #mcp3008_11         spics = 8       #mcp3008_10         spiclk2 = 17    #mcp3008_13         spimiso2 = 27   #mcp3008_12         spimosi2 = 22   #mcp3008_11         spics2 = 7      #mcp3008_10         # set spi interface pins          gpio.setup(spiclk, gpio.out)         gpio.setup(spimiso, gpio.in)         gpio.setup(spimosi, gpio.out)         gpio.setup(spics, gpio.out)         gpio.setup(spiclk2, gpio.out)         gpio.setup(spimiso2, gpio.in)         gpio.setup(spimosi2, gpio.out)         gpio.setup(spics2, gpio.out)          while true:             #print "",             time.sleep(1)             adcnum in range(8):                 mcp3008_a = readadc(adcnum, spiclk, spimosi, spimiso, spics)                 mcp3008_b = readadc(adcnum, spiclk2, spimosi2, spimiso2, spics2)                  print '  chip - ' "%4d" % mcp3008_a,                 print '      chip b - ' "%4d" % mcp3008_b,                 print ''                 time.sleep(0.3)                  d1=str(mcp3008_a)                 d2=str(mcp3008_b)             print "--------------------------------------"                  #v1 = input.readline()                 #v2 = input.readline(2)                 #v3 = input.readline()                 #v4 = input.read()        except keyboardinterrupt:         pass      gpio.cleanup() 


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -