arbitrary block counting problem

Hi...!!!

Respected Sir

I want to generate 10KHz discrete serial signal on one Arduino board and want to send some some data on digital pin. And want to read data this data sent by first Arduino board to another Arduino Board(Pin).
I mean one Arduino will send data and another will read the data on 10KHz.

How can we do it....!!!

Thanks & Regards.... :slight_smile:

When do we have to complete our assignment by?
(and quit the "Sir" crap)

How can we do it

That is typically done by writing code.

AWOL:
When do we have to complete our assignment by?
(and quit the ‚ÄúSir‚ÄĚ crap)

Arrey Sir

Nothing like that , do not take it personally.
I have following codes on generation of 10KHz frequency and receiving data but it is not reading properly.
So I thought you have better solution and suggestion.
If you are taking it as an assignment then please help me Sir.

Code for generation 10KHz frequency:

const int pin2 = 2;
const int pin4 = 4;
//int clock;

int val[50] = {1,1,0,0,1,0,1,0,1,0,1,0,1,1,0,0,0,0,0,1,1,1,1,1};

void setup()
{
  pinMode(pin2, OUTPUT);
  
  pinMode(pin4, OUTPUT);
  
}

void loop() 
{
  for(int i=0; i<=23; i++){   
 
  //delayMicroseconds(20);
  digitalWrite(pin2, HIGH);
  delayMicroseconds(30);
  
   
    if (val[i] == 1)
        digitalWrite(pin4, HIGH);
     
    else
        digitalWrite(pin4, LOW);
  digitalWrite(pin2, LOW);
  //delayMicroseconds(20);
  //digitalWrite(pin4, L);
  //delayMicroseconds(20);
  
  delayMicroseconds(30);
 // delayMicroseconds(20);
 
  } 
}

Code for Receiving data:

const int CLOCK_PIN     =     2;
const int DATA_PIN      =     4;
const int PACKET_BITS   =     128;
const int PREAMBLE_LEN  =    6;
const int DATA_LEN      =    ((PACKET_BITS / 4) - PREAMBLE_LEN);

enum {
    PRE_0,    PRE_1,    PRE_2,    PRE_3,    PRE_4,    PRE_5,    DATA
} states;    

byte     preamble [] = {0x0C,0x0A,0x0A,0x0C,0x01,0x0F};
char     hexAsciiVals[] = "0123456789ABCDEF";
byte     state = PRE_0;
byte     nibble;
int        nibble_count = 0;

void setup() {
  pinMode(CLOCK_PIN, INPUT);
  pinMode(DATA_PIN, INPUT);
  Serial.begin(115200);
}

void loop() {

    nibble = getNibble();
    nibble_count++;
    
//    Serial.print(digitalRead(CLOCK_PIN));
    
    switch (state) {    
        case PRE_0:
            if (nibble_count > 32) {
                // we've read 32 bytes and still not found a match 
                // for the preamble so skip a clock pulse
                while (digitalRead(CLOCK_PIN) == LOW);
                while (digitalRead(CLOCK_PIN) == HIGH);
                nibble_count = 0;
            } else {
                state = (nibble == preamble[0]) ? PRE_0 : PRE_1;
            }
            break;
        
        case PRE_1:
            state = (nibble == preamble[1]) ? PRE_0 : PRE_2;    
            break;
            
        case PRE_2:
            state = (nibble == preamble[2]) ? PRE_0 : PRE_3;
            break;

        case PRE_3:
            state = (nibble == preamble[3]) ? PRE_0 : PRE_4;
            break;

        case PRE_4:
            state = (nibble == preamble[4]) ? PRE_0 : PRE_5;
            break;
        
        case PRE_5:
            state = (nibble == preamble[5]) ? PRE_0 : DATA;
            break;
            
        case DATA:
            Serial.write (hexAsciiVals[nibble]);
            if (nibble_count == DATA_LEN) {
                // all done, start again
                state = PRE_0;
                nibble_count = 0;
                Serial.println();
            }
            break;
    }
}

byte getNibble() {

    byte val = 0;
    
    for (byte bit_count = 0; bit_count < 4; bit_count++) {
        while (digitalRead(CLOCK_PIN) == HIGH);
        
          while (digitalRead(CLOCK_PIN) == LOW);
        
          val <<= 1;
          val |= digitalRead(DATA_PIN);
        
          
    }
    return (val &= 0x0F);
}

Thanks & Regards… :slight_smile:

dhenry:

How can we do it

That is typically done by writing code.

ohhhh....!!! I will try.

Thanks for your kind suggestion.

ranjeetray:

AWOL:
When do we have to complete our assignment by?
(and quit the ‚ÄúSir‚ÄĚ crap)

Arrey Sir

Nothing like that , do not take it personally.
I have following codes on generation of 10KHz frequency and receiving data but it is not reading properly.
So I thought you have better solution and suggestion.
If you are taking it as an assignment then please help me Sir.
Anyway I always add Respected Sir for Nick Gammon Sir, because he also reads my thread, I hope that is OK with you. And in that case you can ignore this thread.

Code for generation 10KHz frequency:

const int pin2 = 2;

const int pin4 = 4;
//int clock;

int val[50] = {1,1,0,0,1,0,1,0,1,0,1,0,1,1,0,0,0,0,0,1,1,1,1,1};

void setup()
{
  pinMode(pin2, OUTPUT);
 
  pinMode(pin4, OUTPUT);
 
}

void loop()
{
  for(int i=0; i<=23; i++){

//delayMicroseconds(20);
  digitalWrite(pin2, HIGH);
  delayMicroseconds(30);
 
   
    if (val[i] == 1)
        digitalWrite(pin4, HIGH);
     
    else
        digitalWrite(pin4, LOW);
  digitalWrite(pin2, LOW);
  //delayMicroseconds(20);
  //digitalWrite(pin4, L);
  //delayMicroseconds(20);
 
  delayMicroseconds(30);
// delayMicroseconds(20);

}
}





Code for Receiving data:


const int CLOCK_PIN     =     2;
const int DATA_PIN      =     4;
const int PACKET_BITS   =     128;
const int PREAMBLE_LEN  =    6;
const int DATA_LEN      =    ((PACKET_BITS / 4) - PREAMBLE_LEN);

enum {
    PRE_0,    PRE_1,    PRE_2,    PRE_3,    PRE_4,    PRE_5,    DATA
} states;

byte     preamble = {0x0C,0x0A,0x0A,0x0C,0x01,0x0F};
char¬† ¬† ¬†hexAsciiVals = ‚Äú0123456789ABCDEF‚ÄĚ;
byte     state = PRE_0;
byte     nibble;
int        nibble_count = 0;

void setup() {
  pinMode(CLOCK_PIN, INPUT);
  pinMode(DATA_PIN, INPUT);
  Serial.begin(115200);
}

void loop() {

nibble = getNibble();
    nibble_count++;
   
//    Serial.print(digitalRead(CLOCK_PIN));
   
    switch (state) {   
        case PRE_0:
            if (nibble_count > 32) {
                // we’ve read 32 bytes and still not found a match
                // for the preamble so skip a clock pulse
                while (digitalRead(CLOCK_PIN) == LOW);
                while (digitalRead(CLOCK_PIN) == HIGH);
                nibble_count = 0;
            } else {
                state = (nibble == preamble[0]) ? PRE_0 : PRE_1;
            }
            break;
       
        case PRE_1:
            state = (nibble == preamble[1]) ? PRE_0 : PRE_2;   
            break;
           
        case PRE_2:
            state = (nibble == preamble[2]) ? PRE_0 : PRE_3;
            break;

case PRE_3:
            state = (nibble == preamble[3]) ? PRE_0 : PRE_4;
            break;

case PRE_4:
            state = (nibble == preamble[4]) ? PRE_0 : PRE_5;
            break;
       
        case PRE_5:
            state = (nibble == preamble[5]) ? PRE_0 : DATA;
            break;
           
        case DATA:
            Serial.write (hexAsciiVals[nibble]);
            if (nibble_count == DATA_LEN) {
                // all done, start again
                state = PRE_0;
                nibble_count = 0;
                Serial.println();
            }
            break;
    }
}

byte getNibble() {

byte val = 0;
   
    for (byte bit_count = 0; bit_count < 4; bit_count++) {
        while (digitalRead(CLOCK_PIN) == HIGH);
       
          while (digitalRead(CLOCK_PIN) == LOW);
       
          val <<= 1;
          val |= digitalRead(DATA_PIN);
       
         
    }
    return (val &= 0x0F);
}




Thanks & Regards.... :-)

If it is clocked, then the rate is immaterial, so slow it right down until it works.
I can't see a "start-of-transmission" type condition, so it may be your two ends are unsynchronised.

Your quoting layout is confusing.

useful tip:

const int clockPin = 2;
const int dataPin = 4;

Your code for generating the 10KHz signal is occupying ALL the time. You don't have any time left to

and want to send some some data on digital pin.

Nor are you actually trying to.

What data do you want to send, and why this convoluted way of doing it when there are far easier ways?

PaulS:
Your code for generating the 10KHz signal is occupying ALL the time. You don't have any time left to

and want to send some some data on digital pin.

Nor are you actually trying to.

What data do you want to send, and why this convoluted way of doing it when there are far easier ways?

why this convoluted way of doing it when there are far easier ways?

Thanks a lot for your kind reply.

How can we do it in easier way, please guide me Sir.

Right now I am able to read this value but it is not proper:

1FCAAC1FCAAC1FCAAC1
F95583F95583F95583F9
AB07F2AB07F2AB07F2AB
0FE5560FE5560FE5560F
1FCAAC1FCAAC1F95
B07F2AB07F2AB07F2AB0
FE5560FE5560FE5560FE
1FCAAC1FCAAC1FCAA
83F95583F95583F95583
B07F2AB07F2AB07F2

I am sending CAAC1F, so I want to read data like this only, I mean a block of data as CAAC1F and after reading each block of CAAC1F I want to have a new line or count so that I can understand how many times this block of data has come.

Thanks & Regards... :slight_smile:

There seems to be some mission creep here.
The problem has gone from ‚ÄúHow to generate 10kHz discrete serial signal on Arduino UNO board‚ÄĚ to some arbitrary block counting problem.
Can you explain clearly and concisely what it is you are trying to do?

Please, cut out the ‚Äúsir‚ÄĚ - this is a forum, you are not addressing an individual and it sounds phoney.

AWOL:
There seems to be some mission creep here.
The problem has gone from "How to generate 10kHz discrete serial signal on Arduino UNO board" to some arbitrary block counting problem.
Can you explain clearly and concisely what it is you are trying to do?

Please, cut out the "sir" - this is a forum, you are not addressing an individual and it sounds phoney.

Hi...!!

I am getting data as follow on serial monitor

7F2AB07F2AB07F2AB07F2AB07F2AB07F2AB07F25C1F2A61F9AB0FC550FEA587E5A83F55C3F2A61F9AB0FC5B0FCA587E5A83F55C3F2561F9AB0FC5B0FCA507EAA87F55C3F2561F9A60F95B0FCA507EAA87F5AC3F2561F9A60F95B0FC550FEAA87F5AC3F25C1F2A61F95B0FC550FEA587E5AC3F25C1F2A61F9AB0F 
 
1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FC5B0FCA507EAA87F55C3F2561F9A60F95B0FCA507EAA87F5AC3F25C1F9A60F95B0FC550FEA587F5AC3F25C1F2A61F9AB0FC550FEA587E5A83F25C1F2A61F9AB0FC5B0FEA587E5A83F55C3F2561F9AB0FC5B0FCA507E5A83F55C3F2561 
 
1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1F95B0FC550FEA587E5AC3F25C1F2A61F9AB0FC550FEA587E5A83F55C1F2A61F9AB0FC5B0FCA587E5A83F55C3F2561F9AB0FC5B0FCA507EAA83F55C3F2561F9A60F95B0FCA507EAA87F5AC3F2561F9A60F95B0FC550FEAA87F5A 
 
1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1F9AB0FC550FEA587E5A83F55C3F2A61F9AB0FC5B0FCA507E5A83F55C3F2561F9A60FC5B0FCA507EAA87F55C3F2561F9A60F95B0FCA507EAA87F5AC3F25C1F9A60F95B0FC550FEAA87F5AC3F25C1F2A61F95B0FC550FEA587E5A83F25C1F2A61F9AB0FC5B0FEA587 
 
5560FE5560FE5560FE5560FE5560FE5560FE5561F9A60FC5B0FCA507EAA87F5AC3F2561F9A60F95B0FC5507EAA87F5AC3F25C1F2A60F95B0FC550FEA587F5AC3F25C1F2A61F9AB0FC550FEA587E5A83F55C1F2A61F9AB0FC5B0FEA587E5A83F55C3F2561F9AB0FC5B0FCA507EAA83F55C3F2561F9A60F95B0FCA 
 
83F95583F95583F95583F95583F95583F95583F25C1F2A61F95B0FC550FEA587E5AC3F25C1F2A61F9AB0FC550FEA587E5A83F55C3F2A61F9AB0FC5B0FCA587E5A83F55C3F2561F9AB0FC5B0FCA507EAA87F55C3F2561F9A60F95B0FCA507EAA87F5AC3F2561F9A60F95B0FC550FEAA87F5AC3F25C1F2A61F9AB0 
 
5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560 
 
B07F2AB07F2AB07F2AB07F2AB07F2AB07F2AB07EAA87F5AC3F2561F9A60F95B0FC5507EAA87F5AC3F25C1F2A60F95B0FC550FEA587E5AC3F25C1F2A61F9AB0FC550FEA587E5A83F55C1F2A61F9AB0FC5B0FCA587E5A83F55C3F2561F9AB0FC5B0FCA507EAA87F55C3F2561F9A60F95B0FCA507EAA87F5AC3F256 
 
AC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1F2A61F9AB0FC5B0FEA587E5A83F55C3F2A61F9AB0FC5B0FCA507E5A83F55C3F2561F9A60FC5B0FCA507EAA87F55C3F2561F9A60F95B0FCA507EAA87F5AC3F25C1F9A60F95B0FC550FEA587F5AC3F25C1F2A61F95B0FC550FEA587E5A 
 
1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1F9AB0FC5B0FCA507EAA83F55C3F2561F9A60F95B0FCA507EAA87F5AC3F2561F9A60F95B0FC5507EAA87F5AC3F25C1F2A60F95B0FC550FEA587E5AC3F25C1F2A61F9AB0FC550FEA587E5A83F55C1F2A61F9AB0FC5B0FCA587E5A83F55C3F2561F9AB0FC5B0FCA507 
 
5560FE5560FE5560FE5560FE5560FE5560FE5561F9A60F95B0FC550FEAA87F5AC3F25C1F2A61F95B0FC550FEA587E5AC3F25C1F2A61F9AB0FC550FEA587E5A83F55C3F2A61F9AB0FC5B0FCA587E5A83F55C3F2561F9AB0FC5B0FCA507EAA87F55C3F2561F9A60F95B0FCA507EAA87F5AC3F25C1F9A60F95B0FC5 
 
83F95583F95583F95583F95583F95583F95583F25C1F2A61F9AB0FC5B0FEA587E5A83F55C3F2561F9AB0FC5B0FCA507E5A83F55C3F2561F9A60FC5B0FCA507EAA87F5AC3F2561F9A60F95B0FC5507EAA87F5AC3F25C1F9A60F95B0FC550FEA587E5AC3F25C1F2A61F9AB0FC550FEA587E5A83F55C1F2A61F9AB0 
 
1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCA507EAA87F5AC3F2561F9A60F95B0FC5507EAA87F5AC3F25C1F2A60F95B0FC550FEA587E5AC3F25C1F2A61F9AB0FC5B0FEA587E5A83F55C3F2A61F9AB0FC5B0FCA507E5A83F55C3F2561F9AB0FC5B0FCA507EAA87F55C3F25 
 
0FE5560FE5560FE5560FE5560FE5560FE5560FC550FEAA87F5AC3F25C1F2A61F95B0FC550FEA587E5A83F25C1F2A61F9AB0FC5B0FEA587E5A83F55C3F2A61F9AB0FC5B0FCA507E5A83F55C3F2561F9A60FC5B0FCA507EAA87F5AC3F2561F9A60F95B0FCA507EAA87F5AC3F25C1F9A60F95B0FC550FEA587F5AC3 
 
B07F2AB07F2AB07F2AB07F2AB07F2AB07F2AB07F2AB07F2AB07E5A83F55C3F2561F9AB0FC5B0FCA507EAA83F55C3F2561F9A60F95B0FCA507EAA87F5AC3F2561F9A60F95B0FC5507EAA87F5AC3F25C1F2A60F95B0FC550FEA587E5AC3F25C1F2A61F9AB0FC550FEA587E5A83F55C3F2A61F9AB0FC5B0FCA587 
 
5560FE5560FE5560FE5560FE5560FE5560FE5561F9A60F95B0FCA507EAA87F5AC3F2561F9A60F95B0FC550FEAA87F5AC3F25C1F2A61F95B0FC550FEA587E5A83F25C1F2A61F9AB0FC550FEA587E5A83F55C3F2A61F9AB0FC5B0FCA507E5A83F55C3F2561F9A60FC5B0FCA507EAA87F5AC3F2561F9A60F95B0FC5 
 
83F95583F95583F95583F95583F95583F95583F25C1F2A61F9AB0FC550FEA587E5A83F25C1F2A61F9AB0FC5B0FEA587E5A83F55C3F2561F9AB0FC5B0FCA507E5A83F55C3F2561F9A60FC5B0FCA507EAA87F5AC3F2561F9A60F95B0FC5507EAA87F5AC3F25C1F2A60F95B0FC550FEA587E5AC3F25C1F2A61F9AB0 
 
5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560 
 
B07F2AB07F2AB07F2AB07F2AB07F2AB07F2AB07EAA87F5AC3F25C1F9A60F95B0FC550FEA587F5AC3F25C1F2A61F95B0FC550FEA587E5A83F25C1F2A61F9AB0FC5B0FEA587E5A83F55C3F2561F9AB0FC5B0FCA507EAA83F55C3F2561F9A60FC5B0FCA507EAA87F5AC3F2561F9A60F95B0FC5507EAA87F5AC3F25C 
 
AC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1F2A61F9AB0FC5B0FCA587E5A83F55C3F2561F9AB0FC5B0FCA507EAA83F55C3F2561F9A60F95B0FCA507EAA87F5AC3F2561F9A60F95B0FC550FEAA87F5AC3F25C1F2A61F95B0FC550FEA587E5AC3F25C1F2A61F9AB0FC550FEA587E5A

But I want to have a new line after each block of CAAC1F data.
Can we do it.
It is my mistake that I could not give proper heading for this thread.

Thanks & Regards.... :slight_smile:

So, you're asking "how do I recognise the preamble?" ?

AWOL:
So, you're asking "how do I recognise the preamble?" ?

Yes.
I mean I want to print this CAAC1F in new line.
I want to recognize CAAC1F as a one block of data .

Thanks & Regards.... :slight_smile:

const int pin2 = 2;
const int pin4 = 4;

Someone’s told you to use meaningful names for your variables, haven’t they?


int val[50] = {1,1,0,0,1,0,1,0,1,0,1,0,1,1,0,0,0,0,0,1,1,1,1,1};

…

  for(int i=0; i<=23; i++){

Why?

How about:

// number of items in an array
#define NUMITEMS(arg) ((unsigned int) (sizeof (arg) / sizeof (arg [0])))

...

int val[] = {1,1,0,0,1,0,1,0,1,0,1,0,1,1,0,0,0,0,0,1,1,1,1,1};

...

 for(int i=0; i < NUMITEMS (val); i++){

And to save memory, since an int takes two bytes, and you only seem to have 0 and 1 in it:

byte val[] = {1,1,0,0,1,0,1,0,1,0,1,0,1,1,0,0,0,0,0,1,1,1,1,1};

...

 for(int i=0; i < sizeof (val); i++){

I have following codes on generation of 10KHz frequency and receiving data but it is not reading properly.

How does the code you posted generate 10 KHz, and how does it receive data?

The receiver code you posted earlier appears to have some sort of preamble detection built into it.
Have you thought of using the detection event to trigger a "Serial.println ();" ?

Hi…!!!

I am trying now like this:

//const int pin2 = 2;
//const int pin4 = 4;
 int CLOCK_PIN     =     2;
 int DATA_PIN      =     4;
//int clock;
int i;
#define NUMITEMS(arg) ((unsigned int) (sizeof (arg) / sizeof (arg [0])))

byte val[24] = {1,1,0,0,1,0,1,0,1,0,1,0,1,1,0,0,0,0,0,1,1,1,1,1};


void setup()
{
  pinMode(CLOCK_PIN , OUTPUT);
  
  pinMode(DATA_PIN , OUTPUT);
  
}

void loop() 
{
 
  for(int i=0; i < sizeof (val); i++){   
 
  //delayMicroseconds(20);
   digitalWrite(CLOCK_PIN , HIGH);
  delayMicroseconds(30);
  
   
    if (val[i] == 1)
        digitalWrite(DATA_PIN , HIGH);
     
    else
        digitalWrite(DATA_PIN , LOW);
  digitalWrite(CLOCK_PIN , LOW);
  //delayMicroseconds(20);
  //digitalWrite(pin4, L);
  //delayMicroseconds(20);
  
  delayMicroseconds(30);
  Serial.println(' ');
 // delayMicroseconds(20);
 
  } 
}

But I am getting following results:

FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE55 
60FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE 
5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560 
FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE55 
60FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE 
5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FC550F 
83F95583F95583F95583F95583F95583F95583F55C3F2A61F9AB 
5583F95583F95583F95583F95583F95583F95507EAA87F55C3F2 
F95583F95583F95583F95583F95583F95583F95B0FC5507EAA87 
1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1F9AB0FC5 
5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560 
FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE55 
60FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE 
5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560 
FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE55 
60FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE 
5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FC550F 
83F95583F95583F95583F95583F95583F95583F55C1F2A61F9AB 
5583F95583F95583F95583F95583F95583F95507EAA83F55C3F2 
F95583F95583F95583F95583F95583F95583F95B0FC5507EAA87 
1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1F9AB0FC5 
5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560 
FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE55 
60FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE 
5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560 
FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE55 
60FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FE 
5560FE5560FE5560FE5560FE5560FE5560FE5560FE5560FC550F 
83F95583F95583F95583F95583F95583F95583F55C1F2A61F9AB 
5583F95583F95583F95583F95583F95583F95507EAA83F55C3F2

Above you can see in 1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1F9AB0FC5 , 1F is getting attached before CAAC1F , can we get without 1F like CAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1FCAAC1F

Thanks and Regards… :slight_smile:

AWOL:
The receiver code you posted earlier appears to have some sort of preamble detection built into it.
Have you thought of using the detection event to trigger a ‚ÄúSerial.println ();‚ÄĚ ?

Hi…!!!

If I am using Serial.println(hexAsciiVals[nibble]); (or Serial.println(’ '); after Serial.write(hexAsciiVals[nibble]):wink: then I am getting following results:

F
B
C
0
A
7
5
F
6
9
0
5
F
5
5
5
6
!j
F
EB
0
7
F
2
A
B
0
7
F
2
A
B
0
7
F
2
A
B
0
7
F
2
A
B
0
7
F
2
A
B
C
0
A
7
A
F
C
2
1
A
F
B
E
8
5
3
5
F
6
9
0
5
5
8
E
8
5
3
5
F
6
C
0
A
7
A
F
C
2
1
A
F
B
C
0
A
7
A
F
C
2
0
5
F
5
E
8
5
3
5
F
6
9
0
5
F
5
E
8
2
1
A
F
B
0
7
A
7
A
F
C
2
1
A
F
B
C
0
5
3
5
F
6
9
0
5
F
5
E
8
5
3
5
F
6
9
0
A
7
A
F
C
2
1
A
F
B
C
0
A
7
A
F
C
2
1
F
C
5
E
8
5
3
5
F
6
9
0
5
F
5
E
8
5
3
A
F
B
C
0
A
7
A
F
C
2
1
A
F
B
C
0
A
7
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5
E
8
5
3
5
F
9
5
0
5
F
5
E
8
5
3
A
F
B
C
0
A
7
A
F
C
2
1
A
F
B
C
0
A
7
5
F
6
9
0
5
F
5
E
8
5
3
5
F
6
9
0
5
7
A
F
C
B
0
7
F
B
C
0
A
7
A
F
C
2
1
A
F
5
E
8
5
3
5
F
6
9
0
5
F
5
E
8
5
3
5
F
B
C
0
A
7
A
F
C
2
1
A
F
B
C
0
1
F
C
A
6
9
0
5
F
5
E
8
5
3
5
F
6
9
0
5
F
5
F
C
2
1
A
F
B
C
0
A
7
A
F
C
2
1
A
F
B
E
8
5
3
5
F
6
9
0
F
E
5
E
8
5
3
5
F
6
C
0
A
7
A
F
C
2
1
A
F
B
C
0
A
7
A
F
C
9
0
5
F
5
E
8
5
3
5
F
6
9
0
5
F
5
E
8
2
1
A
A
C
1
F
A
7
A
F
C
2
1
A
F
B
C
0
5
3
5
F
6
9
0
5
F
5
E
8
5
3
5
F
6
9
0
A
7
A
F
C
2
1
A
F
B
C
0
A
7
A
C
1
2
0
5
F
5
E
8
5
3
5
F
6
9
0
5
F
5
E
8
5
3
A
F
B
C
0
A
7
A
F
C
2
1
A
F
B
C
0
A
7
5
F
6
9
0
5
F
5
E
8
3
F
5
F
6
9
0
5
F
A
F
C
2
1
A
F
B
C
0
A
7
A
F
C
2
1
A
F
5
E
8
5
3
5
F
6
9
0
5
F
5
E
8
5
3
5
F
B
C
 int CLOCK_PIN     =     2;
 int DATA_PIN      =     4;
 int PACKET_BITS   =     256;
 int PREAMBLE_LEN  =    6;
 int DATA_LEN      =    ((PACKET_BITS / 4) - PREAMBLE_LEN);
 char arrax[4] ;
 int count = 0;


enum {
    PRE_0,    PRE_1,    PRE_2,    PRE_3,    PRE_4,    PRE_5,    DATA
} states;    

int     preamble [] = {0x0C,0x0A,0x0A,0x0C,0x01,0x0F};
char     hexAsciiVals[] = "0123456789ABCDEF";
int     state = PRE_0;
int    nibble;
int        nibble_count = 0;

void setup() {
  pinMode(CLOCK_PIN, INPUT);
  pinMode(DATA_PIN, INPUT);
  Serial.begin(9600);
}

void loop() {

    nibble = getNibble();
    nibble_count++;
    
//    Serial.print(digitalRead(CLOCK_PIN));

    
    switch (state) {
     
        case PRE_0:
            if (nibble_count > 32) {
                // we've read 32 bytes and still not found a match 
                // for the preamble so skip a clock pulse
                while (digitalRead(CLOCK_PIN) == LOW);
                while (digitalRead(CLOCK_PIN) == HIGH);
                nibble_count = 0;
            } else {
                state = (nibble == preamble[0]) ? PRE_0 : PRE_1;
            }
            break;
        
        case PRE_1:
            state = (nibble == preamble[1]) ? PRE_0 : PRE_2;    
            break;
            
        case PRE_2:
            state = (nibble == preamble[2]) ? PRE_0 : PRE_3;
            break;

        case PRE_3:
            state = (nibble == preamble[3]) ? PRE_0 : PRE_4;
            break;

        case PRE_4:
            state = (nibble == preamble[4]) ? PRE_0 : PRE_5;
            break;
        
        case PRE_5:
            state = (nibble == preamble[5]) ? PRE_0 : DATA;
            
            break;
            
        case DATA:
     
           
          
          //Serial.write(nibble);
          Serial.println(hexAsciiVals[nibble]);
        //  Serial.println(' ');
            
        
            if (nibble_count == DATA_LEN) {
                // all done, start again
                state = PRE_0;
                nibble_count = 0;
               // Serial.println(' ');
                
            }
            break;
    }
}

byte getNibble() {

    byte val = 0;
    
    for (byte bit_count = 0; bit_count < 4; bit_count++) {
        while (digitalRead(CLOCK_PIN) == HIGH);
        
          while (digitalRead(CLOCK_PIN) == LOW);
        
          val <<= 1;
          val |= digitalRead(DATA_PIN);
        
          
    }
    return (val &= 0x0F);
}

Here

       case PRE_5:
            state = (nibble == preamble[5]) ? PRE_0 : DATA;
            
            break;

it looks to me like your code is detecting the end of the preamble (the "event" I wrote about earlier).
Why not use that to perform a "Serial.println ();", also like I wrote earlier?

Hi…!!!

This is generating 10.02KHz.

const int CLOCK_PIN     =     2;
 const int DATA_PIN      =     4;

#define NUMITEMS(arg) ((unsigned int) (sizeof (arg) / sizeof (arg [0])))

byte val[24] = {1,1,0,0,1,0,1,0,1,0,1,0,1,1,0,0,0,0,0,1,1,1,1,1};


void setup()
{
  pinMode(CLOCK_PIN , OUTPUT);
  
  pinMode(DATA_PIN , OUTPUT);
  
}

void loop() 
{
 
  for(int i=0; i < sizeof (val); i++){   
 
  
   digitalWrite(CLOCK_PIN , HIGH);
  delayMicroseconds(30);
  
   
    if (val[i] == 1)
        digitalWrite(DATA_PIN , HIGH);
     
    else
        digitalWrite(DATA_PIN , LOW);
  digitalWrite(CLOCK_PIN , LOW);
  
  
  delayMicroseconds(58);

  } 
}
  

Thanks & Regards....  :-)

TEK0000.BMP (76.1 KB)