Read Information from a Sensor with esp8266

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
till90
Posts: 1
Joined: Fri Dec 01, 2017 3:45 pm

Read Information from a Sensor with esp8266

Post by till90 » Fri Dec 01, 2017 4:00 pm

Hi people,

im new to this iot things and also to programming :mrgreen: . I give my best to explain my problem.

I have a Nodemcu V3 (with ESP8266) connected with a SDS 011 Nova PM Dust Sensor.
I want to read the PM 2.5 and PM 10 Value from the meassurement of the Sensor.

When i understand it right. The TXD and RXD connection is important for me?!
I set the TXD from the SDS011 Sensor to the Pin 4 and the RXD to Pin 5.

my Code until now:

import machine

#TXD = 4 output? RXD = 5 input?
pin4 = machine.Pin(4, machine.Pin.OUT)
pin5 = machine.Pin(5, machine.Pin.IN, machine.Pin.PULL_UP)
print (pin4.value())
print (pin5.value())

>>> thats what i get back
1
1

I dont really understand what it means? I test a little bit and sometimes i get 0 instead of 1. What exactly does it say to me? Do i think wrong when i belive that
pin4.value() gives me the value for PM 10 or PM 2.5 ?

On the manuel for the Sensor i found this:

Needs all sensor response:
Send command:
AA B4 04 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 02 AB
Sensor with ID A160 Reply:
AA C0 D4 04 3A 0A A1 60 1D AB
Show PM2.5 data is 04D4, convert it to a decimal 1236,then it show PM2.5 to 123.6μg/m3,PM10 data is 0A3A, convert it to a decimal 2618, then it show PM10 to 261.8μg/m3.

but how can i send this to the sensor that i can get the response?

Thank you verry much for helping ;)

best regards
Till

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: Read Information from a Sensor with esp8266

Post by OutoftheBOTS_ » Mon Dec 04, 2017 5:57 am

Ok I just Googled the sensor.

It is a 5v sensor so you will need a level shifter to shift the signal between 5v and 3.3v as all these new generation processors are 3.3v (5v is a bit old school)

The pins have multi purpose, you have set them up as just GPIO pin(general input/output pins)you need them to be setup for serial communication instead. I did google "SDS011 python" and this simple short program was the firts at the top of the page https://github.com/fsteinhardt/sds011/b ... /sds011.py take a look at it to get some ideas of how it works also google "uart serial communication protocol"

Online
User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Read Information from a Sensor with esp8266

Post by Roberthh » Mon Dec 04, 2017 8:20 am

The sensor has two types of output, a serial communication with 9600 baud at Pins 6 and 7, and a kind of PWM output at pin 2.
The ESP9266 has just one serial port, used for USB. There were some attempts to use a GPIO for software based UART, but not successful so far at a rate of 9600 Baud, at least not for receiving. Since the PWM of the sensor is rather slow, you can poll that by software, preferrebly with an Interrupt Service Routine, which triggers on both the rising and falling slope. The ISR on an ESP8266 has a jitter of about 300 us, which adds an error of just 0,03% here, which is obviously neglegible.
And, like @outofthebots said, you'll need a level shifter, or at least a current limiting resistor, if you poll the output.
Using an ESP32 maybe more suitable, because that device has more than one UART.
P.S.: There was some discussion about this sensor before, edither in this forum or in forrm.pycom.io. You might search for that, and maybe contact the people who already dealt with it.

Post Reply