I have a basic sketch which outputs to the serial monitor.
Without anything connected to the Arduino Uno board though except the USB cable, I am finding that the board no longer outputs to the Serial monitor on a power down (via disconnecting the serial cable and plugging it back in again).
I have found a few people with the same problem but those are old threads (as in back to 2011). I havent been able to find anything else except that "it should be fine". Am I missing something here?
When you disconnect the USB cable and reconnect it, that will break any currently open connection - you're yanking the hardware device out from under serial monitor (or whatever serial terminal you're using). You have to "close" and reopen the connection after disconnecting and reconnecting the Arduino.
When you open a connection (via serial monitor/etc) it should reset the board and the sketch should run from the beginning.
What I want to be able to do is load the Arduino with a sketch that does writes to the TXD to transmit the data to another device RXD port. Im not getting that data (I dont think) on the other device. Eventually I will be running the arduino off a battery, so if I load the sketch onto the arduino using USB I would expect that disconnecting the USB and connecting the battery should make the arduino sketch run and send the data to the TXD without a problem. Is that right?
A second question if I can. Does the Arduino send the data to the TXD serial at the same time as it sends to the Serial Monitor? i.e. should I see data at both points, or is the TXD pin "disconnected" when the serial cable is plugged in?
void loop(){
if (Serial.available()>0){
Serial.print (Serial.read() );
}
}
This should output on the Tx line whatever comes in on the Rx line, so you'll see it on the serial monitor,
and if you have something else's Rx line connected to the Tx line that device will get the data also.
If battery powered (no USB connected) the other device will see what ever you output with Serial.print.
Serial.write may be needed if you want to send 'raw' numbers vs ASCII version of a number.
See www.asciitabl.com to see the difference between a Character and its raw number equivalent (in Decimal, or Hex format (0x00 to 0xFF for bytes, or 0x0000 to 0xFFFF for ints in C++ code).
The number 0 for example. If you Serial.print ("0"); the Serial monitor will show 0, while your other device will see 0x30.
If you Serial.write(0), the device will see 0x00, while the Serial monitor will not show anything as 0 is a Null character and nothing is printed.