Advertisement
SoapSuds

Beaglebone Speaker DAC test GPIO driver

Jun 20th, 2012
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.94 KB | None | 0 0
  1. import os
  2. import time
  3.  
  4.  
  5.  
  6. #Functions
  7. def setDirection(pin, direction):
  8.     pin = str(pin)
  9.     direction = str(direction)
  10.    
  11.     os.system("echo "+pin+" > /sys/class/gpio/export")
  12.     os.system("echo "+direction+" > /sys/class/gpio/gpio"+pin+"/direction")
  13.    
  14.    
  15. def setPinValue(pin, pinValue):
  16.     pin = str(pin)
  17.     pinValue = str(pinValue)
  18.    
  19.     os.system("echo "+pinValue+" > /sys/class/gpio/gpio"+pin+"/value")
  20.    
  21.    
  22. #Begin Script
  23. #######################
  24.  
  25. #Turn on P8 Pin 40
  26. #Data Line 0
  27. setDirection(77, "out")
  28.  
  29. #Turn on P8 Pin 42
  30. #Data Line 1
  31. setDirection(75, "out")
  32.  
  33. #Turn on P8 Pin 44
  34. #Data Line 2
  35. setDirection(73, "out")
  36.  
  37. #Turn on P8 Pin 46
  38. #Data Line 3
  39. setDirection(71, "out")
  40.  
  41. #Turn on P8 Pin 45
  42. #Data Line 4
  43. setDirection(70, "out")
  44.  
  45. #Turn on P8 Pin 43
  46. #Data Line 5
  47. setDirection(72, "out")
  48.  
  49. #Turn on P8 Pin 41
  50. #Data Line 6
  51. setDirection(74, "out")
  52.  
  53. #Turn on P8 Pin 39
  54. #Data Line 7
  55. setDirection(76, "out")
  56.  
  57. startValue = 0
  58.  
  59. while True:
  60.     startValue = startValue + 1
  61.     if startValue > 255:
  62.         startValue = 0
  63.        
  64.     #Reset datapins before setting datapins
  65.     #setPinValue(77, 0)
  66.     #setPinValue(75, 0)
  67.     #setPinValue(73, 0)
  68.     #setPinValue(71, 0)
  69.     #setPinValue(70, 0)
  70.     #setPinValue(72, 0)
  71.     #setPinValue(74, 0)
  72.     #setPinValue(76, 0)
  73.    
  74.     #Turn on datalines accordingly
  75.     #convert dec to binary
  76.     binary_value = bin(startValue)
  77.     binary_value = binary_value[2:]
  78.    
  79.     print binary_value
  80.    
  81.     if binary_value.__len__() == 1:
  82.         binary_value = "0000000"+str(binary_value)
  83.    
  84.     if binary_value.__len__() == 2:
  85.         binary_value = "000000"+str(binary_value)
  86.    
  87.     if binary_value.__len__() == 3:
  88.         binary_value = "00000"+str(binary_value)
  89.    
  90.     if binary_value.__len__() == 4:
  91.         binary_value = "0000"+str(binary_value)
  92.        
  93.     if binary_value.__len__() == 5:
  94.         binary_value = "000"+str(binary_value)
  95.    
  96.     if binary_value.__len__() == 6:
  97.         binary_value = "00"+str(binary_value)      
  98.        
  99.     if binary_value.__len__() == 7:
  100.         binary_value = "0"+str(binary_value)
  101.        
  102.            
  103.  
  104.  
  105.  
  106.     #Data Line 0
  107.     ########
  108.     if binary_value[7] == "1":
  109.         setPinValue(77, 1)
  110.     else:
  111.         setPinValue(77, 0)
  112.     ########
  113.    
  114.  
  115.     #Data Line 1
  116.     ########
  117.     if binary_value[6] == "1":
  118.         setPinValue(75, 1)
  119.     else:
  120.         setPinValue(75, 0)
  121.     ########
  122.    
  123.    
  124.     #Data Line 2
  125.     ########
  126.     if binary_value[5] == "1":
  127.         setPinValue(73, 1)
  128.     else:
  129.         setPinValue(73, 0)
  130.     ########
  131.    
  132.    
  133.     #Data Line 3
  134.     ########
  135.     if binary_value[4] == "1":
  136.         setPinValue(71, 1)
  137.     else:
  138.         setPinValue(71, 0)
  139.     ########
  140.    
  141.    
  142.     #Data Line 4
  143.     ########
  144.     if binary_value[3] == "1":
  145.         setPinValue(70, 1)
  146.     else:
  147.         setPinValue(70, 0)
  148.     ########
  149.    
  150.    
  151.     #Data Line 5
  152.     ########
  153.     if binary_value[2] == "1":
  154.         setPinValue(72, 1)
  155.     else:
  156.         setPinValue(72, 0)
  157.     ########
  158.    
  159.    
  160.     #Data Line 6
  161.     ########
  162.     if binary_value[1] == "1":
  163.         setPinValue(74, 1)
  164.     else:
  165.         setPinValue(74, 0)
  166.     ########
  167.    
  168.    
  169.     #Data Line 7
  170.     ########
  171.     if binary_value[0] == "1":
  172.         setPinValue(76, 1)
  173.     else:
  174.         setPinValue(76, 0)
  175.     ########
  176.  
  177.    
  178.     #time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement