Create an experiment - fdechaumont/micecraft GitHub Wiki
Introduction
TODO
In this example, we will create a simple device based on Arduino. We will base this example by re-creating a simple version of the Lever of MiceCraft.
To create a device for MiceCraft, we need to write at least:
- The arduino code.
- A python code able to communicate with your device. If you use the ComManager this is super easy, and the connection/deconnection is managed for you.
Then you can extend the functionalities of your device by adding the followings options:
- Alarm management
- Creating a Widget to insert your device in the Graphical interface:
- providing live visual feedback / monitoring of the state of your device.
- displaying alarms linked to your device.
- adding right-click menu on your widget to let people control it from the interface (and enable Testing experiment without animals )
- A description and blueprints to reproduce your hardware.
Let's code it !
[!TIP]
Practically, you may start by the arduino code, and you will surely go back and forth between your arduino code and your driver code as you implement function. For the purpose of the example, we start by writing the python-side driver.
[!NOTE] Now that your lever widget is created, you can put it in the main interface of your experiment. Check Device: Lever section to see the code to embed a lever in GUI.
Displaying alarms linked to your device.
In the previous code, the alarm calls are the followings:
from micecraft.soft.gui.VisualDeviceAlarmStatus import VisualDeviceAlarmStatus
# the object (that will keep for instance the state of the blinking message)
self.visualDeviceAlarmStatus = VisualDeviceAlarmStatus()
# in the paint section:
self.visualDeviceAlarmStatus.draw( painter, self.lever )
[!NOTE] Note that in the VisualDeviceAlarmStatus, the device is checked like this:
alarm = device.isAlarmOn() in your device
So you need to implement isAlarmOn()
Other hardware
Raspberry Pi:
You can create a more complex device with a Raspberry Pi. The Device: Touch Screen is build around this device, check its code to see how it works. To put it in a nutshell, the only difference is that the Raspberry will most probably be driven with a Python code, and you need to set some system setting to load your code at startup, enable serial communication. The main idea is the same as in this example.