Skip to main content

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()

Metadata

Release files for hackeeg 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hackeeg 0.3.0
File Size Uploaded Provenance Actions
hackeeg-0.3.0.tar.gz 16.4 kB Without provenance Details for hackeeg-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hackeeg 0.3.0
File Interpreter ABI Platform Actions
hackeeg-0.3.0-py3-none-any.whl Python 3 none any Details for hackeeg-0.3.0-py3-none-any.whl

Total release size: 39.3 kB

Release files / hackeeg-0.3.0.tar.gz

Download URL hackeeg-0.3.0.tar.gz
Size 16.4 kB
Tags Source
SHA-256 checksum
How to use checksums
773c577f492d6b3398dc5dfd36f89a2608ce2a1a8293b3a192b0790d3a071955
BLAKE2b-256 checksum
How to use checksums
05aa9824c14d46caa72276ce5799375f225b9f00ec9274ccb2760c3302549e8a
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / hackeeg-0.3.0-py3-none-any.whl

Download URL hackeeg-0.3.0-py3-none-any.whl
Size 22.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
917a195b36f57c6deec1c23d1c23a98a47223011b8e507a7257024782730a396
BLAKE2b-256 checksum
How to use checksums
ed86d6e861c0f03836a51fe72c76b94e87e3c31643b435f740fccaf5978b8334
Upload date
Uploaded using Trusted Publishing?
What is 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

Security for hackeeg 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page