Hi all, I needed help with reading RS 232 Data (pin 3) with Teensy 3.5, which is stressing me so much. I have googled a bunch, but could not find the solution to it.
I have connected the multimeter DM3068 RS232 output to the TTL converter, and then connected the pin 3 (data pin) of TTL converted RS 232 to Serial port 1 of the teensy. I have used the following code to obtain a single capacitance measurement signal (it was 110.5 micro farads).
int incomingByte = 0; // for incoming serial data
void setup() {
Serial1.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
// send data only when you receive data:
if (Serial1.available() > 0) {
// read the incoming byte:
incomingByte = Serial1.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
}
From this code, I have received an output on the serial monitor as the following:
I received: 49
I received: 46
I received: 49
I received: 48
I received: 53
I received: 51
I received: 51
I received: 49
I received: 69
I received: 45
I received: 48
I received: 52
I received: 13
I received: 10
Question: How will I be able to interpret this signal into a form of what I know? (value of 110.5 micro farads)
I have tried the following code as well, but I did not get any output on the serial monitor screen.
const byte numBytes = 32;
#define multimeter Serial1
byte receivedBytes[numBytes];
byte numReceived = 0;
boolean newData = false;
void setup() {
Serial.begin(9600);
multimeter.begin(9600);
}
void loop() {
recvBytesWithStartEndMarkers();
showNewData();
}
void recvBytesWithStartEndMarkers() {
static boolean recvInProgress = false;
static byte ndx = 0;
byte startMarker = 0x3C;
byte endMarker = 0x3E;
byte rb;
while (multimeter.available() > 0 && newData == false) {
rb = multimeter.read();
if (recvInProgress == true) {
if (rb != endMarker) {
receivedBytes[ndx] = rb;
ndx++;
if (ndx >= numBytes) {
ndx = numBytes - 1;
}
}
else {
receivedBytes[ndx] = '\0'; // terminate the string
recvInProgress = false;
numReceived = ndx; // save the number for use when printing
ndx = 0;
newData = true;
}
}
else if (rb == startMarker) {
recvInProgress = true;
}
}
}
void showNewData() {
if (newData == true) {
Serial.print("This just in (HEX values)... ");
for (byte n = 0; n < numReceived; n++) {
Serial.print(receivedBytes[n], HEX);
Serial.print(' ');
}
Serial.println();
newData = false;
}
}
Thank you so so much in advance!