Useful Mobile Apps
         


Bluetooth data logger for Arduino (Serial plotter)

The purpose of the application is to collect and visualize data from Arduino platforms (Arduino NANO, MEGA, UNO et al.). Data transfer takes place via Bluetooth and requires a Bluetooth module that supports Bluetooth 4.0 LE (HM-10 Bluetooth module). HC-06, HC-05 modules CANNOT be used. The "float" type is used for data transfer. A single data stream achieves a sampling rate of approximately 245 Hz. If a greater sampling rate is required, the Vibration analysis application can be used. It achieves a sampling rate of approximately 1867 Hz.



Sketch 1:

///////////////////////////////
// © 2017 Dmitriy Kharutskiy //
///////////////////////////////

byte ByteArr[20];
int i = 0;
int ii = 0;
int X = 0;
float C;
float Y1;
float Y2;
float Y3;
float Y4;
float Y5;

void setup() 
{
	// put your setup code here, to run once:

	Serial.begin(9600);
	//Serial.begin(115200);

	//D4 => GND
	pinMode(4, OUTPUT); 
	digitalWrite(4, LOW);  
}

void loop() 
{
	// put your main code here, to run repeatedly:

	X++;
	C = 2*PI*(1/100.0); // PI = Pi = 3.14159...
	Y1 = sin(C * X);
	C = 2*PI*(1/2000.0);
	Y2 = 10 + sin(C * X) * 7;
	Y3 = Y1 * Y2;
	C = 2*PI*(1/90.0);
	Y4 = sin(C * X);
	Y5 = Y1 + Y4;
	if (X == 30000) X = 0;
  

	Marking();
	//WriteToByteArr(Y1);
	//WriteToByteArr(Y2);
	WriteToByteArr(Y3);
	//WriteToByteArr(Y4);
	//WriteToByteArr(Y5);


	//Serial.begin(9600);
	delay(8); // 1: 124Hz
	//delay(17); // 2: 58Hz
	//delay(20); // 3: 50Hz
	//delay(32); // 4: 31Hz
	//delay(35); // 5: 28Hz

	//Serial.begin(115200);
	//delay(4); // 1: 245Hz
	//delay(7); // 2: 140Hz
	//delay(8); // 3: 122Hz
	//delay(13); // 4: 75Hz
	//delay(20); // 5: 48Hz 
}

void Marking()
{
	if (i >= 100)
	{
		for (int iii = 0; iii < 4; iii++) 
		{
			ByteArr[ii] = 255;
			i++;
			ii++;   
			WriteFunction();
		}
		i = 0;
	}
}

void WriteToByteArr(float value)
{    
	byte *p = (byte *)(&value);
	for (int iii = 0; iii < 4; iii++) 
	{
		ByteArr[ii] = *p++;
		i++;
		ii++;		
		WriteFunction();
	}
}

void WriteFunction()
{
	if (ii == 20) 
	{
		Serial.write(ByteArr, ii);   
		ii = 0;
	}
}



Setting up the HM-10 Bluetooth module to increase the data transmission rate

The Bluetooth module can be connected to a PC via a USB-UART adapter. However, this involves extra expenses and possibly unnecessary work of search for drivers and their installation. The Bluetooth module can also be configured via the Arduino Nano.

However, the data transmission rate can be changed only up to 115200 bps, because SoftwareSerial does not support the 230400 bps transmission rate.

Moreover, the actual increase in the transmission rate at 230400 bps is not observed, as compared to 115200 bps. And, unfortunately, SoftwareSerial cannot be used during operations of the Bluetooth accelerometer (if the sampling rate is over 500 Hz), because data sending via SoftwareSerial stops the main program for about 2 ms.

SoftwareSerial Library
Software Serial Example
SoftwareSerial

Sketch 2:

#include  //Include the SoftwareSerial library so you can use its functions.

SoftwareSerial softSerial(11, 12); //Set up a new serial port. D11 => RX (connect to TX of other device), D12 => TX (connect to RX of other device).

void setup()
{
	//Set the data rate for the SoftwareSerial port.
	//softSerial.begin(115200); //115200 bps (bits per second)
	softSerial.begin(9600); //9600 bps (bits per second)   

	//Opens serial port, sets data rate.
	//Serial.begin(115200); 
	Serial.begin(9600);

	//D9 => (+)
	pinMode(9, OUTPUT); 
	digitalWrite(9, HIGH);
    
	//D10 => GND
	pinMode(10, OUTPUT); 
	digitalWrite(10, LOW);
}

void loop()
{
	if (softSerial.available()) Serial.write(softSerial.read()); //If date is coming from software serial port. softSerial date => Serial.
	if (Serial.available()) softSerial.write(Serial.read()); //If data is available on hardwareserial port. Serial date => softSerial
} 





Check if the command terminal work normally: AT


List all the commands: AT+HELP


Get firmware, bluetooth, HCI and LMP version: AT+VERSION


Get/Set baud rate: AT+BAUD (AT+BAUD8 => 115200 bps, AT+BAUD4 => 9600 bps)