lcokenm 发表于 2014-3-22 16:37:25

Arduino leonardo 蓝牙

我的项目使用了Arduino + OLED + 按键 + 蓝牙
在我把蓝牙加上去之前OLED + 按键跑得好好的
也没有连不上电脑的问题,
但是!!!我加进了蓝牙之后,Leonardo就连不上电脑了!!!
在设备管理器中根本就找不到它,但是它的电源是亮的,我用引线把RST强制复位,电脑能识别到器件。
但是!!!几秒钟之后它又从设备管理器中“噔噔”一下,消失了!!!
这是怎么回事?

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

lcokenm 发表于 2014-3-22 16:47:52

这是bootloader坏了的节奏吗?:Q

八硝基立方烷 发表于 2014-3-22 17:00:59

跟我一样,同问

八硝基立方烷 发表于 2014-3-22 17:02:02

只有在复位时可以连接,复位完成后就会断开连接,不知为何

BD7IBB 发表于 2014-3-22 21:27:24

我的也一样,后来烧了bootloader就好了

沧海笑1122 发表于 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/forum.php?mod=viewthread&tid=8732
用上位机(电脑或者平板)与Leonardo+蓝牙配对连接后,传送一个字符“r”,看看响应正确否。如果没问题。
step2:恢复按键,
step3:再恢复oled,最后判断问题所在。(对了,你的蓝牙模块本身的主从模式,波特率,验证码,校验方式都设置无误吧?要是拿上位机连Leonardo+BT,蓝牙是从机模式。)

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

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

希望能够帮助你。祝你好运。

lcokenm 发表于 2014-3-23 23:12:24

本帖最后由 lcokenm 于 2014-3-24 09:46 编辑

沧海笑1122 发表于 2014-3-23 12:38 static/image/common/back.gif
几点建议:
1、请将全部代码贴上来,看看你的初始化部分有问题没,或者定义是否有冲突。
2、我理解你是在 ...//Declare:for the wireless setup terminal
//1->initial devices
//2->refresh OLED display
//3->PIT setup catch the key input
//4->send the user message from bluetooth
//5->waiting for reciving the ach from the other bluetooth,if failed,resend
//6->turn off the bluetooth
//7->if key input from user,make sure the other bluetooth have turned on by user
//8->reset
//Includes!
//Includes!
//Includes!
#include "SSD1306.h" //for OLED display
#include <Event.h>   //for PIT event
#include <Timer.h>   //for PIT event
//Defines!
//Defines!
//Defines!
//define user
#define TURE1
#define FALSE 0
//define UART speed
#define bluetooth_btl   9600
//difine OLED PINs
#define OLED_CS   2      
#define OLED_D0   3
#define OLED_D1   4
#define OLED_RT   5
#define OLED_DC   6
SSD1306 oled(OLED_D1, OLED_D0, OLED_DC, OLED_RT, OLED_CS);
//define display content
#define display_content_column0
#define display_content_row   5
#define display_page_0_column   0
#define display_page_0_row      0
#define display_page_1_column   0
#define display_page_1_row      0
//define PIT events
Timer t;
//define keyinput
#define key_input_Pin10 //
#define key_input_refresh_time 150//ms
int reset_order_by_user;
//define system
#define start_delay_time         2000
#define initial_sensor_time      5000
#define setup_success_delay_time 5000
//define bluetooth static
#define bluetooth_wait            0x00
#define bluetooth_setup_success   0xF0
#define bluetooth_setup_failed      0x0F
#define bluetooth_setup_angle_okay0x44
#define bluetooth_setup_reset       0x33
#define bluetooth_setup_reset_ack   0x55
int bluetooth_receive = bluetooth_wait;

//Functions!
//Functions!
//Functions!
//Function:for OLED display a int num
void OLED_Dis_int(int dis_int_num)
{
char a;
a = dis_int_num / 100;
oled.drawchar(display_content_column + 0, display_content_row, a + 48);
a = dis_int_num % 100 /10;
oled.drawchar(display_content_column + 6, display_content_row, a + 48);
a = dis_int_num % 10;   
oled.drawchar(display_content_column +12, display_content_row, a + 48);
}
//Function:for catch a key input and return the key number
void Function_key_input(void)
{
int key_in = digitalRead(key_input_Pin);
if(key_in == 0)
{
    reset_order_by_user = TURE;
}
}
//Function:for HMI
void Function_display_welcome_interface(void)
{
//for the first to setup
//if(reset_order_by_user == FALSE){
    oled.clear();
    oled.drawstring(display_page_0_column, display_page_0_row + 0, "Welcome to use lgy's product!");
    oled.drawstring(display_page_0_column, display_page_0_row + 3, "Now I will tell how to use...");
    oled.drawstring(display_page_0_column, display_page_0_row + 5, "Press the key to continue...");
    oled.display();

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

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

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

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

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

      while(digitalRead(key_input_Pin) == 1);
      //bluetooth send the message to set the angle
      Serial1.println(bluetooth_setup_angle_okay);
      while(bluetooth_receive != bluetooth_setup_success){
      bluetooth_receive = Serial1.read();
      Serial1.println(bluetooth_setup_angle_okay);
      }
      bluetooth_receive = bluetooth_wait;

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

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

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

      oled.clear();
      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");
      oled.display();
      delay(setup_success_delay_time);

      oled.clear();
      oled.drawstring(display_page_0_column + 20, display_page_0_row + 3, "Enjoy it!");
      oled.display();
      delay(setup_success_delay_time);
      oled.clear();
      oled.display();   
    }
    else{
      bluetooth_receive = 0;

      oled.clear();
      oled.drawstring(display_page_0_column, display_page_0_row + 0, "Sorry! initial failed! Turn off the power and retry again!");
      oled.display();
    }
}
//for reset the terminal
/*
else{
    oled.clear();
    oled.drawstring(display_page_0_column, display_page_0_row + 0, "Now will reset the terminal...");
    oled.drawstring(display_page_0_column, display_page_0_row + 5, "Press the key to continue...");
    oled.display();

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

    while(bluetooth_receive != bluetooth_setup_reset){
      bluetooth_receive = Serial1.read();
      Serial1.println(bluetooth_setup_reset_ack);
    }
    bluetooth_receive = bluetooth_wait;

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

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

    while(digitalRead(key_input_Pin) == 1);
    //bluetooth send the message to set the angle
    Serial1.println(bluetooth_setup_angle_okay);
    while(bluetooth_receive != bluetooth_setup_success){
      bluetooth_receive = Serial1.read();
      Serial1.println(bluetooth_setup_angle_okay);
    }
    bluetooth_receive = bluetooth_wait;

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

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

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

    oled.clear();
    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");
    oled.display();
    delay(setup_success_delay_time);

    oled.clear();
    oled.drawstring(display_page_0_column + 20, display_page_0_row + 3, "Enjoy it! Thank you!");
    oled.display();
    delay(setup_success_delay_time);
    oled.clear();
    oled.display();      
}
*/
}
//Function:for initial each device
void setup()
{
//for key_input_pin_mode
pinMode(key_input_Pin,INPUT_PULLUP);
//for initial UART for bluetooth
Serial1.begin(bluetooth_btl);
//while (!Serial1) ;
//for initial OLED
oled.ssd1306_init(SSD1306_SWITCHCAPVCC);
Function_display_welcome_interface();
//for initial PIT events
t.every(key_input_refresh_time, Function_key_input);
}
//Function:for main
void loop()
{
//for refresh the OLED display content
//oled.clear();
//oled.drawstring(display_page_1_column + 0, display_page_1_row + 1, "Bluetooth for setup:");
//oled.drawstring(display_page_1_column + 0, display_page_1_row + 3, "The Bot angle:");
//oled.drawstring(display_page_1_column + 0, display_page_1_row + 4, "The Top angle:");
//oled.drawstring(display_page_1_column +25, display_page_1_row + 7, " ---Design BY LGY");
//oled.display();
//for refresh the PIT events
t.update();
if(reset_order_by_user == TURE)
{   
    Function_display_welcome_interface();
    reset_order_by_user = FALSE;
}
}

lcokenm 发表于 2014-3-23 23:15:53

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

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

沧海笑1122 发表于 2014-3-23 23:56:40

程序不小,我手头没有那几个库和oled,没办法帮你测试。
建议你还是先用我给你的例程,测试一下Leonardo+BT和电脑的连接。用电脑的蓝牙和Leonardo+BT配对。先把按钮和oled拔掉,把蓝牙搞定后,一个个加上去。如果你原来的程序不是在Leonardo上的,就先找一块2560(硬串口丰富),先试。

lcokenm 发表于 2014-3-24 09:42:09

本帖最后由 lcokenm 于 2014-3-24 09:56 编辑

沧海笑1122 发表于 2014-3-23 23:56 static/image/common/back.gif
程序不小,我手头没有那几个库和oled,没办法帮你测试。
建议你还是先用我给你的例程,测试一下Leonardo+B ...

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

沧海笑1122 发表于 2014-3-24 10:01:03

lcokenm 发表于 2014-3-24 09:42 static/image/common/back.gif
我想告诉你的是,在Setup()中加入Serial1之前都是好好的,也就是加蓝牙之前是好好的,但是,加了蓝牙后 ...

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

lcokenm 发表于 2014-3-24 10:03:39

沧海笑1122 发表于 2014-3-24 10:01 static/image/common/back.gif
我明白你的描述。
1、请先做最基础的正常测试,即:不插任何外接元件(蓝牙、按键和OLED),电脑是否 ...

= =,我的板子已经连不上电脑了...没办法下程序...

lcokenm 发表于 2014-3-24 10:09:02

沧海笑1122 发表于 2014-3-24 10:01 static/image/common/back.gif
我明白你的描述。
1、请先做最基础的正常测试,即:不插任何外接元件(蓝牙、按键和OLED),电脑是否 ...

我得等快递到才能继续了...

沧海笑1122 发表于 2014-3-24 14:42:20

就是说,这个蓝牙模块的连接,使得你原来的板子,现在裸板都不能被电脑识别了。而且是连续两块板子,这很不合理啊。

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

lcokenm 发表于 2014-3-25 11:35:29

本帖最后由 lcokenm 于 2014-3-25 20:19 编辑

沧海笑1122 发表于 2014-3-24 14:42 static/image/common/back.gif
就是说,这个蓝牙模块的连接,使得你原来的板子,现在裸板都不能被电脑识别了。而且是连续两块板子,这很不 ...

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