How to use digital pin 3 and 6 of wemos D1 R1
As it is giving this error when using it-
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 3584, room 16
tail 0
chksum 0xb0
csum 0xb0
v2843a5ac
~ld
How to use digital pin 3 and 6 of wemos D1 R1
As it is giving this error when using it-
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 3584, room 16
tail 0
chksum 0xb0
csum 0xb0
v2843a5ac
~ld
To give detailed advice would require that you provide us with some information regarding how you are attempting to use those pins. Some example code and a diagram showing how they are connected and to what would have been helpful.
Having said that, some pins of the 8266 are not recommended to be used:
Pins 3 and 6 appear to be among them.
Which pins.
GPIO 3 is the TX pin and GPIO 6 is not exposed (used for communication with flash)
or do you mean do start counting from somewhere ?
Or is it D3 & D6 ? D3 is GPIO 0 and if you pull it LOW at boot it will go into the wrong boot mode.
D6 is GPIO 12.
But the error code refers to a wdt reset, what code are you using ?
Actually, i was making tachometer using wemos d1 r1.
So I was not getting any formula for calculating RPM
So i used this arduino uno's code which uses digital pin 3 where to connect the ir sensor.
void setup() {
// put your setup code here, to run once:
float REV = 0;
int RPM_VALUE;
int PREVIOUS = 0;
int TIME;
void INTERRUPT()
{
REV++;
}
void setup()
{
Serial.begin(9600);
attachInterrupt(1, INTERRUPT, RISING);
}
}
void loop() {
delay(1000);
detachInterrupt(0);
TIME = millis() - PREVIOUS;
RPM_VALUE = (REV / TIME) * 60000;
PREVIOUS = millis();
REV = 0;
Serial.println(RPM_VALUE);
attachInterrupt(1, INTERRUPT, RISING);
delay(1000);
}
Actually i am not getting where to change pin from 3 to any else.
Have a look at this explanation of the interrupts, and not in particular that you do not just name the pin nr, but use
digitalPinToInterrupt(pin)
to find the inetrrupt for the pin.
Again you should use the GPIO nrs, or the Dx marking. (eg D1 , D2 etc)
About that code it is not ideal, but it should probably work.
can you please modify my code with this line as if i am using this in the setup the same error is comming.
// put your setup code here, to run once:
float REV = 0;
int RPM_VALUE;
int PREVIOUS = 0;
int TIME;
void INTERRUPT()
{
REV++;
}
void setup()
{
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(4), INTERRUPT, RISING);
}
void loop() {
delay(1000);
detachInterrupt(0);
TIME = millis() - PREVIOUS;
RPM_VALUE = (REV / TIME) * 60000;
PREVIOUS = millis();
REV = 0;
Serial.println(RPM_VALUE);
attachInterrupt(digitalPinToInterrupt(4), INTERRUPT, RISING);
delay(1000);
}
my new code
For starters, this should only be in setup() --
attachInterrupt(digitalPinToInterrupt(4), INTERRUPT, RISING);
You have placed it in setup() and loop().
the problem is stll there
Why detachInterrupt()?
Why is there delay(1000); at the beginning and end of loop() ?
Variables associated with millis()-stuff should be unsigned long.
Is this a jumble of cut, paste and hope for the best ?
He wants to disable the interrupt while he is updating the values.
Of course noInterrupts() is probably the way to go.
Anyway there are some more issues with the code.
First of all, all ISR's on an ESP8266 need to be placed in RAM and you can do tha by adding the
ICACHE_RAM_ATTR
macro to the declaration.
Secondly, and probably most importantly, any value that gets updated within an ISR and read outside an ISR and vice versa, should be declared 'volatile' or the ISR or the main loop may read the variable from a register, while there is already a different value in the memory address. Declaring it 'volatile' ensures that the value is always loaded from it address in memory.
thirdly, and now i am getting to some other minor things, i think 'REV' should not be a float, but an integer (16 or 32 bit) , it's a counter. If you want to do the calculation in floating point, you can still do this outside the ISR.
And what that pancake said, don't re-attach an interrupt.
In fact there is no need to turn the interrupt off, since the esp is a 32-bit MCU, so we can just read a 32-bit value in one go.
Then there is the whole millis() thing which i admit, shows that you don't really know what you're doing, but... the code should sort of work or at least give you some result, and i am not going to improve upon it for you. It is a kind of test sketch anyway isn't it ?
// put your setup code here, to run once:
volatile uint32_t REV = 0;
uint32_t RPM_VALUE;
uint32_t PREVIOUS = 0;
uint32_t TIME;
ICACHE_RAM_ATTR void INTERRUPT() // or use IRAM_ATTR from core 3.x onwards
{
REV++;
}
void setup()
{
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(4), INTERRUPT, RISING);
}
void loop() {
delay(1000);
TIME = millis() - PREVIOUS;
RPM_VALUE = REV * 60000 / TIME; // if you do the multiplication first you don't need fractions
REV = 0;
PREVIOUS = millis();
Serial.println(RPM_VALUE);
delay(1000);
}
This code is perfectly working on Arduino UNO
your code ? well without the 'volatile' declaration for 'REV' it is coincidence that it does. Ah hold on an Atmega 328P deosn't have 32-bit registers, so the variable is always loaded from memory.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.