极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 14517|回复: 4

Android手机Bluetooth与Microduino~Bluetooth串口传输数据

[复制链接]
发表于 2013-10-12 23:36:19 | 显示全部楼层 |阅读模式
     室友送了一个Microduino Bluetooth2.1版本的,还送了Microduino—OLED显示屏,于是想法是通过Android手机Bluetooth与Microduino Bluetooth实现串口数据传输,将数据通过OLED显示屏显示出来。在此还有个背景:前期做了一个8*8真彩点阵,在Colorduino上找到了一些资料,另外想增加Android Bluetooth手机直接控制RGB点阵,因此通过Microduino Bluetooth2.1与Android Bluetooth手机之间数据传输做个测试,方便设计8*8RGB点阵。经过一个上午,Android手机控制程序已经做好,调试OK,接下来设计8*8RGB点阵驱动,希望能够与老外那样可以用手机控制8*8RGB点阵。

附Microduino程序:




  1. #include "U8glib.h"

  2. String comdata = "";  //显示的字符串
  3. String;  //判断clean缓存字符串

  4.   static  unsigned long k,m;

  5. int pinRx = 0;
  6. int pinTx = 1;

  7. U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);        
  8. // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are  SCK = 13 and MOSI = 11)
  9. static unsigned char u8g_logo_bits[] U8G_PROGMEM = {
  10.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  11.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  12.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x01,0xE0,
  13.   0x03,0x00,0x00,0x00,0x00,0x7E,0x00,0xF0,0x01,0x00,0x00,0x00,
  14.   0x00,0xFE,0xF9,0xF7,0x07,0x00,0x00,0x00,0x00,0x3C,0x00,0xF8,
  15.   0x03,0x00,0x00,0x00,0x00,0xFC,0xF9,0xE1,0x03,0x00,0x00,0x00,
  16.   0x00,0x38,0x00,0xF0,0x01,0x00,0x00,0x00,0x00,0xFC,0xFF,0x01,
  17.   0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,
  18.   0x00,0xFC,0xEF,0xF9,0x8F,0xD7,0x73,0xF1,0xC1,0x3B,0x9F,0xFF,
  19.   0xFF,0x1E,0x3E,0x00,0x00,0xBC,0xEF,0xC1,0xE1,0x9F,0xFF,0xDD,
  20.   0xE3,0x3F,0xCC,0xE1,0xF0,0xBF,0x7B,0x00,0x00,0x3C,0xF7,0xE1,
  21.   0xE1,0x9F,0xFF,0xC6,0xF7,0x3E,0x8E,0xF3,0xF0,0xFF,0xF8,0x00,
  22.   0x00,0x3C,0xF3,0xE1,0xF1,0x93,0xFF,0xE6,0xF7,0x3C,0x8F,0xF7,
  23.   0xF0,0xFF,0xFC,0x00,0x00,0x7C,0xF2,0xE1,0xF1,0x83,0x87,0xFE,
  24.   0xF7,0x39,0xFF,0xF7,0xF0,0xFF,0xFF,0x00,0x00,0x7C,0xF0,0xE3,
  25.   0xF3,0xA3,0x03,0xFE,0xF7,0x3F,0xFF,0xF7,0x71,0xFC,0xFF,0x00,
  26.   0x00,0x7C,0xF8,0xE3,0xF3,0xBF,0x03,0xFE,0xE3,0x3F,0xFF,0xF3,
  27.   0x71,0xDC,0x7F,0x00,0x00,0x7E,0xFC,0xE7,0xE3,0xBF,0x03,0xFC,
  28.   0xE3,0x3F,0xFE,0xF3,0x71,0x9C,0x7F,0x00,0x00,0xC1,0x03,0xF8,
  29.   0xCF,0xE7,0x0F,0xF0,0x00,0x7F,0xFC,0xFC,0xFF,0x3E,0x1E,0x00,
  30.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };//Microduino
  34.   
  35. static unsigned char u8g_logo_bits1[] U8G_PROGMEM = {

  36. 0x00,0x40,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0xC0,0x03,0x00,0x00,0xC0,0x07,0x00,
  37. 0x00,0xC0,0x0F,0x00,0x00,0xC0,0x1F,0x00,0x00,0xC0,0x3F,0x00,0x00,0xC0,0x7F,0x00,
  38. 0xC0,0xC1,0xFB,0x00,0xE0,0xC3,0xE3,0x03,0xC0,0xC7,0xF3,0x03,0x80,0xCF,0xFB,0x01,
  39. 0x00,0xDF,0x7F,0x00,0x00,0xFE,0x3F,0x00,0x00,0xF8,0x1F,0x00,0x00,0xF0,0x0F,0x00,
  40. 0x00,0xE0,0x03,0x00,0x00,0xF0,0x07,0x00,0x00,0xFC,0x1F,0x00,0x00,0xFE,0x3F,0x00,
  41. 0x00,0xDF,0x7F,0x00,0x80,0xCF,0xFB,0x00,0xE0,0xC7,0xF3,0x01,0xE0,0xC1,0xE3,0x03,
  42. 0xC0,0xC0,0xF3,0x03,0x00,0xC0,0xFF,0x00,0x00,0xC0,0x7F,0x00,0x00,0xC0,0x1F,0x00,
  43. 0x00,0xC0,0x0F,0x00,0x00,0xC0,0x03,0x00,0x00,0xC0,0x01,0x00,0x00,0x40,0x00,0x00,/*"C:\Users\ylb\Desktop\bluetooth1.bmp",0*/
  44. };//Microduino
  45. static unsigned char u8g_logo_bits2[] U8G_PROGMEM = {
  46. 0x00,0x04,0x60,0x00,0x00,0x0C,0x20,0x00,0x00,0xEC,0x37,0x00,0x00,0xF8,0x1F,0x00,
  47. 0x00,0xFE,0x7F,0x00,0x00,0xFF,0xFF,0x00,0x80,0xF7,0xEF,0x01,0x80,0xFF,0xFF,0x01,
  48. 0x80,0xFF,0xFF,0x03,0x80,0xFF,0xFF,0x03,0x98,0xFF,0xFF,0x3B,0xBC,0xFF,0xFF,0x7B,
  49. 0xBE,0xFF,0xFF,0x7B,0xBE,0xFF,0xFF,0x7B,0xBE,0xFF,0xFF,0x7B,0xBE,0xFF,0xFF,0x7B,
  50. 0xBE,0xFF,0xFF,0x7B,0xBE,0xFF,0xFF,0x7B,0xBE,0xFF,0xFF,0x7B,0xBE,0xFF,0xFF,0x7B,
  51. 0xBE,0xFF,0xFF,0x7B,0xBC,0xFF,0xFF,0x3B,0x98,0xFF,0xFF,0x13,0x80,0xFF,0xFF,0x03,
  52. 0x80,0xFF,0xFF,0x01,0x00,0xFF,0xFF,0x00,0x00,0x7C,0x3E,0x00,0x00,0x7C,0x3E,0x00,
  53. 0x00,0x7C,0x3E,0x00,0x00,0x7C,0x3E,0x00,0x00,0x78,0x3E,0x00,0x00,0x10,0x08,0x00,/*"C:\Users\ylb\Desktop\android.bmp",0*/};//Microduino

  54. static unsigned char u8g_logo_bits3[] U8G_PROGMEM = {
  55. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  56. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  57. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  58. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  59. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  60. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  61. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  62. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"C:\Users\ylb\Desktop\android.bmp",0*/};//Microduino

  63. void setup()
  64. {  
  65. Serial.begin(115200);
  66. pinMode(pinTx,OUTPUT);
  67. pinMode(pinRx,INPUT);
  68. while(!Serial)
  69. {
  70. }
  71. }

  72. void draw(void) {  
  73.   u8g.setFont(u8g_font_7x14);
  74.   
  75.   u8g.drawXBMP( 0, 0, 128, 18, u8g_logo_bits);//显示Microdiuno
  76.   u8g.drawXBMP( 96,18, 32, 32, u8g_logo_bits2);//显示Android符号  
  77.   u8g.setPrintPos(0, 64);
  78.   u8g.print(comdata);
  79.   
  80.       switch(k) {
  81.       case 1: u8g.drawXBMP( 0,18, 32, 32, u8g_logo_bits1);//显示蓝牙符号  
  82.       case 2: u8g.drawXBMP( 0,18, 32, 32, u8g_logo_bits1);//显示蓝牙符号
  83.       case 3: u8g.drawXBMP( 0,18, 32, 32, u8g_logo_bits3);//显示蓝牙符号  
  84.       case 4: u8g.drawXBMP( 0,18, 32, 32, u8g_logo_bits3);//显示蓝牙符号
  85.     }
  86.   }
  87. void loop()
  88. {
  89.           k++;
  90.   if (k>4)
  91.   k = 0;
  92. delay(60);
  93.   while (Serial.available() > 0)  //判断串口是否有输入
  94.   {

  95.     comdata = "";                     //清空显示字符
  96.     onedata += char(Serial.read()); //读取字符
  97.     comdata += onedata;               //同上
  98.     delay(2);                         //等待串口缓存

  99.   }

  100.   Serial.println(comdata);
  101.   Serial.println(onedata);
  102.   
  103.     if(onedata=="clean")           //清屏
  104.     comdata = "";
  105.    ;  //缓存字符串清空
  106.    
  107.   u8g.firstPage();  
  108.   do {
  109.     draw();
  110.   } while( u8g.nextPage() );
  111.   delay(100);
  112. }
复制代码


附上视频:


附上图片:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

评分

参与人数 1 +3 收起 理由
Microduino + 3 很给力!

查看全部评分

回复

使用道具 举报

发表于 2013-10-13 08:48:19 | 显示全部楼层
看起好屌啊
回复 支持 反对

使用道具 举报

发表于 2013-10-14 22:19:18 | 显示全部楼层
这个厉害的!太棒了!
回复 支持 反对

使用道具 举报

发表于 2013-10-14 23:55:29 | 显示全部楼层
感谢linux和蓝牙协议吧~因为蓝牙可以直接支持串口。。。要是换成wifi就有的折腾了……
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-10-16 22:54:41 | 显示全部楼层
friskit 发表于 2013-10-14 23:55
感谢linux和蓝牙协议吧~因为蓝牙可以直接支持串口。。。要是换成wifi就有的折腾了……

恩恩。正道~~~~~~
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-6-24 20:40 , Processed in 0.058249 second(s), 22 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表