10 Replies Latest reply on Aug 9, 2019 2:37 AM by g_i_h

    serial communication between arduino

    menuth

      i have two arduinos connected serially meaga and uno i have a numbers 0 to 255 in the uno i should be able to read the numbers 0 to 255 from the uno to the mega and print it on the serial monitor. but i am not getting it correct. Can anyone please help me out.

      thanks in advance

        • Re: serial communication between arduino
          genebren

          Greetings,

           

          Communicating between arduinos is a well established process.  There should be plenty of examples out there of how to do this.

           

          In asking a question like this, the more information that you provide, describing the approach you are taking and the results that you are getting, the more likely it is that people are going to be able to help you.  Providing you code, and examples of the data you are getting will help people better understand the problem.  Also it helps if you can explain your skills and level of understanding of coding/computing to people can frame their response better.

           

          Best of luck with your project!

          Gene

          1 of 1 people found this helpful
            • Re: serial communication between arduino
              menuth

              i have two arduino boards hooked up serially (uno is the sender and mega is the receiver) the mega is connected to pc i need to print the data received from the sender on the serial monitor, can anyone please help me out? this the function which i'm using for it.

               

              void transmit()

              {

               

                char data[300];

                Wire.beginTransmission(0x08);

                Wire.write(0x0D);

                Wire.endTransmission();

               

               

                Wire.requestFrom(0x08, 1);  //requesting slave to send data

                x = Wire.read();

                if (x == 0x1D)

                {

                  Serial.print("slave response is: ");

                  Serial.println(x, HEX);

                  Serial1.begin(115200);

                  {

                  Serial1.readBytes(data, 255);

                  Serial.print(data);

                 }

                }} 

               

              the result which i get is some garbage values.

              please help me out

              2 of 2 people found this helpful
                • Re: serial communication between arduino
                  genebren

                  Ok, thanks for the additional information.  First off, I am not an ardunio expert (in fact I have never used one myself), but I have a lot of knowledge in writing communication software.

                   

                  First, the the good news is that you see some data.  That usually implies that things are connected correctly.  From here I would suspect things like baudrate and signaling voltages, etc.  Are the PC and arduino talking on the same baudrate? (I notice that there are two serial streams being used here, Serial and Serial1, which is talking to the PC?)  Is the ardunio communication in true RS232 levels?

                   

                  These would be my first guesses as to why you are getting garbage data back.

                   

                  Good luck!

                  1 of 1 people found this helpful
                    • Re: serial communication between arduino
                      menuth

                      serial is talking to pc and serial1 is the link between 2 arduinos. the baud rates are same. i think some logical error in programming.

                      thank you

                        • Re: serial communication between arduino
                          genebren

                          That is a pretty big jump to believe that it is about programming, as there is very little programming shown (you could simplify the programming by just outputting a simple string, over and over from the arduino to the PC).  Garbage data is a good indication that the two ends of the serial link are not talking the same language (i.e. baudrate, start/stop bits, or signaling voltage).  If you have access to an oscilloscope you could verify baudrate and voltage levels fairly easily.

                      • Re: serial communication between arduino
                        balearicdynamics

                        Hello Rabada,

                         

                        based on the code it seems you are using the SPI serial connection, or I am wrong? If so, you can follow a more reliable and better approach, IMHO.

                         

                        Enrico

                        1 of 1 people found this helpful
                        • Re: serial communication between arduino
                          fmilburn

                          There still is not enough information to give a definitive reply and your problem could be the way it is wired, the code, or both.  The posted code is incomplete and confusing - so post complete code for both the sender and the receiver.  Also indicate which pins are connected between the two Arduinos.  Are you trying to use I2C (Wire Library) or Serial (Serial1) to communicate between the Arduinos?  It appears the two are being mixed.  I suggest trying working code from the many available examples first.

                           

                          For example if trying to use I2C to communicate between the two then Arduino has this example:  https://www.arduino.cc/en/Tutorial/MasterReader .  Be sure to connect to the correct pins on the Mega for SDA and SCL.

                           

                          If trying to use Serial communication between two Arduinos then doing an internet search turns up this:  http://robotic-controls.com/learn/arduino/arduino-arduino-serial-communication .  Note that RX and TX are "crossed" when using Serial - i.e. RX connects to TX and TX connects to RX.  Serial1 works on the Mega but not the Uno.

                          4 of 4 people found this helpful
                          • Re: serial communication between arduino
                            g_i_h

                            Looks like your reading the serial buffer regardless of any data being in the buffer. Use the wire.available to check the buffer status. As other say the examples so a look of information on this.

                            3 of 3 people found this helpful