Final Project: EEG Control Electrical Devices Using Neural Network Algorithm on
STM32
Thanks
Firstly, we would like to thank to teachers, everyone in Ho Chi Minh City
University of Technical and Education (HCMUTE) has created best conditions for us the
opportunity to exchange schooling at Rajamangala University of Technology Lanna
(RMUTL). Thanks to the enthusiastic assistance of RMUTL teachers, especially Dr.
Nopadon Maneetien and many Thai friends. They help us to complete successfully project
“EEG Control Electrical Devices Using Neural Network Algorithm On STM32”. In the
process to implement the project certain inevitable mistakes, we hope to receive your
comments. Thank you parents, friends,etc. we have been the spiritual source of motivation
for us to complete the subject.
Finally, congratulations to the relationship between
HCMUTE and RMUTL becomes better and better.
Comment
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
…………………………………………………………………………………………….....
Chiang Mai ………………………
Group of students: Âu Văn Bằng
Nguyễn Đức Tài
1
Final Project: EEG Control Electrical Devices Using Neural Network Algorithm on
STM32
Contents
Chapter 1: Introduction.................................................................................... 1
1.1.
The origin and significance of the project...................................................1
1.2.
The purpose of the project...........................................................................1
1.3.
The scope of the project..............................................................................1
1.4.
The benefits of the system...........................................................................2
Chapter 2: The theory and research..................................................................3
2.1.
The principle of project...............................................................................3
2.2.
Theory of project.........................................................................................3
2.2.1.
Overview of ARM...........................................................................................3
2.2.2.
EEG and Brainwaves.......................................................................................6
2.2.3.
Neurosky mind wave mobile...........................................................................8
2.2.4.
Classification algorithms.................................................................................9
2.2.5.
LCD (Liquid Crystal Display) 16x2..............................................................10
2.2.6.
Relay.............................................................................................................. 13
2.2.7.
OPTO PC817.................................................................................................13
2.2.8.
Module Bluetooth HC05................................................................................15
2.2.9.
ESP 8266.......................................................................................................16
Chapter 3: Design........................................................................................... 18
3.1.
Introduction...............................................................................................18
3.2.
Block diagram...........................................................................................18
3.3.
Design........................................................................................................19
3.3.1.
Brainwave block............................................................................................19
3.3.2.
Webserver block............................................................................................19
3.3.3.
Bluetooth block..............................................................................................20
3.3.4.
ESP8266 Block..............................................................................................21
2
Final Project: EEG Control Electrical Devices Using Neural Network Algorithm on
STM32
3.3.5.
Display Block................................................................................................21
3.3.6.
Control Device Block....................................................................................22
3.3.7.
Center processing block.................................................................................24
3.3.8.
Power block...................................................................................................26
Chapter 4: Implementation.............................................................................27
4.1.
Make PCB.................................................................................................27
4.1.1.
Required components....................................................................................27
4.1.2.
Draw PCB......................................................................................................28
4.1.3.
Completed circuit...........................................................................................29
4.2.
Flow chart..................................................................................................29
4.3.
KeilC 5......................................................................................................32
4.4.
Web server interface..................................................................................32
4.4.1.
The requirements of the web server interface................................................32
4.4.2.
Programs to build webserver.........................................................................32
4.5.
Test............................................................................................................35
Chapter 5: Results and Future Works.............................................................36
5.1.
Results.......................................................................................................36
5.2.
Future Works.............................................................................................36
References....................................................................................................... 37
Addendum...................................................................................................... 38
3
Final Project: EEG Control Electrical Devices Using Neural Network Algorithm on
STM32
List of Figures
Figure 2.1. Hardware block diagram....................................................................................5
Figure 2.2. Neurosky Mindwave mobile..............................................................................9
Figure 2.3. LCD 16x2........................................................................................................11
Figure 2.4. Timing chart LCD............................................................................................12
Figure 2.5. Relay 5VDC....................................................................................................13
Figure 2.6. PC817..............................................................................................................14
Figure 2.7. Module HC05..................................................................................................15
Figure 2.8. Module ESP8266.............................................................................................16
Figure 3.1. Diagram block.................................................................................................18
Figure 3.2. Bluetooth block...............................................................................................20
Figure 3.3. ESP8266 Block................................................................................................21
Figure 3.4. Display Block..................................................................................................22
Figure 3.5. Control Device Block......................................................................................22
Figure 3.6. Process block...................................................................................................25
Figure 4.1. PCB.................................................................................................................28
Figure 4.2. 3D....................................................................................................................28
Figure 4.3. Completed circuit............................................................................................29
Figure 4.4. Main flow chart...............................................................................................30
Figure 4.5. Neural network flow chart...............................................................................31
Figure 4.6. Icon keilc 5......................................................................................................32
Figure 4.7. Start xampp for run web offline.......................................................................33
Figure 4.8. Create new file.................................................................................................33
Figure 4.9. Selcet the PHP programming language............................................................34
Figure 4.10. Save file path.................................................................................................34
Figure 4.11. Web interface completed................................................................................35
4
Final Project: EEG Control Electrical Devices Using Neural Network Algorithm on
STM32
List of Tables
Table 2.1. Pin LCD............................................................................................................11
Table 2.2. Commands LCD................................................................................................12
Table 2.3. Feature of PC817...............................................................................................14
Table 4.1. Components......................................................................................................27
5
Final Project: EEG Control Electrical Devices Using Neural Network Algorithm on
STM32
Chapter 1: Introduction
1.1. The origin and significance of the project
These days, there is a rapid increasing of the global economic development as well
as technology explosion, people tend to enhance the standard of living based on hi-tech
devices and smart inventions, this leads to scientists and technology specialists must
propose projects as well as look for the new approaches for meeting people’s demand. As
a result, IoT-Internet of Things, which is commonly used a term in recent year, sets a
signal for the 4th industrial revolution. In fact, there is a vast range of invented smart
systems which support the general public in many fields such as manufacturing,
agriculture and health care. Also, people are able to operate those systems in numerous
ways and one of them is a Mind-Controlled method, which is a technology for
manipulating objects via brainwaves. We find it’s interesting between IoT and this one
playing a crucial role in life quality, therefore, we choose the project called “Controlling
internet-connected devices through brainwaves”.
“Controlling internet-connected devices through brainwaves” is capable of
supporting users control electronics devices in the house without moving the body.
Especially, this is a light point for paralysis victims can take care themselves, even though
nobody around them.
Implementing this tool include a lot of methodologies such as FPGA, ARM
microcontrollers, etc. In this project, we use ARM microcontrollers to create this one.
1.2. The purpose of the project
Understand how to operate the module to read the brainwaves and then handle
signals in order to return.
Construct a web server to update the control signals as well as allow users to
control the system by pushing buttons on the screen.
Research and build controlling internet-connected devices through brainwaves with
3 modes-controlled, namely brainwaves, website and Android app.
1
Final Project: EEG Control Electrical Devices Using Neural Network Algorithm on
STM32
1.3. The scope of the project
Control on/off two devices.
Using mind wave mobile.
Using power 3.3 and 5v.
1.4. The benefits of the system
Support those who is paralysis.
Control robot, computer and other devices by brainwaves.
2
Final Project: EEG Control Electrical Devices Using Neural Network Algorithm on
STM32
Chapter 2: The theory and research
2.1. The principle of project
The principle of project are based on the brainwave-receive, analysis, classification,
control and sending data to web server. There are numerous classification algorithm for
EEG such as Neural Networks, Nonlinear Bayesian classifiers, …. However, Neural
Networks are the most popular algorithm for its high performance.
2.2. Theory of project
2.2.1. Overview of ARM
Family of ARM
These days, there is a vast range of type of ARM such as STM32F1, STM32F4,
STM32F7, etc. However, each version has distinctive standards about memory, speed
analysis and so on. Take STM32F103 as an example, which uses ARM 32-bit Cortex-M3
CPU Core, includes 64 or 128 Kbytes of Flash memory, 20 Kbytes of SRAM and 72 MHz
maximum of the frequency. Another instance is STM32F4, which uses 32-bit ARM
Cortex-M4 with FPU core, includes 1-Mbyte Flash memory, 192-Kbyte RAM and 168
MHz maximum of the frequency.
In the contrast, as the requirement of the subject's brain waves handling neural
network algorithms need an ARM kit with relative speed to run well and test. Kit needs an
ergonomic design with easy usage and low cost. Therefore, we choose the Kit, namely
STM32F407VGT6 for this subject.
Introduce STM32F407VGT6
The STM32F4DISCOVERY Discovery kit allows users to easily develop
applications with the STM32F407 high performance microcontroller with ARM®
Cortex®-M4 32-bit core. It includes everything required either for beginners or for
experienced users to get quickly started.
Based on the STM32F407VGT6, it includes an ST-LINK/V2 or ST-LINK/V2-A
embedded debug tool, two ST MEMS digital accelerometers, a digital microphone, one
audio DAC with integrated class D speaker driver, LEDs and push buttons and an USB
3
Final Project: EEG Control Electrical Devices Using Neural Network Algorithm on
STM32
OTG micro-AB connector. To expand the functionality of the STM32F4DISCOVERY
Discovery kit with the Ethernet connectivity, LCD display and more, visit the
www.st.com/stm32f4dis-expansion webpage. The STM32F4DISCOVERY Discovery kit
comes with the STM32 comprehensive software HAL library, together with various
packaged software examples.
Features
STM32F407VGT6 microcontroller featuring 32-bit ARM® Cortex®-M4
with FPU core, 1-Mbyte Flash memory, 192-Kbyte RAM in an LQFP100
package.
On-board ST-LINK/V2 on STM32F4DISCOVERY (old reference) or STLINK/V2-A on STM32F407G-DISC1 (new order code).
USB ST-LINK with re-enumeration capability and three different
interfaces:
Debug port.
Virtual Com port (with new order code only).
Mass storage (with new order code only).
Board power supply: through USB bus or from an external 5V supply
voltage.
External application power supply: 3V and 5V.
LIS302DL or LIS3DSH ST MEMS 3-axis accelerometer.
MP45DT02 ST-MEMS audio sensor omnidirectional digital microphone.
CS43L22 audio DAC with integrated class D speaker driver.
Eight LEDs:
LD1 (red/green) for USB communication.
LD2 (red) for 3.3V power on.
Four user LEDs, LD3 (orange), LD4 (green), LD5 (red) and LD6
(blue).
2 USB OTG LEDs LD7 (green) VBUS and LD8 (red) over-current.
Two push-buttons (user and reset).
USB OTG FS with micro-AB connector.
Extension header for all LQFP100 I/O for.
Quick connection to prototyping board and easy probing.
Comprehensive free software including a variety of examples, part of
STM32CubeF4 package or STSW-STM32068 to use legacy standard
libraries.
4
Final Project: EEG Control Electrical Devices Using Neural Network Algorithm on
STM32
Hardware and layout
The
STM32F4DISCOVERY
is
designed
around
the
STM32F407VGT6
microcontroller in a 100-pin LQFP package.
Figure 2.1 illustrates the connections between the STM32F407VGT6 and its
peripherals (STLINK/V2 or ST-LINK/V2-A, pushbutton, LED, Audio DAC, USB, ST
MEMS accelerometer, ST MEMS microphone, and connectors).
Figure 2.1. Hardware block diagram
Software and programming language
There is a variety of different programming languages, the most popular
programming language is C. Thus, manufacturers have fabricated kit for ARM C language
programming.
Additionally, the programming software also has a lot of choice such as EWARM,
MDK-ARM, TrueSTUDIO, tasking, etc. We decide to choose MDK-ARM because it
gains a popularity of market as well as easy using and friendly interface with users.
2.2.2. EEG and Brainwaves
EEG
5
Final Project: EEG Control Electrical Devices Using Neural Network Algorithm on
STM32
An electroencephalogram is a measure of the brain's voltage fluctuations as
detected from scalp electrodes. It is an approximation of the cumulative electrical activity
of neurons. Electroencephalography (EEG) is the most studied potential non-invasive
interface, mainly due to its fine temporal resolution, ease of use, portability and low set-up
cost. But as well as the technology's susceptibility to noise, another substantial barrier to
using EEG as a brain-computer interface is the extensive training required before users can
work the technology. For example, in experiments beginning in the mid-1990s, Niels
Birbaumer at the University of Tubingen in Germany trained severely paralyzed people to
self-regulate the slow cortical potentials in their EEG to such an extent that these signals
could be used as a binary signal to control a computer cursor (Birbaumer had earlier
trained epileptics to prevent impending fits by controlling this low voltage wave). The
experiment saw ten patients trained to move a computer cursor by controlling their
brainwaves. The process was slow, requiring more than an hour for patients to write 100
characters with the cursor, while training often took many months.
Brainwaves
At the root of all our thoughts, emotions and behavior is the communication
between neurons within our brains. Brainwaves are produced by synchronized electrical
pulses from masses of neurons communicating with each other.
Brainwaves are detected using sensors placed on the scalp. They are divided into
bandwidths to describe their functions (below), but are best thought of as a continuous
spectrum of consciousness, from slow, loud and functional to fast, subtle, and complex.
It is a handy analogy to think of Brainwaves as musical notes the low frequency
waves are like a deeply penetrating drum beat, while the higher frequency brainwaves are
more like a subtle high pitched flute. Like a symphony, the higher and lower frequencies
link and cohere with each other through harmonics.
Our brainwaves change according to what we’re doing and feeling. When slower
brainwaves are dominant we can feel tired, slow, sluggish, or dreamy. The higher
frequencies are dominant when we feel wired, or hyper-alert.
6
Final Project: EEG Control Electrical Devices Using Neural Network Algorithm on
STM32
The descriptions that follow are only broadly descriptions in practice things are far
more complex, and brainwaves reflect different aspects when they occur in different
locations in the brain.
Brainwave speed is measured in Hertz (cycles per second) and they are divided into
bands delineating slow, moderate, and fast waves.
Infra-Low brainwaves (frequency <0.5HZ) (also known as Slow Cortical
Potentials), are thought to be the basic cortical rhythms that underlie our higher brain
functions. Very little is known about infra-low brainwaves. Their slow nature make them
difficult to detect and accurately measure, so few studies have been done. They appear to
take a major role in brain timing and network function.
Delta Waves (frequency 0.5 to 3 HZ), the slowest but loudest brainwaves. Delta
brainwaves are slow, loud brainwaves (low frequency and deeply penetrating, like a drum
beat). They are generated in deepest meditation and dreamless sleep. Delta waves suspend
external awareness and are the source of empathy. Healing and regeneration are stimulated
in this state, and that is why deep restorative sleep is so essential to the healing process.
Theta brainwaves (frequency 3 to 8 HZ), occur in sleep and are also dominant in
deep meditation. It occur most often in sleep but are also dominant in deep meditation. It
acts as our gateway to learning and memory. In theta, our senses are withdrawn from the
external world and focused on signals originating from within. It is that twilight state
which we normally only experience fleetingly as we wake or drift off to sleep. In theta we
are in a dream, vivid imagery, intuition and information beyond our normal conscious
awareness. It’s where we hold our “stuff”, our fears, troubled history, and nightmares.
Alpha brainwaves (frequency 8 to 12 HZ), occur during quietly flowing thoughts,
but not quite meditation. It are dominant during quietly flowing thoughts, and in some
meditative states. Alpha is “the power of now”, being here, in the present. Alpha is the
resting state for the brain. Alpha waves aid overall mental coordination, calmness,
alertness, mind/body integration and learning.
Beta brainwaves (frequency 12 to 38 HZ), are present in our normal waking state of
consciousness. It dominate our normal waking state of consciousness when attention is
7
Final Project: EEG Control Electrical Devices Using Neural Network Algorithm on
STM32
directed towards cognitive tasks and the outside world. Beta is a “fast” activity, present
when we are alert, attentive, engaged in problem solving, judgment, decision making, and
engaged in focused mental activity. Beta brainwaves are further divided into three bands.
Low Beta (Beta1, 12-15Hz) can be thought of as a fast idle, or musing. Beta (Beta2, 1522Hz) is high engagement or actively figuring something out. Hight Beta (Beta3, 2238Hz) is highly complex thought, integrating new experiences, high anxiety, or
excitement. Continual high frequency processing is not a very efficient way to run the
brain, as it takes a tremendous amount of energy.
Gamma brainwaves (frequency 38 to 42 HZ), are the fastest of brain waves and
relate to simultaneous processing of information from different brain areas Gamma
brainwaves are the fastest of brain waves (high frequency, like a flute), and relate to
simultaneous processing of information from different brain areas. It passes information
rapidly, and as the most subtle of the brainwave frequencies, the mind has to be quiet to
access it. Gamma was dismissed as “spare brain noise” until researchers discovered it was
highly active when in states of universal love, altruism, and the “higher virtues”. Gamma
is also above the frequency of neuronal firing, so how it is generated remains a mystery. It
is speculated that Gamma rhythms modulate perception and consciousness, and that a
greater presence of Gamma relates to expanded consciousness and spiritual emergence.
2.2.3. Neurosky mind wave mobile
NeuroSky Technology
Your brain is constantly producing electrical signals while it operates, as the
cellular components of the brain (neurons) communicate with each other. At a macro scale,
they produce a range of frequencies that scientists have found relate to particular mental
states. For example, a sleeping person’s brain produces an abundance of delta waves,
whereas an alert and awake person concentrating hard on something will produce far more
beta waves.
The Mindwave headset picks up your brain’s electrical activity and divides the
signal by frequency into various types of waves, allowing it to infer your mental state. For
8
Final Project: EEG Control Electrical Devices Using Neural Network Algorithm on
STM32
the most of the non-scientific apps however, it primarily reads how relaxed (as measured
by alpha/theta waves) or concentrated (as measured by beta/gamma waves) you are.
Unfortunately your body makes a lot of other electrical noise, in addition to the
activity coming from your brain. For this reason there is a “reference” contact, in the form
of a clip that attaches to your earlobe, which allows the headset to filter out non-brain
related electrical activity.
Hardware
It connects via bluetooth to the device of your choice, and works with most modern
operating systems (Windows XP or newer, Mac OS X 10.6.5 or newer) and mobile devices
running android or IOS. It’s battery life is rated at 8-10 hours with a single AAA battery.
Figure 2.2. Neurosky Mindwave mobile
2.2.4. Classification algorithms
Neural Networks
Neural Networks (NN) is the category of classifiers mostly used in BCI research.
Let us recall that a NN is an assembly of several artificial neurons which enables to
produce nonlinear decision boundaries. This section first describes the most widely used
NN for BCI, which is the multilayer Perceptron (MLP).
9
Final Project: EEG Control Electrical Devices Using Neural Network Algorithm on
STM32
An MLP is composed of several layers of neurons: an input layer, possibly one or
several hidden layers, and an output layer. Each neuron’s input is connected with the
output of the previous layer’s neurons where as the neurons of the output layer determine
the class of the input feature vector.
Neural Networks and thus MLP, are universal approximators, i.e., when composed
of enough neurons and layers, they can approximate any continuous function. Added to the
fact that they can classify any number of classes, this makes NN very flexible classifiers
that can adapt to a great variety of problems. Consequently, MLP, which are the most
popular NN used in classification, have been applied to almost all BCI problems such as
binary or multiclass, synchronous or asynchronous BCI. However, the fact that MLP are
universal approximators makes these classifiers sensitive to overtraining, especially with
such noisy and non-stationary data as EEG. Therefore, careful architecture selection and
regularization is required.
A multilayer Perceptron without hidden layers is known as a perceptron.
Interestingly enough, a perceptron is equivalent to LDA and, as such, has been sometimes
used for BCI applications.
Nonlinear Bayesian classifiers
This section introduces Bayesian classifiers used for BCI: Bayes quadratic. All
these classifiers produce nonlinear decision boundaries. Furthermore, they are generative,
which enables them to perform more efficient rejection of uncertain samples than
discriminative classifiers. However, these classifiers is not as widespread as Neural
Networks in BCI applications.
Bayesian classification aims at assigning to a feature vector the class it belongs to
with the highest probability. The Bayes rule is used to compute the so-called a posteriori
probability that a feature vector has of belonging to a given class. Using the MAP
(Maximum A Posteriori) rule and these probabilities, the class of this feature vector can be
estimated.
10
Final Project: EEG Control Electrical Devices Using Neural Network Algorithm on
STM32
Bayes quadratic consists in assuming a different normal distribution of data. This
leads to quadratic decision boundaries, which explains the name of the classifier. This
classifier is not widely used for BCI.
2.2.5. LCD (Liquid Crystal Display) 16x2
Introduction
There are many types of LCD with multiple shapes and sizes vary from a few
letters to dozens of characters, from one to several tens restaurant row. 16x2 LCD means 2
rows and each row has 16 characters.
Figure 2.3. LCD 16x2
Pin Description
Table 2.1. Pin LCD
Pin
No
1
2
3
4
5
6
7
8
9
10
11
12
13
Name
VSS
VDD
VS
RS
R/W
E
D0
D1
D2
D3
D4
D5
D6
Input/ Output
Power
Power
Analog
Input
Input
Input
I/O
I/O
I/O
I/O
I/O
I/O
I/O
Function
GND
+5V
Contrast Control
Register Select. H: data signal, L: instruction signal
Read/Write. H: read mode, L: write mode
Enable (strobe)
DATA (LSB)
DATA
DATA
DATA
DATA
DATA
DATA
11
Final Project: EEG Control Electrical Devices Using Neural Network Algorithm on
STM32
14
15
16
D7
LED_A
LED_K
I/O
Input
Input
DATA (MSB)
Backlight Anode
Backlight Cathode
Function commands
LCD Driver IC has dedicated the integrated LCD below code 447801 to 447809 the
IC.
Table 2.2. Commands LCD
Function
NOP
Clear Display
Cursor Home
RS RW D7 D6 D5 D4
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
D3
0
0
0
D2
0
0
0
D1 D0
0
0
0
1
1
0
I/
S
D
C
B
clock
0
1.52ms
39s
Entry Mode Set
0
0
0
0
0
0
0
1
Display Control
Cursor/Display
0
0
0
0
0
0
1
D
0
0
0
0
0
1
S/C
R/L
Function Set
0
0
0
0
1
Set CGRAM addr
Set DDRAM
0
0
0
1
0
0
1
Display data ram address
39s
0
1
1
1
1
0
BF
Address counter
Read data
Write data
0
43s
43s
Shift
addr
Buzy flag & Addr
Read data
Write data
0
39s
39s
0
39s
N
F
0
0
L
Character Generator RAM
39s
D
39s
Figure 2.4. Timing chart LCD
12
Final Project: EEG Control Electrical Devices Using Neural Network Algorithm on
STM32
2.2.6. Relay
Relay is resemble a switch. However, the others than a switch in basic
accommodation. Relays are activated by electricity, which has two states close and open.
Figure 2.5. Relay 5VDC
Features
Voltage control: 5VDC.
Time Impact: 10ms.
Brake release time: 5ms.
Operating temperature: -45ºC ~ 75ºC.
Current activities at 5VDC: 70mA.
Minimum current, Voltage Minimum: 100 mA, 5VDC.
Maximum voltage: 250VAC/30VDC.
Maximum current: 15A.
2.2.7. OPTO PC817
Opto is not only the optical coupling (also called OPTO) but also a semiconductor
made up of an optical transmitter and an optical sensor integrated in one block of
semiconductor. Optical transmitter is a light emitting diode which emits light stimulus for
photoconductor sensors. Optical sensors are also photo transistor.
Opto is used as a separator between different blocks of power capacity like cubic
capacity or small capacity with large voltage blocks. It can used to prevent noises for the
H-bridge circuits, output PLCs or microcontrollers and anti-jamming measuring devices.
The principle of OPTO led glow when there is existed a current in the circuit, then
photo diodes (or photo transistor) is opened allowing the electricity past through.
13
Final Project: EEG Control Electrical Devices Using Neural Network Algorithm on
STM32
Figure 2.6. PC817
Table 2.3. Feature of PC817
14
Final Project: EEG Control Electrical Devices Using Neural Network Algorithm on
STM32
2.2.8. Module Bluetooth HC05
HC05 is a bluetooth module with AT command interface, used to connect bluetooth
microcontrollers with a device that has bluetooth waves.
Figure 2.7. Module HC05
Hardware features
Typical -80dBm sensitivity.
Up to +4dBm RF transmit power.
3.3 to 5V I/O.
PIO (Programmable Input/Output) control.
UART interface with programmable baud rate.
With integrated antenna.
With edge connector.
Software features
Slave default Baud rate: 9600, Data bits: 8, Stop bit: 1, Parity: No parity.
Auto connect to the last device on power as default.
Permit pairing device to connect as default.
Auto pairing PINCODE: “1234” as default.
Work modes
HC-05 embedded Bluetooth serial communication module (can be short for
module) has two work modes: order-response work mode and automatic connection work
mode. And there are three work roles (Master, Slave and Loopback) at the automatic
connection work mode. When the module is at the automatic connection work mode, it
will follow the default way set lastly to transmit the data automatically.
15
Final Project: EEG Control Electrical Devices Using Neural Network Algorithm on
STM32
When the module is at the order-response work mode, user can send the AT
command to the module to set the control parameters and sent control order. The work
mode of module can be switched by controlling the module PIN (GPIO11) input level.
2.2.9. ESP 8266
ESP8266 WIFI module can be programmed directly on the chip or as an
intermediary device with internet connection between two devices used the AT command.
In this project, we use ESP8266 internet connection between STM32 and web server.
Figure 2.8. Module ESP8266
Feature
Power supply: 3.3VDC.
3.3VDC UART interface.
Support 802.11 b/g/n.
WIFI 2.4 GHz, support WPA/WPA2.
There are three modes of operation as a client, access point, both shows.
Supporting both TCP and UDP protocols are.
UART Baud rate can be selected: 1200, 2400, 4800, 9600, 19200, 38400,
57600, 115200.
Series provides up to 300mA.
Using
ESP8266 connects with UART interface STM32. STM32 is used with the AT
command set to send control data transmission. The first ESP8266 configure for the client
mode and WIFI access, then access to the web address with a port 80 for data transmission
from the STM32 to the web.
16
Final Project: EEG Control Electrical Devices Using Neural Network Algorithm on
STM32
17
Final Project: EEG Control Electrical Devices Using Neural Network Algorithm on
STM32
Chapter 3: Design
3.1. Introduction
Project “EEG Control Electrical Devices Using Neural Network Algorithm On
STM32”. In this chapter, we need to do the following tasks design the system block
diagram, design schematic, calculate electronic components and select the power supply.
3.2. Block diagram
From the target of the project “EEG Control Electrical Devices Using Neural
Network Algorithm On STM32” we have the following block diagram.
Figure 3.9. Diagram block
Function blocks.
Power block: power supply function for the entire system.
Brainwaves block: measure brainwave and transmit data to the central processor via
bluetooth.
Web server block: receive data from the central processing unit and send control
commands to the central processor and other connected devices.
Bluetooth block: function the connection between the central processing block and
the brainwaves block.
ESP8266 block: function connection between the central processing block and web
server.
Display block: display for user information observation.
Control device block: function to receive control signals from the central
processing unit for controlling the devices.
18
Final Project: EEG Control Electrical Devices Using Neural Network Algorithm on
STM32
Center processing block: receive data from brainwaves, computation, analysis give
control commands to send out signals to the web and device drivers.
3.3. Design
3.3.1. Brainwave block
Measures brainwaves and sends the data to the center processing block via
bluetooth.
Options
Use device have one electrode.
o Advantage: low cost, easy to use.
o Disadvantage: accuracy about 70%.
Use device have more electrode.
o Advantage: high-precision signal.
o Disadvantage: expensive.
We choose devices having one electrode, in particular mobile devices
mindwaves NeuroSky because if the group can handle data from mobile
mindwaves we can do it with other devices.
3.3.2. Webserver block
There are functions to receive data from the center processing unit and send control
commands to the central processor and other devices.
Options
Use web support for IoT.
o Advantage: simple, register an account can be used.
o Disadvantage: can’t change the user interface.
Design web server.
o Advantage: build interface preferences, easier data management.
o Disadvantage: know web programming language.
We choose design web server. Because we want to build a separate interface,
simple and user-friendly.
3.3.3. Bluetooth block
There is functional connection between the center processing blocks and brainwave
block.
Options
Use HC-05.
19
Final Project: EEG Control Electrical Devices Using Neural Network Algorithm on
STM32
o Advantage: simple, can activity two mode. MASTER or SLAVE.
o Disadvantage: relatively high cost.
Use HC-06.
o Advantage: easy to use.
o Disadvantage: only working in SLAVE mode.
We choose HC-05.
Figure 3.10. Bluetooth block
Calculations
HC-05 module with UART interface voltage is 3.3V, Kit STM32F4-discovery with
UART interface is 5V. So, we uses bridge potentiometer to reduce the voltage applied in
communication between STM32F4-discovery and HC-05. Let say V 1 is the voltage of the
Tx pins STM32F4 kit, we have: V 1 = 5V. Let say V2 is the voltage received on the HC-05
Rx pins, V2 = 3.3V.
Applying formula:
V2 = = .
Choose: R18 = 1 (kΩ) and R17 = 2 (kΩ).
20