• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

ESP32 read Sharp Dust sensor GP2Y10 Switch Micropython

Q&A Forum › ESP32 read Sharp Dust sensor GP2Y10 Switch Micropython
0 Vote Up Vote Down
Muenny asked 6 years ago
10 Answers
0 Vote Up Vote Down
Muenny answered 6 years ago

I want to read The dust density with The Sharp GP2Y10.  The Sensor ist connected to ESP32. I implemented the Module with Arduino Sketch and it Workstation eine. Now I migrated the Routine to Micropython but I get only zero as the result. Please Help.

0 Vote Up Vote Down
Sara Santos Staff answered 6 years ago

Hi Muenny.

I’ve never used that sensor. But after searching for a while I see that it is an analog sensor.

So, to get the sensor value you need to read an analog pin.

What pin are you using and what method in MicroPython are you using to read the sensor?

Regards,

Sara

0 Vote Up Vote Down
Muenny answered 6 years ago

Hi Sara,
this is the code I use to read the sensor:
#DUst Sensor Sharp GP2Y1010AU0F
######################
# 1 blau LED R 150 Ohm
# 2 gr眉n LED Ground
# 3 wei脽 LED Pin 16
# 4 gelb Ground
# 5 schwarz V0  measure Pin 32
# 6 rot Vcc 3,3V
######################
from machine import Pin, ADC
from utime import sleep, sleep_us
measurePIN = ADC(Pin(32))
#measurePIN = Pin(32)
measurePIN.atten(ADC.ATTN_11DB) #range 0-4095 -> 3,3 V
LedPower = Pin(16)
samplingTime = 280 #original 280
deltaTime = 40
sleepTime = 9680
voMeasured = 0
calcVoltage = 0
dustDensity = 0
print(‘***************** START *************************’)
while True:
LedPower.off
sleep_us(samplingTime)
voMeasured = measurePIN.read() # read Dust Value
sleep_us(deltaTime)
LedPower.on
sleep_us(sleepTime)

print(‘***************** 1111111 *************************’)

#0 – 3,3 V mapped to 0 – 4095
calcVoltage = voMeasured * (3.3 / 4096)
dustDensity = 0.17 * calcVoltage – 0.01

print(“Raw Signal Value (0-4095): {0:3.2f}”.format(voMeasured))
print(” – Voltage: {0:3.2f}”.format(calcVoltage))
print(” – Dust Density: {0:3.2f}”.format(dustDensity))

sleep(1)

print(‘***************** ENDE *************************’)

0 Vote Up Vote Down
Sara Santos Staff answered 6 years ago

Hi.
I’ve tested your code with a potentiometer to mimic an analog sensor and it is working fine.
Where do you get zeros? For the raw input voltage? Or for the dust value?

0 Vote Up Vote Down
Muenny answered 6 years ago

Hi Sara,
measurePIN has always a value of zero.
I have the code also in A>rduino Sketch and that works fine.
Do you have any idea?

0 Vote Up Vote Down
Sara Santos Staff answered 6 years ago

That’s a very weird behavior. If it works well with Arduino IDE, it should also work with MicroPython because your code works well and that pin works well too.
I have no idea why that is happening…
Did you try using another pin? Do you get the same behavior?
 

0 Vote Up Vote Down
Muenny answered 6 years ago

Could it be that the behaviour regarding the timing is different between Micropython and Sketch (spleep() / delay())? 

0 Vote Up Vote Down
Sara Santos Staff answered 6 years ago

I don’t think it is related with that…
I’m out of ideas on what may be causing your issue :/

0 Vote Up Vote Down
Muenny answered 6 years ago

I found now the reason. It was a stupid syntax error (I forgot Pin.OUT for the LEDPin).
Sorry to have you contacted for that and thank you for your help and advice.
Norbert

0 Vote Up Vote Down
Sara Santos Staff answered 6 years ago

Don’t worry.
I’m glad you’ve found the error.
I’ll mark this question as resolved. If you need further help, you just need to create a new question in our forum.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.