Howdy,
Just having some issues getting communication between an A-Star 32u4 ULV (Arduino micro clone) and a Arduino MKR WiFi 1010
This is the code I am using on both:
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(57600);
Serial.println("Goodnight moon!");
// set the data rate for the SoftwareSerial port
Serial1.begin(4800);
Serial1.println("Hello, world?");
}
void loop() { // run over and over
Serial.println(Serial1.read());
Serial1.write(random(512));
}
They’re connected together by RX and TX ports and same ground - I had previously been using a logic level shifter between the two but found this was causing major issues.
Currently, the A-Star outputs the random numbers (sent from the MKR) correctly. However, the MKR constantly outputs “-1” on the serial monitor.
Please use the .available method of either serial or softwareserial before reading data. In a tight loop such as in your code, data will only be available at best once in every couple of milliseconds, or after about 2000 cycles.
Thanks for that - I had forgotten about that limitation.
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(57600);
Serial.println("USB Serial...");
// set the data rate for the Serial1 port
Serial1.begin(4800);
Serial1.println("Serial Port 1...");
}
void loop() { // run over and over
if(Serial.available()){
Serial.println(Serial1.read());
}
if(Serial1.available()){
Serial1.write(random(512));
}
}
That’s how I have changed the code - Is this correctly changed to work? (I will test it later today)
// Open serial communications and wait for port to open:
Serial.begin(57600);
Serial.println("USB Serial...");
// set the data rate for the Serial port
Serial1.begin(4800);
Serial1.println("Serial Port 1...");
}
void loop() { // run over and over
if (Serial1.available()) {
Serial.println(Serial1.read());
Serial1.write(random (512));
}
}
On both the A-Star and the MKR 1010 results in the A-Star outputting random numbers to the serial monitor even when disconnected from the mkr and the MKR not outputting anything. Please help!!
Please show the pin connections for the two boards. You may not have the boards properly connected. All the ports in use are hardware backed, so pin connection is relevant here.