Details:
The sensor is a Telaire 8001 Single-Beam Infrared CO2 Gas Dispersion Sensor > telaire.com
It has an RJ45 type jack which, when used with a RJ45-DB9 adapter, can be used to connect the unit through a PC serial port. They provide a utility to change settings, test, and calibrate the sensor.
I have successfully connected to the sensor with their software on an XP virtual machine (since the utility apparently doesn't like Win7x64).
The problem I am having is when I try to talk to it with my ATMega1280.
Here's what I know about the sensor:
I have an ATMega1280 running off of USB power and I'm running Arduino-0018 IDE. On a breadboard I have a MAX235 Datasheet: http://datasheets.maxim-ic.com/en/ds/MAX220-MAX249.pdf. As seen on Figure 13 of the MAX235's datasheet, I have pins 8 and 9 on the MAX235 going to Pins 18 and 19 on the Mega, respectively. I have pins 11 and 12 on the MAX235 going to ground and +5v on Mega, respectively. I have Pins 20 and 21 on the MAX235 tied LOW. I have Pins 3 and 10 on the Max235 going to the Tx and Rx pins on the sensor's Rj45 jack (Pins 1 and 2), respectively. The sensor's ground pin on its RJ45 jack (Pin 3), the MAX235's ground pin (Pin 11), and the Mega all share a common ground.
I have set up a simple test sketch to try to initiate a conversation between the sensor and the Mega. If I send any character on Serial0, it sends out a STATUS command to the sensor on Serial1. If the Mega receives a response from the sensor, it is echoed back on Serial0.
Code is a bit of a mess because I'm been trying so many different things to get this to work.
//uint8_t Req_Co2[5] = {255, 254, 02, 02, 03};
const byte FLAG = 0xFF;
const byte BRDCST = 0xFE;
const byte CMD_READ = 0x02;
const byte CMD_UPDATE = 0x03;
const byte CMD_STATUS = 0xB6;
const byte hex_one = 0x01;
const byte hex_two = 0x02;
const byte CO2_PPM = 0x03;
const byte ELEVATION = 0x0F;
void setup() {
Serial.begin(9600);
Serial1.begin(19200);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
digitalWrite(2, HIGH);
delay(50);
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
delay(50);
digitalWrite(3, LOW);
}
void loop() {
// read from port 0, send commands to port 1:
if (Serial.available()) {
int inByte = Serial.read();
//Serial1.write(Req_Co2, 5);
//Serial1.print(FLAG);
//Serial1.print(BRDCST);
// Serial1.print(hex_one);
//Serial1.print(CMD_STATUS);
//Serial1.print(CO2_PPM);
Serial1.print(FLAG, BYTE);
Serial1.print(BRDCST, BYTE);
Serial1.print(0x00, BYTE);
Serial1.print(0x01, BYTE);
Serial1.print(CMD_STATUS, BYTE);
//Serial1.print(CO2_PPM, HEX);
digitalWrite(2, HIGH);
delay(500);
digitalWrite(2, LOW);
}
// read from port 1, send to port 0:
if (Serial1.available()) {
byte inByte = Serial1.read();
Serial.print(inByte, HEX);
digitalWrite(3, HIGH);
delay(500);
digitalWrite(3, LOW);
}
}
I have tested loopback by shorting Pins 3 and 10 on the MAX235. I correctly read back the command I send out to the sensor on the Serial Monitor. I have tried reversing Tx and Rx Pins on the sensor to no avail.
As I mentioned earlier, I tested the sensor's Serial communication with my PC, so I know things on that end are working correctly. I don't have an oscilloscope, but I can measure -9.25v coming out of the RS232 Tx Pin (Pin 3) on the MAX235, and -9.84v on the Tx Pin on the sensor's RS232/RJ45 port.
I have spent many hours reading trying to find a solution, but I have come to a point where I'm not sure what to try next. I turn to the many brilliant minds that roam this forum to help in my journey....