I am new to Arduino programming and I have trouble with a task I would like to perform. I have a scale which is able to communicate via serial port. For example, I can turn the scale on and off, or I can ask for the scaling value. The manual of the scale states that if I send the sign combination SS + CR + LF, I can turn the scale on or off. So I would like to write a quick program which does exactly that. I am using a Mega 2560 and I have the wiring from the scale with RX, TX and GND. I connected GND to Arduino GND for common ground, and then I connected RX and TX to TX0 and RX0. Now I have already some problems in understanding the difference between Serial.print and Serial.write. Whats the difference? The example code I am running and which does nothing, is as follows
Thank you for your help! Unfortunately, it still does not work. There were minor mistakes in your code, but only a missing ' and a missing }. So after that fix, still nothing is happening. Right now I could imagine that the scale has some kind of setting which is not set up properly. I will consult the customer support of the scale and ask them if there is such setting. If I find out if thats the problem, I will post again.
The shape of the connector in the image in Reply #3 (and the reference at the top of the image to "RS232C") strongly suggest that the scale operates at RS232 voltage levels rather than the TTL voltage levels that an Arduino uses. RS232 voltage levels can damage an Arduino - as well as being unintelligible.
You need an RS232 to TTL serial adapter such as a MAX232.
The extra serial ports are Serial1 (RX1=pin 19, TX1=pin 18), Serial2 (RX2=pin 17, TX2=pin 16) and Serial3 (RX3=pin 15, TX3=pin 14). Those ports are used the same as Serial (USB. RX0 and TX0).
Can you upload sketches (like Blink) to the Mega? If not, you may have damaged the board by connecting the high voltage RS232 signals.
loewph: @david_2018 And how do I implement which TX RX I want to use?
Instead of Serial, use Serial1 for TX1/RX1, Serial2 for TX2/RX2, or Serial3 for Tx3/RX3. Each serial port has its own baud rate, so you can run the scale at 4800 baud and the serial monitor at 19200 simultaneously.
Alright, blink does compile and runs without any problems (LED blinks on the board), so the boards seems to be ok. I changed the code from Serail to Serial1, however, I do not get any output on the serial monitor any more. i picked the baud rate for Serial1 to 4800, that should not be a problem in this case, or should it?