Page 5 of 6

Re: How to switch on a electric bulb with ESP8266 board?

Posted: Tue Jun 18, 2019 11:17 am
by RajaRamesh
pythoncoder wrote:
Tue Jun 18, 2019 9:49 am
The Wiki http://wiki.micropython.org/Home has links to drivers for a variety of devices. You can also search this forum.
Thank you python coder. i will check and get back to you if i have any question.

Re: How to switch on a electric bulb with ESP8266 board?

Posted: Sat Jun 22, 2019 7:42 pm
by RajaRamesh
Hi , i am trying to blink inbuilt led only once if the level value is less than 10. with below code i am able to blink once.but when the level value increases more than 10 and reduces less then 10 led is not blinking. can someone help me how to achieve this ?

Note:- if i include i=0 inside while loop, i value in if condition treating as zero and it is not increasing.

Code: Select all

from machine import Pin,ADC
import time
adc=ADC(0)
pin=Pin(14,Pin.OUT)
i=0
while True:
    level=adc.read()
    print(level)
    if level<10 and i==0:
       print('blink')
       pin.on()
       time.sleep(5)
       pin.off()
       i=i+1
    time.sleep(1)
output :
----------
32
30
10
9
blink
7
6
40
33
23
11
9
8
4
5
32

Re: How to switch on a electric bulb with ESP8266 board?

Posted: Sat Jun 22, 2019 7:58 pm
by Roberthh
You must reset i=0 if level raises again to 10 and more.e.g.

Code: Select all

from machine import Pin,ADC
import time
adc=ADC(0)
pin=Pin(14,Pin.OUT)
i=0
while True:
    level=adc.read()
    print(level)
    if level<10 and i==0:
       print('blink')
       pin.on()
       time.sleep(5)
       pin.off()
       i=i+1
    if level >= 10:
       i = 0
    time.sleep(1)

Re: How to switch on a electric bulb with ESP8266 board?

Posted: Sun Jun 23, 2019 6:48 am
by RajaRamesh
Roberthh wrote:
Sat Jun 22, 2019 7:58 pm
You must reset i=0 if level raises again to 10 and more.e.g.

Code: Select all

    if level >= 10:
       i = 0
    time.sleep(1)
Thank you Robert. Now logic is working fine.

Re: How to switch on a electric bulb with ESP8266 board?

Posted: Sun Jun 23, 2019 7:50 am
by RajaRamesh
Roberthh wrote:
Sat Jun 22, 2019 7:58 pm
You must reset i=0 if level raises again to 10 and more.e.g.
Hi Robert, i have a doubt. Logic is working when level<10 and power is on. But what if power off and power is back in midnight. how to handle logic not work in midnight for few censorious?

Re: How to switch on a electric bulb with ESP8266 board?

Posted: Mon Jun 24, 2019 10:10 am
by RajaRamesh
RajaRamesh wrote:
Sun Jun 23, 2019 7:50 am
Roberthh wrote:
Sat Jun 22, 2019 7:58 pm
You must reset i=0 if level raises again to 10 and more.e.g.
Hi Robert, i have a doubt. Logic is working when level<10 and power is on. But what if power off and power is back in midnight. how to handle logic not work in midnight for few censorious?
typo mistake. now i have changed scenarios from censorious

Hi Robert, i have a doubt. Logic is working when level<10 and power is on. But what if power off and power is back in midnight. how to handle logic not to work in midnight for few scenarios ?

Re: How to switch on a electric bulb with ESP8266 board?

Posted: Mon Jun 24, 2019 10:18 am
by Roberthh
You can control that by the initial value of i 0 or 1. If you want the behaviour to change in certain times, you need to know the real time. But you were at that question before.

Re: How to switch on a electric bulb with ESP8266 board?

Posted: Mon Jun 24, 2019 10:38 am
by RajaRamesh
Roberthh wrote:
Mon Jun 24, 2019 10:18 am
You can control that by the initial value of i 0 or 1. If you want the behaviour to change in certain times, you need to know the real time. But you were at that question before.
Hi Robert, yes, i am aware of real time which we need to synchronize with ntptime and for this we need internet. But, i am trying to make the code to work without ntptime. so i thought that there will be a way to handle esp8266 when power is on and off. i see you stated initial value of i 0 or 1. do i need to declare this values in the code to make esp8266 to work when power is on and off ? just assuming. correct me if i am wrong.

Re: How to switch on a electric bulb with ESP8266 board?

Posted: Tue Jun 25, 2019 7:37 am
by RajaRamesh
RajaRamesh wrote:
Mon Jun 24, 2019 10:38 am
Roberthh wrote:
Mon Jun 24, 2019 10:18 am
You can control that by the initial value of i 0 or 1. If you want the behaviour to change in certain times, you need to know the real time. But you were at that question before.
Hi Robert, yes, i am aware of real time which we need to synchronize with ntptime and for this we need internet. But, i am trying to make the code to work without ntptime. so i thought that there will be a way to handle esp8266 when power is on and off. i see you stated initial value of i 0 or 1. do i need to declare this values in the code to make esp8266 to work when power is on and off ? just assuming. correct me if i am wrong.
Hi Robert, After googling and searching in forum i found " DS3231 RTC module which work with battery cell independently " and operate at certain time in remote areas where internet is not available. Now, i need to figure out how to connect DS3231 with ESP8266 and need to build code to get time. could you please share any useful link or code to work with DS3231 if you have any?

sample DS3231 link :- https://www.amazon.in/Robodo-Electronic ... 285&sr=8-1

Re: How to switch on a electric bulb with ESP8266 board?

Posted: Tue Jun 25, 2019 10:23 am
by Roberthh
You should try the driver made by @pythoncoder https://github.com/peterhinch/micropyth ... ter/DS3231
It was made for PyBoard, ESP8266 and others.