Hello.
I'm trying to make arduino to be able to read string in serial monitor, that if a string from a detector arrives, it will split them. And before that, it needs to be started by writing "0R" in the serial monitor. I write a long string in displayMeasurement to simulate what is the string that the detector is about to send. But when i simulate this code in Proteus, the serial monitor kept saying SSD1306 Allocation Failed.
I heard from other forum that i might used too much string, but isn't the string I used here was stored in Arduino and will be sent right to the serial monitor? And if I don't use that long string for OLED function, then what could possibly be the problem?
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Keypad.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, 10); //tadinya OLED reset pin -1
//define keypads
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {3,4,5,6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7,8,9}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
Serial.begin(115200);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3D)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.println("Calibrator");
}
void loop() {
if (Serial.available() > 0) {
String data = Serial.readString();
Serial.println("Write 0R to read detector data!");
if (data.indexOf("0R")>=0) {
Serial.println("0R written");
displayMeasurement();
}
}
delay(500);
}
void displayMeasurement() {
Serial.println("@RAD,VL=12.21,IL=59.00,HV=95.60,CPM=0.00,TEMP=26.80,RH=59.70,OK=1,CHK=0,Tu=11884#");
// LD, HV, T/R, VS (total 6 data)
float LD = 0.0; // cpm
float HV = 0.0;
float Temp = 0.0;
float RH = 0.0;
float Vl = 0.0;
float Il = 0.0;
int dat0,dat1;
String str1;
//define read string
String readString;
String data = Serial.readString();
dat0 = readString.indexOf(",");
dat1 = readString.indexOf(',',dat0+1);
str1 = readString.substring(0,dat1);
// Show to display
if (data.indexOf("@RAD")>0) {
dat0;
dat1;
str1;
}
display.setCursor(0,28);
display.print("LD = ");
display.println(str1.toFloat());
}