Hello !
I am experimenting with ESP-8266 and programmable LED's PL9823(equal to WS2812).
So PL9823 needs 800kHz signal to latch it, so I found out that delays in code, takes too much time, so I manage to get correct timing (or close to it) by just writing
" digitalWrite(13, HIGH);digitalWrite(13, HIGH); digitalWrite(13, LOW); " for HIGH
" digitalWrite(13, HIGH); digitalWrite(13, LOW);digitalWrite(13, LOW); digitalWrite(13, LOW); " for LOW
void setup() {
pinMode(13, OUTPUT);
delay(2000); }
void loop() {
for (int b=0; b < 10; b++){ flash(); }
delay(5000); }
void flash(){
h();h();h();h();h();h();h();h(); //1st LED white
h();h();h();h();h();h();h();h();
h();h();h();h();h();h();h();h();
l();l();l();l();l();l();l();l(); //2nd LED off
l();l();l();l();l();l();l();l();
l();l();l();l();l();l();l();l();
h();h();h();h();h();h();h();h(); //3rd LED white
h();h();h();h();h();h();h();h();
h();h();h();h();h();h();h();h();
delay(40);
l();l();l();l();l();l();l();l(); //1st LED off
l();l();l();l();l();l();l();l();
l();l();l();l();l();l();l();l();
h();h();h();h();h();h();h();h(); //2nd LED white
h();h();h();h();h();h();h();h();
h();h();h();h();h();h();h();h();
l();l();l();l();l();l();l();l(); //3rd LED off
l();l();l();l();l();l();l();l();
l();l();l();l();l();l();l();l();
delay(80);
}
void h() {
digitalWrite(13, HIGH);digitalWrite(13, HIGH); digitalWrite(13, LOW);
}
void l() {
digitalWrite(13, HIGH); digitalWrite(13, LOW);digitalWrite(13, LOW); digitalWrite(13, LOW);
}
With this I manage to fully control individually 3 LEDs. My question is how I can make edit void flash() to for example to change
l();l();l();l();l();l();l();l(); //LED off
l();l();l();l();l();l();l();l();
l();l();l();l();l();l();l();l();
to
l();l();l();l();l();l();l();l(); //LED Green
h();h();h();h();h();h();h();h();
l();l();l();l();l();l();l();l();
But from my experiments with oscilloscope to get:
HIGH signal (digitalWrite(13, HIGH);digitalWrite(13, HIGH); digitalWrite(13, LOW))
It takes total of 1,18us (0,88us HIGH, 0,3us LOW)
LOW signal (digitalWrite(13, HIGH); digitalWrite(13, LOW);digitalWrite(13, LOW); digitalWrite(13, LOW))
It takes total of 1,55us (0,44 HIGH, 1,11 LOW)
And it somehow works without flaws.
If write bits like this
digitalWrite(13, HIGH); digitalWrite(13, LOW);digitalWrite(13, LOW); digitalWrite(13, LOW)
in main loop there is some sort of memory problems , i guess, because I cannot get any consistent results with LEDs.
I think easier way will be to pair ESP with arduino and use C+ or libraries. But I do this for education proposes not in a name of a result.
Doing things that have to happen at intervals of less than 2 µsecs is going to be difficult with a 16MHz Arduino.
Are you planning to run your program directly on an ESP8266 or on an Arduino connected to an ESP8266 ?
I have not yet tried programming an ESP8266.
For those data rates on a 16MHz Arduino you would need direct port manipulation rather than use digitalWrite(). Even then it may not be possible to operate at the required rate.
I ran it directly on ESP, programmed by arduino IDE. Like I said before 800kHz on arduino is possible with library , but on 80Mhz ESP I managed to get out 1600 kHz with only digitalWrite.
This is the Arduino forum, you use a different hardware and ask questions about it. Not only you but many ESP8266 users come here and do the same, this shouldn't be allowed. There is a website/forum for the ESP8266 so why don't you go there instead?
guix:
There is a website/forum for the ESP8266 so why don't you go there instead?
I suspect the answer to that is that it is possible to program an ESP8266 with the Arduino IDE.
Personally I am happy to see the Arduino IDE used as widely as possible.
I did suggest, in the Website and Forum section, that a new section should be created for ESP8266 projects (just as there is for the Yun and the Zero, for example). That way the expertise could accumulate in one place.