kammo:
De plus, le moniteur série fait planter le PC, je l'ai déjà redémarré trois fois...
Tu dois avoir un court-jus quelque part : vérifie tes branchements...
Ça m'étonne quand même que ça ne fonctionne pas, j'ai trouvé un autre code, tu peux tester :
#include <SoftwareSerial.h>// import the serial library
SoftwareSerial BT(10, 11); // RX, TX
int ledpin = 13; // led on D13 will show blink on / off
int BluetoothData; // the data given from Computer
void setup() {
BT.begin(9600);
BT.println("Bluetooth On please press 1 or 0 blink LED ..");
pinMode(ledpin, OUTPUT);
}
void loop() {
if (BT.available()) {
BluetoothData = BT.read();
if (BluetoothData == '1') { // if number 1 pressed ....
digitalWrite(ledpin, 1);
BT.println("LED On D13 ON ! ");
}
if (BluetoothData == '0') { // if number 0 pressed ....
digitalWrite(ledpin, 0);
BT.println("LED On D13 Off ! ");
}
}
delay(100);// prepare for next data ...
}
Il faut choisir les pins RX et TX (ici 10 et 11) dans celles qui marchent (ça dépend de ton Arduino) :
The Arduino hardware has built-in support for serial communication on pins 0 and 1 (which also goes to the computer via the USB connection). The native serial support happens via a piece of hardware (built into the chip) called a UART. This hardware allows the Atmega chip to receive serial communication even while working on other tasks, as long as there room in the 64 byte serial buffer.
The SoftwareSerial library has been developed to allow serial communication on other digital pins of the Arduino, using software to replicate the functionality (hence the name "SoftwareSerial"). It is possible to have multiple software serial ports with speeds up to 115200 bps. A parameter enables inverted signaling for devices which require that protocol.
Limitations
If using multiple software serial ports, only one can receive data at a time.
Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).
Not all pins on the Leonardo and Micro support change interrupts, so only the following can be used for RX: 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
On Arduino or Genuino 101 the current maximum RX speed is 57600bps
On Arduino or Genuino 101 RX doesn't work on Pin 13