mikedb
March 11, 2024, 7:17pm
1
Hi Everyone.
I connected the Serial pins on two Nanos TX Pin to RX Pin.
The one Nano sends "PROGRAM".
The Receiving Nano only print "PROGRAM" on the LCD if there is a Serial.print funtion on the first line below void loop() it also works even when the Serial cable to my PC is not connected.
When I remove the first Serial.print in void loop() the LCD only shows "P" and 6 blocks.
Thanks.
void setup()
{
Serial.begin(9600);
delay(1000);
Serial.write("PROGRAM");
}
void loop()
{
}
Receiver side.
#include <LiquidCrystal.h>
const unsigned int numReadings = 7;
unsigned int myArray[numReadings];
int counter = 0;
int doneRead = 0;
char myChar = 0;
// RS E D4 D5 D6 D7
LiquidCrystal lcd(A4, A3, 4, 5, 6, 7);
//----------------
void setup()
{
Serial.begin(9600);
lcd.begin(20, 4 );
lcd.setCursor(0, 3);
lcd.print("LCD_Serial_Read");
delay(1000);
//lcd.clear();
}
void loop()
{
Serial.println("start");//Only works if this line is here.
if (Serial.available())
{
Serial.println("serial avail");
for (unsigned int i = 0; i < numReadings; i++)
{
myArray[i] = Serial.read() ;
Serial.println("serial read");
}
lcd.setCursor(0, 0);
for (unsigned int i = 0; i < numReadings; i++)
{
char aaa = ( myArray[i]) ;
lcd.print (aaa);
lcd.print(" ");
Serial.print(aaa);
counter ++;
if (counter == 7)
{
while (1)
{}
}
}
}
}
xfpd
March 11, 2024, 8:32pm
2
mikedb:
below void loop()
You have no function below loop().
mikedb
March 12, 2024, 5:19am
4
After compilation Serial.print() will get replaced by the Library function.
So why not just call it a function .. a choice of words.
So the Serial.print(); inserts a small delay so the read buffer will catch all the bytes?
mikedb
March 12, 2024, 5:57am
5
I found this.
http://www.gammon.com.au/serial
I have not seen any examples where a small delay is used between Serial.read();
xfpd
March 12, 2024, 12:44pm
7
This link explains (briefly) the physical/electrical reason using hardware serial (Uno/Nano Tx/Rx/Pin0/Pin1) will not work.
You will not be able to send from the PC to an arduino when the Rx line of that arduino is connected to the Tx line of another arduino. The Tx from the USB-to-serial chip is fed to the Rx of the atmega328 through a resistor, the Tx from the other arduino will overpower the signal from the USB-to-serial chip and it will never reach the atmega328.
This link (shortly following the link above) says you should use software serial and shows how this will work.
You need an Example/Tutorial. Follow these steps, see the output, and then write your own sketch to reproduce the results.
1. Connect UNO-1 and UNO-2 as per diagram of Fig-1 using Software UART (SUART) Port. The Hardware UART Ports of both UNOs are engaged with PC/SM for sketch uploading and debugging.
[uartUNO-UNO]
Figure-1:
2. Upload the following sketch (not tested) in UNO-1 (Arduino-1).
#include<SoftwareSerial.h>
SoftwareSerial SUART(7, 8); //SRX = 7, STX = 8
void setup()
{
Seria…
AND... the following link shows how to use ONE Arduino (the example is using Mega2560) to configure TWO serial ports to do the tx/rx...
https://docs.arduino.cc/tutorials/communication/TwoPortReceive/
1 Like
mikedb
March 12, 2024, 1:32pm
8
I still dont get it , is that not what I am doing?
I removed the Serial.print(); in the void loop(); and replace it with delay(100); and this works , " P R O G R A M" is printed on the LCD every time.
I have 2 Nanos RX TX pins cross connected with the Serial USB Cable connected to my PC and "PROGRAM" is printed on the LCD and also in the Serial monitor.
I can however not program the Nano while the RX TX pins is connected , that's why I have 2 header pin that can be removed when programing.
See Photo.
Latest code with delay in first line of void loop();
While(1) stop removed.
mikedb
March 13, 2024, 5:11am
10
Thanks , yes took me way to long to "see" what was wrong.
Thanks for the Link , very interesting.
system
Closed
September 9, 2024, 5:12am
11
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.