Brief description about the problem History
Communicating with a old VersaStat II used GPIB port but the GPIB ports PCI card stopped working but there was a another port 25 pin rs232 Serial communication port
but even now, too bad computers are abending the Serial port luckily there is still virtual Blutooth COM port
which can be used with a modern laptop so ESP32 microcontroller was selected to communicate with this device wirelessly (might later go for HC05 module etc.).
Fixing the voltage difference problem
Now there is a big problem the esp32 Serial uses +3.3 V
or logic 1
& 0 V
for logic 0
But in the rs232 port logic 0
is +3 V ~ +12 V
and logic 1
is -3 V ~ -12 V
also ± 3V
undefined region. To overcome this problem I have used the following circuit with optocouplers.
Here is the circuit diagram
The following code was used to communicate with the device easy as seems
Code
#include "BluetoothSerial.h"
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
BluetoothSerial SerialBT;
int speedsend = 9600;
void setup() {
Serial.begin(speedsend);
Serial2.begin(speedsend);
SerialBT.begin("ESP32SERIAL");
delay(500);
}
void loop() {
if (Serial2.available()) {
//incoming data from the device
int i = Serial2.read();
SerialBT.write(i);
Serial.println(i); // To check what is coming as output
}
if (SerialBT.available()) {
Serial2.write(SerialBT.read());
}
}
But I see no meaningful characters in putty (Bluetooth COM port) in Arduino Serial I see some numbers in HEX representation. Is this the way old devices communicate?
This link show how HEX numbers correlate with ASCII characters
https://www.rapidtables.com/convert/number/hex-to-ascii.html
How to fix this issue am I doing something wrong in here the circuit parameters etc.
Communication Example with device
For a start the ID
command should give a number as 2532 according to book after the conversion it gives me 32 32 34 32 0 0 , 2242 looking at the Arduino Serial numbers with the help of the converting web site shown in above url. That's how I noticed It gives me HEX numbers.
Here is the PDF rs232c Interface section PDF the original Book came with ID command page too.
https://drive.google.com/file/d/1BHhIsloF4voMxoFeSlz1GsjwfgHwgsPJ/view?usp=sharing
Another book looks same but not from the book came with
https://drive.google.com/file/d/1z0NUOe17SpVYTIBfEE8s0EKStfLKKv_-/view?usp=sharing