pedroe

Forum Replies Created

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • in reply to: pserial with 3 parsed variables numbers #11051
    pedroe
    Participant

    Michael,

    One more question;
    The above solution worked fine, but i notice that frequently the pserial communication skips some characters/numbers.
    For example, if the master arduino sends 245 through serial, the slave with the shield might only overlay 24 skipping a 5. In the next loop the value is corrected, but after a few seconds it happens again. Per my understanding is a communication problem, and the variable in the slave side actually only gets the value 24 instead of 245.

    Do you have any idea about this? Memory again? Sorry to bother.

    in reply to: pserial with 3 parsed variables numbers #11047
    pedroe
    Participant

    Michael,

    Reducing to 128×72 WORKED!!! Thank you very much!
    You have no idea how many hours i spent trying to solve this problem! Ready for the next one 🙂

    in reply to: pserial with 3 parsed variables numbers #11044
    pedroe
    Participant

    Michael I really appreciate your input! Thank you!

    If i apply your suggestion using Serial instead of pserial and removing the TVout and the overlay, it outputs for the Serial monitor the correct values, parsed and in numbers:

    char *strings[10];
    char *ptr = NULL;
    
            
    
    void setup()
    {
    Serial.begin(4800);
    }
    
    void loop()
    {
      //Reads serial
       if (Serial.available()) {
    
     static char input[25];
     static uint8_t i;
     char c = Serial.read ();
    
     if ( c != '\r' && i < 24 ) // assuming "Carriage Return" is chosen in the Serial monitor as the line ending character
       input[i++] = c;
       
     else
     {
       input[i] = '\0';
       i = 0;
        
    
         //Parsing the input
         byte index = 0;
        ptr = strtok(input, ",");  // takes a list of delimiters
        while(ptr != NULL)
        {
            strings[index] = ptr;
           
            index++;
            ptr = strtok(NULL, ",");  // takes a list of delimiters
            
           // t0=atoi(strings[0]);
          
           // t1=atoi(strings[1]);
          
           // t2=atoi(strings[2]);
          
        }
    
      String longString = String(strings[0]);
      String intString = String(strings[1]);
      String floatString = String(strings[2]);
        
        
    
      long int dist = longString.toInt(); // returns long
      int var = (int)intString.toInt(); // returns long, so cast to int
      float rad = floatString.toFloat();
    
       Serial.println(dist+1);
       Serial.println( var+1);
       Serial.println( rad+1);
     
    
           
       }//if
     
     }//pserial available
    
    }//loop  

    But using pserial and the tvout library with overlay it doesnt work. The overlayd output is:
    0
    0
    0.00

    #include <TVout.h>
    #include <pollserial.h>
    #include <fontALL.h>
    
    TVout TV;
    pollserial pserial;
    
    char *strings[10];
    char *ptr = NULL;
    
            
    
    void setup()
    {
      TV.begin(PAL,184,72);
      TV.select_font(font6x8);
      initOverlay();
      TV.println("Serial Terminal");
      TV.println("-- Version 0.1 --");
      TV.set_hbi_hook(pserial.begin(4800));
    }
    
    void initOverlay() {
      TCCR1A = 0;
      // Enable timer1.  ICES0 is set to 0 for falling edge detection on input capture pin.
      TCCR1B = _BV(CS10);
    
      // Enable input capture interrupt
      TIMSK1 |= _BV(ICIE1);
    
      // Enable external interrupt INT0 on pin 2 with falling edge.
      EIMSK = _BV(INT0);
      EICRA = _BV(ISC01);
    }
    
    // Required to reset the scan line when the vertical sync occurs
    ISR(INT0_vect) {
      display.scanLine = 0;
    }
    
    void loop()
    {
      //Reads serial
       if (pserial.available()) {
    
     static char input[25];
     static uint8_t i;
     char c = pserial.read ();
    
     if ( c != '\r' && i < 24 ) // assuming "Carriage Return" is chosen in the Serial monitor as the line ending character
       input[i++] = c;
       
     else
     {
       input[i] = '\0';
       i = 0;
        
    
         //Parsing the input
         byte index = 0;
        ptr = strtok(input, ",");  // takes a list of delimiters
        while(ptr != NULL)
        {
            strings[index] = ptr;
           
            index++;
            ptr = strtok(NULL, ",");  // takes a list of delimiters
            
           // t0=atoi(strings[0]);
          
           // t1=atoi(strings[1]);
          
           // t2=atoi(strings[2]);
          
        }
    
      String longString = String(strings[0]);
      String intString = String(strings[1]);
      String floatString = String(strings[2]);
        
        
    
      long int dist = longString.toInt(); // returns long
      int var = (int)intString.toInt(); // returns long, so cast to int
      float rad = floatString.toFloat();
    
       TV.print(0,20, dist);
       TV.print(0,30, var);
       TV.print(0,40, rad);
    
           
       }//if
     
     }//pserial available
    
    }//loop
    • This reply was modified 5 years, 8 months ago by pedroe.
Viewing 3 posts - 1 through 3 (of 3 total)