Python client library for HackEEG Arduino Due shield
Project description
hackeeg-client-python
Python client software for HackEEG TI ADS1299 Arduino shield
Python Client Software
The Python client software is designed to run on a laptop computer. There is a hackeeg
driver Python module for communicating with the Arduino over the USB serial port, a command line client (hackeeg_shell
wrapper and hackeeg_shell.py
Python client), and a demonstration and performance testing script (hackeeg_test.py
).
The hackeeg_shell.py
and hackeeg_test.py
programs set the Arduino driver to JSON Lines mode, and communicate with it that way. They issue JSON Lines commands to the Arduino, and recieve JSON Lines or MessagePack data in response.
Using Python 3.6.5 on a 2017 Retina Macbook Pro, connected to an Arduino Due configured to use the SPI DMA included in the driver, and using the MessagePack mode, the hackeeg_test.py
program can read and transfer 8 channels of 24-bit resolution data at 16,384 samples per second, the maximum rate of the ADS1299 chip.
The Python client software requires the PySerial module.
General Operation
The ADS129x chips are configured by reading and writing registers. See the chip datasheet for more information about configuring the ADS129x and reading data from it.
If the host program (the program that reads data from the driver) does not pull data from the serial or USB interface fast enough, the driver will block on sending when the serial or USB buffers fill up. This will cause the driver to lose samples.
The driver uses the Arduino Native port for serial communication, because it is capable of 2 megabits per second or more.
In most applications, the Python 3 usage will go something like this:
#!/usr/bin/env python
SERIAL_PORT_PATH="/dev/cu.usbmodem14434401" # your actual path to the Arduino Native serial port device goes here
import sys
import hackeeg
from hackeeg import ads1299
hackeeg = hackeeg.HackEEGBoard(SERIAL_PORT_PATH)
hackeeg.connect()
hackeeg.sdatac()
hackeeg.reset()
hackeeg.blink_board_led()
hackeeg.disable_all_channels()
sample_mode = ads1299.HIGH_RES_250_SPS | ads1299.CONFIG1_const
hackeeg.wreg(ads1299.CONFIG1, sample_mode)
test_signal_mode = ads1299.INT_TEST_4HZ | ads1299.CONFIG2_const
hackeeg.wreg(ads1299.CONFIG2, test_signal_mode)
hackeeg.enable_channel(7)
hackeeg.wreg(ads1299.CH7SET, ads1299.TEST_SIGNAL | ads1299.GAIN_1X)
hackeeg.rreg(ads1299.CH5SET)
# Unipolar mode - setting SRB1 bit sends mid-supply voltage to the N inputs
hackeeg.wreg(ads1299.MISC1, ads1299.SRB1)
# add channels into bias generation
hackeeg.wreg(ads1299.BIAS_SENSP, ads1299.BIAS8P)
hackeeg.rdatac()
hackeeg.start()
while True:
result = hackeeg.read_response()
status_code = result.get('STATUS_CODE')
status_text = result.get('STATUS_TEXT')
data = result.get(hackeeg.DataKey)
if data:
decoded_data = result.get(hackeeg.DecodedDataKey)
if decoded_data:
timestamp = decoded_data.get('timestamp')
ads_gpio = decoded_data.get('ads_gpio')
loff_statp = decoded_data.get('loff_statp')
loff_statn = decoded_data.get('loff_statn')
channel_data = decoded_data.get('channel_data')
print(f"timestamp:{timestamp} | gpio:{ads_gpio} loff_statp:{loff_statp} loff_statn:{loff_statn} | ",
end='')
for channel_number, sample in enumerate(channel_data):
print(f"{channel_number + 1}:{sample} ", end='')
print()
else:
print(data)
sys.stdout.flush()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file hackeeg-0.3.0.tar.gz
.
File metadata
- Download URL: hackeeg-0.3.0.tar.gz
- Upload date:
- Size: 16.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 773c577f492d6b3398dc5dfd36f89a2608ce2a1a8293b3a192b0790d3a071955 |
|
MD5 | 89183bd931be4a643066500918e68411 |
|
BLAKE2b-256 | 05aa9824c14d46caa72276ce5799375f225b9f00ec9274ccb2760c3302549e8a |
File details
Details for the file hackeeg-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: hackeeg-0.3.0-py3-none-any.whl
- Upload date:
- Size: 22.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 917a195b36f57c6deec1c23d1c23a98a47223011b8e507a7257024782730a396 |
|
MD5 | 306039f98e743bb591c83582672b3732 |
|
BLAKE2b-256 | ed86d6e861c0f03836a51fe72c76b94e87e3c31643b435f740fccaf5978b8334 |