/* * PIC_2Serial_115200.ino * For Mega 2560 and PIC18F14K22, RX on RB5, TX on RB7 * Connect Meg pin 18 to RB5 and pin 19 to RB7 * * (c)2016 Forward Computing and Control Pty. Ltd. * www.forward.com.au * This code may be freely used * * Use this sketch to change baud rate of the RN42-HID (XBee format) bluetooth module * from its factory default of 115200 to 9600. * see http://www.forward.com.au/pfod/ArduinoProgramming/FioV3/index.html for details * * default baud rate is 115200 * */ #define BAUD_RATE 9600 void setup() { // Open serial communications and wait for port to open: Serial.begin(BAUD_RATE); // this should match the USB driver connect baud rate Serial.println(); for (int i=10; i>0; i--) { Serial.print(i); Serial.print(' '); delay(500); } Serial.println(); Serial.print("Waiting for I/O on Serial1 pins 18/19 TX/RX at "); Serial.println(BAUD_RATE); Serial1.begin(BAUD_RATE); // This is TX1 pin 18 and RX1 pin 19 on Meg 2560 } void loop() { if (Serial1.available()) Serial.write(Serial1.read()); if (Serial.available()) { byte in = Serial.read(); // Serial.write(in); // suppress local echo from Mega Serial1.write(in); } }