I am having issues building an Arduino module that can help me read what a pressure transducer outputs. I have an RS232 to TTL converter that is going to convert the data between the Arduino and the transducer, it looks like this:
The transducer has a D-sub15 connection, I made a cable for it so it has an D-sub9 end, the diagram looks like this (the cable looks terrible! But it works):
I have tested that the cable works by using an RS232 to USB cable, and using a serial terminal and sending the command to the transducer, and effectively receiving the ambient pressure (the command is: @253PR3?;FF).
However having the transducer connected to my computer is not efficient, so I want an Arduino to keep sending the string @253PR3?;FF while having the result in an LCD. As of now, I am just trying to have the Arduino send @253PR3?;FF through the TX pin and receiving data through the RX pin, then printing it in the serial monitor, obviously the TX, RX, VCC (5 or 3.3 V) and GND pins of the Arduino are connected to the max3232 converter.
When I open the serial monitor I only get @253PR3?;FF instead of the desired 7.10E+2, the Arduino TX led does blink, but the RX does not. I checked with a voltmeter and the max3232 seems to work fine. Could this be a problem with having a ground between the transducer and dsub9 head, and then having the Arduino ground? Or perhaps I can't print the result on the serial monitor?
Please help with anything you could see that could be the source of the problem,
One cannot have more than one deice connected to a serial port. As it is your sketch has both the transducer and serial monitor connected to hardware serial. I would suggest that you set up a software serial port for the transducer and use the hardware serial port (pins 0 ans 1) for program output and upload. There is the Software serial library that comes with the IDE and a couple others that are "better" (NeoSWSerial and AltSoftSerial).
Here is your sketch with an added software serial port to illustrate how it would work. One suggestion. Don't use the String class and readString(). The String class can cause memory fragmentation if not used carefully and readString() is a blocking function which can make the sketch less responsive. Robin2's serial input basics thread shows how to do serial in a robust and non blocking manner and uses null terminated character arrays (strings [small s]).
#include <SoftwareSerial.h>
SoftwareSerial xducer(4, 5); // set up a software serial port in pins 4 and 5 (RX, TX)
// or pins of your choice
String sensorValue;
void setup()
{
Serial.begin(9600);
xducer.begin(9600);
}
void Pressure()
{
xducer.print ("@253PR3?;FF"); // does the transducer need a carrialge return line feed terminating characters?
// if so use xducer.println ("@253PR3?;FF"); println sends "\r\n"
sensorValue = xducer.readString();
//sensorValue = sensorValue.remove(0, 7); //Go from @253ACK7.10E+2;FF to 7.10E+2;FF
//sensorValue = sensorValue.remove(7); //To get 7.39E+2
Serial.println (sensorValue);
}
void loop()
{
Pressure(); //loop de sensorValue
delay(500); // to keep from flooding the serial port
}
That would require 2 TTL to RS232 adapters, right? Perhaps instead I could install the LCD display and that way I use the serial hardware for the transducer and the digital pins to print the result on the LCD. What do you think?
Also is there a way to use the LCD without POTs? One time I had a project that used a voltage divider and an LCD and when adjusting the POTs my values changed (As if the pot interfered the voltage divider) will the POTs affect in any way the serial communication?
What LCD display. That's the first mention of an LCD. Can you post a picture or data sheet for the LCD. I don't see why you would need a RS232 converter for an LCD. The serial LCDs that I know of are TTL serial. Please post a schematic of your entire setup.
I meant 2 TTL adapters if I wanted to display the pressure on the serial monitor. With the LCD there is no adapter needed, it is a 16x2 LCD, OK I will make the schematic.
Here is a schematic I made for the Arduino, LCD display (without pots) and max3232 adapter. If I do this, my plan would be to use the liquidcristal library and print the data I receive from the transducer there.
So you will use hardware serial for the transducer? You will lose the ability to use serial monitor for debug output. And you may have trouble uploading code unless you make sure to unplug the transducer from the serial pins.
My project consists of making a module for a high precision vacuum gauge, the vacuum gauge (the transducer) outputs pressure with the command "@253PR3?;FF", it can do a lot more things, but I just need to display the pressure. I was lazy at first to solder/breadboard all the LCD components and tried to do it in the serial monitor, now I've realized I do want to be able to see the pressure in a separate component (LCD). The transducer has a dsub15 head that I can unplug when I need to upload code.
So, do you think my schematic of the electronics will work?
Sketch mistake, its supposed to be t1out, my actual hardware is as the first post describes, already built in with the capacitors and dsub9 head.
Update:
I tried wiring everything up, the LCD works fabulous, but still can't get the Arduino to receive something from the transducer.
// include the library code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
String sensorValue;
void setup() {
Serial.begin(9600);
//Contrast
analogWrite(6,100);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
}
void Pressure() {
lcd.setCursor(0, 0);
lcd.print("Pressure:"); //texto que me dice que estoy midiendo
Serial.println ("@253PR3?;FF");
sensorValue = Serial.readString();
sensorValue.remove(0, 7); //Quitar los primeros 7 caracteres de @253ACK7.10E+2;FF para tener 7.10E+2;FF
sensorValue.remove(7); //Quitar caracteres desde el 7mo, oara obtener 7.39E+2
lcd.setCursor(0,1);
lcd.print(sensorValue);
lcd.print(" Torr");
}
void loop() {
//
Pressure(); //loop de sensorValue
}