Generating Square Wave using Adafruit Library in Python

squarewave.py : python rogram for square/sine wave generation using ADC-DAC card.

#!/usr/bin/python 
##########################################################
# * Python code (Adafruit BBIO Library Version) for 
# * Square/Sine wave generation using ADC-DAC Card and 
# * Beaglebone Black running Debian 7 Linux distribution
##########################################################
# * Developed by MicroEmbedded Technologies
##########################################################
 
# Import standard python libraries
import sys
import os
import time

# Import GPIO part of Adafruit BBIO Library
import Adafruit_BBIO.GPIO as GPIO
# Import ADC part of Adafruit BBIO Library
import Adafruit_BBIO.ADC as ADC

##############################################################
# GPIO Pin definitions for Square wave traffic board LD1 
# Please refer "MicroEmbedded_BBB_Interfacing Details_New.pdf" 
# for all the PIN details
##############################################################

SQW_PIN = "P9_21"
 
##############################################################
# Description : This function turns the PIN ON 
# It will setup a PIN as GPIO, sets the 
# direction as OUT and then makes the PIN high 
# Input : @pin = Pin No associated with LED
# Return : None 
# Note : 
##############################################################

def Sq_wave(pin, val):
 GPIO.setup(pin, GPIO.OUT)
 if (val == "1"):
 GPIO.output(pin, GPIO.HIGH)
 else:
 GPIO.output(pin, GPIO.LOW)
 return


while True:
 Sq_wave(SQW_PIN,"1")
 time.sleep(0.01) # pause 
 Sq_wave(SQW_PIN,"0")
 time.sleep(0.01) # pause 
exit()

Leave a Reply

Your email address will not be published. Required fields are marked *