ESP8266 and Dust Sensor - no communication?


#1

Hi folks,

This project will be monitoring temp, humidity, particulates, and airflow. I’ve been able to get a Sanyo IR dust sensor running on this unit - but the values from the Sanyo don’t have the accuracy for the job.

I bought a SEN0177 Laser dust sensor here on Little Birds. I’m trying to read the sensor values from it and just simply display them in the serial window in the arduino IDE.

No luck.

I have the SEN0177 connected to its sensor adaptor board. The board is connected to 5v off the breadboard rail, TX and RX from there are connected to RX and TX on the GeekCreit ESP8266 board. It’s the bare minimum I think (although I’ve read I could leave the ESP8266’s TX pin disconnected). The ESP is connected to the same power rail on the breadboard (to VIN and GND).

The SEN0177 itself seems alive - the fan powers up and spins. The adaptor board has a green light on the RX light and a red light for the “ON” led.

But that is it.

The TX light never really seems to do anything?

I have tried so many different code examples off the web - I just can’t seem to get any values out of this sensor.

I’m hoping I can get some guidance? I’m not a real coder, not a real Engineer - but I’m bloody determined!

Thanks folks,
Brendan

PS - Code follows

//******************************
 //*Abstract: Read value of PM1,PM2.5 and PM10 of air quality
 //*Product Link: http://www.dfrobot.com.cn/goods-1113.html
 //*
 //*
 //*The TX pin on the sensor connects to pin 10 on the Arduino
 //*The RX pin on the sensor connects to pin 11 on the Arduino
 // DIFFERENT ON ESP!!
 //
 //*Version:V3.1
 //*Author:Zuyang @ HUST
 //*Date:March.25.2016
 //******************************
 
#include <Arduino.h>
#include <SoftwareSerial.h>
#define LENG 31   //0x42 + 31 bytes equal to 32 bytes
unsigned char buf[LENG];

int PM01Value=0;          //define PM1.0 value of the air detector module
int PM2_5Value=0;         //define PM2.5 value of the air detector module
int PM10Value=0;         //define PM10 value of the air detector module

SoftwareSerial PMSerial(3, 1); // RX, TX - ESP specific pins

String data = "";

void setup()
{
  PMSerial.begin(9600);   
  PMSerial.setTimeout(1500);    
  Serial.begin(9600);

}

void loop()
{
  Serial.println("Looking for val "); 
  if(PMSerial.available()>0 ){
    Serial.println("PMSerial avail");  

// try to debug if there is any content
    char ch=PMSerial.read();
    data.concat(ch);
    Serial.println((int)ch, HEX); 
   
    if(PMSerial.find(0x42)){
      Serial.println("found 0x42");    
      PMSerial.readBytes(buf,LENG);
  
      if(buf[0] == 0x4d){
        if(checkValue(buf,LENG)){
          PM01Value=transmitPM01(buf); //count PM1.0 value of the air detector module
          PM2_5Value=transmitPM2_5(buf);//count PM2.5 value of the air detector module
          PM10Value=transmitPM10(buf); //count PM10 value of the air detector module 
        }           
      } 
    }
  }

  static unsigned long OledTimer=millis();  
    if (millis() - OledTimer >=1000) 
    {
      OledTimer=millis(); 
      
      Serial.print("PM1.0: ");  
      Serial.print(PM01Value);
      Serial.println("  ug/m3");            
    
      Serial.print("PM2.5: ");  
      Serial.print(PM2_5Value);
      Serial.println("  ug/m3");     
      
      Serial.print("PM1 0: ");  
      Serial.print(PM10Value);
      Serial.println("  ug/m3");   
      Serial.println();
    }
  
}
char checkValue(unsigned char *thebuf, char leng)
{  
  char receiveflag=0;
  int receiveSum=0;

  for(int i=0; i<(leng-2); i++){
  receiveSum=receiveSum+thebuf[i];
  }
  receiveSum=receiveSum + 0x42;
 
  if(receiveSum == ((thebuf[leng-2]<<8)+thebuf[leng-1]))  //check the serial data 
  {
    receiveSum = 0;
    receiveflag = 1;
  }
  return receiveflag;
}

int transmitPM01(unsigned char *thebuf)
{
  int PM01Val;
  PM01Val=((thebuf[3]<<8) + thebuf[4]); //count PM1.0 value of the air detector module
  return PM01Val;
}

//transmit PM Value to PC
int transmitPM2_5(unsigned char *thebuf)
{
  int PM2_5Val;
  PM2_5Val=((thebuf[5]<<8) + thebuf[6]);//count PM2.5 value of the air detector module
  return PM2_5Val;
  }

//transmit PM Value to PC
int transmitPM10(unsigned char *thebuf)
{
  int PM10Val;
  PM10Val=((thebuf[7]<<8) + thebuf[8]); //count PM10 value of the air detector module  
  return PM10Val;
}

#2

G’day,

Are you giving the sensor 30 seconds to start up? it won’t send data until it is ready.

The RX LED isn’t specified to be glowing without data, so it is odd that it glows. It would glow if the ESP8266 was driving the wrong signal, if polarity was wrong, or if the signal names are swapped. Check that you are correctly wiring TX and RX signals. They may need to swap.

Temporarily power the sensor with both TX and RX wires disconnected, and see if the LEDs on the adapter behave differently; giving it at least 30 seconds.

Temporarily power the sensor with the RX wire disconnected, see if the RX LED stops glowing.

Check the voltages of the TX and RX pins.

You also posted to arduino.cc? Picture was very helpful. Also confirmed 5V is given to the sensor. I’ve no issues with the mix of system voltages; the sensor has 3V3 I/O as does the ESP8266 ESP-12.


#3

Oh, looking at your photograph again, you have the sensor attached to the TXD and RXD of the ESP-12 module, so you’re wiriing to the USB serial adaptor chip next to the ESP-12, and the USB serial adaptor would be driving the RXD pin, which would be back-driving the sensor RX pin. You’ll have to use different ESP-12 pins for the sensor, or cut the PCB trace which would disable the USB socket for programming.


#4

Hi Quozi,

Thanks for taking the time to read both of my posts. I posted here first then I saw that this forum was a little quiet - figured I had to look further afield for my answers. Maybe not!

Ok. I hear you, my USB connection may well be an interference, good catch.

I had tried some other ports, the other pair of RX/TX pins on the esp12e units - then came to the realisation of software serials ability to use other pins a bit later. I’ll give that a bigger push.

I’ll power up the sensor on its own and see if there is any TX indications - and I’ll exercise some patience - I’ll run it for 45 seconds!

I’m feeling under the pump for this one, I’m building it for a guy who really wants to measure these data points for his own project and then have them logged on a web dashboard. I feel I’m letting him down on the length of time I’m taking. Anyway, onwards and upwards!

Thanks again for your time! Very appreciated!

Brendan


#5

Great. Just to be sure, it’s not just the USB cable, it’s the USB chip on the GeekCreit board, which even with the USB cable removed remains powered by your 5V supply and drives the RX pin of the ESP-12. You can test that by measuring voltages of the pins. I can’t find a schematic for the board, but similar boards like the NodeMCU or Adafruit Feather Huzzah ESP8266 schematics show no isolation between the USB chip and the ESP-12.


#6

Ok!

So I removed the power supply (I checked a spare and found it was going to feed 10v over my 5v rail! Bin time!) and now I am running it off the 5v supply from the VIN and USB.

I also changed the TX RX pins to:

SoftwareSerial PMSerial(13, 12); // RX, TX - ESP specific pins

I’m using thinger.io to send my values to - so I’m not sure my code will help anyone else out there.

Link to thinger dashboard (WIP)

I am finding that the unit won’t start when I reset/reflash the ESP - I have to remove/replace the power lead to the rail to jolt the sensor into action. I’m thinking this may abate when I make it more permanent?

Thanks for your time Quozl, you really helped me out of my funk on this one!


#7

Looking good.

On dodgy power supplies; if you tested without a load, even a properly regulated 5V USB supply can show 10V, especially if it was designed for high current charging. Power supplies need a minimum load to ensure they start properly. I would plot the voltage under varying loads before binning.

ESP8266 not restarting after reflash or reset is usually caused by GPIO0 or GPIO2 pins not in correct configuration, or by power supply noise at reset time. The 3.3V power supply is local on the module, but you’ve extended it a distance; 3.3V to the temperature and humidity sensor, and 5V to the dust sensor. See if it resets reliably if those wires are not connected. When you shorten these wires, the problem may be reduced. Adding a small capacitance may help. If you have an oscilloscope, trace the 3.3V and 5V pins during reset.

Also try a different ESP8266 and see if the problem follows the module. I’ve had ESP8266 modules that cannot reliably reset after wake from sleep, but the problem followed the module.


#8

This is all on me :slight_smile:
So when I mentioned that:

I am finding that the unit won’t start when I reset/reflash the ESP - I have to remove/replace the power lead to the rail to jolt the sensor into action. I’m thinking this may abate when I make it more permanent?

I meant the dust sensor :slight_smile: The ESP and I get on great, almost no problems (though I did notice that the ESP died overnight with an exception - will have to look into that). The dust sensor doesn’t start up properly after the ESP reboots. The unit powers up, but doesn’t send any data until after I fiddle with the rail connection.

I’ll take on board the extended cables comment - I’ll tidy and harden this up a bit tonight if time permits!

I’m also noticing that after a while the sensor locks up value-wise. IOW, it’s sending values but they seem to be a random amount of 1200 or 0. The public dashboard will exhibit what I mean…

Nothing is ever simple eh?

Thanks!

Brendan


#9

Hey Brendan,

Any joy with that? I’m observing very similar behavior of my SEN0177 connected to ESP8266 chip. What I’ve noticed is:

  • RX led is constantly on on y PM2.5 Sensor Adapter
  • When I connect both TX & RX lines to ESP8266 - sensor will not produce any output. Moreover - SLEEP pin would not work (FAN will always spin and wouldn’t stop even if I provide LOW signal on SLEEP pin)
  • When I connect only TX pin (leaving RX unattached), sensor would sometimes come up - it reacts to SLEEP pin state and will stop the FAN and start depending on the LOW/HIGH signal
  • It would also transmit the data to my ESP
  • Unfortunately in a bit unreliable way - i.e. it may transmit fine for few hours, and then for no reason go into ‘stuck’ state and as such would not transmit any new values to ESP and not react to SLEEP anymore

Sometimes when it comes up it only reports “0” or “1200” - similar to what you wrote.

Have you manged to get to the bottom of that?

Also, anyone knows how the RESET or SET pin works? Maybe those are a source of the whole evil