Replacing NIDAQ with Arduino

Yoon Bai's Avatar

Yoon Bai

16 Apr, 2021 01:32 PM

Hi Chris,

It looks like we’re ready for next steps in replacing the NI DAQ. I was wondering if you have example code for Arduino that can achieve the same functionality of the current NI DAQ?

The two functions I need are: (a) convert Mac serial USB signals to digital pulses, and (b) signal the reward system. In case it helps, here is the current MWorks code snippet that communicates with the NI DAQ:

nidaq daq (
    name = Dev1
    update_interval = 3ms
    analog_input_data_interval = 1ms
    analog_output_data_interval = 1ms
    autostart = true
    ) {
    nidaq_digital_output (
        port_number = 2
        num_lines_in_port = 8
        line4 = reward_line
        line2 = experiment_state_line
        line0= stim_start_line
        )
}

Thanks again!
Yoon

  1. Support Staff 1 Posted by Christopher Sta... on 16 Apr, 2021 01:43 PM

    Christopher Stawarz's Avatar

    Hi Yoon,

    Here's the Firmata equivalent of your NIDAQ code. The pin numbers are just examples. Any digital I/O pins will work:

    firmata daq (autostart = true) {
        firmata_digital_output (
            pin_number = 2
            value = reward_line
            )
        firmata_digital_output (
            pin_number = 3
            value = experiment_state_line
            )
        firmata_digital_output (
            pin_number = 4
            value = stim_start_line
            )
    }
    

    That should be the only change needed to get existing experiments working with the new hardware.

    Cheers,
    Chris

  2. 2 Posted by Yoon Bai on 16 Apr, 2021 03:07 PM

    Yoon Bai's Avatar

    Thank you, Chris!

    I will try this out and will keep you posted (“StandardFirmata” example on Arduino (Nano 33 BLE)).

    Best,
    Yoon

  3. 3 Posted by Yoon Bai on 23 Apr, 2021 04:40 PM

    Yoon Bai's Avatar

    Hi Chris,

    I’m pleased to let you know that Arduino worked on rig 2. I saw the digital pulses and the reward system worked. I will upgrade the Mac OS to the latest once I get a go-ahead from other lab mates.

    Thanks for your help!

    Yoon

  4. Support Staff 4 Posted by Christopher Sta... on 23 Apr, 2021 07:57 PM

    Christopher Stawarz's Avatar

    Great! Thanks for letting me know.

    Chris

  5. Support Staff 5 Posted by Christopher Sta... on 05 May, 2021 12:42 PM

    Christopher Stawarz's Avatar

    Hi Yoon & Alina,

    While testing the Arduino Nano 33 BLE, I've discovered that communication with the board can be unreliable. Specifically, messages between the board and the connected Mac are sometimes truncated, meaning commands sent to the board (e.g. to change a pin's state) can be lost. It doesn't happen all the time, and it's most apparent when you try to configure multiple pins at once (such as when using a word output channel). However, it's very easy to induce with my standard Firmata tests.

    This appears to be a known issue in the software stack for the board. There doesn't seem to be any fix or workaround at present. While I expect the issue will be fixed eventually, I think the best course of action for now is to switch to a different board.

    The most obvious choice for replacement board is the Arduino Nano 33 IoT. It has the same form factor and pinouts as the Nano 33 BLE, so it should work as a drop-in replacement. However, the IoT's microcontroller and software stack are completely different from those of the BLE, so the BLE's USB issue won't affect it. In fact, the IoT uses the same type of processor as the Adafruit Feather M0 Bluefruit LE, which I've used for many years as an MWorks Firmata device via both USB-serial and Bluetooth.

    Does this sound like a good plan to you? If so, I'll ask Chris to order one Nano 33 IoT for me. Once I've tested it and confirmed that it works as expected, we can get more for the lab.

    Thanks,
    Chris

  6. 6 Posted by Alina Peter on 05 May, 2021 01:32 PM

    Alina Peter's Avatar

    Sounds good to me. Would be good to get going asap, I cannot use rig 4 without this, meaning I cannot train my animals.
    Very happy that you tested this and that I didn’t have to figure this one out myself!

  7. Support Staff 7 Posted by Christopher Sta... on 06 May, 2021 09:07 PM

    Christopher Stawarz's Avatar

    I've now tested the Nano 33 IoT, and it appears to work perfectly. Also, the Firmata library already supports it, so you should be able to use the standard setup instructions without modification.

    I say go ahead and get some more!

    Chris

  8. 8 Posted by Alina Peter on 11 May, 2021 09:48 PM

    Alina Peter's Avatar

    I installed one in my setup, it required more installations on Arduino and computer restarts but generally speaking no big deal to switch.

  9. Support Staff 9 Posted by Christopher Sta... on 12 May, 2021 12:52 PM

    Christopher Stawarz's Avatar

    Hi Alina,

    I installed one in my setup, it required more installations on Arduino and computer restarts but generally speaking no big deal to switch.

    I'm glad the switch went OK.

    While you certainly need to install a core for the board the first time your program it, I don't understand why you would need to restart your computer. Quitting the Arduino IDE and disconnecting and reconnecting the board should be all that's required after installing the firmware. Did you try that and find that MWorks still wouldn't connect to the board?

    Chris

  10. 10 Posted by Alina Peter on 12 May, 2021 01:29 PM

    Alina Peter's Avatar

    Yes. I even disconnected and reconnected the board twice since this is faster than a restart. But I think it had the old board in the system still somehow, it also still showed in the Arduino software in addition to the new board. After it worked I also did another restart to see if it works immediately now. And after that restart I still had to disconnect and reconnect the Arduino another time before the mworks test worked, even though it ran before that restart. I don’t know yet if that has to happen every time, I hope not. I will let you know if I always need to do this.

  11. Support Staff 11 Posted by Christopher Sta... on 13 May, 2021 12:38 PM

    Christopher Stawarz's Avatar

    Hmm. I've never seen this before, and I have no idea why it's happening. If/when I'm ever back in the lab, maybe I can take a hands-on look at the issue and try to figure out what's going on.

    Thanks,
    Chris

  12. Christopher Stawarz closed this discussion on 25 May, 2021 04:20 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