We are connecting a CO2 sensor with the RJ12 connector.
RJ12 Connector only gives us 4 pins that are required for this sensor, but we are missing 2 pins.
The pins that we don’t get from RJ12 connector are the signal and en_vbb pins. Can we connect them to the board? How and which ones?
Here is the snippet of the code:
local LP = hardware.uartFG;
imp.setpoweren(true);
local state = 1
hardware.pinS.write(state);
hardware.pinY.configure(DIGITAL_OUT, state);
hardware.pinS.configure(DIGITAL_OUT, state);
LP.configure(9600, 8, PARITY_NONE, 2, NO_CTSRTS);
Not sure how to read/write from the sensor after reading the manual.
VBB shorted to EN_VBB connected to 3V3 on imp (pin 5 on the RJ12). There’s no need to use the sensor’s shutdown mode as the imp has a power switch integrated.
TXD on sensor to RXD on imp (pin 6 on the RJ12)
RXD on sensor to TXD on imp (pin 1 on the RJ12)
RDY to the 1wire line on the imp (pin 3 on the RJ12)
Connect VCAP to 3V3 on the imp; I would put at least 220uF on there (right at the sensor itself) to help with the current peak during a reading. A supercap shouldn’t be necessary but I would recommend using the Energizer Lithium AAs here as they are better with high current than alkalines.
Luckily, the RDY signal (which is useful) is open drain so can be connected to the 1wire line. After powering up the imp you can wait for pinM to go low which indicates the sensor is ready for commands.
See the “standard RDY polling” flow in the datasheet
@hugo
We are following the arduino project below.
We are able to get the first read down and but then the subsequent read is not working. We tried different ways. Any help would be appreciate!
for (local i = 0; i < n; i++)
{
response[i] = LP8.read();
server.log(“response[” + i + "] = " + response[i]);
}
if(n == 37){
local decimal = 256 * response[29] + response[30];
server.log("CO2: " + decimal);
}
}
function simpleWrite(command){
local timeout = 0;
imp.sleep(0.2);
while (pinM.read() == 1) {
timeout++;
if (timeout > 10){
break;
}
server.log(“waiting for rdy to go low”);
}
server.log(“rdy now LOW, an active LOW signal. Low means READY.”);
LP8.write(command);
imp.sleep(1);
}
function waitRead(command){
local timeout = 0;
imp.sleep(0.1);
while (pinM.read() == 0) {
timeout++;
if (timeout > 10){
break;
}
server.log(“waiting for rdy to go HIGH”);
}
server.log(“rdy now HIGH, an active HIGH signal. HIGH means READ.”);
LP8.write(command);
imp.sleep(1);
}
So, here I’m particularly concerned about the way you’re reading the packet.
The read() command does not block - so if all the data has not arrived yet, you’ll get -1 back from this and I would suspect that your buffer appears to have some of them in there (though they’ll appear as 255 in your logging as you’re reading them back out of the buffer).
Would that summarize what you’re seeing? If so, the hacky way to work around this would be to just put a long delay before reading, to ensure the whole response has been received, but the real answer is to process the bytes individually as they come in with a state machine.
Also, waitRead will essentially just wait for 0.1s as there is no delay in the loop; I’m guessing you’re trying to wait for up to 1s? (same for simpleWrite).
I’ve also just started with the LP8. I wasn’t too impressed by the Arduino code in their docs so I pretty much started from scratch. The problem I’m running into is that I’m not getting any response from the LP8 … at all. I’ve checked out my connections and all seems good. The LP8 RDY pin never goes high. If I force it high and send out a request on ModBus, I get no reply.
//set up serial bus ====
LP8 <- hardware.uartWJ
LP8.configure(9600, 8, PARITY_NONE, 2, TIMING_ENABLED , LP8_answer)
Turns out that the reset pin is not used by the LP8 and the enable pin is not needed (as per Hugo’s comment)
Checked to make sure my the LP8 RxD goes to PinW and TxD to PinJ. The LP8 RDY pin goes to PinT. I used the TIMING_ENABLED in the uart config because imp docs seemed to indicate it was necessary for ModBus.