Beispiel #1
0
def CS_CAL_PWM_process(processEXIT, output_array):
    # output_array[0]=PWM_CH2
    # output_array[1]=PWM_CH3
    # output_array[2]=PWM_CH4

    print('Starting CS CAL PWM process.')

    # Setup PWM outputs for controls
    rcou1 = pwm.PWM(0)
    rcou2 = pwm.PWM(1)
    rcou3 = pwm.PWM(2)
    rcou4 = pwm.PWM(3)
    # Setup PWM frequencies
    rcou1.set_period(50)  #Hz
    rcou2.set_period(50)
    rcou3.set_period(50)
    rcou4.set_period(50)
    # Set initial commands
    rcou1.set_duty_cycle(1091 * 0.001)  # u_sec to m_sec
    rcou2.set_duty_cycle(1500 * 0.001)
    rcou3.set_duty_cycle(1500 * 0.001)
    rcou4.set_duty_cycle(1500 * 0.001)

    while processEXIT.value == 0:
        rcou1.set_duty_cycle(1091 * 0.001)
        rcou2.set_duty_cycle(output_array[0] * 0.001)
        rcou3.set_duty_cycle(output_array[1] * 0.001)
        rcou4.set_duty_cycle(output_array[2] * 0.001)
        time.sleep(0.02)
    # Set all commands except throttle back to neutral before exiting
    rcou1.set_duty_cycle(1091 * 0.001)  # u_sec to m_sec
    rcou2.set_duty_cycle(1500 * 0.001)
    rcou3.set_duty_cycle(1500 * 0.001)
    rcou4.set_duty_cycle(1500 * 0.001)
    print('CS CAL PWM  process stopped.')
  def __init__(self, pins_dict, reverse_pols=False):

    self.__enable   = pins_dict['enable']
    self.__control0 = pins_dict['control0'] if not reverse_pols else pins_dict['control1']
    self.__control1 = pins_dict['control1'] if not reverse_pols else pins_dict['control0']

    self.__pwm = pwm.PWM(self.__enable)
    self.__control0.init(pyb.Pin.OUT_PP)
    self.__control0.low()
    self.__control1.init(pyb.Pin.OUT_PP)
    self.__control1.low()
Beispiel #3
0
    def init(self):
        self.sensor = Adafruit_DHT.AM2302
        self.pin = 23

        Logger.info('va bien') #borrar esto

        self.PID = pid.PID(-60, -0.02, 0, Integrator_max=100, Integrator_min=-100)
        self.PID.setPoint(self.temperaturaDeseada)

        GPIO.setmode(GPIO.BCM)

        GPIO.setup(16, GPIO.OUT)
        GPIO.setup(21, GPIO.OUT)

        GPIO.output(16, GPIO.HIGH)
        GPIO.output(21, GPIO.LOW)

        self.fan = pwm.PWM(500, 0, 0, 12)
Beispiel #4
0
    def __init__(self, pins_dict, timer=6, reverse_pols=False):

        self.__enable = pwm.PWM(pins_dict['enable'])

        self.__control0 = pins_dict[
            'control0'] if not reverse_pols else pins_dict['control1']
        self.__control0.init(pyb.Pin.OUT_PP)
        self.__control0.low()
        self.__control1 = pins_dict[
            'control1'] if not reverse_pols else pins_dict['control0']
        self.__control1.init(pyb.Pin.OUT_PP)
        self.__control1.low()

        self.__led = pins_dict['led']
        self.__led.init(pyb.Pin.OUT_PP)

        self.__tack0 = pins_dict['tack0'] if not reverse_pols else pins_dict[
            'tack1']
        self.__tack1 = pins_dict['tack1'] if not reverse_pols else pins_dict[
            'tack0']
        self.__tack1.init(pyb.Pin.IN)

        #pyb.millis doesn't have enough resolution
        #start timer at TIMER_FREQ, with max possible period
        if timer in [1, 8, 9, 10, 11]:
            self.__ucounter = pyb.Timer(timer,
                                        prescaler=int(pyb.freq()[3] /
                                                      TIMER_FREQ),
                                        period=0x7fffffff)
        elif timer in [2, 3, 4, 5, 6, 7, 12, 13, 14]:
            self.__ucounter = pyb.Timer(timer,
                                        prescaler=int(pyb.freq()[2] /
                                                      TIMER_FREQ),
                                        period=0x7fffffff)
        self.__tim_rollover = False
        #set a callback on the timer which sets __tim_rollover true if it overflows
        #i.e. it counts past it's period, without a tack occuring.
        #if so we assume speed is zero as we can no longer measure it
        self.__ucounter.callback(self.__ISR_TIMER_SPEED)
        self.__pulsetime = 0  #this is measured speed ... we are at rest
        self.__pulsedir = 0  #at init doesn't matter what direction this indicates
        #register interrupt on tack0
        self.__extint = pyb.ExtInt(self.__tack0, pyb.ExtInt.IRQ_RISING,
                                   pyb.Pin.PULL_UP, self.__ISR_TACK_SPEED)
Beispiel #5
0
 def setUp(self):
     self.tmp_config = tempfile.NamedTemporaryFile(delete=False)
     self.tmp_config.write(
         textwrap.dedent("""\
     [pwm]
     database = sqlite://
     """).encode('utf-8'))
     self.tmp_config.close()
     db = sa.create_engine('sqlite://')
     pwm.Base.metadata.create_all(db)
     DBSession = sessionmaker(bind=db)
     self.session = DBSession()
     self.session.add(pwm.Domain(name='example.com', salt='NaCl'))
     self.session.add(pwm.Domain(name='otherexample.com',
                                 salt='supersalty'))
     self.session.add(pwm.Domain(name='facebook.com', salt='notsomuch'))
     self.session.commit()
     self.pwm = pwm.PWM(config_file=self.tmp_config.name,
                        session=self.session)
Beispiel #6
0
    def on_start(self):

        sensor = Adafruit_DHT.AM2302
        pin = 23

        Logger.info('va bien')  #borrar esto

        p = pid.PID(-60, -0.02, 0, Integrator_max=100, Integrator_min=-100)
        p.setPoint(8)

        GPIO.setmode(GPIO.BCM)

        GPIO.setup(16, GPIO.OUT)
        GPIO.setup(21, GPIO.OUT)

        GPIO.output(16, GPIO.HIGH)
        GPIO.output(21, GPIO.LOW)

        fan = pwm.PWM(500, 0, 0, 12)
Beispiel #7
0
    def __init__(self, platform):
        sys_clk_freq = int(32e6)
        # SoC with CPU
        SC.SoCCore.__init__(self,
                            platform,
                            cpu_type="lm32",
                            clk_freq=32e6,
                            csr_data_width=32,
                            ident="CPU Test SoC",
                            ident_version=True,
                            integrated_rom_size=0x8000,
                            integrated_main_ram_size=16 * 1024)

        # Clock Reset Generation
        self.submodules.crg = CRG(platform.request("clk32"),
                                  ~platform.request("cpu_reset"))

        # pwm
        self.submodules.pwm = PWM.PWM(platform.request("pwm1", 0))
        # generic
        self.submodules.generic = generic.GenericP()
Beispiel #8
0

##### MAIN PROGRAM #####
# Setup LED
led = leds.Led()

# Read command line inputs during program excecution and direct program accordingly
mode = check_CLI_inputs()

# Setup RCinput
rcin = rcinput.RCInput()

# NORMAL OPERATION
if (mode > 0):
    # Setup PWM outputs for controls
    rcou1 = pwm.PWM(0)
    rcou2 = pwm.PWM(1)
    rcou3 = pwm.PWM(2)
    rcou4 = pwm.PWM(3)

    # Setup external status LED
    rcou7 = pwm.PWM(6)
    rcou8 = pwm.PWM(7)
    rcou9 = pwm.PWM(8)

    # Setup PWM frequencies
    rcou1.set_period(50)  #Hz
    rcou2.set_period(50)
    rcou3.set_period(50)
    rcou4.set_period(50)
    rcou7.set_period(50)
Beispiel #9
0
import pwm

if __name__ == '__main__':

    t1 = tsys01_spi.TSYS01(0, 0)
    t1.open()
    t1.reset()
    t1.readRom()

    t2 = tsys01_spi.TSYS01(0, 1)
    t2.open()
    t2.reset()
    t2.readRom()

    print('setup')
    p1 = pwm.PWM(True)
    p2 = pwm.PWM(False)
    p1.setup()
    p2.setup()
    print('wait')
    for i in range(10):
        t1.startADC()
        t2.startADC()
        time.sleep(1)
        raw1 = t1.readADC()
        raw2 = t2.readADC()
        print("T1:", t1.temperatureCelsius(raw1))
        print("T2:", t2.temperatureCelsius(raw2))
    p1.start()
    p2.start()
Beispiel #10
0
SMALLFONTSIZE = 12

# Setup which pins we are using to control the oled
RESET_PIN = 15
DC_PIN = 16
# Using a 5x8 font
ROW_HEIGHT = 8
ROW_LENGTH = 20
NO_OF_ROWS = 4

MAX_X_AXIS = 25
VALUEFILE = '/home/pi/master/therm/log/values.log'

print("TFT control using new adafruit code")
myalarm = alarm.Alarm()
mypwm = pwm.PWM()

# Setup which pins we are using to control the oled
# These are for the 2.2" tft soldered onto proto board.
cs_pin = digitalio.DigitalInOut(board.CE0)
dc_pin = digitalio.DigitalInOut(board.D17)
reset_pin = digitalio.DigitalInOut(board.D23)
# Config for display baudrate (default max is 24mhz):
BAUDRATE = 24000000
# Setup SPI bus using hardware SPI:
spi = board.SPI()
# disp = ili9341.ILI9341(spi, rotation=90,cs=cs_pin, dc=dc_pin, rst=reset_pin, baudrate=BAUDRATE)  # 2.2", 2.4", 2.8", 3.2" ILI9341
# disp = ssd1351.SSD1351(spi, height=96, y_offset=32, rotation=180, # 1.27" SSD1351
disp = ssd1331.SSD1331(spi, rotation=180, cs=cs_pin, dc=dc_pin)

if disp.rotation % 180 == 90:
Beispiel #11
0
import pwm
import time

a = pwm.PWM(0)

a.start()
a.period = 1000000
a.polarity = 0
i = 0
while (i < a.period):
	a.duty = i
	time.sleep(0.001)
	i += 1000
a.polarity = 1
i = 0
while (i < a.period):
	a.duty = i
	time.sleep(0.001)
	i += 1000
a.stop()
a = None


b = pwm.PWM(0, 2000000, 0)
b.start()
i = 0
while (i < b.period):
	b.duty = i
	time.sleep(0.001)
	i += 1000
b.stop()
Beispiel #12
0
	def __init__(self, rowcount = NO_OF_ROWS, rowlength = ROW_LENGTH, rotation = 90):
		self.Event = threading.Event()
		self.threadLock = threading.Lock()
		threading.Thread.__init__(self, name='mytft')
		self.q = Queue(maxsize=12)
		self.rowcount = rowcount+1
		self.rowlength = rowlength
		self.last_prog_row = LAST_PROG_ROW
		self.rotation = rotation

		# Setup which pins we are using to control the hardware display
		if protoboard:
		# These are for the 2.2" tft soldered onto proto board.
			cs_pin = digitalio.DigitalInOut(board.CE0)
			dc_pin = digitalio.DigitalInOut(board.D18)		
			reset_pin = digitalio.DigitalInOut(board.D23)	
		else:				# wired tft
			cs_pin = digitalio.DigitalInOut(board.CE0)
			dc_pin = digitalio.DigitalInOut(board.D17)		
			reset_pin = digitalio.DigitalInOut(board.D23)

		# Setup SPI bus using hardware SPI:
		spi = board.SPI()
		self.disp = ili9341.ILI9341(spi, rotation=0,cs=cs_pin, dc=dc_pin, rst=reset_pin, baudrate=BAUDRATE)
		if self.disp.rotation % 180 == 90:
			height = self.disp.width   # we swap height/width to rotate it to landscape!
			width = self.disp.height
		else:
			width = self.disp.width   # we swap height/width to rotate it to landscape!
			height = self.disp.height

		self.image = Image.new("RGB", (width, height)) 	# Draw and text
		self.draw = ImageDraw.Draw(self.image)				# Get drawing object to draw on image.
		# Load a TTF Font
		self.big_font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", BIGFONTSIZE)
		self.time_font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", SMALLFONTSIZE)

#		self.disp = TFT.ILI9341(DC, rst=RST, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=64000000))
#		self.disp.begin()
#		self.disp.clear()	# black
		self.old_text = [' ' for i in range(self.rowcount)]	# used for clearing oled text
#		self.font = ImageFont.load_default()
#		self.font = ImageFont.truetype('binary/morningtype.ttf',FONTSIZE)
#		self.font = ImageFont.truetype('binary/secrcode.ttf',FONTSIZE)
#		self.font = ImageFont.truetype('binary/DS-DIGI.TTF',FONTSIZE)
#		self.font = [ImageFont.load_default() for i in range(self.rowcount)]
#		self.fontsize = [DEFAULT_FONT_SIZE for i in range(self.rowcount)]
#		self.fontsize[BIG_ROW] = 36
#		if TESTING:
#			self.fontsize[2] = 24
#			self.fontsize[3] = 24
#		for i in range(self.rowcount):
#			self.font[i] = ImageFont.truetype(FONT_DIR+'Hack-Regular.ttf',self.fontsize[i])
		# setup row colours
		self.rowcolour = [WHITE for i in range(self.rowcount)]			# set the defaults
		self.rowcolour[0] = YELLOW
#		self.rowcolour[self.rowcount-1] = BLUE
#		self.calc_offsets()
#		GPIO.setmode(GPIO.BCM)
#		GPIO.setup(LED,GPIO.OUT)
#		pi_pwm=GPIO.PWM(LED,100)		# pin number, frquency
#		pi_pwm.start(100)				# duty cycle
#		GPIO.setup(L_BUTTON, GPIO.IN, pull_up_down = GPIO.PUD_UP)
#		GPIO.setup(R_BUTTON, GPIO.IN, pull_up_down = GPIO.PUD_UP)
		self.myalarm = alarm.Alarm()
		self.mypwm = pwm.PWM()
		self.mysystem = system.System()