Announcement

Collapse
No announcement yet.

Send number info via Serial

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

  • Send number info via Serial

    I'm working on a project for my college and I am having issues getting my arduino to communicate with my utoled-20-G2. I'm just trying to send a string of numbers 11 digits long (ddddddddddd) that will then be interpreted and separated by the display. The display is not receiving it using the basic serial in code example I found. The arduino is an Uno and I'm running a 115200 baud rate.

  • #2


    Hello

    Can you please post your code so we have a hope to see what the problem might be?

    Thanks
    James

    Comment


    • #3


      Does it work at 9600 baud? The baud rate 'error' at 115200 may be too much for the devices to communicate
      Mark

      Comment


      • #4


        Sorry I've been busy with other things. I'll try the 9600 and post the code when I get home tonight. Thanks for the suggestion.

        Comment


        • #5
          Alright so I have tested with the terminal and it isn't working there with the 9600 or the 115200 rates... below is my code..

          Code:
          #platform "GOLDELOX"
          // Program Skeleton 1.0 generated 2/20/2014 5:50:02 PM
          
          #inherit "4DGL_16bitColours.fnc"
          #inherit "VisualConst.inc"
          #inherit "serialtestingConst.inc"
          
          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
              var incoming,d;
              setbaud(BAUD_9600);
              print("serial input Test\n");
              repeat
          
              incoming := serin();
              if (incoming == -1)
                  print("No Serial Input\n");
                  d++;
              else
          
                  txt_MoveCursor(3,3);
                  print(incoming);
          
              endif
          
              if (d== 15) SystemReset();
              pause(2000);
              forever
          endfunc

          Comment


          • #6


            You are using unbuffered serial with a 2 second pause between attempts to read from the serial port, you are unlikely to ever receive anything.

            Adding
            var combuf[10] ;

            func main()
            // Uncomment the following if uSD images, fonts or strings used.

            com_Init(combuf,20,0) ;

            around 'func main()' will get the code working a bit better
            Mark

            Comment


            • #7


              Awesome! That worked it's now receiving from the terminal. My end goal is to have it receive that string of #'s from an arduino (###########) but whenever i try to send a string of 5 numbers ##### the arduino stops transmitting. I'm using the same code and the arduino code is...

              HTML Code:
              void setup() {
                // put your setup code here, to run once:
                Serial.begin(9600);
                pinMode(0,INPUT);
                pinMode(1,OUTPUT);
              }
              void loop() {
                // put your main code here, to run repeatedly:
                int transmit;
                transmit = 12021;
                Serial.print(transmit);
                delay(500);  
              }

              Comment


              • #8


                Can't see anything wrong with that, it should just send the same number every 500ms, I would think.

                Can you see that on the terminal monitor?
                Mark

                Comment


                • #9


                  Confirmed the above (what you wrote in your last post) works fine here.

                  So all you have connected is your Arduino to USB, and monitoring the serial output, and the Arduino stops transmitting? With that exact piece of code?

                  Regards
                  James

                  Comment


                  • #10


                    After messing with it a while I noticed it sends smaller numbers (under 100) so I think it's sending numbers as an ASCII code. I'm pretty sure I just have to send and interpret single numbers at a time. I'll test it out and get back to you. But I am able to communicate between the two which is where I had the largest issue. Thanks for all your help!

                    Comment


                    • #11
                      Alright well now they aren't wanting to communicate anymore. Here is the code:

                      Display:

                      Code:
                      #platform "GOLDELOX"
                      
                      // Program Skeleton 1.0 generated 2/20/2014 5:50:02 PM
                      
                      #inherit "4DGL_16bitColours.fnc"
                      
                      #inherit "VisualConst.inc"
                      
                      #inherit "serialtestingConst.inc"
                      var combuf[10] ;
                      
                      func main()
                      //  Uncomment the following if uSD images, fonts or strings used.
                          com_Init(combuf,20,0) ;
                          print("Starting\n") ;
                          while(!media_Init())
                              putstr("Drive not mounted...");
                              pause(200);
                              gfx_Cls();
                              pause(200);
                          wend
                          var incoming,d,actual;
                          setbaud(BAUD_9600);
                          d:=1;
                          print("serial input Test\n");
                          repeat
                      
                          incoming := serin();
                          if (incoming == -1)
                      
                          else
                              if (d == 1)
                                  actual := incoming;
                                  txt_MoveCursor(5,3);
                                  actual := actual - 48;
                                  print(actual);
                              endif
                      
                              if (d == 2)
                                  actual := incoming;
                                  txt_MoveCursor(6,4);
                                  actual := actual - 48;
                                  print(actual);
                              endif
                      
                              if (d == 3)
                                  actual := incoming;
                                  txt_MoveCursor(7,5);
                                  actual := actual - 48;
                                  print(actual);
                              endif
                      
                              if (d == 4)
                                  actual := incoming;
                                  txt_MoveCursor(8,6);
                                  actual := actual - 48;
                                  print(actual);
                      
                              endif
                      
                              if (d == 5)
                                  actual := incoming;
                                  txt_MoveCursor(9,7);
                                  actual := actual - 48;
                                  print(actual);
                      
                              endif
                              if (d == 5)
                                  d := 1;
                              else
                                  d++;
                              endif
                          endif
                      
                          txt_MoveCursor(11,3);
                          print(incoming);
                          txt_MoveCursor(11,7);
                          print(d);
                          pause(500);
                          forever
                      endfunc
                      Arduino:
                      Code:
                      void setup() {
                        // put your setup code here, to run once:
                        Serial.begin(9600);
                        pinMode(0, INPUT);
                        pinMode(1, OUTPUT);
                        delay(2000);
                      }
                      int transmit, t2, t3, alt, head;
                      void loop() {
                        // put your main code here, to run repeatedly:
                      
                        transmit = transmit + 1;
                        //  t2 = 20;
                        //  t3 = 50;
                        //  alt = 30;
                        //  head = 40;
                        Serial.print(transmit);
                        delay(500);
                        //  Serial.print(t2);
                        //  delay(500);
                        //  Serial.print(t3);
                        //  delay(500);
                        //  Serial.print(alt);
                        //  delay(500);
                        //  Serial.print(head);
                        //  delay(500);
                      }

                      Comment


                      • #12


                        I actually have gotten it to communicate. It's transmitting a 255 instead of 1,2,3,4,5,6

                        Comment


                        • #13


                          In your Arduino code you appear to be writing a new number to the serial port in ASCII every 500ms.
                          So you are writing
                          0 (0x30, one character)
                          1
                          2
                          3
                          4
                          5
                          6
                          7
                          8
                          9
                          10 (0x31, 0x30 two characters)
                          11
                          12

                          In your 4DGL code you are potentially reading one character from the serial port every 500ms (amongst other things)
                          So you are reading
                          0
                          1
                          2
                          3
                          4
                          5
                          6
                          7
                          8
                          9
                          1 (1 char will be in the buffer)
                          0 (2 chars will be in the buffer)
                          1 (3 chars will be in the buffer)
                          1 (4 chars will be in the buffer)
                          This will continue until the buffer becomes full and com_Error() gets set and your program, as it is will appear to stop.

                          You need to think more about what you are doing and what you are trying to achieve. Computers do what you tell them to, not what you think you tell them to.

                          From what you have done so far and what I can see of it, I'd be using Serial.Write as that will produce a constant number of serial characters every 500ms, but that might ultimately be wrong as well as I don't know what your final goal is.
                          Mark

                          Comment


                          • #14


                            My final goal is to use the arduino to send critical values from a flight simulator to the display. It will be a total number of 5 numbers for the altitude and 3 for the heading and speed each. I'm just trying to send 5 values right now.

                            Comment


                            • #15


                              I am trying Serial.write(49); and when I run it with the same code as above it prints 0 -16 0 -16 17. meaning it receives 48,32,48,32,65. It then stops receiving anything.

                              thanks for all your help.

                              Comment

                              Working...
                              X