UART API for Two Microcontrollers

be80be

Joined Jul 5, 2008
2,395
Dear god I'm not confused you all going down the wrong road here.
Can none of you read I said it liked ASCII what did it print
if you all read what I said
I said you can send whatever you want just takes more work

I really got no time for this
I no how to send data the TS ask about better ways the AT to send Hex time they add code to print what they need
At is going to look a lot better
 

philba

Joined Aug 17, 2017
959
Sigh. I certainly hope no one is confused by this. Binary data CAN be sent via the Arduino libraries and the underlying AVR microcontrollers. It's a clearly demonstrable fact.

If you have a better way, show it so we can all learn.
 

be80be

Joined Jul 5, 2008
2,395
Robin tells this better I can send whatever this was about easy the built in command don't even have good examples
And lot's of people run into where they think there sending raw numbers and there sending text .
happens a lot with case test from one uC to the next

Introduction
============
Newcomers often seem to have difficulty with the process of receiving Serial data on the Arduino - especially when they need to receive more than a single character. The fact that there are 18 different functions listed on the Serial reference page probably does not help

You could write a small book and still not cover every possible situation for data reception. Rather than write pages and pages that few would read I thought it would be more useful to present a few examples which will probably cover all of a newcomer's needs. And when you understand these examples you should be able to figure out solutions for other strange cases.

Almost all serial input data can be covered by three simple situations

A - when only a single character is required
B - when only simple manual input from the Serial Monitor is required
C - other
 

be80be

Joined Jul 5, 2008
2,395
philba In post 13 what did it send the code is right out of the arduino reference

The code said it sending 45 and hello thats not my code thats the arduino reference code
Now you said it sent 45 because - is 45

Tell me what is - is that a ASCII or is that what most people call 45 hell no that text.
Now to send numbers even things as simple as 1 2 3 which are bytes if some one new is not careful they be sending 49 50 51

Say that new person has a program running and looking for a 1 if they don't no they will spend a lot of time trying to figure out why
there code sends 1 but the monitor now if you use the monitor to send a 1 it sends 49
which is not what the code is looking for.

You have to write code for both one to format to the monitor and one to read the ASCII
from the monitor

Now I post that arduino is more about ASCII It's is and you have to see what is being sent
Well you can't with the serial monitor that ships with the arduino Ide there no lets's send raw numbers on it and anything you send is in text ASCII
 
Last edited:

philba

Joined Aug 17, 2017
959
No, it sent the binary value of 45 dec. The arduino library code has NO IDEA what it is sending. It doesn't know ASCII, integer or any other data type. It's job is to send some bits. just bits. Period.

On the PC, the arduino terminal program gets the bits from the USB emulation of a UART com port (which has NO IDEA of what it is). In the end the arduino terminal program knows what it is and prints a '-' on the screen.

And again I ask, what part of the code example I posted don't you understand? That shows very clearly that you can send and receive binary data with Arduinos. Let's talk about how that squares up with your comment
You may as well forget the arduino it sends everything out ASCII .
 

be80be

Joined Jul 5, 2008
2,395
OK, one last try. Did you actually read my example? What part did you not understand?
Why would I I like mine better
C:
const int redPin = 3;

// Example 3 - Receive with start- and end-markers

const byte numChars = 32;
char receivedChars[numChars];

boolean newData = false;

void setup() {
    Serial.begin(115200);
    Serial.println("<Arduino is ready>");
}

void loop() {
    recvWithStartEndMarkers();
    showNewData();
}

void recvWithStartEndMarkers() {
    static boolean recvInProgress = false;
    static byte ndx = 0;
    char startMarker = '<';
    char endMarker = '>';
    char rc;
    while (Serial.available() > 0 && newData == false) {
        rc = Serial.read();

        if (recvInProgress == true) {
            if (rc != endMarker) {
                receivedChars[ndx] = rc;
                ndx++;
                if (ndx >= numChars) {
                    ndx = numChars - 1;
                }
            }
            else {
                receivedChars[ndx] = '\0'; // terminate the string
                recvInProgress = false;
                ndx = 0;
                newData = true;
            }
        }

        else if (rc == startMarker) {
            recvInProgress = true;
        }
    }
}

void showNewData() {
    if (newData == true) {
        Serial.print("This just in ... ");
        Serial.println(receivedChars);
        newData = false;
        if (receivedChars == 5 )
        {
          digitalWrite(redPin, HIGH);
        }
        else
        {
         digitalWrite(redPin, LOW);
        }
    }
}
 
Last edited by a moderator:

be80be

Joined Jul 5, 2008
2,395
No, it sent the binary value of 45 dec.
Does billy bob no that I sure when
he try's to send a 1 and a 2 his code needs to be like this
C:
if (Serial.available() > 0)
  {
    serialData = Serial.read();
    if (serialData == 49) digitalWrite(ledPin, HIGH);
    else if (serialData == 50) digitalWrite(ledPin, LOW);
    Serial.println(serialData);
  }
And you still saying the serial monitor handes raw numbers it does not
 

philba

Joined Aug 17, 2017
959
Yeah, I kind of thought something like that would be the response. OK, I'm just going to say this very clearly so others will understand:

The Arduino system supports sending and receiving binary data. Do not believe that it sends things out in some other format. Ignore all the ASCII blather. That's completely irrelevant. It is up to you, the programmer, to decide how to send and receive things.

However, if you want to send data to a program that interprets things in ASCII, then it behooves you to send the data in a way that it will understand. That point is tangential, at best, to the question of whether an Arduino can send or receive binary data.
 

philba

Joined Aug 17, 2017
959
Show me where I said the serial monitor (aka Arduino terminal) handles raw numbers?

Does billy bob no that I sure when
he try's to send a 1 and a 2 his code needs to be like this
C:
if (Serial.available() > 0)
  {
    serialData = Serial.read();
    if (serialData == 49) digitalWrite(ledPin, HIGH);
    else if (serialData == 50) digitalWrite(ledPin, LOW);
    Serial.println(serialData);
  }
And you still saying the serial monitor handes raw numbers it does not
 

be80be

Joined Jul 5, 2008
2,395
I really don't care first off I just pointed out that you have to no what your sending and the arduino is set up for ASCII
which it is. the serial monitor has no means to show raw data type and the library for arduino are more for formatting text then numbers

I never said you cant send any numbers I said you have to first figure what is being sent and you do
Have a good life.
 
Top