Serial1 on Mega 2560 board [message #1754936] |
Fri, 24 February 2017 09:34 |
Francis Pantus Messages: 3 Registered: February 2017 |
Junior Member |
|
|
Dear Forum members,
My setup:
Eclipse, 64 bit, V Neon.2
Java runtime environment, use 64 bits, V 8.12
Python environment, use 64 bit, V 3.5.3
Mega 2560 board
Arduino AVR boards platform
Arduino/BGenuino Mega or Mega 2560 connection
Arduino Software serial library for the project to test SoftwareSerial
Adafruit Ultimate GPS board connected to serial 1 port (TX pin 18, RX pin 19)
The test program
#include <Arduino.h>
#include <HardwareSerial.h>
void setup() {
while (!Serial);
Serial.begin(115200);
Serial1.begin(9600);
Serial1.print("HardwareSerial started");
}
void loop() {
if (Serial1.available()) {
char c = Serial1.read();
Serial.write(c);
}
}
After going around in circles for days , the above program now works in the Eclipse Arduino IDE. I'm not sure why the same code didn't work for about 4 days, but it must have decided that I spent enough time and started working this morning . Maybe because I started a new project from scratch, copy/pasted the same code into the source file and re-linked libraries. Or maybe the sacrificial chicken.
For others struggling with Mega 2560 board serial ports: if you're testing this code with a software serial port, you can't use the 'normal' serial ports Rx pins (i.e. 19, 17 or 15 on my board) as they do not accept interrupts (needed by SoftwareSerial). Only the following pins can be used for RX:
10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69 (see SoftwareSerialExample). I used port 50.
Cheers
[Updated on: Sun, 26 February 2017 06:05] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.07883 seconds