Temporal limits of Firmata Arduino device

mil's Avatar

mil

13 Dec, 2019 08:46 PM

Hey Chris,

We are using a Firmata Arduino device's (connected via bluetooth) digital pin to toggle a liquid pump into a pumping / not pumping state, based on the state of a .mwel variable which is changed based on the behavior of the subject.

We execute a wait statement of some duration (e.g., 100 msec) after turning the pump on, and after the wait statement returns, we turn the pump off. This seems to work fine.

However, if we reduce the duration to 10 msec, we find that the liquid pump is triggered somewhat randomly: sometimes the pump turns on for a brief period of time when the experiment reaches this block of code (as expected), but sometimes the pump does not do anything at all.

I think this might be related to latencies in the Bluetooth connection, but I'm not sure. Do you have any idea as to why this behavior is happening with a 10 msec wait?

I've attached the relevant code.

  1. Support Staff 1 Posted by Christopher Sta... on 16 Dec, 2019 09:13 PM

    Christopher Stawarz's Avatar

    Hi Michael,

    However, if we reduce the duration to 10 msec, we find that the liquid pump is triggered somewhat randomly: sometimes the pump turns on for a brief period of time when the experiment reaches this block of code (as expected), but sometimes the pump does not do anything at all.

    Bluetooth low energy (BLE) devices have a "connection interval", which determines how often data is exchanged over the Bluetooth connection. Firmata BLE devices set up in the recommended way support a connection interval between 15ms and 30ms (which follows Apple's recommendations).

    I suspect what's happening is, because 10ms is less than the minimum connection interval, sometimes the commands to start and stop the pump are being sent at the same time. (That is, the iPad is queueing BLE messages until the next connection happens, at which point it sends all the queued messages at once.) The result of this is that the Firmata device turns the pump-control line high and then immediately sets it low again, and it looks like the line was never set at all.

    I think the solution is to lengthen the interval between turning the pump on and off. Since the maximum connection interval is 30ms, using a delay longer than that should be safe. Alternatively, you could start with the minimum interval (15ms), and keep raising it until the pump responds consistently. (I don't know if there's a way to determine what connection interval the iPad and Firmata device have actually agreed upon.)

    Cheers,
    Chris

  2. Christopher Stawarz closed this discussion on 03 Jan, 2020 02:38 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