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.
本文详细介绍如何在Raspberry Pi 4b上设置TGAM蓝牙运行环境,包括下载PyBluez,配对蓝牙适配器,安装python-mindwave-mobile库,以及运行测试脚本。此外,还提供了一个使用思维波数据控制LED灯的示例。
4936

被折叠的 条评论
为什么被折叠?



