Introduction to NeuroSky TGAM usage on RaspberryPi(4b, 4G RAM)

This passage will lead you to set up the TGAM bluetooth runtime environment on RaspverryPi(4b).

Follow these steps and then you can meet the benchmark.


1. Download PyBluez:

1-1 Download dependencies of PyBluez:

sudo apt-get install libbluetooth-dev python-bluetooth -y

1-2 Install PyBluez with pip/pip3:

sudo pip3 install pybluez

 Tip: For Chinese, changing the repository source with attribute -i can help:

sudo pip3 install pybluez -i https://pypi.tuna.tsinghua.edu.cn/simple

2. Pair Your Bluetooth Adapter:

Find the bluetooth icon on right-top of the screen, then click: Add Device. Wait a few seconds then you can select the right device to pair.(For me, the device name shows as Sichiray and PIN code was set to 0000)

3. Install python-mindwave-mobile

Visit this site: https://github.com/robintibor/python-mindwave-mobile, you can use git clone or just download the zip archive. Then:

cd python-mindwave-mobile/
sudo python3 setup.py install

4. Run the following test script or write your own 

Tip: Remember to alter the MAC address of the bluetooth adapter on TGAM where the code indicates.

import bluetooth
from mindwavemobile.MindwaveDataPoints import RawDataPoint, AttentionDataPoint, MeditationDataPoint
from mindwavemobile.MindwaveDataPointReader import MindwaveDataPointReader
import RPi.GPIO as gpio
import time
import re

def manipulate_led_with_mind():
	mindwaveDataPointReader = MindwaveDataPointReader(address='[MAC address of your Bluetooth Adapter on TGAM]')
	mindwaveDataPointReader.start()
	if (mindwaveDataPointReader.isConnected()):
		while(True):
			dataPoint = mindwaveDataPointReader.readNextDataPoint()
			if (not dataPoint.__class__ is RawDataPoint):
				if dataPoint.__class__ is AttentionDataPoint:
					attention = dataPoint.attentionValue
					print("attention: %d" % attention)
					#pwm.ChangeDutyCycle(attention)
					if attention < 40:
						gpio.output(GPIO_PORT_NUMBER,gpio.HIGH)
					else:
						gpio.output(GPIO_PORT_NUMBER,gpio.LOW)
				elif dataPoint.__class__ is MeditationDataPoint:
					meditation = dataPoint.meditationValue
					print("meditation: %d" % meditation)
			else:
				pass
	else:
		print("Exiting because the program could not connect to the TGAM device.")

def init_gpio():
	gpio.setmode(gpio.BCM)
	gpio.setup(GPIO_PORT_NUMBER, gpio.OUT)
	# gpio.setup(3, gpio.OUT)
	# gpio.output(3, gpio.LOW)
	if DO_FLASH_LED:
		global pwm
		pwm = gpio.PWM(GPIO_PORT_NUMBER, PWM_FREQUENCY)
		pwm.start(0)

if __name__ == '__main__':
	GPIO_PORT_NUMBER = 2
	PWM_FREQUENCY = 80
	DO_FLASH_LED = False

	print("working...")
	init_gpio()
	manipulate_led_with_mind()

 Enjoy~

In addition, you will see a led lights up, provided with connecting a led to GPIO2 and GND.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值