Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Writing eeprom flash memory of node mcu

Status
Not open for further replies.

tapu

Full Member level 5
Full Member level 5
Joined
Sep 15, 2014
Messages
244
Helped
1
Reputation
2
Reaction score
2
Trophy points
1,298
Location
india
Activity points
3,145
Dear All,
I have designed multi event alarm clock by node mcu.i store alarm schedule on eeprom of node mcu.here now I want to add or edit alarm times by using mobile app.where I will set all alarms and post to node mcu.But how to make app and edit code for eeprom to take data from mobile.please give me hints.
Thanks,
Tepu
 

Hi,

nodeMcu is an IOT platform using (afaik) ESPxxxx microcontrollers.

Are you referring to a special hardware? If so it has an exact name/version ID. Look for this exact ID to find the according datasheet.

If I´m not mistaken most of the nodeMcu modules use an Espressiv ESP8266 microcontroller. It also comes with a datasheet.
Read the datsheets.
And - again: if I´m not mistaken - ESP8266 do not include true EEPROM. It might be emulated with the included FLASH.
(I think I´ve seen libraries for this)

I personally don´t like the "FLASH emulation". I´d simply add an external SPI or I2C EEPROM.

****
Indeed your informations are very vague. One does not know what hardware, what language, what IDE, what libraries you use / are talking about.
It´s very hard to give useful informations this way.

Klaus
 

Yes, I am using esp8266 node mcu.actually I am using flash memory to store alarms.
 

Use the filesystem :


OR

Google "node mcu save variables eeprom"

So create a server or client, many projects on web for either.

CPU in ESP8266 is

ESP8266EX integrates Tensilica L106 32-bit micro controller (MCU) and ultra-low-power 16-bit RSIC.


Regards, Dana.
 

It is safe to use the EEPROM emulation in flash memory as the limited number of write cycles is observed. If it is just for storing alarm times there shouldn't be any problem.

Develop a web interface to gather the alarm information from a normal HTML page so you can use any browser without having to write an app. Not that difficult, especially if you can use a WiFi router to extend the range over the internet instead of just connecting locally.

Brian.
 

    tapu

    Points: 2
    Helpful Answer Positive Rating
Thank you for Replies.here is a actual circuit of my project.first thing i have to make simple html page to send data that i make and try to succeed.second thing i am using node mcu first time then is my circuit is correct in all respect or i have to change something ? As it seems run on display according to my goal of making multi event alarm clock.But sometimes error occure after sometime.Below is my circuit please guide.

Thanks
Tepu

node.png
 
Last edited by a moderator:

The relay driver is wired incorrectly. I suggest putting the relay in the transistors collector instead of emitter and using the opto-coupler to provide bias current to the base pin. A the moment the transistor can never switch on.

Make sure you have the internal pull-up sources enabled on in the NodeMCU or else S1,S2,S3 and S5 will be unreliable at best and may not work at all. Better to add external resistors of say 10K to pull the inputs high until the switches are pressed.

Brian.
 

Hi betwixt, yes I have enabled internal pullups for switches.can you provide me any reference relay driver circuit with optocoupler? I have googled relay circuit and somewhere I found this circuit.
 

1718044656813.png


Missing is a 10K R to ground at transistor base, to insure relay stays off when system
powered up until it can take control of the circuit.

R2 = (Voh - Vbe) / (Irelay/10) to insure transistor saturates when relay turned on.
Voh is high level out of MCU or whatever source signal you have when its is loaded
with Ibase, or an approximation. Diode across relay can be one of the 1N4000 series
typically, say a 1N4004.....

Depending on Relay current you may not have to use a darlington as shown. They have
a higher Vsat, more power consumed by device. eg. Pdiss = Vcesat x Irelay

Note the PC817 may not have enough available Icollector to supply the Ibase of a
non darlington transistor to get it to sat. Either pick a better part or use a MOSFET
in lieu of the bipolar transistor. MOSFET would have to be a logic level MOSFET type.

What is the required relay current worst case I and V for turn on ? What is its max allowed
coil current ?


Regards, Dana.
 
Last edited:

    tapu

    Points: 2
    Helpful Answer Positive Rating
I´ve seen such circuits many time from tinkerers. They multiply like a disease. I guess AI spreads them, too.
I never understand why one uses this optocoupler.

I´d simply omit R1 and the optocoupler .... and drive directly Arduino --> R2

Klaus
 

If isolation is one of the goals then use OptoCoupler.

It does have the additional attribute if diode fails on clamping
relay transient might keep from hosing the MCU side. Usually
couplers have KV levels of isolation.


Regards, Dana.
 
Last edited:

Hi,

According the schematic the input side refers to the same GND as the output side --> Then there is no isolation at all at the optocoupler.
If isolation is the goal ... then this is the feature a relay already offers.

If diode fails ... then it also needs the transitor to fail ... but to fail in the unique way that CE becomes isolated while CB becomes shorted. Never heared of this before.
Then still the current is limited by the coil (inductance) ... and the pulse energy is limited by the energy stored in the coil ... and a lot of the energy is absorbed by the resistor ....
And all this exactly needs to happen for one single event ... because a next time will not happen .. because the BJT is broken ...
If one expects this all to happen ... then one should play the lottery, it is much more likely to win the main prize.

After all this happened "as pulse", there is this continous current: 5V through relay - through CB - through the resistor - through the microcontroller port. It´s less than 5mA in this case. I call it not hurtful, unless one considers the resistor as "short" broken at the same time .. then still the relay limits the current, unless the coil is also broken short circuited.

Really ... this scenario is very, very, very unlikely to happen.
But there is a likelyhood, and if one considers it as real ... one also has to consider the fails of assembling and the fail of the additional parts themselves as real.
Costwise: One has to spent a lot of money for the optocoupler, the resistor, assembling, the repair of the opto-coupler-fails and the assembling fails.

No way that the optocoupler pays out over the whole production lot.

****

There are isolation devices ... like optocouplers.
There are protection devices ... diodes, zeners, MOVs. They usually are cheaper than an optocoupler.

And if a diode fails ... in most cases it fails "short circuit".
And if a bjt fails due to overvoltage .. it fails as "short circuit in CE"

****

My personal experience: I never had a diode fail open in my devices ... but I had optocoupler fails. A whole bunch failed to drop CTR down to less than 30% of initial CTR over a couple of years (not specified in the datasheet). I had to replace ALL optocouplers an ALL produced PCBs. That was a lot of money! Not even considering the production fails at the customer side (silicon production plant).
And the optocouplers were operated well within the limits. Major brand genuine parts, no fake.

****

I would be happy to hear how often a relay diode failed in a properly designed circuit ... where the use of an additional optocoupler saved money .. in average over the whole prodction batches.

Klaus
 

The OP Schematic seems to imply isolation. My example, lifted from net, the schematic does not show isolation, my error.
So just use the schematic of the coupler example in post #9 as if the grounds are isolated.

As a field engineer in Boston region for quite a few years we had to handle failure analysis cases, gathering info for submission.
Categorically all possible open short failures of anything from diodes to 3 terminal devices were handled. We saw them all.
If I can find it we had a reliability handbook with SEM and other photographs of all these cases, quite illuminating. Bond wires blown,
melted silicon, gate OX ruptures......and very subtle stuff like characteristics degradation, regional limited die failures to complete
silicon meltdown.

And if a diode fails ... in most cases it fails "short circuit".
And if a bjt fails due to overvoltage .. it fails as "short circuit in CE"

Huh, love to see your supporting statistics on this.....but would not question your career saw this subset and is a legit
observation for your experience and design activity....

Failure in a CMOS output not infrequently punch thru gate OX related from excess V, not current. And we saw current
related failures as well, eg latchup related problems....

I would be happy to hear how often a relay diode failed in a properly designed circuit
Consult the experts, the rel departments of your fav vendors. I am not a rel expert of all possible applications/failures,
just a prior EE in submission path for 100's of customers in Boston region, discretes thru NMOS and CMOS and PMOS
devices. Applications from micropower thru Plasma Cutters and welders (lots of diode, as well as IGBT, MOSFET
failures). And I am sure thats a subset of other peoples experiences. I cant speak for all on the planet. I was fortunate
enough, when working inside NSC, to have aperiodic lunches with my boss and Gus Mellick, NSC GURU on all things
discrete. Learned a lot about how little I knew, then, and still consider my expertise as a 1%'er.

Costwise: One has to spent a lot of money for the optocoupler, the resistor, assembling, the repair of the opto-coupler-fails and the assembling fails.

Excellent observation, I did not know protection circuits cost $$.


Knight
 

Hi,

I tried to focus on the given circuit.
I tried to keep my post "non personal".

Still you get triggerd .. and talk (excuse me) a lot of non related s**t.

Klaus
 

Thank you for replies,here I used relay to switch ac load like electrical school bell.in my experience if I didn't use optocoupler then at the time of ringing of alarm bell then sometimes controller stops or hang.if I use solid state relay then it works without any error . But solid state relay is too costly then magnetic relay.and when anyone ring electrical bell manually then ssr will damage.
 

Yes, I remember the discussion.

My opinion is that the optocoupler in your case may have cured the symptom, maybe by accident, maybe by just modifying the current path, the noise pickup path, or just slowing down the edges ... Maybe just modifying the PCB - even wihtout optocoupler - had also removed the problem. I don´t know.
And I belive that the use of the optocoupler in your case improved the behaviour (the question still is: why)
I´m sure a proplerly designed circuit will work using an SSR, as standard relay, a triac .... without the need (regarding the observed fail) of an optocoupler

A properly designed circuit avoids/reduces the root cause ... and thus does not need to cure symptoms.
I don´t know if you ever have tested one of your circuits according EMI/EMC. I´ve seen many designs, where they did some "strange" modifications just to make it work - but since the root cause still was there .. they failed EMI/EMC compliance.

I don´t say optocouplers are a bad thing at all - but I had my bad experience with them ... and I had good experience without them.
(For sure I also had good experience with optocouplers as isolation devices).

***

I just can recommend:
* do a proper design
* use isolating devices for isolation purpose
* use protection devices for protection purpose
I can recommend it because I do it this way .. and it worked 100%. It´s physics, it´s maths ... not hearsay, not "I think", not "I believe".

And since I have good experience this way .. why should I recommend something different.
I just try to help...

Klaus
 

Thank you for replies,here I used relay to switch ac load like electrical school bell.in my experience if I didn't use optocoupler then at the time of ringing of alarm bell then sometimes controller stops or hang.if I use solid state relay then it works without any error . But solid state relay is too costly then magnetic relay.and when anyone ring electrical bell manually then ssr will damage.

Isolation often excellent solution to noise and transient problems.

If you have a DSO scope you can use infinite persistence as a way of hunting down
the culprits. Look at your power rails and grounding with this mode. Scope set to AC,
~ 200 mV / box. Another test use single shot trigger set at V's that exceed either rail
by ~ 1V, on MCU to see errant events. Can be an eye opener I have found. Many times
we think our power rails pristine and they are not. Use good quality caps, for equal C
not all vendors have same ESR performance. And by technology :

1718131926263.png


Note OSCON is polymer based C's.

SSRs you can get both non and isolated.

A lot of useful links here (at bottom) :


Dont be concerned about being "triggered" if you use them. Designer is best decision
maker of his application generally speaking. And it seems well ongoing design utility
in our profession based on https://www.mordorintelligence.com/industry-reports/optocouplers-market


Regards, Dana.
 
Last edited:

@tapu, One last thought on relay, why maybe as you stated :

Thank you for replies,here I used relay to switch ac load like electrical school bell.in my experience if I didn't use optocoupler then at the time of ringing of alarm bell then sometimes controller stops or hang.if I use solid state relay then it works without any error . But solid state relay is too costly then magnetic relay.and when anyone ring electrical bell manually then ssr will damage.

1718188127986.png


R1 in this sim is CPU output approximation to its drive R + external to limit current while
also providing enough to sat the transistor. Note I used a darlington in sim, so current
needed << than classic Ic/10 for a non darlington to saturate it. Note most relay datasheets
do not give L values of their coils, you can always do a bench test for the one you choose.
Note the HV developed w/o protection diode, or failure of the diode depending on failure
mode. Note transient spike applied to cpu pin. I used I think 100 nSec as sim timing step,
maybe if I went to 10 nSec or even 1 that would be much worse. So you can play with sim
to better predict possible problems in the future, if needed.

The diode turn on time controls, rather limits, the V developed. So use a decent diode for
that problem. A slow diode permits more of that KV transient to occur.

Last comment, as betwixt stated using flash as emulated EEPROM great way to get EEPROM
functionality w/o using external part. There are ratings for this, R/W cycle count limits, but
in your case you have fixed alarm constants. If you need more R/W behaviour then R/W
cycles are in effect. However even those can be enhanced using a wear leveling algorithm.
This approach used widely in embedded work.

Note I got the value for L in relay from chatGPT for a 5A typical relay, I used its low answer
for the L. I guess some relays in the 5A range exceed 1H, kind of an eye opener. But one
still has to double check chatGPT, its still learning :)


Regards, Dana.
 
Last edited:

thank you for replies.the optocoupler circuit of Dana is running well.but now I observed time is 8 minute back in 7 hours.this is huge time difference and inaccuracy.is this due to faulty crystel or coding error that delays the time in program? I couldn't understand please guide.my code is below.
 

Attachments

  • node mcu timer latest.txt
    26.2 KB · Views: 62

I'm not familiar wit the uRTC functions but in general, the coding is FAR too long.
I would suggest you convert all the times to a standard format, preferably as Unix 4-byte format and write a simple routine to write and read EEPROM in 4 byte blocks. That will allow you to eliminate probably 75% of your code. This is code I use:
Code:
/************************************************************/
// save a floating point value to EEPROM
void EE_SaveFloat(int BaseAddress, int EEoffset, float FloatValue)
{
  union EE_float
  {
    float FloatVal;
    byte EEBytes[4];
  };

  EE_float FloatBytes;
  
  FloatBytes.FloatVal = FloatValue;

  EEaddress = BaseAddress + (EEoffset * 4);  // to save calculating address offsets in main code
 
  ee.writeByte(EEaddress,FloatBytes.EEBytes[3]);
  ee.writeByte(EEaddress+1,FloatBytes.EEBytes[2]);
  ee.writeByte(EEaddress+2,FloatBytes.EEBytes[1]);
  ee.writeByte(EEaddress+3,FloatBytes.EEBytes[0]);
  delay(6);
}

/************************************************************/
// retrieve a floating point number from EEPROM
float EE_GetFloat(int BaseAddress, int EEoffset)
{
  union EE_float
  {
    float FloatVal;
    byte EEBytes[4];
  };

  EE_float FloatBytes;  

  EEaddress = BaseAddress + (EEoffset * 4);  // to save calculating address offsets in main code

  FloatBytes.EEBytes[3] = ee.readByte(EEaddress);
  FloatBytes.EEBytes[2] = ee.readByte(EEaddress+1);
  FloatBytes.EEBytes[1] = ee.readByte(EEaddress+2);
  FloatBytes.EEBytes[0] = ee.readByte(EEaddress+3);

  return FloatBytes.FloatVal;
}
I use it for storing floating point numbers but it will work with any 4-byte value including Unix time. Use the principle, not the exact code because it will need some modification to use ESP32 internal memory. The 'BaseAddress' is like the number of a table (for example it could be the day) and 'EEoffset' is how far into that table you read or write (for example it could be the hour in that day).

You will also find the math much easier if you standardize the time format, for example you can use "if(present time == alarm time)" instead of lots of individual digit checks.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top