Serial data Transfer

Hello Arduino gurus
I am in serious need of help
I am making a Dart Scoreboard (The scoreboard is made and works fine) but I am trying to send the info to a separate Display (2 Leds and 2 Number displays (8 x 8 x 4))
So - I’m using 2 x Arduino UNO boards
One board to send (Serial) 4 pieces of information to the 2nd Arduino
(eventually this will be done via Bluetooth but at the moment Serial is fine)
: LED 1 (On/Off)
: LED 2 (On/Off)
: Score 1 Numbers (0 to 1000)
: Score 2 Numbers (0 to 1000)
Could someone PLEASE write me 2 pieces of code (Basic is fine I can sort out the fluffy bits later)
1 – how do I send the data from the Master? (4 different values at different times)
And 2 – How do I receive and split the data on the 2nd board? (4 different values at different times)
“Int” “char” “String” “parseInt” – It is not good for my brain :frowning:

Thanks in advance

Glen

The serial input basics tutorial may be of interest..

Also look up how to use the struct. That can make setting up a data packet easier.

1 Like

And it would be a good thing to know the number of bytes in the struc so your receive knows when it has all been received and can be processed.

Not how the forum works. We help you to write the code by pointing out useful tutorials and exsmples.

You try to write the code. If it does not work, tell us what the code actually does and what the code should do. Then we can suggest changes. We have been very successful at helping those that want to learn.

The alternative is to move your thread to the
Jobs and paid consultancy section. Expect to pay for someone to write code.

So, study the serial input basics tutorial and give it a try. Do one step at a time.

Hi groundFungus
Thanks for the reply and links
I'm sure I have read the whole internet and it is becoming very evident that I am as thick as mince because none of it is sinking in (to many paths to go down).
this is why I have reached out to the knowledgeable Arduino community for 2 pieces of code to get me started with.
Thanks again and merry Christmas :slight_smile:
Glen

Sadly, OP, the way you’re phrasing your post, begs the question “Do you want to be a programmer, or a darts player?”

You CAN be both, but both activities need discipline, learning, time and practice.

I also recommend the Serial Input Basics tutorial linked above. That will get you started transferring data between Arduinos. Might take part of a day or so.

Thanks

Post here if you want someone to just write it for you. Let them know what you're willing to pay up front or you won't get much action.

Thanks for the input - I now feel I am a better person because of it.
I just cant figure out how to split 4 lots of incoming data
however I could just use a whiteboard...
Merry Christmas

1 Like

There is no need to "figure out how", as that is explained in the Serial Input Basics tutorial.

Please, give an example of these four pieces of data items that you waant to send from UNO-1 to UNO-2 using UART Port.

Hi
The data sent would be:
anything to turn on a LED 1 (maybe "A" or "1")
anything to turn on a LED 2 (maybe "B" or "2")
Score 1 is a number from 0 to 1000
Score 2 is a number from 0 to 1000
Thanks

1 Like

Really if you carefully read the tutorial and run the examples you will get what you need.

It is helpful to use 2 separate Arduinos to run the examples of course. One as the sender and one as the receiver. You will need 2 separate instances of serial monitor running. To do that you must have 2 separate instances of th IDE running. Then set each instance to the required serial port. If you can't set the 2 instances to separare ports, they are not separate instances.

Do things a bit at a time. Run the first example. Get it to work. Play with it till you understand all about it. Then move to the next. If you want to learn, you will pick it up. I did, so you can.

Will do
Thanks for a good direction to start at
I have set up the 2 Arduino's 2 x serial comms and some basic code.
I will just have to be a little more persistent (and patient)
cheers

If you get stuck, we are ready to help.

why not send the four values separated with commas as an ASCII c-string (char [], not String) terminated with a linefeed, '\n'? use sprintf() to format the c-string

on the receive side, you can use Serial.readBytesUntil() to read the complete string up to the linefeed, then use strtok() to locate each field delimited by the commas and use atoi() to convert the c-sub-string to an integer.

first get sending and receiving a linefeed terminated c-string working, then separating the fields and finally converting then to integers

The method that @gcjr describes is shown in example 5 of the basics tutorial. Work through all the examples and it will be easier to understand.

1. Connect UNO-1 and UNO-2 as per Fig-1.


Figure-1:

2. Upload the following sketches to transmit <A,B,234,567> from UNO-1 to UNO-2 and receive the same string by UNO-2. The SM2 shows: A, B, 234, 567. The data items are saved in variables:

char y1;
char  y2; 
int y3;
int y4;

UNO1/TX Sketch:

#include<SoftwareSerial.h>
SoftwareSerial SUART(A4, A5); //SRX = A4, STX = A5
char y1 = 'A';
char y2 = 'B';
int y3 = 234;
int y4 = 567;

void setup()
{
  Serial.begin(9600);
  SUART.begin(9600);
}

void loop()
{
  SUART.print('<'); //start mark
  SUART.print(y1); //data for LED1
  SUART.print(','); //seperator
  SUART.print(y2); //data for LED2
  SUART.print(','); //start mark
  SUART.print(y3, DEC); //data for ScoreBoard 1
  SUART.print(','); //seperator
  SUART.print(y4, DEC); //data for ScoreBoard 2
  SUART.print('>'); //end mark
  delay(1000);
}

UNO-2/RX Sketch:

#include<SoftwareSerial.h>
SoftwareSerial SUART(A4, A5); //SRX = A4, STX = A5
char myData[30];
char *token;

void setup()
{
  Serial.begin(9600);
  SUART.begin(9600);
}

void loop()
{
  byte n = SUART.available();
  if (n != 0)
  {
    char ch = SUART.read();
    if (ch == '<') //start mark found
    {
      byte m = SUART.readBytesUntil('>', myData, sizeof myData - 1);
      myData[m] = '\0';   //null-charcater
      Serial.println(myData);
      //--------------------------
      token = strtok(myData, ",");
      char y1 = *token;
      Serial.println(y1);  //y1 = A
      //-------------------------
      token = strtok(NULL, ",");
      char y2 = *token;
      Serial.println(token);   //y2 = B
      //-------------------------
      token = strtok(NULL, ",");
      int y3 = atoi(token);
      Serial.println(y3, DEC);  //234
      //-------------------------
      token = strtok(NULL, ",");
      int y4 = atoi(token);
      Serial.println(y4, DEC);  //567
    }
  }
}

3. Connect LED1 with a 2.2k series resistor at DPin-4 of UNO-2 and conditionally use the value of y1 to control the On/Off state of LED1.

4. Connect LED2 with a 2.2k series resistor at DPin-5 of UNO-2 and conditionally use the value of y2 to control the On/Off state of LED2.

5. Connect 4-digit cc-type 7-segment display unit (Score Board 1) as per Fig-2 and show the value of y3 of Step-2. Add codes with the sketches of Step-2 to show 234 on DP1-DP3 of display unit.
cc4Digit
Figure-2:

6. Add four more cc-type 7-segment display devices with Fig-2 to form Score Board 2 (Fig-3, DP4 - DP7). Add codes with the sketches of Step-2 to show 567 on DP4-DP7 of display unit.


Figure-3:

A BIG thank you to all for your assistance and guidance
I think I am on a path to some sort of success :slight_smile:
Kind Regards
Glen