# Low Power EEG Data Encoding for Brain Neurostimulation Implants +
## 2 Materials and Methods
### Design Methodology
#### 2.2.5 Data Transmission with BLE  
After the neurostimulator has been implanted and activated for recording, the following step gathers the EEG data collected by the implanted electrodes. The rod is employed to initiate the transmission of signals via the RF communication protocol. The bar is then linked via a USB connection to a portable computer unit, where the data is kept for monitoring and patient assessment purposes. Many gadgets, including mobile phones, WIFI devices, satellite communications systems, and Bluetooth, employ electromagnetic radiation or electromagnetic radio waves to transmit and receive data wirelessly. It is separated into frequency bands (low, medium, and high) to make tuning the devices more accessible.  
As proof of concept, an Arduino platform was programmed to gather data from a computer, encode it, store it, and deliver it via the BLE communication protocol to demonstrate the system's functioning. The Arduino model used was the Arduino Nano 33 BLE because it already integrates the BLE module. To enable Arduino for data transmission, each value must be divided from 32 bits of information in the form of four bytes. When new data arrives on the computer's serial connection, the Arduino reads it in groups of four bytes. After transferring a data packet, the Arduino gets a signal indicating that information is available (Serial. available () > 0). As a result, it begins receiving this data (Serial. read ()), saving it in a struct that takes quadruple Bytes, which it joins (fourByteMerge) to produce the 32-bit long integer that represents the same bits as the EEG signal's equivalent floating-point element. The integers are then saved in a FIFO buffer (buff.push ()), and when it is full (buff.size ()) equals a specific amount), data extraction (buff.pop ()) is enabled as depicted in Figure 2. The RingBuf.h library contains functions for this type of FIFO buffer. The large numbers that depart the buffer are broken down into 4-byte clusters and wirelessly sent via the BLE (valueLevelChar.write value ()) protocol (showing in Listing 3). Simultaneously, a link has been formed between the Arduino platform and another device (central) that supports the communication protocol. In our case, the central device was a mobile phone with the \"nRF Connect\" application installed. The code appearing below implements what we describe above.  
Figure 2: Evaluation of accurate EEG data transmission with Arduino. The values received by Arduino from the computer are identical to the values transmitted to the smartphone.  
```
voidupdatevalueLevel(){ byteb1,b2,b3,b4; intnum1,num2,num3,num4; if(!buff.isFull()){ for(inti=0;i<64;i++){ if(Serial.available()){ combined.parts.firstByte=Serial.read(); while(Serial.available()==0){ } combined.parts.secondByte=Serial.read(); while(Serial.available()==0){ } combined.parts.thirdByte=Serial.read(); while(Serial.available()==0){ } combined.parts.fourthByte=Serial.read(); //combineallthebytes //tocreatethelonginteger combined.merged= ((unsignedint) (combined.parts.firstByte)<<24){ (unsignedint) (combined.parts.secondByte<<16){ (unsignedint) (combined.parts.thirdByte<<8){ (unsignedint) (combined.parts.fourthByte); //deltaencoding cur_val=combined.merged; delta=cur_val-prev_val; buff.push(delta); prev_val=cur_val; length_buff++; } }
```  
**Listing 3** Arduino code for the evaluation of the transmission with BLE protocol.