Firmata bare bones for Arduino

meyert11's Avatar

meyert11

23 Apr, 2018 07:54 PM

Hi Chris,
I'm in the process of using an Arudino to measure a capacitor lick sensor and I want to use this to trigger a solenoid burst.
I have an ITC-18 controlling the solenoid, and I have Arduino code for the capacitor sensor both working, now I'm trying to incorporate the two.

Mworks integrates with an arduino through firmata, which essentially is a program running on arduino that take in external commands (Mworks, python ...) and spits out outputs. My plan 'A' is to to run the arduino capacitor code 'inside' of the firmata code so every time it loops through 'listen to input' 'send output' it'll run the capacitor code.

My question is, what is the barebones firmata code that Mworks needs? In the Arduino-Examples-firmata menu, there is a 'Standard' example code, but it's quite lengthy, I was wondering if you used a stripped down version of this?

Thanks!

  1. Support Staff 1 Posted by Christopher Sta... on 24 Apr, 2018 02:16 PM

    Christopher Stawarz's Avatar

    Hi Travis,

    My question is, what is the barebones firmata code that Mworks needs? In the Arduino-Examples-firmata menu, there is a 'Standard' example code, but it's quite lengthy, I was wondering if you used a stripped down version of this?

    I've only tested MWorks' Firmata interface against boards running StandardFirmata or StandardFirmataBLE. While MWorks doesn't use all of the Firmata protocol, it does use quite a bit of it. (You can see the commands it uses at the top of FirmataDevice.cpp).

    If you want a more "minimal" Firmata firmware, you might try ConfigurableFirmata. I've never used it, so I can't comment on how it works.

    My plan 'A' is to to run the arduino capacitor code 'inside' of the firmata code so every time it loops through 'listen to input' 'send output' it'll run the capacitor code.

    What exactly does the capacitor code do? Does it just read the value from an analog input, or is it more complicated? If the former, then you should be able to use a Firmata analog input channel (assuming you're using the MWorks nightly build or the on-the-brink-of-release version 0.8).

    Cheers,
    Chris

  2. 2 Posted by meyert11 on 24 Apr, 2018 02:31 PM

    meyert11's Avatar

    Hi Christ,

    - I've only tested MWorks' Firmata interface against boards running
    StandardFirmata
    <https://github.com/firmata/arduino/tree/master/examples/StandardFirmata> or
     StandardFirmataBLE
    <https://github.com/firmata/arduino/tree/master/examples/StandardFirmataBLE>.
    While MWorks doesn't use all - of the Firmata protocol
    <https://github.com/firmata/protocol/blob/master/protocol.md>, it does use
    quite a bit of it. (You can see the commands it uses at the top of
    FirmataDevice.cpp
    <https://github.com/mworks/mworks/blob/master/plugins/core/Firmata/Firmata/FirmataDevice.cpp>
    ).

    Great, answers my question!

    - What exactly does the capacitor code do?
    It actually uses the digital channels. I put a resistor between 2 digital
    channels, and turn one channel on high (source), while listening to the
    other channel (target). I also connect the source channel to a lick tube.
    When the animal licks, the charge flows to the animal and the target
    channel goes to zero. So the only code I need in the loop is the checking
    of the channel target, and the sending of a code back (I was thinking of
    just turning another digital channel on/off).

    T

  3. Support Staff 3 Posted by Christopher Sta... on 25 Apr, 2018 02:40 PM

    Christopher Stawarz's Avatar

    Hi Travis,

    I put a resistor between 2 digital channels, and turn one channel on high (source), while listening to the other channel (target). I also connect the source channel to a lick tube. When the animal licks, the charge flows to the animal and the target channel goes to zero. So the only code I need in the loop is the checking of the channel target, and the sending of a code back (I was thinking of just turning another digital channel on/off).

    This shouldn't require any custom firmware on the Arduino. Just use StandardFirmata, and define two channels in your MWorks experiment: a digital output for the source (always set to high), and a digital input for the target:

    var target_value = 0
    
    firmata arduino {
        firmata_digital_output (
            pin_number = source_pin
            value = 1  // Always high
            )
        firmata_digital_input (
            pin_number = target_pin
            value = target_value
            )
    }
    

    Then, elsewhere in your experiment, watch for target_value to go low. StandardFirmata continually checks the state of all digital inputs, so it will notify MWorks as soon as the pin state changes.

    Chris

  4. 4 Posted by meyert11 on 25 Apr, 2018 02:58 PM

    meyert11's Avatar

    Chris,

    thanks for the suggestion, I'll give it a try and let you know how it goes.

    T

  5. 5 Posted by meyert11 on 25 Apr, 2018 04:41 PM

    meyert11's Avatar

    Hi Chris,

    Your suggestion worked-sorta! Technically speaking your logic was spot on,
    and I was able to trigger an event, however only when the voltage got all
    the way down to zero (complete grounding of the source voltage). When I
    would touch the sensor, it wasn't enough to completely ground it, so in
    practice it would need some extra thresholding.

    I introduced the capacitorsensor.h library and some extra code into the
    firmata code and it worked with just touching!!! I get some sperious,
    unknown firmata command errors, but I think that's ok for now.

    I bet feeding the digital voltage to an analog channel (as you suggested
    originally) would be a more exact way to handle this, however, also as you
    suggested, it would require the latest nightly, and I've got a ton of
    moving variables, and a mostly working system so i'm going to clean up the
    code and use this :) . Thanks for all the help!!

    Travis

  6. Support Staff 6 Posted by Christopher Sta... on 26 Apr, 2018 02:10 PM

    Christopher Stawarz's Avatar

    OK, glad you got it working!

    Chris

  7. Christopher Stawarz closed this discussion on 26 Apr, 2018 02:10 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac