Hi all,
This maybe is an old issue. I tried searching in the forum but in vain.
I am trying to communicate a Leonardo with an UNO through USB.
Leonardo - OTG USB - USB - Uno(Type B connector)
Both the devices seem to work in the serial monitor of Arduino IDE(running in a Windows8).
But when i connect them, i am not able to get the serial data.
Kindly find my sketches attached.
Uno sketch:
#include <LiquidCrystal.h>
const char len_sTx = 8, len_sRx = 8;
byte sTx[len_sTx], sRx[len_sRx];
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
void setup() {
// put your setup code here, to run once:
Serial.begin(262144);
lcd.begin(16,2);
}
void loop() {
char i;
if(Serial.available() > 0)
{
Serial.readBytes(sRx, len_sRx);
sTx[0] = sRx[7];
}
lcd.setCursor(0,0);
lcd.print("Rx:");
for(i = 0; i < len_sRx; i++)
{
lcd.setCursor(i+3,0);
lcd.print(sRx[i]);
i++;
}
for(i = 1; i<len_sTx; i++)
{
sTx[i] = sTx[i-1] + 1;
}
Serial.write(sTx, len_sTx);
lcd.setCursor(16,1);
lcd.print("Tx:");
for(i =0; i < len_sTx; i++)
{
lcd.setCursor(i+19,1);
lcd.print(sTx[i]);
i++;
}
delay(500);
}
Leonardo sketch:
const char len_sTx = 8, len_sRx = 8;
byte sTx[len_sTx], sRx[len_sRx];
char flag_sTx = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(262144);
while(!Serial){
;
}
}
void loop() {
char i;
// put your main code here, to run repeatedly:
if(flag_sTx == 0)
{
sTx[0] = 49;
flag_sTx = 1;
}
else
{
if(Serial.available() > 0)
{
Serial.readBytes(sRx, len_sRx);
sTx[0] = sRx[7];
}
}
for(i = 1; i<len_sTx; i++)
{
sTx[i] = sTx[i-1] + 1;
}
Serial.write(sTx, len_sTx);
delay(500);
}
I am not sure what I am doing wrongly here.
The sketches does the nearly same job. Gets the array from a serial, uses the last element alone as the first element, increments the values of other elements and sends it back.
