예제 #1
0
def create_analog_reader():
    spi_port = 0
    spi_device = 0
    spi = SpiDev(spi_port, spi_device)
    mcp = MCP3008(spi=spi)
    analog_reference_volts = 3.3
    return MCP3004AnalogReader(mcp, analog_reference_volts)
예제 #2
0
    def __init__(self):
        # Create the MCP input
        self.mcp = MCP3008(spi=SPI(self.spi_port, self.spi_device))

        # Create the LCD output
        self.lcd = LCD(self.lcd_rs, self.lcd_en, self.lcd_d4, self.lcd_d5,
                       self.lcd_d6, self.lcd_d7, self.lcd_columns,
                       self.lcd_rows)
    def __init__(self, mode):

        logging.debug("IOUTILS::init")

        # Setting mode
        self.mode = mode

        ## State to retrieve current finger's position
        self.currentState = State()

        ## init MYO
        self.myo = Myoutils(mode)

        if (self.mode == OPERATION_MODE):
            self.myo.startThreadMyo()

        ## Test helper class attribute
        self.test = Test(self.myo)

        # Initialize raspberry board
        GPIO.setmode(GPIO.BCM)

        # Initialize input elements
        #GPIO.setup(GPIO_INPUT_BUTTON_0, GPIO.IN)
        #GPIO.setup(GPIO_INPUT_BUTTON_1, GPIO.IN)
        #GPIO.setup(GPIO_INPUT_SWITCH_0, GPIO.IN)
        #GPIO.setup(GPIO_INPUT_SWITCH_1, GPIO.IN)
        #GPIO.setup(GPIO_INPUT_SWITCH_2, GPIO.IN)
        #GPIO.setup(GPIO_INPUT_SWITCH_3, GPIO.IN)

        # Initialize output elements
        GPIO.setup(GPIO_OUTPUT_LED_VBAT_OK, GPIO.OUT)
        GPIO.setup(GPIO_OUTPUT_LED_VBAT_LOW, GPIO.OUT)
        #GPIO.setup(GPIO_OUTPUT_POWER_CUT, GPIO.OUT)

        GPIO.setup(MOT_0_A_CTRL, GPIO.OUT)
        GPIO.setup(MOT_0_B_CTRL, GPIO.OUT)
        GPIO.setup(MOT_1_A_CTRL, GPIO.OUT)
        GPIO.setup(MOT_1_B_CTRL, GPIO.OUT)
        GPIO.setup(MOT_2_A_CTRL, GPIO.OUT)
        GPIO.setup(MOT_2_B_CTRL, GPIO.OUT)

        # Initialize PWM
        # TODO - Here or in fingerControl?
        #self.pwm = PCA9685(PCA_I2C_ADDR)
        #self.pwm.set_pwm_freq(PWM_FRQUENCY)

        #initialize ADC
        # TODO - Here or in fingerControl?
        self.adc = MCP3008(clk=GPIO_BUS_SCLK,
                           cs=GPIO_BUS_ADC_CS,
                           miso=GPIO_BUS_MISO,
                           mosi=GPIO_BUS_MOSI)
예제 #4
0
파일: R2D2.py 프로젝트: curtisblack/R2D2
    def __init__(self):
        logging.basicConfig(format="%(levelname)s (%(asctime)s): %(message)s", datefmt="%I:%M:%S %p", level=logging.INFO, filename="/var/tmp/R2D2.log")        
        GPIO.setwarnings(False)
        GPIO.setmode(GPIO.BCM)
        atexit.register(self.Exit)
        self.MCP3008 = MCP3008(spi=SPI.SpiDev(0, 0))
        self.Voltage = VoltageDivider(self.MCP3008, 0, 984.0, 101.0)
        self.Current = ACS711EX(self.MCP3008, 1)
        self.BrightnessControl = Potentiometer(self.MCP3008, 2)
        self.Battery = LiPo(self.Voltage, self.Current, 6, 10)
        
        self.DomeLightsRelay = self.Relay1 = Relay(16)
        self.DomeServosRelay = self.Relay2 = Relay(17)
        self.DomeMotorRelay = self.Relay3 = Relay(18)
        self.Relay4 = Relay(19)
        self.Relay5 = Relay(20)
        self.SoundRelay = self.Relay6 = Relay(21)
        self.BodyServosRelay = self.Relay7 = Relay(22)
        self.BodyLightsRelay = self.Relay8 = Relay(23)
        self.Relay9 = Relay(24)
        self.Relay10 = Relay(25)
        self.Relay11 = Relay(26)
        self.Relay12 = Relay(27)

        self.Network = Network()
        
        self.Head = HeadMotor(self.DomeMotorRelay)
        self.Sound = Sound()
        self.StatusDisplay = StatusDisplay(self)

        self.FrontLogicDisplay = FrontLogicDisplay(self.DomeLightsRelay)
        self.RearLogicDisplay = RearLogicDisplay(self.DomeLightsRelay)
        self.FrontProcessStateIndicator = FrontProcessStateIndicator(self.DomeLightsRelay)
        self.RearProcessStateIndicator = RearProcessStateIndicator(self.DomeLightsRelay)
        self.FrontHoloProjector = FrontHoloProjector(self.DomeLightsRelay)
        self.TopHoloProjector = TopHoloProjector(self.DomeLightsRelay)
        self.RearHoloProjector = RearHoloProjector(self.DomeLightsRelay)
        self.MagicPanel = MagicPanel(self.DomeLightsRelay)
        self.LifeFormScanner = LifeFormScanner(self.DomeServosRelay)
        self.DomePanels = Panels()
        
        self.BodyServos = Maestro("00126418")
        self.LeftUtilityArm = MaestroServo(self.BodyServos, 16, 2390, 1520, 20, 1)
        self.RightUtilityArm = MaestroServo(self.BodyServos, 17, 2390, 1520, 20, 1)
예제 #5
0
if (_DEBUGVAR_):
    print ("After:")
    for p in port_list:
        print (p)

if port_list is not None:
    sd_port = port_list[0]
    aerocet_port = port_list[1]
    
print("Baiden passec section 3")

sdObject = SD_4023(sd_port,1)
aeroObject = Aerocet531s(38400,aerocet_port,1)
#maObject = MA200(aethlabs_symlink,1)
mcp = MCP3008(clk=CLK, cs=CS, miso=MISO, mosi=MOSI)
am = AM2315(0x5c,"/dev/i2c-1")

print("Baiden passec section 4")

file_aero = open(AERO_FILE_NAME,"a",0)
file_sd = open(SD_FILE_NAME,"a",0)
file_co2 = open(CO2_FILE_NAME,"a",0)
file_flow = open(FLOW_FILE_NAME,"a",0)
file_am = open(AM_FILE_NAME,'a',0)
#file_ma200 = open(MA200_FILE_NAME,"a",0)

if os.path.getsize(AERO_FILE_NAME) == 0:
    print ("(AEROCET531s): Empty output log. Writing header.")
    file_aero.write(OUTPUT_LOG_HEADERS['aero'])
if os.path.getsize(SD_FILE_NAME) == 0:
예제 #6
0
from time import sleep
from colorsys import hsv_to_rgb
from gpiozero import RGBLED
from Adafruit_MCP3008 import MCP3008

adc = MCP3008(clk=11, cs=8, miso=9, mosi=10)
led = RGBLED(14, 20, 21)

JOY_X = 0      # Which pin on the A/D converter
JOY_Y = 1
MAX_ANALOG = 1023
MAX_HUE = 950  # Stop at violet (avoid wrapping around to red)

try:
    while True:
        joy_x = adc.read_adc(JOY_X)
        joy_y = adc.read_adc(JOY_Y)
        hue = min(joy_x, MAX_HUE)
        brightness = MAX_ANALOG - joy_y  # Invert so up is brightest
        hsv = hue / MAX_ANALOG, 1, brightness / MAX_ANALOG  # Hue, saturation, value
        rgb = hsv_to_rgb(*hsv)  # Red, green, blue
        led.color = rgb
        sleep(1/30)
except KeyboardInterrupt:
    pass

led.off()
예제 #7
0
"""
this is a test of reading 'SCT-013 50amp 1V' sensor w/ a MCP3008 ADC
"""
import time
from Adafruit_GPIO import SPI
from Adafruit_MCP3008 import MCP3008

SPI_PORT = 0
SPI_DEVICE = 1
mcp = MCP3008(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))

print('Reading MCP3008 values, press Ctrl-C to quit...')
"""
# Print nice channel column headers.
print('| {0:>4} | {1:>4} | {2:>4} | {3:>4} | {4:>4} | {5:>4} | {6:>4} | {7:>4} |'.format(*range(8)))
print('-' * 57)
# Main program loop.
while True:
    # Read all the ADC channel values in a list.
    values = [0]*8
    for i in range(8):
        # The read_adc function will get the value of the specified channel (0-7).
        values[i] = mcp.read_adc(i)
    # Print the ADC values.
    print('| {0:>4} | {1:>4} | {2:>4} | {3:>4} | {4:>4} | {5:>4} | {6:>4} | {7:>4} |'.format(*values))
    # Pause for half a second.
    time.sleep(0.1)
        # Grab the difference between channel 0 and 1 (i.e. channel 0 minus 1).
        # Note you can specify any value in 0-7 to grab other differences:
        #  - 0: Return channel 0 minus channel 1
        #  - 1: Return channel 1 minus channel 0
예제 #8
0
 def __init__(self):
     self._mcp = MCP3008(spi = SPI.SpiDev(0, 0))
예제 #9
0
 def __init__(self):
     """
     Initialize the MCP3008 hardware interface used by this class
     """
     self.mcp = MCP3008(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))
예제 #10
0
import time
import Adafruit_GPIO.SPI as SPI
from Adafruit_MCP3008 import MCP3008

# Constants for the SPI connection
spi_port = 0
spi_device = 0
mcp = MCP3008(spi=SPI.SpiDev(spi_port, spi_device))

while True:
    channeldata = mcp.read_adc(0)
    volts = channeldata * (5.0 / 1024.0)
    temperature = (volts - 0.5) * 100.0
    print("Data = {}, Voltage = {:.3f} V, Temperature = {:.1f} °C".format(
        channeldata, volts, temperature))
    time.sleep(1)