利用蓝牙模块HC-06向手机传送SD卡内的信息
/*Listfiles
This example shows how print out the files in a
directory on a SD card
The circuit:
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4
created Nov 2010
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
modified 2 Feb 2014
by Scott Fitzgerald
This example code is in the public domain.
*/
#include <SPI.h>
#include <SD.h>
File root;
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print("Initializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
pinMode(10, OUTPUT);
if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
root = SD.open("/");
}
void loop()
{
char ch;
if(Serial.read()=='A')
{
printDirectory(root, 0);
Serial.println("done!");
// nothing happens after setup finishes.
}
}
void printDirectory(File dir, int numTabs) {
while(true) {
File entry =dir.openNextFile();
if (! entry) {
// no more files
break;
}
for (uint8_t i=0; i<numTabs; i++) {
Serial.print('\t');
}
Serial.print(entry.name());
if (entry.isDirectory()) {
Serial.println("/");
printDirectory(entry, numTabs+1);
} else {
// files have sizes, directories do not
Serial.print("\t\t");
Serial.println(entry.size(), DEC);
}
entry.close();
}
}
将HC-06TX接到arduino RX;RX接arduino TX,Vcc接+3.3V。arduinoSD模块接口及连线在代码中已有声明。连线完成后,HC-06会闪光,这时说明蓝牙模块已在工作,然后打开手机蓝牙串口软件,这个软件在百度上一搜就有。下载安装后,搜索蓝牙模块,找到HC-06,第一次连接可能需要秘钥,可能是0000或者1234.通常就这两种,连接之后,如果连接成功,提示灯就会一直亮。这时根据代码可知向蓝牙模块发送A,(你也可以自定义,但必须修改代码。)就可以收到HC-06发送的数据了。
HC - 05可以麽? 可以問一下?如果要傳整個檔案內
页:
[1]