Go Down

Topic: help with TX / RX communication (Read 374 times) previous topic - next topic

Bartsmetsers

I now have a parking heater for my boat. I have used an arduino uno for the parking heater and there the control program with all kinds of safety in it. 2 push buttons for "on / off" and "reset fault". what I have now works perfectly.
In addition, I now have an Arduino Mega with tft touchscreen and dht22 sensor. Here in for now only a thermostat program. in the end this should therefore become a multifunctional control unit.
now I do not need much for communication.
the thermostat only needs to transmit "on", "off" and "half power" and display an "error message" on the screen next to it.
so the controller unit must therefore receive "on", "off" and "half power" and send a possible "error message".

want to do this via the RX / TX though I do not know what will work best with multiple units in the end.

who can help me in this.
am very new with programming (20 years ago Qbasic). I was fine with that but I'm not getting the hang of this yet
 pffff.

I'm looking for something from a simple example or something from where I can go further.

with my ADHD and unrest in my head now I do not pick it up too quickly and I get the best out of it with common simple examples.

who can help me with this?

Robin2

want to do this via the RX / TX though I do not know what will work best with multiple units in the end.
I don't understand what you mean by multiple units. Earlier you have just mentioned an Uno and a Mega.



Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

The technique in the 3rd example will be the most reliable. It is what I use for Arduino to Arduino communication.

You can send data in a compatible format with code like this (or the equivalent in any other programming language)
Code: [Select]
Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker


...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Bartsmetsers

for now I only use the mega with lcd as a thermostat for the heating.
and UNO for controlling the heating itself. so I have to be able to switch twice with the MEGA ("on / off and" high / low ") via RX / TX on the UNO and display an error message from the UNO on the MEGA later on, it must also show disturbances of other arduinos .
finally it becomes a large operating system with no less than 5 arduinos. most a mega

I saw the example you mentioned but I do not get it right in my head now.

Maybe someone has an example with the functions that I need for this.

I would be very grateful to you.

have been working on this project for 3 weeks now. learned a lot now but the pressure is too high.
the heating had long been supposed to burn on my boat now.
everything is moldy by the moisture now so I do not have the necessary peace in my head now to find this out myself and I really need help here

Robin2

#3
Feb 11, 2019, 10:13 am Last Edit: Feb 11, 2019, 10:14 am by Robin2
for now I only use the mega with lcd as a thermostat for the heating.
and UNO for controlling the heating itself. so I have to be able to switch twice with the MEGA ("on / off and" high / low ") via RX / TX on the UNO and display an error message from the UNO on the MEGA later on, it must also show disturbances of other arduinos .
finally it becomes a large operating system with no less than 5 arduinos. most a mega
Sorry but I find your description very confusing.

What is in charge - the Mega or the Uno?  Is the Mega sending ON/OFF etc commands to the Uno or is the Uno sending them to the Mega?

Assuming the Mega is in charge then all it needs to do is send "<N>" for ON,  "<F>" for OFF, "<H>" for HIGH and "<L>" for LOW. The third example in my Tutorial shows how to receive data like that.

It will make debugging easier if you use SoftwareSerial on the Uno to receive the messages from the Mega as that will leave HardwareSerial free for sending debug messages to the Arduino Serial Monitor.

And use Serial1 on the Mega to talk to the Uno.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Bartsmetsers

Well there is nothing about sending.
but I also see nothing in it what reacts to the received data. Beyond that it is shown on the serial monitor.

is not going well here.

today had a car accident. my head is too full now.
and this project must get to work as quickly as possible.
and at the moment I do not understand this piece of RX / TX at all.
do not get it together in my head really annoying now.

someone else something I can use as an example?

preferably a complete example which, for example,
sends a leter to the other and lights a LED with it.

 Something in that spirit I have to be able to work with now I think

Robin2

#5
Feb 11, 2019, 11:34 pm Last Edit: Feb 11, 2019, 11:34 pm by Robin2
Well there is nothing about sending.
Did you read Reply #1 carefully? I wrote it on the assumption that you would.

Quote
but I also see nothing in it what reacts to the received data. Beyond that it is shown on the serial monitor.
I thought I should leave a little bit of the work for you.

If you just want someone to write a program for you please ask in the Gigs and Collaborations section of the Forum and be prepared to pay.

...R

Two or three hours spent thinking and reading documentation solves most programming problems.

Bartsmetsers

Did you read Reply #1 carefully? I wrote it on the assumption that you would.
I thought I should leave a little bit of the work for you.

If you just want someone to write a program for you please ask in the Gigs and Collaborations section of the Forum and be prepared to pay.

...R


No, it certainly is not. I do not vaguely write a program for me. I am looking for examples of which I understand the work so that I can learn from them.
I have found this now:

https://iotguider.in/arduino/serial-communication-between-two-arduino-boards/

But after having studied it 10 times, I have 2 questions about this example.

1st question:

char mystr [5] = "Hello"; // String data

what is the 5 connected to? the number of letters of HELLO?

2nd question:
can i of this:
Serial.println (mystr); // Print data on Serial Monitor
unpunished to make something of:

if (mystr) = on
 else if (mystr) = off
   else if ...............

or do I still take it completely wrong?

Robin2

#7
Feb 12, 2019, 10:12 am Last Edit: Feb 12, 2019, 10:14 am by Robin2
1st question:

char mystr [5] = "Hello"; // String data

what is the 5 connected to? the number of letters of HELLO?
Yes. However there is BIG error in that code. It should be
Code: [Select]
char mystr [6] = "Hello";
because as well as the 5 characters there must be space for the terminating NULL character. This is a serious error because without the correct space the data will spill over and corrupt memory for something else.

Quote
2nd question:
can i of this:

Serial.println (mystr); // Print data on Serial Monitor
Yes

Quote
unpunished to make something of:

if (mystr) = on
 else if (mystr) = off
   else if ...............
I don't know what the word "unpunished" is for.

There are three mistakes in this piece of code.
  • You must always use == with an IF clause.
  • Your brackets are wrong
  • And you cannot do if (mystr == "off") { - that is not how you check if a cstring matches. You need to use the strcmp() function.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Bartsmetsers

i have this in the mega:

if (mySerial.available() > 0) {
    int inByte = mySerial.read();
    Serial.println(inByte);
    // do something different depending on the character received.
    // The switch statement expects single number values for each case; in this
    // example, though, you're using single quotes to tell the controller to get
    // the ASCII value for the character. For example 'a' = 97, 'b' = 98,
    // and so forth:

    switch (inByte) {
      case 'a':
        rxtxcon=1;
        break;
      case 'b':
        rxtxcon=2;
        break;
      case 'c':
        rxtxcon=3;
        break;
      case 'd':
        rxtxcon=4;
        break;
      case 'e':
        error=0;
        mySerial.write("e");
        Serial.println("ERROR RESET");
        break;
      default:
        {
          Serial.println(rxtxcon);
          return;
        }
    }
  }
 Serial.println(mySerial.read());


and this in the Uno:

if(sw==1)
  {Serial.println("sent a");
   Serial1.write("a");
   sw=0;
  }
  if(sw==2)
  {Serial.println("sent b");
   Serial1.write("b");
   sw=0;
  }



it gives me a 255 output instead of an "a" on the Mega,

but if i sent the "a" with the serial monitor it will work!
what am i doing wrong??

Robin2

i have this in the mega:
Please post the complete program.



When posting code please use the code button </>


Code: [Select]
so your code looks like this
and is easy to copy to a text editor See How to use the Forum

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Bartsmetsers

this is in the Uno.
Uno is thermostat.

https://create.arduino.cc/editor/Bartsmetsers/e233de3c-ae7a-46b4-97e9-a0e5b209ca8c/preview

is to big to copy/paste

this is the Mega.
Mega is the heater controller

https://create.arduino.cc/editor/Bartsmetsers/4e7e7f20-ba8d-4b3f-b619-b06cfc110f96/preview

also to big to cppy/paste

Robin2

is to big to copy/paste
Then please add the .ino file as an attachment to your next Post.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Bartsmetsers


Robin2

Between your two program there is about 31k of code.

Sorry, but I am just too lazy to wade through all of that. Is it not possible to create a short program or pair of programs that illustrates the problem you want help with and nothing more?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Bartsmetsers

have the Uno working.
Also have the mega working.
But if I operate the Uno with the push buttons it works 100%.
But if, for example, I get a start comando from the mega on the Uno, he is stuck in a few lines.
the Uno also runs more often when he is not connected to the mega.

would it be too much for an Uno and should I go to the mega?

this is when the Uno is manually operated:

<Arduino is ready>
myserial started
START PROCEDURE:
1
   - Ventilator HIGH
   - Glow Plug HIGH
   - H_L HIGH
   - Fuel Pump HIGH
STARTEN MISLUKT
gloeispiraal LOW
brandstofpomp LOW
START PROCEDURE:
2
   - Ventilator HIGH
   - Glow Plug HIGH
   - H_L HIGH
   - Fuel Pump HIGH
   - Glow Plug LOW
START PROCEDURE COMPLETE

READY FOR ANOTHER COMMAND

and here he hangs on the mega's comando:

<Arduino is ready>
myserial started
a
START PROCEDURE:
1
   - Ventilator HIGH

and does not do anything anymore to a reset!


Go Up