What is the voltage on the TX / RX ports?
I have a SDS011 sensor, and for the life of me I cannot get any serial input on them.
I found a forum posting that suggest the sensor works on 3v so wanted to check.
Any suggestions?
What is the voltage on the TX / RX ports?
I have a SDS011 sensor, and for the life of me I cannot get any serial input on them.
I found a forum posting that suggest the sensor works on 3v so wanted to check.
Any suggestions?
These are as any other GPIO pins on these devices 3.3V signals, but the pins are 5V tolerant.
Can you clarify how you have wired the sensor and show your code?
Providing a link to hardware you are using is always appreciated too
http://inovafitness.com/software/SDS011%20laser%20PM2.5%20sensor%20specification-V1.3.pdf
Hmmm, what would be preventing it from getting a Serial signal then?
All I get from the output is Check 0, which is before the While loop kicks in…
Here’s the code:
// most of the code is based on code from www.inovafitness.com and
// www.dfrobot.com
// set the LCD address to 0x2? for a 16 chars and 2 line display
// use a i2c scanner to detect the real address!
long previousMillis = 0;
const int analogInPin = A0;
int latch = 8;
int srclk = 9;
int ser = 10;
unsigned char displayTemp[8];
unsigned int Pm25 = 0;
unsigned int Pm10 = 0;
void ProcessSerialData()
{
uint8_t mData = 0;
uint8_t i = 0;
uint8_t mPkt[10] = {0};
uint8_t mCheck = 0;
Particle.publish("Check 0");
while (Serial.available() > 0)
{
Particle.publish("Check 1");
// from www.inovafitness.com
// packet format: AA C0 PM25_Low PM25_High PM10_Low PM10_High 0 0 CRC AB
mData = Serial.read(); delay(2);//wait until packet is received
//Serial.println(mData);
//Serial.println("*");
if (mData == 0xAA) //head1 ok
{
Particle.publish("Check 2");
mPkt[0] = mData;
mData = Serial.read();
if (mData == 0xc0) //head2 ok
{
Particle.publish("Check 3");
mPkt[1] = mData;
mCheck = 0;
for (i = 0; i < 6; i++) //data recv and crc calc
{
mPkt[i + 2] = Serial.read();
delay(2);
mCheck += mPkt[i + 2];
}
mPkt[8] = Serial.read();
delay(1);
mPkt[9] = Serial.read();
if (mCheck == mPkt[8]) //crc ok
{
Particle.publish("Check 4");
Serial.flush();
//Serial.write(mPkt,10);
Pm25 = (uint16_t)mPkt[2] | (uint16_t)(mPkt[3] << 8);
Pm10 = (uint16_t)mPkt[4] | (uint16_t)(mPkt[5] << 8);
if (Pm25 > 9999)
Pm25 = 9999;
if (Pm10 > 9999)
Pm10 = 9999;
// Serial.println(Pm25);
// Serial.println(Pm10);
Particle.publish("Pm 10 = " , Pm10);
//get one good packet
return;
}
}
}
}
}
void setup() {
// Print a message to the LCD.
Serial.begin(9600);
Pm25 = 0;
Pm10 = 0;
}
void loop() {
ProcessSerialData();
Particle.publish("Pm 2.5 = ");
Particle.publish(String(Pm25));
//Particle.publish(float(Pm25) / 10.0);
Particle.publish("Pm 10 = ");
Particle.publish(String(Pm10));
//Particle.publish(float(Pm10) / 10.0);
// Serial.print("Pm2.5 ");
// Serial.print(float(Pm25) / 10.0);
// Serial.println();// Display();
// Serial.print("Pm10 ");
// Serial.print(float(Pm10) / 10.0);
// Serial.println();
delay(2000);
}
e.g. the use of the wrong serial port.
Serial
refers to the USB Serial interface.
You want Serial1
You are also publishing too fast (max 1/s on avg)
Aaah, if that works, I owe you a beer!
Ok, so I owe you a beer!
Welcome!
Next time when I’m near Skopje I’ll pop by