All,
The first version of my code had a couple of shortcomings, which has now been ironed out.
Firstly, it did not comply with the fu-speak pressure unit system. fu-speak?? Confused?, well so was I.
Pressure units were never easy, and the world has odd preferences when it comes to expressing the value of a pressure. In Asia they favour the Pascal (or so I read), and so does the scientific community. Europeans are fond of the Millibar. Yankees swear by the torr.
And then there is that weird little group of fanatics "The Fusioneers" (and the associated group of wannabees), they have their own silly system. A system based on torr, which is the unit down to 1.0E-00, where it changes to the micron, which must be religiously adhered to all the way to 1.0 E-03 torr (0 Microns) where the unit changes again, this time to millitorr.
In appreciation of the immense work given here by mr. Hull, (who is a stern advocate of the micron), and with a nod to a certain mr. Orwell, I call this system for fu-speak, short for fusor-speak.
It only took 25 extra lines of code to comply with fu-speak, it was a fun coding exercise, and besides, I have pledged to use the micron around fusion pressures and generally gotten used to it, so here you have it.
However, it would also be nice to be able to display the pressure in Pascal, since it is so highly touted in the scientific community, and in all the books. And as an educational feature, switch back and forth, to perhaps gain a working ability to switch between units without having to grab a calculator, and/or swear in dispair.
Of course, you could go with HectoPascal and learn to multiply with 1.33 but.....
Anyway, I needed an excuse to learn how to implement the Interrupt routine in programs, so I took this opportunity do use the response to the activation of two switches, to toggle betweeen two branches of the program.
One where the transducer is first prompted to answer in Pascal, the other to report back with the pressure in torr.
This works nicely, and I am satisfied, (as in proud), of my acheivement.
The outputs looke like this now, just a push of a button apart:
- Pressure displayed in fu-speak
- Pressure in proper Pascal
The can of worms approach has to stop, and I have already ordered d-sub receptacles to solder to a motherboard which will form a mechanical backbone for, and harness the arduino nano, the battery charger/boost converter and the MAX232 RS232 to TTL converter, the two switches, a power switch, the battery and the display.
I will also try to find a suitable (as in available) box to wrap up the whole caboodle.
The code needs small adjustments to the placing of the units, for example, millitorr should start further to the left, when this is done and has been tested with a diff-pump, the code will get it's V.1.00 stamp, and I will write a nice little post, with all details needed to replicate the work, in the case that you should want to.
Meanwhile, you can grab the code here:
//VacuuMeter V.0.9
//This program queries MKS 901P and 999 series pressure transducers about pressure,
//either in torr or pascal, and displays the result on small Oled display.
// 27-09-2017 Finn Hammer
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
String sensorValue;
String pressureUnit;
String unitBuffer;
String unit;
const byte ledPin = 13;
const byte interruptPin3 = 3;
const byte interruptPin2 = 2;
void setup() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (initializing the display)
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(interruptPin3, INPUT_PULLUP);
pinMode(interruptPin2, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin3), pascalISP, FALLING);
attachInterrupt(digitalPinToInterrupt(interruptPin2), fuspeakISP, FALLING);
}
void loop() {
if (unit == "Pascal") {
pascal();
}
else if (unit == "Fuspeak") {
fuspeak();
}
display.display();
}
void pascalISP() {
unit = "Pascal";
Serial.print ("@253U!PASCAL;FF");
}
void fuspeakISP() {
unit = "Fuspeak";
Serial.print ("@253U!TORR;FF");
}
void pascal () {
Serial.print ("@254PR3?;FF");
sensorValue = Serial.readString();
sensorValue.remove(0, 7); //Remove the first 7 caracters from @253ACK7.61E+2;FF to get 7.39E+2;FF
sensorValue.remove(7); //Remove caracters from the 7th, to get 7.61E+2}
pressureUnit = "Pascal";
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.setCursor(0, 0);
display.print("Foreline Pressure");
display.setTextSize(2);
display.setCursor(0, 9);
display.print(sensorValue);
display.setTextSize(1);
display.setCursor(85, 25);
display.print(pressureUnit);
}
void fuspeak () {
Serial.print ("@254PR3?;FF");
sensorValue = Serial.readString();
sensorValue.remove(0, 7); //Remove the first 7 caracters from @253ACK7.61E+2;FF to get 7.39E+2;FF
sensorValue.remove(7); //Remove caracters from the 7th, to get 7.61E+2
unitBuffer = sensorValue;
unitBuffer.remove (0, 5);
if (unitBuffer == "+2") {
pressureUnit = "torr";
}
else if (unitBuffer == "+1") {
pressureUnit = "torr";
}
else if (unitBuffer == "+0") {
pressureUnit = "torr";
}
else if (unitBuffer == "-1") {
pressureUnit = "micron";
sensorValue.remove (1, 1);
sensorValue.remove (3);
}
else if (unitBuffer == "-2") {
pressureUnit = "micron";
sensorValue.remove (1, 1);
sensorValue.remove (2);
}
else if (unitBuffer == "-3") {
pressureUnit = "micron";
sensorValue.remove (1, 1);
sensorValue.remove (1);
}
else if (unitBuffer == "-4") {
pressureUnit = "millitorr";
}
else if (unitBuffer == "-5") {
pressureUnit = "millitorr";
}
else if (unitBuffer == "-6") {
pressureUnit = "millitorr";
}
else pressureUnit = "endelse";
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.setCursor(0, 0);
display.print("Foreline Pressure");
display.setTextSize(2);
display.setCursor(0, 9);
display.print(sensorValue);
display.setTextSize(1);
display.setCursor(85, 25);
display.print(pressureUnit);
}
Cheers, Finn Hammer