Firmata bare bones for Arduino

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!

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

Hi Christ,

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

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

Chris,

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

T

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 :slight_smile: . Thanks for all the help!!

Travis

OK, glad you got it working!

Chris