Components: SuperPro and LuminOx 2 oxygen sensor http://sstsensing.com/application-note- ... nox-sensor
The LuminOx 2 oxygen sensor has an on-board ARM processor and communicates via a 3.3 volt UART and serial port. It is plug-in compatible with the SuperPro.
The LuminOx sensor was mounted on a RadioShack perf board which was mounted on stand-offs to the lid of a Mason jar. An M12 connector was used as a vacuum tight feedthru.
Qualification of the apparatus proceeded by heating the Mason jar in an oven to about 220 F and then quickly sealing the jar. The partial pressure inside the jar then decreases as the air inside cools down.
The LuminOx sensor responds to a handful of text commands to either stream the data from periodic measurements or respond with a single measurement. The LuminOx sensor first responds to a command with an acknowledgment. The following program initializes the sensor and periodically requests a reading.
Code: Select all
char* banner1 = "//////////////////////////////////////////////////////////\n";
char* banner2 = "// //\n";
char* banner3 = "// code to read LuminOx sensor and transmit to console //\n";
char* banner4 = "// Jim Willis September 12, 2014 //\n";
char* banner5 = "// //\n";
char* banner6 = "//////////////////////////////////////////////////////////\n";
#include "coridium_pcb.h" // this one is required and configures for the proper CPU
#include "string.h"
#include "printf.h"
#include "uart.h"
#include "breakpoint.h"
#include "systick.h"
#define TIME_BETWEEN_READINGS 60*1000/65 // 60 seconds in multiples of 65 milliseconds
// commands
char* offMode = "M 2\r\n";
char* pollMode = "M 1\r\n";
char* requestAll = "A\r\n";
// booleans
int haveResponse = FALSE;
int echoToConsole = TRUE;
void
waitForResponse()
{
// add time out
while (!haveResponse)
{
checkForInputFromSensor(); // wait - needs timeout
}
}
void
sendCommand(char *inputPtr, int wait)
{
char* ptr = inputPtr;
while(*ptr!=NULL)
{
// putc(*ptr, 0); // echo to console
putc(*ptr, 1); // send to sensor
++ptr;
}
if (wait)
{
haveResponse = FALSE; // to handshake the response
waitForResponse();
}
}
void
checkForInputFromSensor()
{
int charIn;
// getc() will return a single character (0-255) if one is available in the input buffer.
// If no character is available then -1 is returned.
charIn = getc(1); // check the sensor receive buffer
if(charIn != (-1) ) // if the sensor receive buffer is not empty
{
if (echoToConsole == TRUE) // if echoToConsole is TRUE then
putc(charIn, 0); // send it to the console port
if (charIn == '\n') // check for response terminator
{
haveResponse = TRUE;
}
}
}
void
checkForInputFromConsole()
{
int charIn;
charIn=getc(0); // check the console receive buffer
if(charIn != (-1)) // if there is a character waiting
{
putc(charIn, 1); // send it to UART1 -- the sensor port
}
}
void
sysInit()
{
SystemInit(); // initializes clocks
UART_init(0,19200); // turns on UART0 which is the USB serial connection
UART_init(1,9600); // turns on UART1 which is the sensor serial connection
systick_init(); // sets up SysTick as the TIMER 1usec tick
}
void
displayBanner()
{
puts(banner1);
puts(banner2);
puts(banner3);
puts(banner4);
puts(banner5);
puts(banner6);
}
int main(void)
{
unsigned int startTime, numberOfReadings = 0;
sysInit();
startTime = ms65_count;
displayBanner();
puts("turn on poll mode - wait for response\n");
sendCommand(pollMode, TRUE); // send command, wait for response
puts("requestAll - wait for response\n");
printf("%u ", numberOfReadings++);
sendCommand(requestAll, TRUE); // send command, wait for response
// puts("turn sensor off - don't wait for response\n");
// sendCommand(offMode, FALSE); // send command, don't wait for response
while (1)
{
checkForInputFromConsole();
checkForInputFromSensor();
if (ms65_count-startTime >= TIME_BETWEEN_READINGS)
{
startTime = ms65_count;
sendCommand(pollMode, TRUE);
echoToConsole = TRUE; // show on console
printf("%u ", numberOfReadings++);
sendCommand(requestAll, TRUE); // send command, wait for response
echoToConsole = FALSE; // stop showing on console
// sendCommand(offMode, FALSE); // send command, don't wait for response
}
}
return 0;
}
**********************************************************
Termite log, started at Mon Nov 10 17:42:22 2014
**********************************************************
17:42:21
requestAll - wait for response
O 0186.1 T +19.3 P 0912 % 020.40 e 0000
O 0186.1 T +19.3 P 0912 % 020.41 e 0000
O 0186.1 T +19.3 P 0912 % 020.41 e 0000
O 0186.1 T +19.3 P 0913 % 020.39 e 0000
...
Interpreted, partial pressure O2 is 186.1 mBar, temperature is 19.3 C, pressure is 913 mBar, O2 is 20.4 %.
More to follow...