Differences
This shows you the differences between two versions of the page.
bluetooth-serial [2021/02/20 15:24] arthur |
bluetooth-serial [2021/02/22 16:47] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | = Bluetooth Serial Connection | ||
- | If you wish to make your SmoothieBoard wireless, you can easily add a cheap Bluetooth SPP (Serial Port Profile) module. | ||
- | |||
- | === Introduction | ||
- | |||
- | The Bluetooth SPP module on a breakout board makes for an easily configured wireless connection for the SmoothieBoard and other motion-control units. | ||
- | |||
- | === Bluetooth Module | ||
- | |||
- | The most popular of these SPP modules are the ' | ||
- | |||
- | For an SPP module, I recommend the HC-05 Bluetooth 2.1 EDR (Enhanced Data Rate) module on a breakout board (like the JY-MCU or my personal favourite, the CZ-HC-05) | ||
- | |||
- | You can also use a BLE (Bluetooth Low Energy) or BT4.0 device like the HC-10, but you will need a comms device that talks BLE/BT4.0 and not many computers do (a recent-model Apple Macbook Pro/Air will be able to, my recent-model HP doesn' | ||
- | |||
- | {{https:// | ||
- | |||
- | I prefer the CZ over the JY for a few reasons â it is really small, it is really well made, it has the KEY (P34, state pin) already broken out and it does level shifting of all the pins back to the 3.3V required by the HC module, unlike some of the other breakouts. | ||
- | |||
- | Of course, some of the US manufacturers make some great boards with superior features and wonderful quality control, but that comes at a price - personally I like paying $4 for a bluetooth module, rather than $25-30. | ||
- | |||
- | === Tools: | ||
- | |||
- | |||
- | 4 ' | ||
- | An HC-05 BT module of some sort, on a breakout board. Not all ' | ||
- | An Arduino or some other MCU to issue the AT commands to the BT module. | ||
- | A breadboard and jumper wires helps. | ||
- | |||
- | === Wiring | ||
- | |||
- | Connect the BT module to the Arduino as follows: | ||
- | |||
- | Arduino pins: | ||
- | D10 (RX) to HC-05 TX | ||
- | D11(TX) to HC-05 RX | ||
- | GND to HC-05 GND | ||
- | 5V to HC-05 VCC | ||
- | 5v to HC-05 KEY or HC-05 P34 - adding a signal (or voltage) to this pin when you power it on puts the HC-05 in command mode, where you can program the features. Some manufacturers break P34 out on the breakout board, but leave the pin un-soldered, | ||
- | |||
- | === Arduino sketch: to program the HC-05 | ||
- | |||
- | < | ||
- | |||
- | // SERIAL LOOP SKETCH FOR COMMUNICATING WITH A BLUETOOTH SPP MODULE | ||
- | |||
- | // BASE HC-05 Config Commands | ||
- | |||
- | // AT+ORGL ï¼Restore the factory default stateï¼ | ||
- | // AT+UART=115200, | ||
- | // AT+NAME=Smoothie | ||
- | // AT+PSWD=0000 Set pairing code to 0000 | ||
- | |||
- | #include < | ||
- | #define rxPin 10 | ||
- | #define txPin 11 | ||
- | SoftwareSerial mySerial(rxPin, | ||
- | char myChar ; | ||
- | void setup() { | ||
- | Serial.begin(9600); | ||
- | Serial.println(" | ||
- | mySerial.begin(38400); | ||
- | mySerial.println(" | ||
- | } | ||
- | void loop() { | ||
- | while (mySerial.available()) { | ||
- | myChar = mySerial.read(); | ||
- | Serial.print(myChar); | ||
- | } | ||
- | while (Serial.available()) { | ||
- | myChar = Serial.read(); | ||
- | Serial.print(myChar); | ||
- | mySerial.print(myChar); | ||
- | } | ||
- | } | ||
- | </ | ||
- | |||
- | === Configure the Bluetooth Module | ||
- | |||
- | Connect/ | ||
- | |||
- | Recycle the Arduino and the HC05 should initialise and slowly flash its LED â this indicates it is in Command Mode. | ||
- | |||
- | Bring up the Arduino IDE serial monitor and set to 9600+CR+LF | ||
- | |||
- | Enter **AT** and you should get **OK** back. If not, check your settings and electrical connections. Is the HC LED slowly pulsing or fast? If it is fast, you aren't in command mode - go back over the steps above. | ||
- | |||
- | By default, the HC-05 should be set to: | ||
- | |||
- | //Slave Mode | ||
- | Connection mode: Connect to the Bluetooth device specified | ||
- | Transmission rate: 38,400 bps; Stop bit: 1 bit; Parity bit: None. | ||
- | Passkey: â1234â | ||
- | Device name: âH-C-2010-06-01â (or some variant depending on what is programmed in the firmware).// | ||
- | |||
- | The first thing to do is to ensure the module is set to factory defaults, using the AT+ORGL command. | ||
- | |||
- | Then, to set up for the SmoothieBoard | ||
- | |||
- | Set the transmission rate to 115,200 bps: AT+UART=115200, | ||
- | Change the device name: AT+NAME=Smoothie (or anything you like: KillR3D, MyPrinter, Arthur, KZ223398 - the module don't care. | ||
- | |||
- | You can also change the pairing key if you want, either for easier access or for privacy â my Macbook defaults to 0000, but the HC-05 defaults to 1234. To make it publicly accessible, give it a pin of 0000: AT+PSWD=0000 - to make it secure, pick any 4-digits that you will remember. | ||
- | |||
- | < | ||
- | AT+ORGL ï¼Restore the factory default stateï¼ | ||
- | AT+UART=115200, | ||
- | AT+NAME=Smoothie | ||
- | AT+PSWD=0000 | ||
- | </ | ||
- | |||
- | There are other parameters in the AT command set, but none of them are relevant to getting the HC-05 working on the SmoothieBoard. | ||
- | |||
- | Connect the female DuPont cables to the 4 UART pins on the Smoothie (next to the USB connector - labelled TX RX V+ GND) and the corresponding pins on the HC-05 breakout and power up the board. | ||
- | |||
- | === Connect: | ||
- | |||
- | Reboot the SmoothieBoard and you should now be able to connect using a terminal app like CoolTerm or directly using your printer app (like [[Pronterface]]). | ||
- | |||
- | In this configuration, | ||
- | |||
- | In my experience, going over 230400 doesn' | ||
- | |||
- | < | ||
- | # Serial communications configuration ( transmission rate default to 9600 if undefined ) | ||
- | uart0.baud_rate | ||
- | </ | ||
- | |||
- | It may be that you are able to perform the Bluetooth AT command setting using the SmoothieBoard itself, but I haven' |