Announcement

Collapse
No announcement yet.

Problem sending string via serial.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem sending string via serial.

    Hello all,
    I am making a program in which I have to convert 'Speech to Text' in Processing(processing.org) and print the result on my OLED via serial communication.


    The processing sketch generates the result/text but the string doesn't reach the OLED. Can someone help/check what might be the best way to fix this?

    Thanks
    PS: My last project was https://vimeo.com/71064267


    4D Workshop side code

    Code:
    #platform "GOLDELOX"
    
    #inherit "4DGL_16bitColours.fnc"
    
    #platform "GOLDELOX"
    
    #inherit "4DGL_16bitColours.fnc"
    
    func main()
    //  Uncomment the following if uSD images, fonts or strings used.
    
      //  print("Starting\n") ;
        //while(!media_Init())
          //  putstr("Drive not mounted...");
            pause(200);
            gfx_Cls();
            pause(200);
     //   wend
    
    gfx_Cls();
    
    setbaud(BAUD_9600); // this must match the Arduino Mega
    
    var combuf[50]; // a buffer for up ;to 20 characters
    //putstr("Default 115.2kb");
    com_Init(combuf, 50, 0); // initialize small circular queue of 50
    
    var char := -1;
    
    var count := 0;
    var p[4];
    var frame;
    
    var wordBuf[24];
    var state := 0;
    var parity := 0;
    var wordCharCount := 0;
    var finWord[24];
    // bytes, no qualifier
    
    //#IF (LANGUAGE == 1)
    
    repeat
    //putstr(char);
        char := -1;
        if(com_Count()) // if there is a character available
            //serout(serin()); // echo it back to host
            if(com_Count() > 10)
                putnum(DEC, com_Count());
                putch('\n');
            endif
            char := serin();
            com_Init(combuf, 50, 0);
        endif
    
        if(char != -1)
            //_<scheme>^
            if ((char == '_')&&(state== 0))
                // start recieving characters into wordBuf
                state := 1;
                wordCharCount := 0;
                parity:= 0;
            endif
    
            if ((char == '^')&&(state == 1))
                // stop recieving characters into wordBuf and print what you have, reset state
                gfx_Cls();
                gfx_MoveTo(0, 75);
                txt_Height(2);
                txt_Width(2);
                //set zero to terminate string
                wordBuf[wordCharCount] := 0;
                wordCharCount := 0;
                state := 0;
                parity := 0;
                putstr(wordBuf);
            endif
    
            if ((char != '^')&&(char != '_')&&(state == 1))
                // add this character to wordBuf
                // state remains the same
                // increase pointer
                if (parity == 0)
                    wordBuf[wordCharCount] := char;
                    parity := 1;
                else
                    wordBuf[wordCharCount] := (wordBuf[wordCharCount] | (char << 8));
                    wordCharCount := (wordCharCount + 1);
                    parity := 0;
                endif
            endif
    
            if ((char != '^')&&(char != '_')&&(state == 0))
                // do nothing
                state := state;
            endif
    
            repeat
                pause(1);
            until (com_Count() > 0);
        endif
    
        gfx_Cls();
    forever
    endfunc



    Processing Server code( For speech to text translation) using STT library within processing

    Code:
    import com.getflourish.stt.*;
    import processing.serial.*;
    
    STT stt;
    String result;
    String key = "My_API_KEY";
    Serial displayPort;
    int serialDelay; // how long to "pause" between sending data to the display
    
    void setup ()
    {
      size(600, 200);
      // Init STT automatically starts listening
      displayPort = new Serial(this, "COM3", 9600);
      serialDelay = 1200;
    
      stt = new STT(this, key);
      stt.enableDebug();
      stt.setLanguage("en");
      stt.enableAutoRecord();
      
      // Some text to display the result
      textFont(createFont("Arial", 24));
      result = "Say something!";
    }
    
    void draw ()
    {
      background(0);
      text(result, mouseX, mouseY);
    }
    
    // Method is called if transcription was successfull
    void transcribe (String utterance, float confidence)
    {
      println(utterance);
      result = utterance;
      result = "_" + result;
      result = result + "^";
      println(result);
      displayPort.write(result);
      delay(100);
      displayPort.write(result);
      delay(100);
      displayPort.write(result);
    
    }
    Last edited by greendawnhaze; 20 May 2014, 04:05 PM. Reason: formatting

  • #2
    The Goldelox 'bit' seems to work fine for me using Terminal.

    What do you see if you connect your Pogramming cable's (PA5, whatever) RX to your controller's TX and use terminal to monitor it?
    Mark

    Comment


    • #3
      Both sides are compiling fine. I have no problems receiving simple character strings on 4d side. I use this method.

      Code:
       if(char != -1)
              if (char == 97) // the letter "a" in ASCII
                  gfx_MoveTo(0, 75);
                  txt_Height(2);
                  txt_Width(2);
                  putstr("Assistant");
                  repeat
                      pause(1);
                  until (com_Count() > 0);
              endif

      I just want to make sure why am I not able to receive text strings and print them on the display.

      4d program works fine with the 9600 Terminal. Help please!

      Comment


      • #4
        I'm not familiar with your controller, maybe displayPort.write(result); doesn't/can't write a string?
        As I said
        Originally posted by ESPsupport View Post
        What do you see if you connect your Pogramming cable's (PA5, whatever) RX to your controller's TX and use terminal to monitor it?
        Mark

        Comment

        Working...
        X