© 2018 by Blino ltd.

  • White Twitter Icon
  • White Facebook Icon
  • White LinkedIn Icon

Pi-naps :: Tutorial _ 1

Tutorial _ 1 :: Callbacks.py

Tutorial 1 will begin by showing you how to start getting and using data from Pi-naps' EEG sensor.

You are free to write your own script using this tutorial as a guide or simply clone the examples available on our GitHub.

To handle EEG data from Pi-Naps, we need to make use of two simple libraries made to interact with the Pi-Naps shield.

The First is the Pi-Naps Controller.

The Pi-Naps controller. The Pi-Naps controller allows you to interact with the Pi-Naps shield; read data, configure the board and control any built in features.
We designed Pi-Naps to be flexible in order to maximise compatibility with other projects. The trade off for this, is that a little setup is required. In this tutorial we will use a default setup, with Tutorial 2 covering this more comprehensively.

INitialise:

To communicate with Pi-Naps we will need to use both the Pi-Naps controller and BlinoParser classes. To begin with, and ensure that Pi-Naps works as expected, you should create a Controller instance and setup the device.

We can do this quickly using the  '   .defaultInitialise()  ' method. This will allow us to access data such as attention and meditation values, as well as EEG powers on all Pi platforms.

Working with Callbacks:

With the Controller established for working with Pi-Naps, we can now consider handling the data it produces. In order to interact with this data conviniently, we should use the BlinoParser class.

One method for interacting with the data the parser produces, is to register 'callback functions'. We do this by defining functions, then registering these functions to be called on certain events (ie a meditation value being recieved).

We begin by defining a function as we would typically in Python.  We can then give the name of our function to the parser, attaching it as a member of the Parser. For example, we provide a function named  'onMeditation'  to the Parser's  ' meditationCallback'  member. This function will now be called whenever a meditation value is generated.

We must then remember to get data from the Controller and give it to the Parser.

A m0re comprehensive view:

We can see a more comprehensive view of using callbacks to create applications using Pi-Naps in our callbacks.py example script, available on github.

Try cloning the project and running it using the following commands...