Problem with mySerial communication


hi everyone. want send 2 numbers (coordinates x , y) arduino nano arduino leonardo. here code arduino nano:

code: [select]
#include <wire.h>
#include <softwareserial.h>


byte adress = 0x04;
byte data[10]= {0x03,0x03,0x0a,0x01,0x41,0,0,0,0,0};
int i=0,x,y;
byte c[10];
softwareserial myserial(8,9);//rx,tx

void setup() {

wire.begin();
serial.begin(57600);
myserial.begin(57600);

wire.begintransmission(adress);
wire.write(data,10);
wire.endtransmission();
}

void loop() {
wire.requestfrom(4,10);
while(wire.available()){
      for(i=0;i<=9;i++){
      c[i] = wire.read();
      x=c[5];
      y=c[3];
      myserial.write(x);
      myserial.write(y);
     
      }}           
serial.print("\n");
serial.print("x is:");
serial.println(x);
serial.print("y is:");
serial.println(y);

}     


in nano correct , shows values want (shows correct number of x , y sent through myserial).

then, here code leonardo:
code: [select]

#include <adafruit_neopixel.h>
#include <softwareserial.h>

adafruit_neopixel strip = adafruit_neopixel(567,6, neo_grb + neo_khz800);
softwareserial myserial(8,9);
byte c[2];
int led,x,y;
void setup() {
  myserial.begin(57600);
  serial.begin(57600);
  strip.begin();
  strip.show();
  x=0;
  y=0;
  }

void loop(){

if(myserial.available()){
  myserial.readbytes(c,2);//here don't know function have use
 
  x=c[0];
  y=c[1];
  }
  serial.print("x:");
  serial.println(c[0]);
  serial.print("y:");
  serial.println(c[1]); 


it shows me x , y values 0 255 real x , y goes 0 127. how can fix it? thanks



Arduino Forum > Using Arduino > Programming Questions > Problem with mySerial communication


arduino

Comments