Go Down

Topic: Bitbanging replace characters in function (Read 862 times) previous topic - next topic

mixxx2005

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

Code: [Select]


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();


Thanks in advance.

Robin2

Post a link to the datasheet for the PL9823. You seem to have a chosen very strange way to get things to happen. There must be a simpler way.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

mixxx2005

There is not much of a info.
http://www.led-genial.de/mediafiles//Sonstiges/PL9823.pdf

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.

Robin2

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.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

mixxx2005

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.

guix

Hello,

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?

Robin2

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.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

guix

Another section on this forum is acceptable, meanwhile those users should add [ESP8266] in the title of their topics, as to not waste anyone's time.. ;)

mixxx2005

My question is purely about arduino C programming. So what is the point of arguing about hardware?


Robin2

My question is purely about arduino C programming. So what is the point of arguing about hardware?
It is almost impossible to contemplate any Arduino programming question without knowing the hardware because they are so intimately linked.

And the ESP8266 is VERY different from an Uno or Mega. You need to capture the attention of people with experience of programming the ESP8266.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up