Skip to content

a set of libraries that can be added to the top of an arduino .ino file that overwrite IO functions.

Notifications You must be signed in to change notification settings

erlichlab/arduino_emulator

Repository files navigation

Bpod Emulator v0.1

Architecture

Notes

This emulator was developed for an altered version of Bpod in the Erlich Lab. It has not yet been tested with the official Bpod firmware.

Install

  1. Clone this repository
  2. Run install script
    cd bpod-emulator; ./install_emulator_mac (for Mac)
    cd bpod-emulator; ./install_emulator_linux (for Debian/Ubuntu)

Or install it manually:

  1. socat: Use brew install socat on Mac
  2. zeroMQ: Use brew install zmq on Mac
  3. zeroMQ C++ binding: Put zmq.hpp in search path
    On Mac: copy zmq.hpp to /usr/local/include
  4. kivy: Python GUI framework
    (Try pip install cython and pip install kivy first)

Usage

Try this first:

  1. ./start_emulator [path_for_pty] [port_number_for_matlab]
    (e.g., ./start_emulator ~/Desktop/emulator 9000)
    (might need to run chmod 744 ./start_emulator for the first time)
  2. Inside matlab: start_bpod localhost 9000

Or start it manually:

  1. Start a socat relay process (in a different terminal):
    socat -d -d pty,echo=0,raw TCP-LISTEN:9000,fork
    (See TCP over socat if you want to understand what we are doing)
  2. It will return something like this:
    socat[36146] N PTY is /dev/ttys001
    socat[36146] N listening on LEN=16 AF=2 0.0.0.0:9000
  3. ./bpod_em /dev/ttys001 (change the serial port path accordingly)
  4. python kivy_gui.py
  5. Inside matlab: start_bpod localhost 9000 (change port number accordingly)

Notes for updating the emaultor firmware when changes are made

If you have installed bpod in a sister directory to this repository then:

  1. cd FirmwareWrapper/
  2. ./convert_firmware.sh

The covert_firmware.sh file will look for a specific firmware (used in the ErlichLab) and copy it and make the following changes:

  1. Add headers
  2. setup() takes an extra input
  3. Add this line to setup()
  4. setup() and loop() need to be moved to the end of the code
  5. Add delay to prevent emulator taking up all CPU time

If you are using this tool with Sanworks Bpod you will need to change one line of the script to point to the correct firmware.

FAQ

Q: When i try to restart the emulator it doesn't start / i get errors. How do I fix this?
A: If Bpod is still running, you need to shut it down first. Just like with real hardware, you cannot "unplug" and "re-plug" the emulator and expect everything to work. In general, you should close Bpod first and then close the emulator.

Q: Sometimes when I click a poke, it registers as two pokes.
A: When you move focus to another window, the events when you bring focus back to the emulator window are not handled well. It is recommended to click in the background (not on a poke) to get focus back to the emulator before poking.

Q: I can't successfully start emulator even if I successfully install it on mac
A: Change g++ -std=c++11 -pthread -lzmq ./Firmware_Wrapper/main.cpp -o ./Firmware_Wrapper/bpod_em

to g++ -std=c++11 -I /usr/local/include -L /usr/local/lib -pthread -lzmq ./Firmware_Wrapper/main.cpp -o

./Firmware_Wrapper/bpod_em in start_emulator. Your need to explicitly specify your linker if it's not working.

About

a set of libraries that can be added to the top of an arduino .ino file that overwrite IO functions.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published