4.- OTG and FTDI.
p10A_OTG_FTDI.aia (186.6 KB)
When we connect the Arduino to the mobile, we cannot see the information in the Serial Monitor of the Arduino IDE in PC.
We are going to use an FTDI module (USB <> RX/TX converter). We will connect FTDI module to the mobile.
We will connect the Arduino to the PC to see the information in the Serial Monitor. (Look image)
- For the FTDI connection we will use the SoftwareSerial library. We will use terminals 10 and 11 of the Arduino.
In this example Arduino will create a random number and send it to the Arduino IDE on the PC via its USB cable and to the mobile via the FTDI module.
#include <SoftwareSerial.h>
SoftwareSerial FTDI(10,11);
// El TX del módulo FTDI va al pin 10 del Arduino
// El RX del módulo FTDI va al pin 11 del Arduino
// El GND del módulo FTDI va al GND del Arduino
char caracter;
int aleatorio;
void setup(){
FTDI.begin(9600);
Serial.begin(9600);
}
void loop (){
// Lee del Android y escribe Monitor Serie.
if (FTDI.available() > 0) {
caracter = FTDI.read();
Serial.print(caracter);
}
// Crea un número aleatorio y lo envía a Android
aleatorio = random(33,126);
FTDI.write(aleatorio);
delay(500);
}