D4 = nRESET = 1 D5 = nSLEEP = 1 D6 = nENABLE = 0 D7 = - = X """ import time import logging from Path import Path try: from spi import SPI # init the SPI for the DAC spi2_0 = SPI(1, 0) spi2_0.bpw = 8 spi2_0.mode = 1 # Init the SPI for the serial to parallel spi2_1 = SPI(1, 1) spi2_1.bpw = 8 spi2_1.mode = 0 except ImportError: pass class Stepper: all_steppers = list() revision = "A4" SLEEP = 6 ENABLED = 4 RESET = 7
from threading import Event, Thread def repeat(interval, func): def loop(): while not Event().wait(interval): func() Thread(target=loop).start() # uses https://raw.githubusercontent.com/tomstokes/python-spi/master/spi.py from spi import SPI spi = SPI('/dev/spidev1.0') spi.mode = SPI.MODE_0 spi.bits_per_word = 8 spi.speed = 10 * 1000000 IODIRA = 0x00 IOCON = 0x0a GPIOA = 0x12 # write to MCP23S17 register(s), GPIOA by default def mcp23s17(address, values, register=GPIOA): global spi opcode = 0x40 | (address << 1) spi.write([opcode, register] + values)
#!/usr/bin/env python from spi import SPI spi2_1 = SPI(2, 1) spi2_1.bpw = 8 spi2_1.mode = 0 spi2_1.writebytes([0x30])
D2 = MODE1 = X D3 = MODE2 = X D4 = nRESET = 1 D5 = nSLEEP = 1 D6 = nENABLE = 0 D7 = = 0 ''' from spi import SPI from threading import Thread import time import logging # init the SPI for the DAC spi2_0 = SPI(1, 0) spi2_0.bpw = 8 spi2_0.mode = 1 # Init the SPI for the serial to parallel spi2_1 = SPI(1, 1) spi2_1.bpw = 8 spi2_1.mode = 0 class SMD: all_smds = list() ''' Send the values to the serial to parallel chips ''' @staticmethod def commit(): bytes = [] for smd in SMD.all_smds: bytes.append(smd.getState())
D3 = MODE2 = X D4 = nRESET = 1 D5 = nSLEEP = 1 D6 = nENABLE = 0 D7 = - = X ''' from spi import SPI from threading import Thread import time import logging # init the SPI for the DAC spi2_0 = SPI(1, 0) spi2_0.bpw = 8 spi2_0.mode = 1 # Init the SPI for the serial to parallel spi2_1 = SPI(1, 1) spi2_1.bpw = 8 spi2_1.mode = 0 class Stepper: all_steppers = list() revision = "A4" SLEEP = 6 ENABLED = 4 RESET = 7 DECAY = 5 ''' Send the values to the serial to parallel chips '''
#!/usr/bin/env python from spi import SPI from time import sleep from datetime import datetime port = SPI(2,0) port.msh = 100000 #port.lsbfirst = True port.mode = 0b00 _DISPLAY_6X12 = 0x02 _DISPLAY_7X11 = 0x03 _AUTO_INCREMENT = 0x40 _FIXED_ADDRESS = 0x44 _DISPLAY_OFF = 0x80 _DISPLAY_1_16 = 0x88 _DISPLAY_2_16 = 0x89 _DISPLAY_4_16 = 0x8A _DISPLAY_10_16 = 0x8B _DISPLAY_11_16 = 0x8C _DISPLAY_12_16 = 0x8D _DISPLAY_13_16 = 0x8E _DISPLAY_14_16 = 0x8F addresses = (0xC0,0xC2,0xC4,0xC6) font = { 0: 0xFC, 1: 0x60, 2: 0xDA, 3: 0xF2,
#!/usr/bin/env python from spi import SPI # Set up the SPI dac = SPI(2, 0) dac.mode = 1 # SPI mode 1 dac.bpw = 8 # 8 bits pr word dac.lsbfirst = False # MSB transfers # Calculate the value for the DAC iChop = 2.0 # Current chopping limit (This is the value you can change) vRef = 3.3 # Voltage reference on the DAC rSense = 0.1 # Resistance for the vOut = iChop*5.0*rSense # Calculated voltage out from the DAC (See page 9 in the datasheet for the DAC) dacval = int((vOut*256.0)/vRef) # Update all channels with the value for addr in range(8): byte1 = ((dacval & 0xF0)>>4) + (addr<<4) byte2 = (dacval & 0x0F)<<4 dac.writebytes([byte1, byte2]) # Update all channels dac.writebytes([0xA0, 0xFF]) print "All channels now have vOut = "+str(vOut)+", iChop = "+str(iChop)