top of page

Arduino Uno R3+ Android+Adafruit Motor Shield v2 + Bluetooth Transceiver (HC-06) + Stepper motor (FL


Can't upload code when TX - RX pins are connected?

Problem description:

we have to disconnect the RX and TX of Bluetooth before uploading code to Arduino

Why?

Arduino uses serial port for reading/writing programs to the flash memory. These are the same UART (Tx/Rx) pins. If these pins are connected to some external peripheral like Bluetooth module or any other module the Tx/Rx pins cannot be used for programming the Arduino as they appear unavailable to the computer terminal.Hence, you need to disconnect the device which is connected to the Arduino before uploading the code.

Last post:

In Step1: setting up HC-06. I descripted: TXD>>>>RXD RXD>>>>TXD;

Modification:

Here we change this as follows: TXD>>>> D2 RXD>>>>D3

How?

SoftwareSerial is used to create an instance of a SoftwareSerial object, whose name you need to provide as in the example below.

#include <SoftwareSerial.h> const byte rxPin = 2; const byte txPin = 3; SoftwareSerial mySerial (rxPin, txPin); // set up a new serial object.

Programming:

/* This is a test sketch for the Adafruit assembled Motor Shield for Arduino v2 It won't work with v1.x motor shields! Only for the v2's with built in PWM control */ #include <Wire.h> #include <Adafruit_MotorShield.h> #include <SoftwareSerial.h> char blueToothVal; //value sent over via bluetooth Adafruit_MotorShield AFMS = Adafruit_MotorShield(); // Create the motor shield object with the default I2C address // Or, create it with a different I2C address (say for stacking) // Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61); // Connect a stepper motor with 400 steps per revolution (0.9degree) // to motor port #2 (M3 and M4) Adafruit_StepperMotor *myMotor = AFMS.getStepper(400, 2); // Connect a stepper motor with 400 steps per revolution (0.9degree) // to motor port #2 (M3 and M4) const byte rxPin = 2; const byte txPin = 3; // set up a new serial object SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin); void setup() { mySerial.begin(9600); // set up Serial library at 9600 bps mySerial.println("Stepper test!"); AFMS.begin(); // create with the default frequency 1.6KHz //AFMS.begin(1000); // OR with a different frequency, say 1KHz myMotor->setSpeed(100); // 100 rpm } void loop() { if(mySerial.available()) //if there is data being recieved { blueToothVal=mySerial.read(); //read it } if (blueToothVal=='f') //if value from bluetooth serial is f { myMotor->step(1600, FORWARD, DOUBLE); //stepper rotates forward for 4 revolutions } else if (blueToothVal=='b') //if value from bluetooth serial is b { myMotor->step(1600, BACKWARD, DOUBLE); //stepper rotates backward for 4 revolutions } }

References:

https://forum.arduino.cc/index.php?topic=353880.0

https://arduino.stackexchange.com/questions/85/why-cant-i-upload-a-sketch-while-other-components-devices-are-connected-to-my-u

https://www.quora.com/Why-do-we-have-to-disconnect-the-RX-and-TX-of-GSM-before-uploading-code-to-Arduino

https://www.arduino.cc/en/Reference/SoftwareSerialConstructor

https://www.arduino.cc/en/Reference/SoftwareSerialBegin


bottom of page