1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Tone & IRreceive problem

Discussion in 'Arduino' started by flat5, Apr 6, 2015.

  1. flat5

    flat5 Member

    Joined:
    Oct 26, 2008
    Messages:
    866
    Likes:
    8
    Location:
    Amsterdam
    Tone only works the first time through void loop.
    IRreceive only gets &results correct the first time through the loop.
    &results == 0 after the first time.
    Commenting out code for either function, the other will work repeatedly.

    Have tried flushing Serial, changing IRpin,...
    Am not using slowerpin or fasterpin at this time.

    I know this is a stupid way to sound the code but it will do for now.
    I've corrected the code for '6' and 'c' here but if you DL the attached file it will require those two characters to be edited. '6' should be -.... and 'c' should be -.-.

    Edited wrong post so lost the old sketch that was here in code brackets.
    Expect the attachment is what was here.
     

    Attached Files:

    Last edited: Apr 11, 2015
  2. flat5

    flat5 Member

    Joined:
    Oct 26, 2008
    Messages:
    866
    Likes:
    8
    Location:
    Amsterdam
    Added a case 0: send()_e;
    Confirmed Tone function is working repeatedly.
    Something is causing the IR receive function to always output a 0 after the first time through the void loop.
     
  3. flat5

    flat5 Member

    Joined:
    Oct 26, 2008
    Messages:
    866
    Likes:
    8
    Location:
    Amsterdam
    This simple sketch has the same problem. Proper numbers are returned except when the 'tone' function is added.
    After first time only '0' is returned.
    Code (text):

    /*
    IR_remote_detector sketch
    An IR remote receiver is connected to pin 11. Have tried 2-6 & 11.
    Decode problem when using tone function. Always returns 0 after first time.
    The LED on pin 13 toggles each time a button on the remote is pressed.
    */

    #include <IRremote.h>                    //adds the library code to the sketch

    const int irReceiverPin = 11;            //pin the receiver is connected to
    const int ledPin = 13;

    IRrecv irrecv(irReceiverPin);            //create an IRrecv object
    decode_results decodedSignal;         //stores results from IR detectorvoid setup()
    unsigned long value;
    void setup ()
    {
    Serial.begin(9600);
    pinMode(ledPin, OUTPUT);
    irrecv.enableIRIn();                   // Start the receiver object
    }

    boolean lightState = false;     //keep track of whether the LED is on
    unsigned long last = millis();  //remember when we last received an IR message

    void loop()
    {
    if (irrecv.decode(&decodedSignal) == true) //this is true if a message has
                                                //been received
    {
       value = decodedSignal.value;
       delay(200); // extra debounce
       Serial.print(value);
       Serial.print("  ");


       tone(8,600,100);   // comment out this line and the IR receiver works as expected!


       if (millis() - last > 250) {       //has it been 1/4 sec since last message? debounce?
         lightState = !lightState;              //Yes: toggle the LED
         digitalWrite(ledPin, lightState);
       }
       last = millis();
       irrecv.resume();                         // watch out for another message
    }
    }
     
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. flat5

    flat5 Member

    Joined:
    Oct 26, 2008
    Messages:
    866
    Likes:
    8
    Location:
    Amsterdam

    Apparently it's an interrupt problem.
    I'm reading what I can find.
     
  6. flat5

    flat5 Member

    Joined:
    Oct 26, 2008
    Messages:
    866
    Likes:
    8
    Location:
    Amsterdam
    Wrap up. Played with libraries but gave up. Solution for me is not to use 'tone'
    Gated a 555 astable osc. to do what I wanted. At this point I have a Uno sending Morse to another Uno (for no good reason) reliably at 120 wpm. Poor code, I know, but here is the sender and the little circuits.
    code update 28-4-15
    Code (text):

    // Send message by remote control
    // Tested with Philips remote. Will not work with other protocols!
    // interrupt problem avoided by removal of 'tone' function
    // replaced by providing a 555 oscillator and switching pin 13
    // 28-4-15 19:00 GMT+1
    #include <Arduino.h>

    byte signalPin = 13; // will control oscillator speaker
    int wpm = 20; // to start with
    int wpm_step = 5;
    int elementWait = 1200 / wpm; //dit time
    boolean signal_state = LOW;
    int randNumber = 0;
    #include <IRremote.h>
    int IRpin = 11;
    IRrecv irrecv(IRpin);
    decode_results results;
    unsigned long value;
    String call = "WB6CPR"; // customize this

    void setup() {
      pinMode(signalPin, OUTPUT);
      Serial.begin(9600);
      irrecv.enableIRIn(); // Start the receiver
      menu(); // show options on terminal screen
    }

    void loop() {

      if (irrecv.decode(&results))
      {
        delay(200); //debounce further key speak
        //Serial.println(results.value, DEC); // Print to terminal 'results.value' of key pressed for testing
        value = (results.value);
        whatToDo(value); // pass on to case statements
        irrecv.resume();   // Receive the next value
      }
    }

    void whatToDo(unsigned long)
    {
      //Serial.println(value); // TEST - find codes for key of interest
      switch (value) {

        case 65: case 2113: //1 Philips remote control key
          send_hi_k();
          break;
        case 66: case 2114: //2
          send_cq();
          break;
        case 67: case 2115: //3
          send_73();
          break;
        case 68: case 2116: //4
          send_599();
          break;
        case 69: case 2117: //5
          send_qth();
          break;
        case 70: case 2118: //6
          send_equipment();
          break;
        case 71: case 2119: //7
          send_QRM();
          break;
        case 72: case 2120: //8
          send_DX();
          break;
        case 73: case 2121: //9
          send_name();
          break;
        case 64: case 2112: //0
          send_all_messages();
          break;
        case 84: case 2132: //up arrow
          faster();
          break;
        case 83: case 2131: //down arrow
          slower();
          break;
        case 117: case 2165: //ok
          menu();
          break;
        case 74: case 2122: //go back arrow - clear screen on real terminal screens
          screen_refresh();
          break;
        case 77: case 2125: //mute key - toggle long tone
          pitch_adj();
          break;
        case 102: case 2150: // list key - send a long string of random characters for code pratice
          random_code();
          break;
        case 115: case 2163: // toggle wpm increment (1 or 5). default 5
          wpm_increment();
          break;
        case 0: // unknown key press - error
          send_e(); send_r(); send_r();
      }
    }

    void menu() {
      Serial.println();
      Serial.println("| Morse & I by Barry B |");
      Serial.println("|Remote control options|");
      Serial.println("|----------------------|");
      //Serial.println();
      Serial.print("     Speed is ");
      Serial.print(wpm);
      Serial.println("wpm");
      Serial.println();
      Serial.println("Up Arrow> Send Morse faster");
      Serial.println("Dn Arrow> Send Morse slower");
      Serial.println("Adjust> Toggle wpm increment (1 or 5)");
      Serial.println("BackArrow> Clear terminal screen");
      Serial.println("Mute> To toggle long tone to adjust pitch of osc.");
      Serial.println("OK> Show this menu");
      Serial.println("List> Send a random group of characters for Morse practice");
      Serial.println();
      Serial.println("1> Hi Hi");
      Serial.print("2> CQ CQ CQ "); Serial.println(call);
      Serial.println("3> 73");
      Serial.println("4> 599");
      Serial.println("5> QTH");
      Serial.println("6> My Equipment");
      Serial.println("7> QRM");
      Serial.print("8> CQ DX "); Serial.println(call);
      Serial.println("9> My name is Barry"); // customize this
      Serial.println("0> Go Crazy. Send all messages");
      Serial.println();
    }

    void send_hi_k() {
      Serial.println("HI HI K");
      send_h(); send_i();
      word_space();
      send_h(); send_i();
      word_space();
      send_k();
      word_space();
    }

    void send_cq() {
      Serial.print("CQ CQ CQ DE "); Serial.print(call); Serial.print(" "); Serial.println(call);
      for (int i = 0; i < 3; i++) {
        send_c(); send_q();
        word_space();
      }
      send_de();
      word_space();
      send_call();
      word_space();
      send_call();
      word_space();
    }

    void send_de() {
      send_d(); send_e();
      word_space();
    }

    void send_call() { // enter YOUR call here
      send_w(); send_b(); send_6(); send_c(); send_p(); send_r();
      word_space();
    }

    void send_73() {
      Serial.println("73 73 K");
      send_7(); send_3();
      word_space();
      send_7(); send_3();
      word_space();
      send_k();
      word_space();
    }

    void send_599() {
      Serial.println("599 599 K");
      send_5(); send_9(); send_9();
      word_space();
      send_5(); send_9(); send_9();
      word_space();
      send_k();
      word_space();
    }

    void send_qth() {
      Serial.println("QTH QTH AMSTERDAM AMSTERDAM"); // customize this
      send_q(); send_t(); send_h();
      word_space();
      send_q(); send_t(); send_h();
      word_space();
      send_location();
      word_space();
      send_location();
      word_space();
    }

    void send_location() {
      send_a(); send_m(); send_s(); send_t(); send_e(); send_r(); send_d(); send_a(); send_m(); // customize this
      word_space();
    }

    void send_equipment() { // customize this
      Serial.println("ARUDINO UNO, RECEIVER R5000");
      send_a(); send_r(); send_d(); send_u(); send_i(); send_n(); send_o();
      word_space();
      send_u(); send_n(); send_o();
      send_comma();
      word_space();
      send_r(); send_e(); send_c(); send_e(); send_i(); send_v(); send_e(); send_r();
      word_space();
      send_r(); send_5(); send_0(); send_0(); send_0();
      word_space();
    }

    void send_QRM() {
      Serial.println("QRM QRM, AGAIN PLEASE ");
      send_q(); send_r(); send_m();
      word_space();
      send_q(); send_r(); send_m();
      send_comma();
      word_space();
      send_a(); send_g(); send_a(); send_i(); send_n();
      word_space();
      send_p(); send_l(); send_e(); send_a(); send_s(); send_e();
      word_space();
    }

    void send_DX() {
      Serial.print("CQ DX CQ DX CQ DX DE "); Serial.println(call);
      send_c(); send_q();
      word_space();
      send_d(); send_x();
      word_space();
      send_c(); send_q();
      word_space();
      send_d(); send_x();
      word_space();
      send_c(); send_q();
      word_space();
      send_d(); send_x();
      word_space();
      send_d(); send_e();
      word_space();
      send_call();
      word_space();
    }

    void send_name() { // customize this
      Serial.println("MY NAME IS BARRY");
      send_m(); send_y();
      word_space();
      send_n(); send_a(); send_m(); send_e();
      word_space();
      send_i(); send_s();
      word_space();
      send_b(); send_a(); send_r(); send_r(); send_y();
      word_space();
    }

    void send_all_messages() {
      send_hi_k();
      Serial.println();
      send_cq();
      Serial.println();
      send_73();
      Serial.println();
      send_599();
      Serial.println();
      send_qth();
       send_location();
      Serial.println();
      send_equipment();
      Serial.println();
      send_QRM();
      Serial.println();
      send_DX();
      Serial.println();
      send_name();
      Serial.println();
    }

    void screen_refresh() {
      Serial.write(27); // ESC
      Serial.write("[2J"); // clear screen
      Serial.write(27); // ESC
      Serial.write("[H"); // cursor to home
    }

    void pitch_adj() {
      Serial.println("Click 'Mute' again to start/stop long tone.");
      signal_state = digitalRead(signalPin);
      if (signal_state == LOW) {
        digitalWrite(signalPin, HIGH);
      }
      else {
        digitalWrite(signalPin, LOW);
      }
      delay(5);
    }

    void send_a() {
      dit(); dah();
      letter_space();
    }

    void send_b() {
      dah(); dit(); dit(); dit();
      letter_space();
    }

    void send_c() {
      dah(); dit(); dah(); dit();
      letter_space();
    }

    void send_d() {
      dah(); dit(); dit();
      letter_space();
    }

    void send_e() {
      dit();
      letter_space();
    }

    void send_f() {
      dit(); dit(); dah(); dit();
      letter_space();
    }
    void send_g() {
      dah(); dah(); dit();
      letter_space();
    }

    void send_h() {
      dit(); dit(); dit(); dit();
      letter_space();
    }

    void send_i() {
      dit(); dit();
      letter_space();
    }

    void send_j() {
      dit(); dah(); dah(); dah();
      letter_space();
    }
    void send_k() {
      dah(); dit(); dah();
      letter_space();
    }

    void send_l() {
      dit(); dah(); dit(); dit();
      letter_space();
    }

    void send_m() {
      dah(); dah();
      letter_space();
    }

    void send_n() {
      dah(); dit();
      letter_space();
    }

    void send_o() {
      dah(); dah(); dah();
      letter_space();
    }

    void send_p() {
      dit(); dah(); dah(); dit();
      letter_space();
    }

    void send_q() {
      dah(); dah(); dit(); dah();
      letter_space();
    }

    void send_r() {
      dit(); dah(); dit();
      letter_space();
    }

    void send_s() {
      dit(); dit(); dit();
      letter_space();
    }

    void send_t() {
      dah();
      letter_space();
    }

    void send_u() {
      dit(); dit(); dah();
      letter_space();
    }

    void send_v() {
      dit(); dit(); dit(); dah();
      letter_space();
    }

    void send_w() {
      dit(); dah(); dah();
      letter_space();
    }

    void send_x() {
      dah(); dit(); dit(); dah();
      letter_space();
    }

    void send_y() {
      dah(); dit(); dah(); dah();
      letter_space();
    }

    void send_z() {
      dah();  dah(); dit(); dit();
      letter_space();
    }
    void send_comma() {
      dah(); dah(); dit(); dit(); dah(); dah();
      letter_space();
    }
    void send_period() {
      dit(); dah(); dit(); dah(); dit(); dah();
      letter_space();
    }

    void send_0() {
      dah(); dah(); dah(); dah(); dah();
      letter_space();
    }

    void send_1() {
      dit(); dah(); dah(); dah(); dah();
      letter_space();
    }
    void send_2() {
      dit(); dit(); dah(); dah(); dah();
      letter_space();
    }
    void send_3() {
      dit(); dit(); dit(); dah(); dah();
      letter_space();
    }

    void send_4() {
      dit(); dit(); dit(); dit(); dah();
      letter_space();
    }
    void send_5() {
      dit(); dit(); dit(); dit(); dit();
      letter_space();
    }

    void send_6() {
      dah(); dit(); dit(); dit(); dit();
      letter_space();
    }

    void send_7() {
      dah(); dah(); dit(); dit(); dit();
      letter_space();
    }

    void send_8() {
      dah(); dah(); dah(); dit(); dit();
      letter_space();
    }
    void send_9() {
      dah(); dah(); dah(); dah(); dit();
      letter_space();
    }

    void dit() {
      digitalWrite(signalPin, HIGH);
      delay(elementWait);      // milliseconds - one dit
      digitalWrite(signalPin, LOW);
      delay(elementWait);
    }

    void dah() {
      digitalWrite(signalPin, HIGH);
      delay(elementWait * 3);
      digitalWrite(signalPin, LOW);
      delay(elementWait);
    }

    void letter_space() {
      delay(elementWait * 2);
    }

    void word_space() {
      delay(elementWait * 6);
    }

    void faster() {
      wpm = wpm + wpm_step; // increment by 5 till 120
      if (wpm > 200)
      {
        wpm = 200;
        Serial.println("200 max");
      }
      elementWait = 1200 / wpm;
      show_wpm();
    }

    void slower() {
      wpm = wpm - wpm_step; // decrement by 5 till 5
      if (wpm < 5)
      {
        wpm = 5;
        Serial.println("5 minimum");
      }
      elementWait = 1200 / wpm;
      show_wpm();
    }

    void show_wpm() {
      Serial.print("wpm: ");
      Serial.println(wpm);
    }

    void wpm_increment() {
      if (wpm_step == 5)
      {
        wpm_step = 1;
      }
      else
      {
        wpm_step = 5;
      }
      Serial.print("Speed increment: ");
      Serial.println(wpm_step);
    }

    void random_code() {
      // send a random characters Morse equivlent
      char* code_char[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
                           "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
                           ",", ".", "?", "!", ":", "\"", "'", "="
                          };
      char* codes[] = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--",
                       "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", // 26 letters
                       "-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.", // 10 numbers
                       "--..--", ".-.-.-", "..--..", "..--.", "---...", ".-..-.", ".----.", "-...-" // 8 punctuation
                      };
      String send_char;
      String answers;
      randomSeed(analogRead(0));
      for (int t = 0; t < 70 ; t++) {
        randNumber = random(43);
        send_char = codes[randNumber];
        String x;
        for (int i = 0; i < send_char.length(); i++) {
          x = send_char.substring(i, i + 1);
          if (x == ".") {
            dit();
          }
          else {
            dah();
          }
        }
        letter_space();
        letter_space();
        answers.concat(code_char[randNumber]);
        answers.concat(" ");
      }
      Serial.println(answers);
    }
     
    I wanted to see if the 'island' technique would work for DIP sockets.
    I made two rows using a 3mm diamond glass cutter. This to anchor the 8 pin socket.
    It works but poorly. The 3mm is the outside diameter of the drill. The inside island is maybe 1mm.
    This is enough to hold a pin but it is very easy to overheat the pad and lift it.
    This is ok if you still have enough pads to hold the socket in place. I lost one.
    I then used enameled wire to hook around each socket pin and bring out to a 6mm pad.
    Fiddly but can be done. 100k resistor (pitch) has been replaced with 15 turn pot.
    555&IR board2.jpg
    Arduino ir receive & oscillator circuits.png
     
    Last edited: Apr 29, 2015
  7. flat5

    flat5 Member

    Joined:
    Oct 26, 2008
    Messages:
    866
    Likes:
    8
    Location:
    Amsterdam
    Updated code. Added a procedure to practice code. That might be useful to someone.
    This program works with the Philips remote system.
    To use with another type remote, uncomment the appropriate line to see what codes your remote sends.
    Major rewrite is in order. I might bother.
    Updated again. 28-4-15 20:00 GMT+1
     
    Last edited: Apr 28, 2015
  8. Tony Stewart

    Tony Stewart Well-Known Member Most Helpful Member

    Joined:
    Aug 31, 2012
    Messages:
    3,152
    Likes:
    282
    Location:
    Richmond Hill , ON Canada near Toronto
    IR Rx looks like a Buffered Rx with AGC that needs a clean supply . Does it work? What pn?
     
  9. flat5

    flat5 Member

    Joined:
    Oct 26, 2008
    Messages:
    866
    Likes:
    8
    Location:
    Amsterdam
    Everything works fine.
    D11
     
  10. flat5

    flat5 Member

    Joined:
    Oct 26, 2008
    Messages:
    866
    Likes:
    8
    Location:
    Amsterdam
    How did this happen? Running the random core generator two passes came out the same!

    3 s c u . 3 r r h 2 u ? c m 5 , ? z 9 n 9 z 0 . c s a 5 z 9 j y j 0 n u s c 7 m g j 9 . 7 i w c j u v 3 l v 0 v v p m p 2 ' i 7 3 . ! x g
    0 ! s b , 0 6 f ' 9 j ? : 0 t 8 j 2 s y l 1 o q k ! 9 3 s q j 1 , 7 , 7 b " o h e 8 g j 7 l 6 ' q s " ? o q l 5 ! o f 5 j , r w a k i , 3

    t c 9 5 9 0 g b 7 u o 5 2 q v e " 7 j ? w x . ? i , q b g c a 0 n p 1 x 6 e 5 8 8 a q e y 7 : ? o y n z 3 1 y 0 a x 4 ! r v 5 b i , z z 5 p
    t c 9 5 9 0 g b 7 u o 5 2 q v e " 7 j ? w x . ? i , q b g c a 0 n p 1 x 6 e 5 8 8 a q e y 7 : ? o y n z 3 1 y 0 a x 4 ! r v 5 b i , z z 5 p

    z j 7 s y 6 q r " ! : t n a n y u " e 0 h ! 4 n j ! 0 g w c n v o m 8 t s 9 " 9 i x u 7 z i i q : a 5 f w f 5 5 : ! v 6 e w . 5 ? i f w r q
    4 3 d i . i r ? " m l y 2 b 9 1 d 0 2 x y r ! v x 9 u c g 5 b k , 5 d i o 5 9 v 3 9 5 , 6 4 c z e i 6 c x p w w 5 i 2 t w c 1 8 u o s f 1
    , , b ? 0 o 1 l g 5 . m u 2 1 e z 8 x l c 7 z ! 5 ? 4 h w y v f b 2 r e , t c w d p 9 p 7 f u d . 1 a z q a , u v y t m j ! : v h w 8 c n z
    x 9 u ? , i 8 8 6 : j r q " 4 : 9 5 m . ' n t a v 6 b r 4 r 2 q n u . " c 4 j " q b f y x j k o c h : 6 5 0 9 r 9 k r 1 x 4 " n 2 : 9 4 3 .
    f o 7 f : 7 e , p 0 k y e ! l . t h u 4 i p e 6 e . o 5 s y l ? d 3 c d i j w 5 b s a 4 g " g q d 3 , 9 c ' h q i 1 b f 0 8 q c y c 4 ! 2 8

    Guessing somehow the result got printed twice. Odd.
    Also changed the random max to 43. Forgot about zero.
    I had wondered why " showed up in the answers so often.
    Guessing when the index was 43 or 44 the string function chose ".
    I could test this theory....Nah :)
    OK, I did test it. 44 was not printed. 43 was printed as ".
     
    Last edited: Apr 29, 2015
  11. Tony Stewart

    Tony Stewart Well-Known Member Most Helpful Member

    Joined:
    Aug 31, 2012
    Messages:
    3,152
    Likes:
    282
    Location:
    Richmond Hill , ON Canada near Toronto
    Pattern dependent bit errors tell me something is wrong in the channel. This is very common to have a worst case pattern.

    Examine the binary pattern in each stage for flaws, without me looking at it , it could be too low bit rate with AGC overshoot in IR Rx or group delay distortion in filter or carrier rate error with phase shift in BPF edges etc etc.

    trigger with clock and examine eye pattern for zero crossings.
     
    Last edited: Apr 30, 2015
  12. flat5

    flat5 Member

    Joined:
    Oct 26, 2008
    Messages:
    866
    Likes:
    8
    Location:
    Amsterdam
    Ir only calls the function. The one at the end of code.
    So far this is a one off.
    For testing I do have the wpm set to 200 so the run is as fast as can be.
    Also at this time, for fun, I set the serial to 115200.
    Perhaps this combination caused a glitch but I think the board is fast enough for this not to be a problem.
     
  13. Tony Stewart

    Tony Stewart Well-Known Member Most Helpful Member

    Joined:
    Aug 31, 2012
    Messages:
    3,152
    Likes:
    282
    Location:
    Richmond Hill , ON Canada near Toronto
    Well if you want to fix it fast you must try as I say.

    It is called ISI or intersymbol interference where a symbol is one baud
     
  14. flat5

    flat5 Member

    Joined:
    Oct 26, 2008
    Messages:
    866
    Likes:
    8
    Location:
    Amsterdam
    What you're talking about is over my head, Tony. I still think it's a 'random' problem. More results and moving one line of code changes the behavior.

    The code has random seed just above the for loop. ---> means matching lines

    w z k ! e j u z k 1 9 g ! ? m r ! 4 , n n 7 d 4 g 0 ! p q 0 2 o 5 b ? " 6 9 h g c s a q a j g 0 j w u " 9 8 n k h j w c o c : a b c 3 1 w :
    m r 8 ! u w ? v f : ! r 2 2 y d l ? u r d , l j l t u l a " : h b m a 6 3 v m c ! x w r k n h l q w 6 t 0 ' 9 j l c z f 5 g 5 ' x 0 r b s w
    ---> m j a h c g j j , t w ' w ' c 9 ' ? d ? a 5 o 5 f i f 9 7 , m q 9 0 c b d . f 2 4 q y 0 8 8 y t o 0 f . k : s p 3 k : 0 d 5 u l q b p 3 e
    ' i 0 h t a x 6 t 2 . l s f f 2 q 9 9 v 7 l i 9 c j t ? f 3 t 1 e l w ? f f m e , c . 9 r c o x w g c . z x y m a ! ? 8 y p v d . t q o u f
    y x ! r x s 3 8 c o ? l g k 3 z a l a o g n a y v h z j 3 , j g b u 4 a l u z . v t 6 " a 8 k 6 x 2 " e ! ! 6 s q n w m u 0 ! 9 7 y e x t c
    ---> m j a h c g j j , t w ' w ' c 9 ' ? d ? a 5 o 5 f i f 9 7 , m q 9 0 c b d . f 2 4 q y 0 8 8 y t o 0 f . k : s p 3 k : 0 d 5 u l q b p 3 e
    5 y p 4 r s m ? l , : s s u 1 m l g q a 5 r n j x k i . f h s a y ? d k x v i r " k p d j f j , 6 w 0 r 5 9 t x m l : e t " s n z "
    ---> s q " . 8 m t z . ? m 4 o 0 . f v d f 0 v : h g n l p : n , 6 l , x q : z 6 p , e ! 2 m 9 j ' e : c x y d s z n 0 7 5 t 7 z 0 " d q 5 0 7 b
    g c c 1 u a ' , 2 h ! s 4 p k p 1 4 i h p p 2 n : f ? x r a 9 2 8 3 ? f r ' ? 1 n , u : 0 q n 8 5 a . o k t e r ! 4 g 7 q 4 h y 3 , 9 6 s '
    ---> r 3 n e w z k 4 , ' , e 4 a y ? 6 q 1 2 r j x d t e g y r w , f o j o 7 ' 0 ' o i 2 ' 3 8 n s v v 1 n 8 l h j n u p l n 2 l k o " h 2 f o p
    ---> m j a h c g j j , t w ' w ' c 9 ' ? d ? a 5 o 5 f i f 9 7 , m q 9 0 c b d . f 2 4 q y 0 8 8 y t o 0 f . k : s p 3 k : 0 d 5 u l q b p 3 e
    ---> m j a h c g j j , t w ' w ' c 9 ' ? d ? a 5 o 5 f i f 9 7 , m q 9 0 c b d . f 2 4 q y 0 8 8 y t o 0 f . k : s p 3 k : 0 d 5 u l q b p 3 e
    ---> r 3 n e w z k 4 , ' , e 4 a y ? 6 q 1 2 r j x d t e g y r w , f o j o 7 ' 0 ' o i 2 ' 3 8 n s v v 1 n 8 l h j n u p l n 2 l k o " h 2 f o p
    x , l 1 e 5 u d b s 0 9 w 1 q p e y 3 q c z q v 1 h q , 7 w n a w g 2 3 v v j p z i d p ' 5 , g e k y o e 2 q l r ? c g i f q b 2 w b c a q
    ---> s q " . 8 m t z . ? m 4 o 0 . f v d f 0 v : h g n l p : n , 6 l , x q : z 6 p , e ! 2 m 9 j ' e : c x y d s z n 0 7 5 t 7 z 0 " d q 5 0 7 b

    Moved random seed into the for loop. Now some little patterns repeat but not a whole line.

    p 5 n t f f 4 r 8 j 2 v 6 b n n t n 5 4 f ' y q r 2 8 8 8 j ? b i t ? 6 t 5 4 ' 4 l s y k 9 2 : w p v v 2 : 7 ! i ! 6 h 0 z . ? t . s y n t
    r m f y e " q l " w : 8 v p 7 2 j c u 1 1 ? 6 h 0 t i z n z h 0 t 5 ? b g m a m t , m ' y s y 4 f g y f m x 9 ' " 9 3 l ' k 9 k e q f 9 l 9
    r k 3 r f l q f x l k q x r q 3 w x e 2 q k d e 3 d e 9 2 q 2 j e 8 q : e k q j q p v : 1 2 : k : k : k : q 7 q 7 w 8 d q 7 q 7 w 8 j j j j
    2 8 2 q " w : w d q 2 k e " " k p : e q j w q v q p : k : q 7 k 8 j d 7 q ! q ! w : w : 2 w j p 1 1 2 : : ! 2 : : ! 2 : 8 2 2 d d c ! 8 2
    9 8 w " q d d e q d k : k : k : q 7 q 7 q 7 w 8 j j j p 7 8 d 8 w j p 7 8 d 8 2 8 d : ! 2 : : ! 8 d d c c v c c 1 2 : d c c v c c 7 d c ! 8
    d q 8 q 2 j k q j q p 1 2 d k : k : q 7 q 1 2 : w : 2 w j p 7 8 d 2 2 2 d : ! 2 : : c c 1 2 : : c c 1 2 : d c ! : ! 8 d d c ! 8 2 8 d : c c <---
    q : j e 8 q d e w q p 1 2 d k : q 7 q 7 q 7 w 8 d q ! w : w : 2 w j p 1 1 2 : : ! 2 : 8 2 2 d : c c 1 2 : : c c 1 2 : d c ! 8 2 8 d : c c 1 <---
    d q w 9 2 q : e k q j q p 1 2 d k : k : q 7 w 8 j j j p 7 8 j v 2 8 d : c c 1 2 : : c c 1 2 : d c ! : c c 7 d c c v c i 8 8 : p 7 j 7 d j 1
    f k k l 9 r 8 w x " 3 d " k j 9 : j k q j q p 1 2 d k : k 8 j : 7 q 7 q 7 q 7 q ! w : w : w : 2 w j p 7 8 d 8 2 8 d : c c 1 2 : d c ! 8 2 8 <---
    9 e 2 q q w 9 8 w e " e k q j w v d p 8 p : q 7 q 7 w : w 8 j j j p 7 8 j v 2 8 d : ! 8 d d c c v c c 7 d c c p d d c ! 8 2 8 <---
    9 f 9 l " w q 9 9 : q q q w 9 2 q : e k q j q p 1 8 j : 7 q 7 q 7 w d w : w : 2 w j j j p 7 8 d 2 2 8 d : ! 8 d : c c 1 2 : d c ! 8 8 : j
    k l x l k w 3 w 2 q e 3 d k d e 9 8 w " q d d e q d e w q v q p : q 1 2 d q 7 w 8 j j j p 7 8 d 8 2 2 d d c ! 8 2 2 d : c c 1 8 : d c ! : !
    x e 2 q q 2 k e " e e 8 q d e w q p 1 2 d k : q 7 q 7 w : w : 2 w j p 7 8 j v 2 8 d : c c 1 2 : : c c 7 d c ! 8 2 8 d d c ! 8 2 8 j 7 d d c
    q q w 9 2 q 8 j k q j q p 1 8 d k : q 7 q 7 w : 2 w j p 1 v 7 8 d 8 2 2 d d c ! 8 2 8 d d c ! 8 2 8 d d c c v c i 8 2 8 j 7 d d i 8 8 d j 1
    s y x 9 f " " 3 r f l q f x l q x e 2 q 9 9 : q q q w 9 2 q 8 j e 8 q : e k q j q p v : 1 2 : k : k : q 7 q 7 q 7 w : 2 w j j j p 7 8 d 8 2
    k r w x e 2 q q w 9 2 q : e k q j q p v : 1 2 d q 7 q 7 q 7 w : 2 w j p 1 1 2 : : ! 2 d d c ! 8 2 8 d : c c 7 d c ! : ! 8 j 7 d d c c v c i

    I think a better random routine might help.
     
  15. Tony Stewart

    Tony Stewart Well-Known Member Most Helpful Member

    Joined:
    Aug 31, 2012
    Messages:
    3,152
    Likes:
    282
    Location:
    Richmond Hill , ON Canada near Toronto
    Sorry flat5,
    Skim thru this and see eye pattern.
    Then try again or ask.
    http://en.m.wikipedia.org/wiki/Intersymbol_interference

    In old days, all HDD's used encoder/decoders for MFM (RLL1,3) the worst case pattern for bit shift was 110110110110

    In your case , maybe bit is 00001000 or 11110111 or something else.

    Eye pattern test or DSO with phase error detector using XOR and sync clock or a clock window margin tester or ..... Is the desired test you must DO !!! Your choice

    You may be using parity to get " ? Or ?

    " = 34d=22h= 00100010 why this?

    Try wwwwww pattern then w w w w w w .... Then eeeeeeee e e e e
     
    Last edited: Apr 30, 2015
  16. flat5

    flat5 Member

    Joined:
    Oct 26, 2008
    Messages:
    866
    Likes:
    8
    Location:
    Amsterdam
    Now move random seed to the setup() (out of the loop)

    wpm: 20
    p n 8 u c r h x ! v w u ! 1 1 3 q ' j s m ? j l . p ! e 2 ' , 1 w ! i , c f r . z g z l b , d e 2 . g a , 4 4 , : o 2 4 6 . 6 u 5 v y 9 e i
    : , k 1 x l y 5 t 0 ! , g m ! n , 7 ' l z d o w 5 c 9 . t , 3 q m l n , 2 3 6 l 5 w o ! 4 " c g 5 m l g y 6 i t x , j 5 9 g 0 n ! e ? . " 6

    wpm: 100
    s t e a j ! v 3 m h x d ? v z . u : 2 h 8 5 u 8 2 o 3 p k k " ' c . ? 2 p g l c l 1 8 a 1 0 v o m f d 8 7 n r g . i j n i 3 r a 3 " 7 q p i
    : . v w j z 6 u 9 : j w 8 a 5 f p k ! 9 v u o j 5 e p 2 v h x 7 w ' ! h 3 l ? 3 6 0 z v l q m 9 k . h z 4 f z h 3 r f f b c 5 5 h s 8 4 5 e
    e r d ' t v f t m e s 2 e u ! t y 5 j " l k w ' p 3 v l p 0 q f ! r s n b a 0 ? s , r b o o 0 . 7 s w " 4 : 8 ? d g 1 v 8 4 j s t c b 7 ! 3

    and put a delay(5) between each character. This looks better. Only a few repeats.

    wpm: 200
    : d 7 e d " h y j r l e 0 l g o t k a w 0 . n 0 h u x e ! x b g ' 5 . 4 s : , . y 7 : i , t y 2 l 9 q z e " s u o 7 x " h 0 8 k . 1 n x ! o
    s 9 9 ! 5 ! k f d b 4 n ? " i 9 0 c 0 f r 5 " u o o 8 . t c f h z a 0 d e v l ' w l 0 l ! h r ! n ? t x q 5 q q o 5 w x 3 0 e n f c 0 d 6 4
    v 7 l e c 2 r l . 2 f u c x s d r 2 d . s 3 ! c k y 9 , r m t a 6 h 2 t . n ' b 2 m q e 2 k t : z ? 5 v l 6 " " w a 6 b e m ! 2 ? 6 q 0 q 0
    i 6 i 7 l v . ' d p " k " m g 5 z 2 ? ' 3 a 7 a c i j 2 u y 8 w c i t m e q h e v k q v 2 3 h e a 2 , s f z ! d 0 x ? k f 6 n w v 3 1 ? o 4
    ? 4 d i p 9 o h 0 0 , 8 t : y : ! r 3 c f 9 ! q y c 2 h w h j 3 d p a " y r 7 2 " c y q j , l q f u s m y : v , 1 7 f 2 ? b 5 c p ! " h 7 e
    2 s p z t o a i z k p ' v a u ! b t p : : t 8 j 2 , m 2 9 g s x o : g h k b q 6 n 0 c ! t ! 9 u 9 d 8 7 c 0 d 5 , y v 7 m z
    a o 2 ? 5 l 3 i h ' ' s m d . , d 6 6 k , e w 0 1 g 5 s f m d a f 2 , 3 0 , z 3 ' p : 7 n 4 h z o 9 6 0 m ? n , ? 7 , m b 8 o l u z " c w y
    5 ' 4 ! x w n k v 5 ? 0 y e ! s 7 r o ? 8 j 4 " s n , 2 n t 1 d r 4 8 q 9 r x 0 v z c o p x i t b 2 r s 4 2 b z 6 d m p n ! s e d 7 2 k i 5
     
  17. flat5

    flat5 Member

    Joined:
    Oct 26, 2008
    Messages:
    866
    Likes:
    8
    Location:
    Amsterdam
    Tony, thank you, I better understand what you are talking about but I don't think you understand what I am doing.
    I'm not using transmission lines, networks, etc. I'm just using an Arduino R3 USB port to a computer. OS is Win XP.
    The code is just strings manipulation. This all in the Arduino. Then send a string to a monitor.
    The strings are not corrupted. Characters are being repeated. Don't you think this could be a problem in the random routine?
    I'm hoping adding a slight delay between each random call will help since milliseconds are the base of the random function.
    It's all I can think of for now. Putting random seed in the loop did not solve the problem but perhaps having it in the loop plus a delay might improve the results. (more randomy)
     
  18. Tony Stewart

    Tony Stewart Well-Known Member Most Helpful Member

    Joined:
    Aug 31, 2012
    Messages:
    3,152
    Likes:
    282
    Location:
    Richmond Hill , ON Canada near Toronto
    I thought you had an IR path. ( either false assumption from my observation or lack of clarity )

    You should not be trying to find a random problem with random data and report this random data.
    You should be using known worst case patterns and only reporting the bits/ words or frames in exception.
    Then use incremental word and frame latency.

    Either it is a synchronous error, asynchronous error, metastable error, overrun error etc. race condition, maskable interupt glitch, false reported buffer avail or a Random RAM soft error. or ...

    The only thing truly random is thermal noise.
     
  19. flat5

    flat5 Member

    Joined:
    Oct 26, 2008
    Messages:
    866
    Likes:
    8
    Location:
    Amsterdam
    See what I've done here? Took out the random function and delay and ran the prog. at ludicrous speed :)

    //unsigned int randNumber = random(43); // 0 - 43, all characters
    unsigned int randNumber = 43;

    wpm: 100
    = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
    70 characters
    = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
    70 characters
    = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
    70 characters

    wpm: 500
    = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
    70 characters
    = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
    70 characters
    = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
    70 characters

    No odd characters and lines are the correct length. Random has to be part of the problem.
    If I remove every non needed line of code there should be more local variable space.
    Worth a try?
     
  20. flat5

    flat5 Member

    Joined:
    Oct 26, 2008
    Messages:
    866
    Likes:
    8
    Location:
    Amsterdam
    wpm: 30 not very random but the line length is correct...for three runs.

    ? 6 8 5 l 7 y r k i b n h 5 f r ' 9 8 e k : : 2 1 8 j ! : p ! d 8 ! v 2 p ! : j c p : c 1 d 1 ! : 7 ! : 7 ! : 7 ! : 7 ! : 7 ! : ! ! d p i c
    70 characters
    e q k 3 8 d w 2 7 j : c v 8 7 7 : c ! : 7 ! : ! ! : ! ! : ! ! : ! 7 : c ! : ! ! d p i ! : ! ! d v i c : v i 7 : c ! : ! c d p o ! j ! i 1 v
    70 characters
    f e w k " 6 ! w 8 1 2 j b a , l y 0 0 1 d 1 p 2 v 1 2 p 7 2 j ! d 8 ! v 8 1 7 : ! 7 : ! ! d j i c d d 1 ! d p i ! : 1 ! d p c j " w p i p e
    70 characters
    Code (text):

    // send random Morse code
    #include <Arduino.h>
    byte signalPin = 13; // will control oscillator speaker
    int wpm = 30; // to start with
    int elementWait = 1200 / wpm;
    boolean signal_state = LOW;
    #include <IRremote.h>
    int IRpin = 11;
    IRrecv irrecv(IRpin);
    decode_results results;
    unsigned long value;

    void setup() {
      pinMode(signalPin, OUTPUT);
      Serial.begin(9600);
      irrecv.enableIRIn(); // Start the receiver
      menu(); // show options on terminal screen
    }

    void loop() {

      if (irrecv.decode(&results))
      {
        delay(200); //debounce further key speak
        value = (results.value);
        whatToDo(value); // pass on to case statements
        irrecv.resume();   // Receive the next value
      }
    }

    void whatToDo(unsigned long)
    {
      switch (value) {
      case 102: case 2150: // list key - send a long string of random characters for code pratice
           random_code();
          break;
      }
    }


    void menu() {
      Serial.println("List> Send a random group of characters for Morse practice");
    }

    void random_code() {
      // send a random character's Morse equivlent
      char* code_char[] =
      {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
       "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
       ",", ".", "?", "!", ":", "\"", "'", "="
      };
      char* codes[] =
      {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--",
       "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", // 26 letters
       "-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.",     // 10 numbers
       "--..--", ".-.-.-", "..--..", "..--.", "---...", ".-..-.", ".----.", "-...-"                  //  8 punctuation
      };
      String send_char; String answers;
      for (unsigned int t = 0; t < 70 ; t++) // each run will be 70 characters and 69 spaces, one line on my screen
      {
        randomSeed(analogRead(0));
        unsigned int randNumber = random(43); // 0 - 43, all characters
        //unsigned int randNumber = 43;
        send_char = codes[randNumber];
        String x;
        for (unsigned int i = 0; i < send_char.length(); i++)
        {
          x = send_char.substring(i, i + 1);
          if (x == ".") dit(); else dah();
        }
        letter_space(); letter_space(); // this is legal when practicing code
        answers.concat(code_char[randNumber]); answers.concat(" ");
        //delay(15);
      }
      Serial.println(answers);
      Serial.print(answers.length() / 2); // space between characters
      Serial.println(" characters");
    }

    void dit() {
      digitalWrite(signalPin, HIGH);
      delay(elementWait);      // milliseconds - one dit
      digitalWrite(signalPin, LOW);
      delay(elementWait);
    }

    void dah() {
      digitalWrite(signalPin, HIGH);
      delay(elementWait * 3);
      digitalWrite(signalPin, LOW);
      delay(elementWait);
    }

    void letter_space() {
      delay(elementWait * 2);
    }
     
     
  21. flat5

    flat5 Member

    Joined:
    Oct 26, 2008
    Messages:
    866
    Likes:
    8
    Location:
    Amsterdam
    Next step is to remove the IR stuff. I'm thinking an interrupt problem with IR & random.
    Just a guess. Off to sleep. (4am)
     

Share This Page