Hey guys,
currently i am trying to build a miniaturized laser driver using an arduino as main processor. In this project, I have a temperature driver which communicates via Serial. It requires a command for example to read out the temperature etc. The read out structure is something like [12345 ] while im assuming LF will be \n. The datasheet link of the temperature driver is shown below:
https://www.thorlabs.com/drawings/6915011c39013acd-548FE80F-B898-EE51-28A8C7BEA423C59E/MTD415T-DataSheet.pdf
Right now I am in home office and want to imitate the temperature driver with a second arduino, which i use to send byte data via serial to my main processor arduino, whereafter i want to print the value to a SSD1306 OLED.
Im a very low level arduino user but i was able to write a code which can handle the later used temperature driver data structure, but i am not sure how to implement the into my byte-like serial message. The size of the temperature driver data forced me (correct me if im wrong) to implement a low/high-byte split and recombination. With this, i dont know how to include the linefeed command into the sender and receiver code.
My idea behind the system is that i can write a code on my main arduino sending commands to the temperature driver which then sends the information to the main arduino via serial. This data should then be shown on the OLED simultaniously (e.g. 6 different variables i get from the driver).
The code of the sender arduino looks like this:
String test = "[12345 Test Test]"; //Here the Test Test will be changed to \n in the real case
String test1;
int val2;
void writeIntAsBinary(int value){
Serial.write(lowByte(value));
Serial.write(highByte(value));
}
void setup() {
// Begin the Serial at 9600 Baud
Serial.begin(9600);
}
void loop() {
test1 = test.substring(1, (test.length()-1));
val2 = test1.toInt();
writeIntAsBinary(val2);
delay(1000);
}
The code of the receiver arduino like this:
#include <Adafruit_SSD1306.h>
int incomingByte = 0;
#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, -1);
void setup() {
// Begin the Serial at 9600 Baud
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
}
void loop() {
if (Serial.available() > 0) {
byte b1 = Serial.read();
byte b2 = Serial.read();
int val = b1 * 256 + b2;
Serial.println(val); //Print data on Serial Monitor
display.clearDisplay();
display.setCursor(0,0);
display.print("Input: ");
display.setCursor(0,28);
display.print(val);
display.display();
delay(1000);
}
}
I look forward to any ideas regarding this topic