Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 1 of 1

Thread: Decoding a signal meant for an RGB addressable LED (with oscilloscope images)

  1. #1
    Junior Member
    Join Date
    Dec 2019

    Decoding a signal meant for an RGB addressable LED (with oscilloscope images)

    Hi everybody. To start off I want to say that I am not an expert in hardware. I am studying to get a computer science degree but I am trying to get into the hardware side of things too. So I apologize if I use incorrect terminology.

    Here's a deal: I'm trying to decode a signal meant for an RGB led. Or at least I just need to decode the first couple bits. Enough to uniquely identify out of like 10 preset colors. The signal is a 48 bit sequence of either short or long square waves (I think serial is like this?). In the image for example, starts with LOW HIGH LOW LOW. I don't think it is WS2812 but maybe similar. Frequency of the square waves looks to be 800kHz. It is a 5.1 volt signal. The entire 48 bit square wave signal lasts about 60us and then 20ms of nothing in between the square waves. I just got my first oscilloscope to help me in this project and I have included some images of the signal in the oscilloscope here:
    Image 1: First few bits in the signal
    Image 2: Zoomed out, spacing between the signals
    Image 3: All bits in one view

    I own both Teensy3.2 and Teensy4.0. I think that the 96MHz of the Teensy3.2 should be enough. The only reason I'm not trying the much faster Teensy4.0 is because the pins are not 5V tolerant and I read that using a level shifter like the one made by Sparkfun may add too much latency.

    The Teensy also needs to be powered from a small battery and be able to run for a couple hours so I picked a 250mAh Li-Po battery attached to the Vin pin. I can manually take it out and plug it into a charger when I want to charge it so that's no issue.

    Anyway, I'm struggling a little bit with the code. I know that sometimes for high-speed data, it's best to use assembly but I'm not sure if that's the issue here or my technique is just bad. I do know some super basic MASM assembly, so I would be ok to try if I need to.

    I know this is pretty bad but I didn't know if loops would slow down my code so I did it like this. I also don't really know how to align my reads with the squares. I was trying to just insert NOPs. It seems to kind-of work in distinguishing between 2 colors, but not well at all.

    int signalpin = 3;
    int res1, res2, res3, res4, res5, res6, res7, res8, res9;
    void setup() {
      // put your setup code here, to run once:
      pinMode(signalpin, INPUT);
    void loop() {
      // put your main code here, to run repeatedly:
      while(pulseIn(signalpin, HIGH, 7) != 0){} // Wait until there is no square wave (a couple nanoseconds of constant LOW means there is no square wave)
        while(digitalReadFast(signalpin) == LOW){} // Wait until new square wave started
         //__asm( "nop" );
        res1 = digitalReadFast(signalpin);
        res2 = digitalReadFast(signalpin);
        res3 = digitalReadFast(signalpin);
        res4 = digitalReadFast(signalpin);
        res5 = digitalReadFast(signalpin);
        res6 = digitalReadFast(signalpin);
        res7 = digitalReadFast(signalpin);
        res8 = digitalReadFast(signalpin);
        res9 = digitalReadFast(signalpin);
    I found some code online where someone used a PIC18 on 64MHz with a few lines of inline assembly to decode the first byte of a 800kHz LED signal here, but I don't really understand the symbols like _test,f,c.
    Last edited by fruitman; 10-09-2021 at 02:43 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts