def api_pwm(self, chan, command, option, req_method, req_args): resp = copy.deepcopy(self.CHIP_INFO) resp["connected"] = True # Default the channel to PWM0 # CHIP Pro will support PWM1 cname = "PWM0" chan = int(chan) if chan not in [0]: #,1]: resp["message"] = "Invalid PWM Channel Specified" return jsonify(resp) else: if chan == 0: cname = "PWM0" elif chan == 1: cname = "PWM1" # Figure out our command if command == "start" and req_method == 'GET': # Load the overlay OM.load(cname) # Get the arguments duty_cycle = req_args.get('duty_cycle', 25.0) frequency = req_args.get('frequency', 200.0) polarity = req_args.get('polarity', 0) # Start the PWM PWM.start(cname, duty_cycle, frequency, polarity) resp[ "message"] = "Setting {0} to duty cycle: {1}, frequency: {2}, and polarity {3}".format( cname, duty_cycle, frequency, polarity) elif command == "stop" and req_method == 'GET': PWM.stop(chame) resp["message"] = "Stopping {0}".format(cname) elif command == "cleanup" and req_method == 'GET': # TODO: Handle per channel cleanup PWM.cleanup() OM.unload(cname) resp["message"] = "Cleaning up and unloading {0}".format(cname) elif command == "duty_cycle" and req_method in ['GET', 'PUT', 'POST']: PWM.set_duty_cycle(cname, float(option)) resp["message"] = "Changing duty cycle on {0} to {1}".format( cname, option) elif command == "frequency" and req_method in ['GET', 'PUT', 'POST']: PWM.set_frequency(cname, float(option)) resp["message"] = "Changing duty cycle on {0} to {1}".format( cname, option) return jsonify(resp)
def setup_module(module): if not UT.is_chip_pro(): OM.load("PWM0")
import Adafruit_GPIO.SPI as SPI #SPI library import CHIP_IO.OverlayManager as OM # To load/unload SPI import CHIP_IO.GPIO as gpio # To configure GPIO import time OM.load("SPI2") #load SPI2 ADC_CS = "U14_32" #GPIO Pin to be used as Chip select for SPI (here , device is 12-bit ADC MCP3202) gpio.setup(ADC_CS, gpio.OUT) #CS for ADC gpio.output(ADC_CS, gpio.HIGH) #Set as output """configure SPI""" def SPI_configure(): spi = SPI.SpiDev( 2, 0, 500000) # create a class for SPI bus2,device 0, 500kHz clock. spi.set_bit_order(SPI.MSBFIRST) spi.set_clock_hz(500000) spi.set_mode(0) return spi """ Transfer from SPI, for full Duplex""" def SPI_transfer(spi, send_data): data = [0x00, 0x00] # received data tobe stored in 'data' try: gpio.output(ADC_CS, gpio.LOW) # Choose ADC to transfer data = spi.transfer(send_data) # get 12-bit ADC data
from touch_display_ra8875 import * from adafruit_ra8875 import * from netpbm import * import CHIP_IO.GPIO as GPIO import CHIP_IO.OverlayManager as OM OM.load('SPI2') RA8875_INT = 'XIO-P1' RA8875_CS = 'XIO-P2' RA8875_RESET = 'XIO-P3' tft = Adafruit_RA8875(RA8875_CS, RA8875_RESET) if not tft.begin(RA8875sizes.RA8875_800x480): try: raise Exception("RA8875 Not Found!") except Exception as e: print(e) tft.displayOn(True) tft.GPIOX(True) # Enable TFT - display enable tied to GPIOX tft.PWM1config(True, RA8875_PWM_CLK_DIV1024) # PWM output for backlight tft.PWM1out(255) tft.touchEnable(True) GPIO.setup(RA8875_INT, GPIO.IN, pull_up_down=GPIO.PUD_UP) app = TouchDisplay(intPin=RA8875_INT, tft=tft) screen = Screen(id=0, parent=app, fg_color=RA8875_YELLOW, bg_color=RA8875_RED)
#!/usr/bin/python import CHIP_IO.OverlayManager as OM import os # ENABLE DEBUG print("ENABLING OVERLAY MANAGER DEBUG") OM.enable_debug() # **************** PWM ******************* print("\nIS PWM ENABLED: {0}".format(OM.get_pwm_loaded())) OM.load("PWM0") print("IS PWM ENABLED: {0}".format(OM.get_pwm_loaded())) # VERIFY PWM0 EXISTS if os.path.exists('/sys/class/pwm/pwmchip0'): print("PWM DEVICE EXISTS") else: print("PWM DEVICE DID NOT LOAD PROPERLY") print("UNLOADING PWM0") OM.unload("PWM0") print("IS PWM ENABLED: {0}".format(OM.get_pwm_loaded())) # **************** I2C-1 ******************* print("\nIS I2C ENABLED: {0}".format(OM.get_i2c_loaded())) OM.load("I2C1") print("IS I2C ENABLED: {0}".format(OM.get_i2c_loaded())) # VERIFY I2C-1 EXISTS if os.path.exists('/sys/class/i2c-dev/i2c-1'): print("I2C1 DEVICE EXISTS") else: print("I2C1 DEVICE DID NOT LOAD PROPERLY")
import CHIP_IO.GPIO as GPIO import CHIP_IO.OverlayManager as OM import CHIP_IO.PWM as PWM import time # Initialize hardware pwm thorugh the OM OM.enable_debug() OM.load("PWM0") # Test it loaded properly if (OM.get_pwm_loaded()): print("PWM OM Successfully loaded...") # Setup the pins GPIO.setup("XIO-P0", GPIO.OUT) GPIO.setup("XIO-P1", GPIO.OUT) PWM.start("PWM0", 100, 100, 0) # Run the test try: GPIO.output("XIO-P0", GPIO.HIGH) GPIO.output("XIO-P1", GPIO.LOW) print("Testing duty cycle...") # Test duty cycle # for x in range(0,100): # SPWM.set_duty_cycle("PWM0", x) # print(x) # time.sleep(.1)
#!/usr/bin/python import CHIP_IO.OverlayManager as OM import os # ENABLE DEBUG print("ENABLING OVERLAY MANAGER DEBUG") OM.toggle_debug() # **************** PWM ******************* print("\nIS PWM ENABLED: {0}".format(OM.get_pwm_loaded())) OM.load("PWM0") print("IS PWM ENABLED: {0}".format(OM.get_pwm_loaded())) # VERIFY PWM0 EXISTS if os.path.exists('/sys/class/pwm/pwmchip0'): print("PWM DEVICE EXISTS") else: print("PWM DEVICE DID NOT LOAD PROPERLY") print("UNLOADING PWM0") OM.unload("PWM0") print("IS PWM ENABLED: {0}".format(OM.get_pwm_loaded())) # **************** SPI2 ******************* print("\nIS SPI ENABLED: {0}".format(OM.get_spi_loaded())) OM.load("SPI2") print("IS SPI ENABLED: {0}".format(OM.get_spi_loaded())) # VERIFY SPI2 EXISTS if os.listdir('/sys/class/spi_master') != "": print("SPI DEVICE EXISTS") else: print("SPI DEVICE DID NOT LOAD PROPERLY")
import CHIP_IO.OverlayManager as OM OM.load("SPI2")