Skip to content
This repository was archived by the owner on Sep 30, 2019. It is now read-only.

Update mcp3008.py #71

Merged
merged 1 commit into from
Jul 27, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 32 additions & 24 deletions Adafruit_MCP3008/mcp3008.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,35 @@ def readadc(adcnum, clockpin, mosipin, misopin, cspin):
adcout /= 2 # first bit is 'null' so drop it
return adcout

# change these as desired
SPICLK = 18
SPIMOSI = 17
SPIMISO = 21
SPICS = 22

# 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)

# Note that bitbanging SPI is incredibly slow on the Pi as its not
# a RTOS - reading the ADC takes about 30 ms (~30 samples per second)
# which is awful for a microcontroller but better-than-nothing for Linux

print "| #0 \t #1 \t #2 \t #3 \t #4 \t #5 \t #6 \t #7\t|"
print "-----------------------------------------------------------------"
while True:
print "|",
for adcnum in range(8):
ret = readadc(adcnum, SPICLK, SPIMOSI, SPIMISO, SPICS)
print ret,"\t",
print "|"
if __name__=='__main__':

try:
# change these as desired
SPICLK = 18
SPIMISO = 21
SPIMOSI = 17
SPICS = 22

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

# Note that bitbanging SPI is incredibly slow on the Pi as its not
# a RTOS - reading the ADC takes about 30 ms (~30 samples per second)
# which is awful for a microcontroller but better-than-nothing for Linux

print "| #0 \t #1 \t #2 \t #3 \t #4 \t #5 \t #6 \t #7\t|"
print "-----------------------------------------------------------------"
while True:
print "|",
for adcnum in range(8):
ret = readadc(adcnum, SPICLK, SPIMOSI, SPIMISO, SPICS)
print ret,"\t",
print "|"

except KeyboardInterrupt:
pass

GPIO.cleanup()