Difference between revisions of "BT Shield (Slave)"
(→AT command) |
(→Demo Code) |
||
| Line 144: | Line 144: | ||
==Demo Code== | ==Demo Code== | ||
| + | unsigned int timeout=0; | ||
| + | unsigned char state=0; | ||
| + | |||
| + | ISR(TIMER2_OVF_vect) //Timer2 Service | ||
| + | { | ||
| + | TCNT2 = 0; | ||
| + | timeout++; | ||
| + | if (timeout>61) | ||
| + | { | ||
| + | state=1; | ||
| + | timeout=0; | ||
| + | } | ||
| + | |||
| + | } | ||
| + | |||
| + | void init_timer2(void) | ||
| + | { | ||
| + | TCCR2A |= (1 << WGM21) | (1 << WGM20); | ||
| + | TCCR2B |= 0x07; // by clk/1024 | ||
| + | ASSR |= (0<<AS2); // Use internal clock - external clock not used in Arduino | ||
| + | TIMSK2 |= 0x01; //Timer2 Overflow Interrupt Enable | ||
| + | TCNT2 = 0; | ||
| + | sei(); | ||
| + | } | ||
| + | |||
| + | void setup() | ||
| + | { | ||
| + | Serial.begin(9600); | ||
| + | pinMode(2,INPUT); | ||
| + | pinMode(13,OUTPUT); | ||
| + | attachInterrupt(0,cleantime,FALLING); | ||
| + | init_timer2(); | ||
| + | } | ||
| + | |||
| + | void loop() | ||
| + | { | ||
| + | switch(state) | ||
| + | { | ||
| + | case 0: | ||
| + | digitalWrite(13,LOW); | ||
| + | break; | ||
| + | case 1: | ||
| + | digitalWrite(13,HIGH); | ||
| + | Serial.print("Hellow BT"); | ||
| + | break; | ||
| + | } | ||
| + | |||
| + | } | ||
| + | |||
| + | void cleantime() | ||
| + | { | ||
| + | timeout=0; | ||
| + | state=0; | ||
| + | } | ||
==License== | ==License== | ||
Revision as of 05:56, 22 May 2014
Contents
Overview
BT Shield V2.1 is a Serial port Bluetooth module (Slave) breakout board, and it’s compatible with Arduino and IFlat-32, it can directly plug in with Arduino/IFlat-32 board, use the UART port for communicating to Arduino/IFlat-32 or FT232.
Specifications
| Microprocessor | CSR BC417 |
| PCB size | 53.3mm X 47mm X 1.6mm |
| Indicators | PWR,State |
| Power supply | 5V DC |
| IO | 3 |
| Communication Protocol | UART/Bluetooth 2.0 |
| RoSH | Yes |
Electrical Characteristics
| Specification | Min | Type | Max | Unit |
| Power Voltage | 4.5 | 5 | 5.5 | VDC |
| Input Voltage VH (Target Voltage = 3.3V) | 3 | 3.3 | 3.6 | VDC |
| Input Voltage VH (Target Voltage = 5V) | 4.5 | 5 | 5.5 | V |
| Input Voltage VL: | -0.3 | 0 | 0.5 | V |
| Current Consumption | - | 20 | 40 | mA |
Hardware
| Pad Name | Type | Description |
| RX/TX | I/O | UART communication Port (Depend on switcher 4) |
| TX/RX | I/O | UART communication Port (Depend on switcher 4) |
| State | O | State Direction |
| Switcher | Name | Description |
| 4 | UART Communication Switch | Connect to broad or FT232 |
| 5 | Communication Voltage Switch | Set the interface voltage |
| LED | Name | Description |
| 6 | PWR | When power on, the PWR LED light. |
| 7 | State | \"When the module in standby mode, the State LED will alternating light off. When the serial port open, the State LED light.\" |
AT command
Default:
Slave, 9600 baud rate, N, 8, 1. Pincode 1234
AT command:
1. Communications Test:
Sent : AT
receive : OK
2. Change baud rate:
Sent : AT+BAUD1
receive : OK1200
Sent : AT+BAUD2
receive : OK2400
1---------1200
2---------2400
3---------4800
4---------9600
5---------19200
6---------38400
7---------57600
8---------115200
Baud rate setting can be save even power down.
3. Change Bluetooth device name:
Sent : AT+NAMEdevicename
receive : OKname
(devicename is the name you want the device to be , and it will be searched with this name)
Name setting can be save even power down.
4. Change Pincode:
Sent : AT+PINxxxx
receive : OKsetpin
(xxxx is the pin code you set)
Pin code can be save even power down.
Demo Code
unsigned int timeout=0; unsigned char state=0;
ISR(TIMER2_OVF_vect) //Timer2 Service {
TCNT2 = 0;
timeout++;
if (timeout>61)
{
state=1;
timeout=0;
}
}
void init_timer2(void) {
TCCR2A |= (1 << WGM21) | (1 << WGM20); TCCR2B |= 0x07; // by clk/1024 ASSR |= (0<<AS2); // Use internal clock - external clock not used in Arduino TIMSK2 |= 0x01; //Timer2 Overflow Interrupt Enable TCNT2 = 0; sei();
}
void setup() {
Serial.begin(9600); pinMode(2,INPUT); pinMode(13,OUTPUT); attachInterrupt(0,cleantime,FALLING); init_timer2();
}
void loop() {
switch(state)
{
case 0:
digitalWrite(13,LOW);
break;
case 1:
digitalWrite(13,HIGH);
Serial.print("Hellow BT");
break;
}
}
void cleantime() {
timeout=0; state=0;
}
Notice