I send data with Android and read it from the Arduino serial screen. When I use UNO, I can read the data smoothly. When I use MEGA, it uploads the code without error, but does not transfer data on the serial screen. Can you tell me why?
#include <SoftwareSerial.h>
SoftwareSerial bluetooth(2,3); // TX,RX
int bar_analog=0;
int head_analog=0;
int bar_anim=0;
int strip_anim=0;
int motor_speed=1;
int direct=0;
int level=0;
boolean debug = true;
void setup() {
Serial.begin(9600);
bluetooth.begin(9600);
Serial.println("Program is starting...");
Serial.println("by Berke Ogulcan Parlak");
}
void loop() {
if (bluetooth.available()) {
while (bluetooth.available())
{
bar_analog = bluetooth.parseInt();
head_analog = bluetooth.parseInt();
bar_anim = bluetooth.parseInt();
strip_anim = bluetooth.parseInt();
motor_speed = bluetooth.parseInt();
direct = bluetooth.parseInt();
level = bluetooth.parseInt();
if (debug) {
Serial.print("Bar Brightness: ");
Serial.println(bar_analog);
Serial.print("Bar Animation Type: ");
Serial.println(bar_anim);
Serial.print("Headlight Brightness: ");
Serial.println(head_analog);
Serial.print("Strip Animation Type: ");
Serial.println(strip_anim);
Serial.print("Motor Speed Level: ");
Serial.println(motor_speed);
Serial.print("Direction: ");
Serial.println(direct);
Serial.print("Mast Goes: ");
Serial.println(level);
Serial.println("--------------------------------");
}
if (bluetooth.read() == '\n') {
azdırma işlemleri bu satırda yapılacak..
}
}
}
}
1 Answer 1
SoftwareSerial relies on the Pin Change interrupt. Not all pins on the Mega have pin change interrupts.
But that is all a moot point really, because when you're using a microcontroller that has lots of real hardware UARTs there is no call to be using SoftwareSerial in any case.