예제 #1
0
class ThermistorBoard2(ThermistorBoard, AnalogReadBoard2):
    FIRMWARE = 15650180050147573

    thermistor_base_resistance2 = arduio_variable(
        name="thermistor_base_resistance2",
        arduino_data_type=uint32_t,
        eeprom=True,
        default=10**5,
    )
    reference_resistance2 = arduio_variable(
        name="reference_resistance2",
        arduino_data_type=uint32_t,
        eeprom=True,
        default=10**5,
    )

    temperature2 = python_variable("temperature2",
                                   type=np.float,
                                   changeable=False,
                                   is_data_point=True,
                                   save=False)
    reference_temperature2 = python_variable("reference_temperature2",
                                             type=np.float,
                                             default=298.15,
                                             minimum=0)

    a2 = python_variable("a2", type=np.float, default=1.009249522e-03)
    b2 = python_variable("b2", type=np.float, default=2.378405444e-04)
    c2 = python_variable("c2", type=np.float, default=2.019202697e-07)

    def pre_ini_function(self):
        super().pre_ini_function()
        self.thermistor_base_resistance.name = (
            self.thermistor_base_resistance.name + "1")
        self.reference_resistance.name = self.reference_resistance.name + "1"
        self.temperature.name = self.temperature.name + "1"
        self.reference_temperature.name = self.reference_temperature.name + "1"
        self.a.name = self.a.name + "1"
        self.b.name = self.b.name + "1"
        self.c.name = self.c.name + "1"

        self.analog_value2.name = self.analog_value.name + "2"
        self.analog_value.name = self.analog_value.name + "1"

        self.analog_value2.setter = self.resistance_to_temperature2

    @staticmethod
    def resistance_to_temperature2(var, instance, data, send_to_board=True):
        var.default_setter(var=var,
                           instance=instance,
                           data=data,
                           send_to_board=send_to_board)
        try:
            R2 = instance.reference_resistance2 * (1023.0 - data) / data
            logR2 = np.log(R2)
            T = 1.0 / (instance.a2 + instance.b2 * logR2 +
                       instance.c2 * logR2 * logR2 * logR2)
            instance.temperature2 = T
        except ZeroDivisionError:
            pass
예제 #2
0
class PushButtoModule(ArduinoBoardModule):
    # depencies
    basic_board_module = BasicBoardModule

    # arduino_variables
    button_pin = arduio_variable(name="button_pin",
                                 arduino_data_type=uint8_t,
                                 eeprom=True)
    button_pressed = arduio_variable(
        name="button_pressed",
        arduino_data_type=bool_,
        setter=False,
        arduio_setter=False,
        is_data_point=True,
    )
    reinitalize_button = at.Function("reinitalize_button", uint8_t)
    reinitalize_button.add_call(
        Arduino.pinMode(reinitalize_button.arg1, Arduino.INPUT))

    def instance_arduino_code(self, ad):
        ad.setup.add_call(self.reinitalize_button(self.button_pin))
        self.button_pin.arduino_setter.add_call(
            self.reinitalize_button(self.button_pin))

        ad.loop.add_call(
            if_(
                Arduino.digitalRead(self.button_pin) == Arduino.HIGH,
                self.button_pressed.set(Arduino.true),
            ),
            else_(self.button_pressed.set(Arduino.false)),
        )
예제 #3
0
class ThermistorBoardModule(ArduinoBoardModule):
    analog_read_module = AnalogReadModule

    # analog_read_module.analog_value.is_data_point = False

    # arduino_variables
    thermistor_base_resistance = arduio_variable(
        name="thermistor_base_resistance",
        arduino_data_type=uint32_t,
        eeprom=True,
        default=10 ** 5,
    )
    reference_resistance = arduio_variable(
        name="reference_resistance",
        arduino_data_type=uint32_t,
        eeprom=True,
        default=10 ** 5,
    )

    # python_variables
    temperature = python_variable(
        "temperature", type=np.float, changeable=False, is_data_point=True, save=False
    )
    reference_temperature = python_variable(
        "reference_temperature", type=np.float, default=298.15, minimum=0
    )

    b = python_variable("b", type=np.uint32, default=4000)
    # a = python_variable("a", type=np.float,default=1.009249522)
    # b = python_variable("b", type=np.float,default=2.378405444)
    # c = python_variable("c", type=np.float,default=2.019202697)

    @classmethod
    def module_arduino_code(cls, board, arduino_code_creator):
        arduino_code_creator.setup.add_call(Arduino.analogReference(Arduino.EXTERNAL))

    def post_initalization(self):
        self.analog_read_module.analog_value.data_point_modification(
            self.resistance_to_temperature
        )

    def resistance_to_temperature(self, data):
        try:
            R2 = self.reference_resistance * data / (1023.0 - data)
            Tk = R2 / self.thermistor_base_resistance
            Tk = np.log(Tk)
            Tk /= self.b
            Tk += 1 / self.reference_temperature
            Tk = 1 / Tk
            self.temperature = Tk
        except ZeroDivisionError:
            pass
        return data
예제 #4
0
class DutyCycleBoardModule(ArduinoBoardModule):
    basic_board_module = BasicBoardModule

    signal_pin = arduio_variable(name="signal_pin",
                                 arduino_data_type=uint8_t,
                                 eeprom=True)
    full_cycle = arduio_variable(name="full_cycle",
                                 arduino_data_type=uint32_t,
                                 eeprom=True)
    duty_cycle = arduio_variable(
        name="duty_cycle",
        arduino_data_type=float_,
        minimum=0,
        maximum=100,
        html_attributes={"step": 0.1},
        save=False,
    )

    last_cycle = Variable("last_cycle", uint32_t, 0)
    cycletime = Variable("cycletime", uint32_t, 0)

    def instance_arduino_code(self, ad):
        ad.setup.add_call(Arduino.pinMode(self.signal_pin, Arduino.OUTPUT))

        ad.loop.add_call(
            self.cycletime.set(self.basic_board_module.current_time -
                               self.last_cycle),
            if_(
                self.cycletime > self.full_cycle,
                (
                    self.cycletime.set(0),
                    self.last_cycle.set(self.basic_board_module.current_time),
                ),
            ),
            if_(
                self.duty_cycle == 0,
                Arduino.digitalWrite(self.signal_pin, Arduino.HIGH),
            ),
            elseif_(
                self.duty_cycle == 100,
                Arduino.digitalWrite(self.signal_pin, Arduino.LOW),
            ),
            elseif_(
                self.cycletime < self.full_cycle *
                ((self.duty_cycle.cast(float_) / self.duty_cycle.maximum)),
                Arduino.digitalWrite(self.signal_pin, Arduino.LOW),
            ),
            else_(Arduino.digitalWrite(self.signal_pin, Arduino.HIGH)),
        )

        self.signal_pin.arduino_setter.add_call(
            Arduino.pinMode(self.signal_pin, Arduino.OUTPUT))
예제 #5
0
class RelayBoard(ArduinoBasicBoard):
    FIRMWARE = 15650246521463158

    relay_pin = arduio_variable(name="relay_pin",
                                arduino_data_type=uint8_t,
                                eeprom=True)
    open = arduio_variable(name="open",
                           arduino_data_type=bool_,
                           is_data_point=True)

    def add_arduino_code(self, ad):
        ad.setup.add_call(Arduino.pinMode(self.relay_pin, Arduino.OUTPUT))
        ad.loop.add_call(Arduino.digitalWrite(self.relay_pin, self.open))
        self.relay_pin.arduino_setter.add_call(
            Arduino.pinMode(self.relay_pin, Arduino.OUTPUT))
예제 #6
0
class Max6675BoardModule(ArduinoBoardModule):
    spim = SerialPeripheralInterfaceModule
    temperature = arduio_variable(
        name="temperature",
        arduino_data_type=double_,
        arduino_setter=False,
        setter=None,
        is_data_point=True,
        save=False,
    )
    cs_pin = arduio_variable(name="cs_pin",
                             arduino_data_type=uint8_t,
                             eeprom=True)

    def instance_arduino_code(self, ad):
        self.spim.basic_board_module.dataloop.prepend_call(
            self.temperature.set((self.spim.read16(self.cs_pin) >> 3) * 0.25 +
                                 273.15))
예제 #7
0
class RelayBoardModule(ArduinoBoardModule):
    basic_board_module = BasicBoardModule

    relay_pin = arduio_variable(
        name="relay_pin", arduino_data_type=uint8_t, eeprom=True
    )
    active = arduio_variable(
        name="active", arduino_data_type=bool_, is_data_point=True, save=False
    )

    def instance_arduino_code(self, ad):
        ad.setup.add_call(Arduino.pinMode(self.relay_pin, Arduino.OUTPUT))
        ad.loop.add_call(
            if_(self.active, Arduino.digitalWrite(self.relay_pin, Arduino.LOW)),
            else_(Arduino.digitalWrite(self.relay_pin, Arduino.HIGH)),
        )
        self.relay_pin.arduino_setter.add_call(
            Arduino.pinMode(self.relay_pin, Arduino.OUTPUT)
        )
예제 #8
0
class SimplePulseBoard(ArduinoBasicBoard):
    FIRMWARE = 15627604053828192
    CLASSNAME = "Simple Pulse Board"
    PULSE_TYPE_SQUARE = 0
    PULSE_TYPE_SINE = 1
    PULSEPIN = 6

    pulse_type = arduio_variable(
        name="pulse_type",
        default=PULSE_TYPE_SINE,
        maximum=1,
        allowed_values={
            PULSE_TYPE_SQUARE: "square",
            PULSE_TYPE_SINE: "sine"
        },
        eeprom=True,
    )

    pulse_pin = arduio_variable(name="pulse_pin",
                                arduino_data_type=uint8_t,
                                eeprom=True)

    wavelength = arduio_variable(name="wavelength",
                                 arduino_data_type=uint16_t,
                                 minimum=1,
                                 default=1000)  # in millisec
    current_val = arduio_variable(name="current_val",
                                  arduino_data_type=uint16_t,
                                  is_data_point=True,
                                  save=False)  # in mV
    running = arduio_variable(name="pulsing", arduino_data_type=bool_)

    def __init__(self):
        super().__init__()

    def get_frequency(self):
        return 1000 / self.wavelength

    def set_frequency(self, hertz):
        self.wavelength = 1000 / hertz

    frequency = property(get_frequency, set_frequency)
예제 #9
0
class AnalogReadBoard(ArduinoBasicBoard):
    FIRMWARE = 13650142050147572

    samples = arduio_variable(name="samples", arduino_data_type=uint8_t, eeprom=True)
    analog_value = arduio_variable(
        name="analog_value",
        arduino_data_type=uint16_t,
        arduino_setter=False,
        is_data_point=True,
        save=False,
    )
    analog_pin = arduio_variable(
        name="analog_pin", arduino_data_type=uint8_t, eeprom=True
    )

    avg = Variable("average", uint32_t, 0)

    def pre_ini_function(self):
        super().pre_ini_function()

    def add_arduino_code(self, ad):

        ad.setup.add_call(Arduino.analogReference(Arduino.EXTERNAL))

        ad.loop.add_call(
            self.avg.set(0),
            for_(
                for_.i,
                for_.i < self.samples,
                1,
                self.avg.set(self.avg + Arduino.analogRead(self.analog_pin)),
            ),
            self.analog_value.set(self.avg / self.samples),
        )

        self.analog_pin.arduino_setter.add_call(
            Arduino.pinMode(self.analog_pin, Arduino.INPUT)
        )
예제 #10
0
class AnalogReadBoard2(AnalogReadBoard):
    FIRMWARE = 13650142050147573

    samples = arduio_variable(name="samples",
                              arduino_data_type=uint8_t,
                              eeprom=True)

    analog_value2 = arduio_variable(
        name="analog_value2",
        arduino_data_type=uint16_t,
        arduino_setter=False,
        is_data_point=True,
        save=False,
    )
    analog_pin2 = arduio_variable(name="analog_pin2",
                                  arduino_data_type=uint8_t,
                                  eeprom=True)

    def pre_ini_function(self):
        super().pre_ini_function()
        self.analog_value.name = "analog_value1"
        self.analog_pin.name = "analog_pin1"

    def add_arduino_code(self, ad):

        ad.loop.add_call(
            self.avg.set(0),
            for_(
                for_.i,
                for_.i < self.samples,
                1,
                self.avg.set(self.avg + Arduino.analogRead(self.analog_pin2)),
            ),
            self.analog_value2.set(self.avg / self.samples),
        )

        self.analog_pin2.arduino_setter.add_call(
            Arduino.pinMode(self.analog_pin2, Arduino.INPUT))
예제 #11
0
class AnalogPuleBoard(ArduinoBoardModule):
    basic_board_module = BasicBoardModule

    pulse_pin = arduio_variable(
        name="pulse_pin", arduino_data_type=uint8_t, eeprom=True
    )

    full_cycle = arduio_variable(
        name="full_cycle", arduino_data_type=uint32_t, eeprom=True
    )
    duty_cycle = arduio_variable(
        name="duty_cycle",
        arduino_data_type=float_,
        is_data_point=True,
        minimum=0,
        maximum=1,
    )

    last_cycle = Variable("last_cycle", uint32_t, 0)
    cycletime = Variable("cycletime", uint32_t, 0)

    def instance_arduino_code(self, ad):
        ad.setup.add_call(Arduino.pinMode(self.relay_pin, Arduino.OUTPUT))

        ad.loop.add_call(
            self.cycletime.set(self.basic_board_module.current_time - self.last_cycle),
            if_(self.cycletime > self.full_cycle, self.cycletime.set(0)),
            if_(
                self.cycletime > self.full_cycle * self.duty_cycle,
                Arduino.digitalWrite(self.relay_pin, Arduino.HIGH),
            ),
            else_(Arduino.digitalWrite(self.relay_pin, Arduino.HIGH)),
        )

        self.relay_pin.arduino_setter.add_call(
            Arduino.pinMode(self.relay_pin, Arduino.OUTPUT)
        )
예제 #12
0
class AnalogReadModule(ArduinoBoardModule):
    # depencies
    basic_board_module = BasicBoardModule

    # arduino_variables
    samples = arduio_variable(name="samples",
                              arduino_data_type=uint8_t,
                              eeprom=True)
    analog_value = arduio_variable(
        name="analog_value",
        arduino_data_type=uint16_t,
        arduino_setter=False,
        is_data_point=True,
        save=False,
    )
    analog_pin = arduio_variable(name="analog_pin",
                                 arduino_data_type=uint8_t,
                                 eeprom=True)

    average = Variable("average", uint32_t, 0)

    def instance_arduino_code(self, ad):
        ad.loop.add_call(
            Arduino.analogRead(self.analog_pin),
            Arduino.delay(10),
            self.average.set(0),
            for_(
                for_.i,
                for_.i < self.samples,
                1,
                self.average.set(self.average +
                                 Arduino.analogRead(self.analog_pin)),
            ),
            self.analog_value.set(self.average / self.samples),
        )
        self.analog_pin.arduino_setter.add_call(
            Arduino.pinMode(self.analog_pin, Arduino.INPUT))
예제 #13
0
class RgbLed(ArduinoBasicBoard):
    FIRMWARE = 15633540938822172

    LED_PIN_RED = 3
    LED_PIN_GREEN = 5
    LED_PIN_BLUE = 6

    red = arduio_variable(name="red", arduino_data_type=uint8_t)
    green = arduio_variable(name="green", arduino_data_type=uint8_t)
    blue = arduio_variable(name="blue", arduino_data_type=uint8_t)

    red_pin = arduio_variable(name="red_pin",
                              arduino_data_type=uint8_t,
                              eeprom=True)
    green_pin = arduio_variable(name="green_pin",
                                arduino_data_type=uint8_t,
                                eeprom=True)
    blue_pin = arduio_variable(name="blue_pin",
                               arduino_data_type=uint8_t,
                               eeprom=True)

    def add_arduino_code(self, ad):
        ad.loop.add_call(
            Arduino.analogWrite(self.red_pin, self.red),
            Arduino.analogWrite(self.green_pin, self.green),
            Arduino.analogWrite(self.blue_pin, self.blue),
        )

        self.blue_pin.arduino_setter.prepend_call(
            Arduino.analogWrite(self.blue_pin, 0))
        self.blue_pin.arduino_setter.add_call(
            Arduino.pinMode(self.blue_pin, Arduino.OUTPUT))

        self.red_pin.arduino_setter.prepend_call(
            Arduino.analogWrite(self.red_pin, 0))
        self.red_pin.arduino_setter.add_call(
            Arduino.pinMode(self.red_pin, Arduino.OUTPUT))

        self.green_pin.arduino_setter.prepend_call(
            Arduino.analogWrite(self.green_pin, 0))
        self.green_pin.arduino_setter.add_call(
            Arduino.pinMode(self.green_pin, Arduino.OUTPUT))
예제 #14
0
class AccelStepperBoardModule(ArduinoBoardModule):
    # depencies
    basic_board_module = BasicBoardModule

    accel_stepper = AccelStepper()
    stepPin = arduio_variable(name="stepPin",
                              arduino_data_type=uint8_t,
                              eeprom=True,
                              default=2)
    dirPin = arduio_variable(name="dirPin",
                             arduino_data_type=uint8_t,
                             eeprom=True,
                             default=3)
    enablePin = arduio_variable(name="enablePin",
                                arduino_data_type=uint8_t,
                                eeprom=True,
                                default=4)

    stepper = accel_stepper("stepper")

    reinitalize_stepper = at.Function("reinitalize_stepper")
    max_steps_per_loop = arduio_variable(
        name="max_steps_per_loop",
        arduino_data_type=uint8_t,
        eeprom=True,
        default=1,
        minimum=1,
    )

    steps_per_mm = arduio_variable("steps_per_mm",
                                   uint16_t,
                                   eeprom=True,
                                   default=200,
                                   minimum=1)

    # step_per_mm_dependend
    stepper_max_speed = arduio_variable(
        name="stepper_max_speed",
        arduino_data_type=float_,
        eeprom=True,
        default=1000,
        minimum=0.01,
        html_attributes={"step": 0.01},
    )
    stepper_acceleration = arduio_variable(
        name="stepper_acceleration",
        arduino_data_type=float_,
        eeprom=True,
        default=10,
        minimum=0.01,
        html_attributes={"step": 0.01},
    )
    target_position = arduio_variable(
        name="target_position",
        arduino_data_type=float_,
        save=False,
        html_attributes={"step": 0.1},
    )
    stepper_current_position = arduio_variable(
        name="stepper_current_position",
        arduino_data_type=float_,
        default=0,
        save=True,
        is_data_point=True,
        html_attributes={"step": 0.1},
    )

    def instance_arduino_code(self, ad):
        self.stepper = self.accel_stepper(
            "stepper",
            AccelStepper.motor_interface_type["DRIVER"],
            self.stepPin,
            self.dirPin,
        )
        self.reinitalize_stepper.add_call(
            self.stepper.stop(),
            while_(self.stepper.run()),
            self.stepper.disableOutputs(),
            self.stepper.reinitalize(),
            self.stepper.setMaxSpeed(self.stepper_max_speed *
                                     self.steps_per_mm),
            self.stepper.setCurrentPosition(self.stepper_current_position *
                                            self.steps_per_mm),
            self.stepper.setAcceleration(self.stepper_acceleration *
                                         self.steps_per_mm),
            self.stepper.setEnablePin(self.enablePin),
        )
        self.stepPin.arduino_setter.add_call(self.reinitalize_stepper())
        self.dirPin.arduino_setter.add_call(self.reinitalize_stepper())

        self.enablePin.arduino_setter.add_call(
            self.stepper.setEnablePin(self.enablePin))

        ad.setup.add_call(self.reinitalize_stepper())

        self.stepper_current_position.arduino_setter.add_call(
            self.stepper.setCurrentPosition(self.stepper_current_position *
                                            self.steps_per_mm))
        self.stepper_current_position.arduino_getter.prepend_call(
            self.stepper_current_position.set(self.stepper.currentPosition() /
                                              self.steps_per_mm.cast(float_)))

        self.stepper_max_speed.arduino_setter.add_call(
            self.stepper.setMaxSpeed(self.stepper_max_speed *
                                     self.steps_per_mm))
        self.stepper_acceleration.arduino_setter.add_call(
            self.stepper.setAcceleration(self.stepper_acceleration *
                                         self.steps_per_mm))

        self.target_position.arduino_setter.add_call(
            self.stepper.moveTo(self.target_position * self.steps_per_mm))

        steps_in_loop = ad.add(
            at.Variable(name="steps_in_loop", type=uint8_t, value=0))
        ad.loop.add_call(
            steps_in_loop.set(0),
            while_((steps_in_loop.increment() < self.max_steps_per_loop).and_(
                self.stepper.run())),
        )

        self.basic_board_module.dataloop.prepend_call(
            self.stepper_current_position.set(self.stepper.currentPosition() /
                                              self.steps_per_mm.cast(float_)))

    def post_initalization(self):
        for var in [
                self.stepper_max_speed,
                self.stepper_acceleration,
                self.target_position,
                self.stepper_current_position,
        ]:
            # var.modulvar_getter_modification(self.step_to_mm)
            # var.modulvar_setter_modification(self.mm_to_step)
            # var.data_point_modification(self.step_to_mm)
            pass

    def mm_to_step(self, mm):
        return mm * self.steps_per_mm

    def step_to_mm(self, step):
        return step / self.steps_per_mm