Get the full code from below. You would need the OLED libraries as well. You will see that the first thing thew code dose is to power up D8, which is the pin connected to the Bluetooth module MOSFET, so now the HC06 is powered on. Then we start the OLED display and prine hello. In the void loop we check for a serial communication. If we receive something from the Bluetooth moduel, we first check if is a "V" a "A" a "R" and so on, in order to detect if we receive values for voltage, current, resistance and so on. Then we use the Serial.parseFloat() function to get the numeric value. This fucntion will automatically separate the float number from the text values that we receive. That's it, next we print the value on the tiny OLED screen.
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h> //download here: https://www.electronoobs.com/eng_arduino_Adafruit_GFX.php
#include <Adafruit_SSD1306.h> //downlaod here: https://www.electronoobs.com/eng_arduino_Adafruit_SSD1306.php
#define OLED_RESET 5
Adafruit_SSD1306 display(OLED_RESET);
int BT = 8; //Pin used to turn on the HC-06 Mosfet
void setup() {
Serial.begin(9600);
pinMode(BT,OUTPUT);
digitalWrite(BT,HIGH); //Turn on the HC06 module
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32 or 64 from eBay)
delay(100);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(35,38); //X / Y
display.print("Hello");
display.display();
delay(100);
}
void loop() {
if(Serial.available() > 0){ //Detect if we receive something
char type = Serial.read(); //If we receive a "V" then the value is for voltage.
if(type == 'V'){
float volt = Serial.parseFloat(); //Using parseFloat we get only the float value after the "V"
display.clearDisplay();
display.setCursor(32,32); //X / Y
display.print(" Volt");
display.setCursor(32,48); //X / Y
if(volt < 0 ){
volt = volt * -1;
}
display.print(volt);
display.display();
}
else if(type == 'A'){
float curr = Serial.parseFloat();
display.clearDisplay();
if(curr < 1 && curr > -1){
if(curr < 0 ){
curr = curr * -1;
}
display.setCursor(32,32); //X / Y
display.print(" mA");
curr = curr * 1000;
}
else{
if(curr < 0 ){
curr = curr * -1;
}
display.setCursor(32,32); //X / Y
display.print(" A");
}
display.setCursor(32,48); //X / Y
display.print(curr);
display.display();
}
else if(type == 'R'){
float res = Serial.parseFloat();
display.clearDisplay();
display.setCursor(32,32); //X / Y
display.print(" Ohm");
display.setCursor(32,48); //X / Y
display.print(res);
display.display();
}
else if(type == 'k'){
float res = Serial.parseFloat();
display.clearDisplay();
display.setCursor(32,32); //X / Y
display.print(" KOhm");
display.setCursor(32,48); //X / Y
display.print(res);
display.display();
}
else if(type == 'u'){
float uFarad = Serial.parseFloat();
display.clearDisplay();
display.setCursor(32,32); //X / Y
display.print(" uF");
display.setCursor(32,48); //X / Y
display.print(uFarad);
display.display();
}
else if(type == 'p'){
float pFarad = Serial.parseFloat();
display.clearDisplay();
display.setCursor(32,32); //X / Y
display.print(" pF");
display.setCursor(32,48); //X / Y
display.print(pFarad);
display.display();
}
else if(type == 'n'){
float nFarad = Serial.parseFloat();
display.clearDisplay();
display.setCursor(32,32); //X / Y
display.print(" nF");
display.setCursor(32,48); //X / Y
display.print(nFarad);
display.display();
}
else if(type == 'H'){
float henry = Serial.parseFloat();
display.clearDisplay();
display.setCursor(32,32); //X / Y
display.print(" uH");
display.setCursor(32,48); //X / Y
display.print(henry);
display.display();
}
}
}