0

RX and TX on Micro
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

RX and TX on Micro

by Vampyrew0lf on Wed Jan 30, 2019 10:44 pm

I have a program (posted below) that uses a Bluetooth HC-05 dongle and connects to my S8+ and communicates through an app created in Thunkable (very similar to MIT App Inventor). The intent of the program is that when a "button" in the app is pressed and held, the dongle tells the arduino to turn pin 11 HIGH -- on release the pin goes LOW.

The program works wonderfully on an UNO and a MEGA. When I try to use it on a micro, it doesn't work. I've verified the program on 2 different UNOs and 3 different MEGAs because....i dunno....just wanted to make sure. I know the app works and the connection is successful but i don't understand why it won't work on the 2 separate MICROs I've tried.
- Verified that both MICROs work by uploading simpler programs that didn't require RX/TX.

The RX/TX pins on the micro seem pretty straight forward to me. They are, i think, the 3rd and 4th pins from the end of the MICRO next to the reset button. Is there a different way i need to hook them up when using the MICRO with the HC-05?

Another post on this forum suggested that I exchange the Serial to Serial1 but that didn't help either.
viewtopic.php?f=25&t=35649


Code: Select all | TOGGLE FULL SIZE
int lamp = 11;
int vent = 12;
int light = 8;
int pc = 7;

int Received = 0;
int light_state = 0;
int vent_state = 0;
int pc_state = 0;

void setup() {
  Serial1.begin(9600);
  pinMode(lamp, OUTPUT);
  pinMode(vent, OUTPUT);
  pinMode(light, OUTPUT);
  pinMode(pc, OUTPUT);
}

void loop() {
  if (Serial1.available() > 0)
  {
    Received = Serial.read();
    char Rec = char(Received);
    if (Rec != '0')
    {
      Serial1.println(Rec); //This is to visualise the received character
    }
  }
  ////////////////LIGHT/////////////////////
  if (light_state == 0 && Received == '1')
  {
    digitalWrite(light, HIGH);
    light_state = 1;
    Received = 0;
  }
  if (light_state == 1 && Received == '1')
  {
    digitalWrite(light, LOW);
    light_state = 0;
    Received = 0;
  }

  ////////////////VENT/////////////////////
  if (vent_state == 0 && Received == 'a')
  {
    digitalWrite(vent, HIGH);
    vent_state = 1;
    Received = 0;
  }
  if (vent_state == 1 && Received == 'a')
  {
    digitalWrite(vent, LOW);
    vent_state = 0;
    Received = 0;
  }

  ////////////////PC/////////////////////
  if (pc_state == 0 && Received == '2')
  {
    digitalWrite(pc, HIGH);
    pc_state = 1;
    Received = 0;
  }
  if (pc_state == 1 && Received == '2')
  {
    digitalWrite(pc, LOW);
    pc_state = 0;
    Received = 0;
  }

  ////////////////LAMP/////////////////////
  if (Received == '8') {
    digitalWrite(lamp, HIGH);
  }
  if (Received == '9') {
    digitalWrite(lamp, LOW);
  }
}


Vampyrew0lf
 
Posts: 1
Joined: Wed Jan 30, 2019 10:38 pm

Re: RX and TX on Micro

by adafruit_support_bill on Thu Jan 31, 2019 7:27 am

The Micro is based on a 32U4 processor, so "Serial" uses the native hardware usb/serial capability of the processor. Pins 0 and 1 are accessed via "Serial1". Other than that, it should work pretty much the same.

You might try echoing what you receive on Serial1 back out to Serial so you can monitor what is going on via the Serial Monitor.

adafruit_support_bill
 
Posts: 72788
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.