极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 14611|回复: 14

Arduino leonardo 蓝牙

[复制链接]
发表于 2014-3-22 16:37:25 | 显示全部楼层 |阅读模式
我的项目使用了Arduino + OLED + 按键 + 蓝牙
在我把蓝牙加上去之前OLED + 按键跑得好好的
也没有连不上电脑的问题,
但是!!!我加进了蓝牙之后,Leonardo就连不上电脑了!!!
在设备管理器中根本就找不到它,但是它的电源是亮的,我用引线把RST强制复位,电脑能识别到器件。
但是!!!几秒钟之后它又从设备管理器中“噔噔”一下,消失了!!!
这是怎么回事?

板子:ARDUINO Leonardo
蓝牙使用的串口是:Serial1(Serial用于USB)
请问有人遇到过这样的情况乎?求交流。。。

本帖子中包含更多资源

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

x
回复

使用道具 举报

 楼主| 发表于 2014-3-22 16:47:52 | 显示全部楼层
这是bootloader坏了的节奏吗?
回复 支持 反对

使用道具 举报

发表于 2014-3-22 17:00:59 | 显示全部楼层
跟我一样,同问
回复 支持 反对

使用道具 举报

发表于 2014-3-22 17:02:02 | 显示全部楼层
只有在复位时可以连接,复位完成后就会断开连接,不知为何
回复 支持 反对

使用道具 举报

发表于 2014-3-22 21:27:24 | 显示全部楼层
我的也一样,后来烧了bootloader就好了
回复 支持 反对

使用道具 举报

发表于 2014-3-23 12:38:19 | 显示全部楼层
本帖最后由 沧海笑1122 于 2014-3-23 12:41 编辑

几点建议:
1、请将全部代码贴上来,看看你的初始化部分有问题没,或者定义是否有冲突。
2、我理解你是在用usb线从电脑向板子upload程序时遇到的问题,在upload之前,试试先拔掉蓝牙模块。upload后再恢复。
3、一步步查,
step1:先保留蓝牙模块(去除oled和按键),测试电脑---Leonardo的upload是否正常,蓝牙模块工作是否正常,分享一个测试程序,http://www.geek-workshop.com/for ... thread&tid=8732
用上位机(电脑或者平板)与Leonardo+蓝牙配对连接后,传送一个字符“r”,看看响应正确否。如果没问题。
step2:恢复按键,
step3:再恢复oled,最后判断问题所在。(对了,你的蓝牙模块本身的主从模式,波特率,验证码,校验方式都设置无误吧?要是拿上位机连Leonardo+BT,蓝牙是从机模式。)

如果你在Leonardo上用softserial,那一定要注意,不是所有的pin都可以rx的。所以需要你把代码贴上来,帮你分析。

我前几天用Leonardo玩蓝牙,也走了不少弯路,这也是diy的乐趣所在吧。

希望能够帮助你。祝你好运。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-3-23 23:12:24 | 显示全部楼层
本帖最后由 lcokenm 于 2014-3-24 09:46 编辑
沧海笑1122 发表于 2014-3-23 12:38
几点建议:
1、请将全部代码贴上来,看看你的初始化部分有问题没,或者定义是否有冲突。
2、我理解你是在 ...
  1. //Declare:  for the wireless setup terminal
  2. //1->initial devices
  3. //2->refresh OLED display
  4. //3->PIT setup catch the key input
  5. //4->send the user message from bluetooth
  6. //5->waiting for reciving the ach from the other bluetooth,if failed,resend
  7. //6->turn off the bluetooth
  8. //7->if key input from user,make sure the other bluetooth have turned on by user
  9. //8->reset
  10. //Includes!
  11. //Includes!
  12. //Includes!
  13. #include "SSD1306.h" //for OLED display
  14. #include <Event.h>   //for PIT event
  15. #include <Timer.h>   //for PIT event
  16. //Defines!
  17. //Defines!
  18. //Defines!
  19. //define user
  20. #define TURE  1
  21. #define FALSE 0
  22. //define UART speed
  23. #define bluetooth_btl   9600
  24. //difine OLED PINs
  25. #define OLED_CS   2      
  26. #define OLED_D0   3
  27. #define OLED_D1   4
  28. #define OLED_RT   5
  29. #define OLED_DC   6
  30. SSD1306 oled(OLED_D1, OLED_D0, OLED_DC, OLED_RT, OLED_CS);
  31. //define display content
  32. #define display_content_column  0
  33. #define display_content_row     5
  34. #define display_page_0_column   0
  35. #define display_page_0_row      0
  36. #define display_page_1_column   0
  37. #define display_page_1_row      0
  38. //define PIT events
  39. Timer t;
  40. //define keyinput
  41. #define key_input_Pin  10 //
  42. #define key_input_refresh_time 150//ms
  43. int reset_order_by_user;
  44. //define system
  45. #define start_delay_time         2000
  46. #define initial_sensor_time      5000
  47. #define setup_success_delay_time 5000
  48. //define bluetooth static
  49. #define bluetooth_wait              0x00
  50. #define bluetooth_setup_success     0xF0
  51. #define bluetooth_setup_failed      0x0F
  52. #define bluetooth_setup_angle_okay  0x44
  53. #define bluetooth_setup_reset       0x33
  54. #define bluetooth_setup_reset_ack   0x55
  55. int bluetooth_receive = bluetooth_wait;

  56. //Functions!
  57. //Functions!
  58. //Functions!
  59. //Function:for OLED display a int num
  60. void OLED_Dis_int(int dis_int_num)
  61. {
  62.   char a;
  63.   a = dis_int_num / 100;
  64.   oled.drawchar(display_content_column + 0, display_content_row, a + 48);
  65.   a = dis_int_num % 100 /10;
  66.   oled.drawchar(display_content_column + 6, display_content_row, a + 48);
  67.   a = dis_int_num % 10;   
  68.   oled.drawchar(display_content_column +12, display_content_row, a + 48);
  69. }
  70. //Function:for catch a key input and return the key number
  71. void Function_key_input(void)
  72. {
  73.   int key_in = digitalRead(key_input_Pin);
  74.   if(key_in == 0)
  75.   {
  76.     reset_order_by_user = TURE;
  77.   }
  78. }
  79. //Function:for HMI
  80. void Function_display_welcome_interface(void)
  81. {
  82.   //for the first to setup
  83.   //if(reset_order_by_user == FALSE){
  84.     oled.clear();
  85.     oled.drawstring(display_page_0_column, display_page_0_row + 0, "Welcome to use lgy's product!");
  86.     oled.drawstring(display_page_0_column, display_page_0_row + 3, "Now I will tell how to use...");
  87.     oled.drawstring(display_page_0_column, display_page_0_row + 5, "Press the key to continue...");
  88.     oled.display();

  89.     while(digitalRead(key_input_Pin) == 1);   
  90.     oled.clear();
  91.     oled.drawstring(display_page_0_column, display_page_0_row + 0, "First,make sure the head-terminal have been turn on");
  92.     oled.drawstring(display_page_0_column, display_page_0_row + 3, "Then put it on the table...");
  93.     oled.drawstring(display_page_0_column, display_page_0_row + 6, "Please wait for 5 seconds...");
  94.     oled.display();
  95.     delay(initial_sensor_time);

  96.     while(bluetooth_receive == bluetooth_wait)  bluetooth_receive = Serial1.read();
  97.     if(bluetooth_receive == bluetooth_setup_success){
  98.       bluetooth_receive = bluetooth_wait;   
  99.       oled.clear();
  100.       oled.drawstring(display_page_0_column, display_page_0_row + 0, "Congratuation!");
  101.       oled.drawstring(display_page_0_column, display_page_0_row + 2, "The Terminal initial success!");
  102.       oled.drawstring(display_page_0_column, display_page_0_row + 6, "Press the key to continue...");
  103.       oled.display();

  104.       while(digitalRead(key_input_Pin) == 1);      
  105.       oled.clear();
  106.       oled.drawstring(display_page_0_column, display_page_0_row + 0, "Now put the head-terminal on your head");
  107.       oled.drawstring(display_page_0_column, display_page_0_row + 4, "If finish,press the key to continue...");
  108.       oled.display();

  109.       while(digitalRead(key_input_Pin) == 1);      
  110.       oled.clear();
  111.       oled.drawstring(display_page_0_column, display_page_0_row + 2, "Now setup the warning angle");
  112.       oled.display();
  113.       delay(start_delay_time);

  114.       oled.clear();
  115.       oled.drawstring(display_page_0_column, display_page_0_row + 0, "Please adjust your head to set the angle");
  116.       oled.drawstring(display_page_0_column, display_page_0_row + 3, "If okay,press the key and the warning angle will be saved!");
  117.       oled.display();

  118.       while(digitalRead(key_input_Pin) == 1);
  119.       //bluetooth send the message to set the angle
  120.       Serial1.println(bluetooth_setup_angle_okay);
  121.       while(bluetooth_receive != bluetooth_setup_success){
  122.         bluetooth_receive = Serial1.read();
  123.         Serial1.println(bluetooth_setup_angle_okay);
  124.       }
  125.       bluetooth_receive = bluetooth_wait;

  126.       oled.clear();
  127.       oled.drawstring(display_page_0_column, display_page_0_row + 0, "Now we have finished all the setup");
  128.       oled.display();
  129.       delay(setup_success_delay_time);

  130.       oled.clear();
  131.       oled.drawstring(display_page_0_column, display_page_0_row + 1, "And enjoy yourself!");
  132.       oled.drawstring(display_page_0_column, display_page_0_row + 3, "Thank you for choosing my product!");
  133.       oled.display();
  134.       delay(setup_success_delay_time);

  135.       oled.clear();
  136.       oled.drawstring(display_page_0_column, display_page_0_row + 1, "For saving the power,the screen will be turned off few seconds later ");
  137.       oled.display();
  138.       delay(setup_success_delay_time);

  139.       oled.clear();
  140.       oled.drawstring(display_page_0_column, display_page_0_row + 1, "If you want to reset the terminal,5 seconds later you can press the key to reset");
  141.       oled.display();
  142.       delay(setup_success_delay_time);

  143.       oled.clear();
  144.       oled.drawstring(display_page_0_column + 20, display_page_0_row + 3, "Enjoy it!");
  145.       oled.display();
  146.       delay(setup_success_delay_time);
  147.       oled.clear();
  148.       oled.display();     
  149.     }
  150.     else{
  151.       bluetooth_receive = 0;

  152.       oled.clear();
  153.       oled.drawstring(display_page_0_column, display_page_0_row + 0, "Sorry! initial failed! Turn off the power and retry again!");
  154.       oled.display();
  155.     }
  156.   }
  157.   //for reset the terminal
  158.   /*
  159.   else{
  160.     oled.clear();
  161.     oled.drawstring(display_page_0_column, display_page_0_row + 0, "Now will reset the terminal...");
  162.     oled.drawstring(display_page_0_column, display_page_0_row + 5, "Press the key to continue...");
  163.     oled.display();

  164.     while(digitalRead(key_input_Pin) == 1);   
  165.     oled.clear();
  166.     oled.drawstring(display_page_0_column, display_page_0_row + 0, "Now please press the key on the head-terminal...");
  167.     oled.display();

  168.     while(bluetooth_receive != bluetooth_setup_reset){
  169.       bluetooth_receive = Serial1.read();
  170.       Serial1.println(bluetooth_setup_reset_ack);
  171.     }
  172.     bluetooth_receive = bluetooth_wait;

  173.     oled.clear();
  174.     oled.drawstring(display_page_0_column, display_page_0_row + 0, "Okay! Now will reset the warning angle");
  175.     oled.display();
  176.     delay(start_delay_time);

  177.     oled.clear();
  178.     oled.drawstring(display_page_0_column, display_page_0_row + 0, "Please adjust your head to set the angle");
  179.     oled.drawstring(display_page_0_column, display_page_0_row + 3, "If okay,press the key and the warning angle will be saved!");
  180.     oled.display();      

  181.     while(digitalRead(key_input_Pin) == 1);
  182.     //bluetooth send the message to set the angle
  183.     Serial1.println(bluetooth_setup_angle_okay);
  184.     while(bluetooth_receive != bluetooth_setup_success){
  185.       bluetooth_receive = Serial1.read();
  186.       Serial1.println(bluetooth_setup_angle_okay);
  187.     }
  188.     bluetooth_receive = bluetooth_wait;

  189.     oled.clear();
  190.     oled.drawstring(display_page_0_column, display_page_0_row + 0, "Now we have finished all the setup again");
  191.     oled.display();
  192.     delay(setup_success_delay_time);

  193.     oled.clear();
  194.     oled.drawstring(display_page_0_column, display_page_0_row + 1, "And enjoy yourself again!");
  195.     oled.drawstring(display_page_0_column, display_page_0_row + 3, "Thank you for choosing my product!");
  196.     oled.display();
  197.     delay(setup_success_delay_time);

  198.     oled.clear();
  199.     oled.drawstring(display_page_0_column, display_page_0_row + 1, "For saving the power,the screen will be turned off few seconds later");
  200.     oled.display();
  201.     delay(setup_success_delay_time);

  202.     oled.clear();
  203.     oled.drawstring(display_page_0_column, display_page_0_row + 1, "If you want to reset the terminal,5 seconds later you can press the key to reset");
  204.     oled.display();
  205.     delay(setup_success_delay_time);

  206.     oled.clear();
  207.     oled.drawstring(display_page_0_column + 20, display_page_0_row + 3, "Enjoy it! Thank you!");
  208.     oled.display();
  209.     delay(setup_success_delay_time);
  210.     oled.clear();
  211.     oled.display();        
  212.   }
  213.   */
  214. }
  215. //Function:for initial each device
  216. void setup()
  217. {
  218.   //for key_input_pin_mode
  219.   pinMode(key_input_Pin,INPUT_PULLUP);
  220.   //for initial UART for bluetooth  
  221.   Serial1.begin(bluetooth_btl);
  222.   //while (!Serial1) ;  
  223.   //for initial OLED
  224.   oled.ssd1306_init(SSD1306_SWITCHCAPVCC);
  225.   Function_display_welcome_interface();
  226.   //for initial PIT events
  227.   t.every(key_input_refresh_time, Function_key_input);
  228. }
  229. //Function:for main
  230. void loop()
  231. {
  232.   //for refresh the OLED display content
  233.   //oled.clear();
  234.   //oled.drawstring(display_page_1_column + 0, display_page_1_row + 1, "Bluetooth for setup:");
  235.   //oled.drawstring(display_page_1_column + 0, display_page_1_row + 3, "The Bot angle:");
  236.   //oled.drawstring(display_page_1_column + 0, display_page_1_row + 4, "The Top angle:");
  237.   //oled.drawstring(display_page_1_column +25, display_page_1_row + 7, " ---Design BY LGY");
  238.   //oled.display();
  239.   //for refresh the PIT events
  240.   t.update();
  241.   if(reset_order_by_user == TURE)
  242.   {   
  243.     Function_display_welcome_interface();
  244.     reset_order_by_user = FALSE;
  245.   }
  246. }

复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-3-23 23:15:53 | 显示全部楼层
沧海笑1122 发表于 2014-3-23 12:38
几点建议:
1、请将全部代码贴上来,看看你的初始化部分有问题没,或者定义是否有冲突。
2、我理解你是在 ...

下载的程序中,setup() 里边用的是Serial1,不是Serial,求一起讨论。。我已经重新买了芯片,但是看着两个片子用不上挺浪费的
回复 支持 反对

使用道具 举报

发表于 2014-3-23 23:56:40 | 显示全部楼层
程序不小,我手头没有那几个库和oled,没办法帮你测试。
建议你还是先用我给你的例程,测试一下Leonardo+BT和电脑的连接。用电脑的蓝牙和Leonardo+BT配对。先把按钮和oled拔掉,把蓝牙搞定后,一个个加上去。如果你原来的程序不是在Leonardo上的,就先找一块2560(硬串口丰富),先试。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-3-24 09:42:09 | 显示全部楼层
本帖最后由 lcokenm 于 2014-3-24 09:56 编辑
沧海笑1122 发表于 2014-3-23 23:56
程序不小,我手头没有那几个库和oled,没办法帮你测试。
建议你还是先用我给你的例程,测试一下Leonardo+B ...


在Setup()中加入Serial1之前都是好好的,也就是加蓝牙之前是好好的,但是,加了蓝牙后,我的电脑就再也搜不到Leonardo这个串口了,所以,问题的关键还是蓝牙,这个Serial1我是第一次用
后来我换了另外一片Leonardo,果然又坏了,现在手头没有Arduino了,只能等快递了,手头着两片也没办法自己重新bootloader
回复 支持 反对

使用道具 举报

发表于 2014-3-24 10:01:03 | 显示全部楼层
lcokenm 发表于 2014-3-24 09:42
我想告诉你的是,在Setup()中加入Serial1之前都是好好的,也就是加蓝牙之前是好好的,但是,加了蓝牙后 ...

   我明白你的描述。
1、请先做最基础的正常测试,即:不插任何外接元件(蓝牙、按键和OLED),电脑是否能认到板子,然后再测试LED13是否闪灯,以确定板子是好的。bootloader是正常的。(两块板子都做)
2、插蓝牙模块(不插按键和oled),先不要用你的代码,用我给你的链接的例程,试试,确定蓝牙是好的。然后再往下做。现在的故障表现在蓝牙上,但是板子是不是正常也是个需要验证的事,不能两个都是未知数,先一样一样排除。
    排除故障,一定是先易后难,先简后繁。别着急,DIY都这样,你可以看看我以前的帖子,走得弯路多了。。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-3-24 10:03:39 | 显示全部楼层
沧海笑1122 发表于 2014-3-24 10:01
我明白你的描述。
1、请先做最基础的正常测试,即:不插任何外接元件(蓝牙、按键和OLED),电脑是否 ...

= =,我的板子已经连不上电脑了...没办法下程序...
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-3-24 10:09:02 | 显示全部楼层
沧海笑1122 发表于 2014-3-24 10:01
我明白你的描述。
1、请先做最基础的正常测试,即:不插任何外接元件(蓝牙、按键和OLED),电脑是否 ...

我得等快递到才能继续了...
回复 支持 反对

使用道具 举报

发表于 2014-3-24 14:42:20 | 显示全部楼层
就是说,这个蓝牙模块的连接,使得你原来的板子,现在裸板都不能被电脑识别了。而且是连续两块板子,这很不合理啊。

那你的蓝牙模块是不是有问题?用USB-TTL在电脑上连接蓝牙模块,能识别,AT指令可以正确响应吗?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-3-25 11:35:29 | 显示全部楼层
本帖最后由 lcokenm 于 2014-3-25 20:19 编辑
沧海笑1122 发表于 2014-3-24 14:42
就是说,这个蓝牙模块的连接,使得你原来的板子,现在裸板都不能被电脑识别了。而且是连续两块板子,这很不 ...


今天换了两块板子了,单独测试蓝牙是没有问题的,单独测试OLED也是没有问题的,但是一整合,又出问题了,估计是我的程序流程问题,我再查查,不过,之前那两块Leonardo死的真是不明不白的。。是不是烧了程序进去把bootloader给弄坏了?程序太大把bootloader给覆盖了?我看过之前用的那个程序编译出来确实挺大的,我现在换328用了
回复 支持 反对

使用道具 举报

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

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-10 00:41 , Processed in 0.119597 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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