HC-08初次使用记录贴
参加活动,弄了一块HC-08玩儿,记录一下蓝牙模块 HC-08,用HC自已的蓝牙APP测试
1. 建议要没焊插针的,也给配个4针呗,虽然我有一大把呢。:lol
2. 板后大面积丝印的地方,建议可以将过孔周围让一下,我要从板后焊,有丝印遮住,就可能焊不牢靠,(只能通过浸润到板前的锡起到作用,但我焊时有一个怎么也浸不过去,只能反过来在前面补一回)
3.我用了一个备用机,配置比较低,Andriod4.4.3,用HC自带的HC-COM,是可以联上,并且控制NANO的D13LED开关,并且串口回传数据,都没问题,正常
然后需要吐槽一下的是,app没有连接,断开钮,初次连接没啥题,连接,控制 OK。但可是,可但是,我要手欠,断了HC-08的电源呢?想要联其它的蓝牙模块呢?貌似此时唯有关掉再重开app
4.还是备用机(估计也是它太老了吧。。。),用HC自带的另一款蓝牙appHC串口助手,这回有连接按钮啦,但为啥我连不上??点了连接,可以发现HC-08的身影,点击后,也可以看到HC-08上的指示灯由慢闪变成常亮,按说应该是已联机的状态了,但过7秒后,就提示:连接失败!看HC-08又处于未连接状态了。
额。。。
附上NANO的程序,没啥可参考的,非常可以忽略它。
const int ledPin = 13;
int incomingByte;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop()
{
if (Serial.available() > 0)
{
incomingByte = Serial.read();
if (incomingByte == '1')
{
digitalWrite(ledPin, HIGH);
Serial.println("HC-08 led on");
}
if (incomingByte == '2')
{
digitalWrite(ledPin, LOW);
Serial.println("HC-08 led off");
}
}
}
后来发现HC-COM使用时,可以通过手机手退键,断开当前连接,退到蓝牙设备列表界面,还好。
然后又用Andriod 5.1的手机试了HC串口助手,还是老样子。。。 这个是个什么模块啊? 蓝牙模块 HC-08啊
另,客服回复是:HC-08是蓝牙4.0ble协议,需要用蓝牙4.0ble软件才能连接上呢。不能用2.0的
HC串口助手不适用HC-08 本帖最后由 Bone 于 2020-6-8 10:54 编辑
可以自己用App Inventor2写一个手机端控制软件
/*
蓝牙控制步进电机
*/
//四线
int out1=8;
int out2=9;
int out3=10;
int out4=11;
//绝对位置控
int absposition=0;
int num=512; //点击一次的旋转拍数 8*num//4096拍外轴转动一圈
const int speedval=1;///旋转速度
void setup()
{
//串口通信的设计
Serial.begin(9600);
//设置D8-D11脚为步进电机控制脚。
pinMode(out1,OUTPUT);
pinMode(out2,OUTPUT);
pinMode(out3,OUTPUT);
pinMode(out4,OUTPUT);
}
void loop() {
while(Serial.available())
{
char ValueBle=Serial.read();
switch (ValueBle) {
case 'F':
//Serial.println("开门");
eight_step_f(num,speedval);
wait();
absposition+=1;
break;
case 'B':
//Serial.println("关门");
eight_step_b(num,speedval);
wait();
absposition-=1;
break;
case 'S':
//Serial.println("复位");
if(absposition>0)
for (int i=0; i <absposition; i++){
eight_step_b(num,speedval);
wait();
}
if (absposition<0)
for (int i=0; i>absposition; i--){
eight_step_f(num,speedval);
wait();
}
absposition=0;
break;
default:
break;
}
Serial.println(absposition);
//Serial.write(absposition);
}
}
//此函数正向驱动8*num拍 参数t控制速度
void eight_step_f(int num,int t) {
for (int i=0; i <= num; i++){
//(0001)对应8拍不同的输出值。
digitalWrite(out1,LOW);
digitalWrite(out2,LOW);
digitalWrite(out3,LOW);
digitalWrite(out4,HIGH);
delay(t);
//(0011)
digitalWrite(out1,LOW);
digitalWrite(out2,LOW);
digitalWrite(out3,HIGH);
digitalWrite(out4,HIGH);
delay(t);
//(0010)
digitalWrite(out1,LOW);
digitalWrite(out2,LOW);
digitalWrite(out3,HIGH);
digitalWrite(out4,LOW);
delay(t);
//(0110)
digitalWrite(out1,LOW);
digitalWrite(out2,HIGH);
digitalWrite(out3,HIGH);
digitalWrite(out4,LOW);
delay(t);
//(0100)
digitalWrite(out1,LOW);
digitalWrite(out2,HIGH);
digitalWrite(out3,LOW);
digitalWrite(out4,LOW);
delay(t);
//(1100)
digitalWrite(out1,HIGH);
digitalWrite(out2,HIGH);
digitalWrite(out3,LOW);
digitalWrite(out4,LOW);
delay(t);
//(1000)
digitalWrite(out1,HIGH);
digitalWrite(out2,LOW);
digitalWrite(out3,LOW);
digitalWrite(out4,LOW);
delay(t);
//(1001)
digitalWrite(out1,HIGH);
digitalWrite(out2,LOW);
digitalWrite(out3,LOW);
digitalWrite(out4,HIGH);
delay(t);
}
}
//此函数反向驱动8*num拍 参数t控制速度
void eight_step_b(int num,int t) {
for (int i=0; i <= num; i++){
//(1001)
digitalWrite(out1,HIGH);
digitalWrite(out2,LOW);
digitalWrite(out3,LOW);
digitalWrite(out4,HIGH);
delay(t);
//(1000)
digitalWrite(out1,HIGH);
digitalWrite(out2,LOW);
digitalWrite(out3,LOW);
digitalWrite(out4,LOW);
delay(t);
//(1100)
digitalWrite(out1,HIGH);
digitalWrite(out2,HIGH);
digitalWrite(out3,LOW);
digitalWrite(out4,LOW);
delay(t);
//(0100)
digitalWrite(out1,LOW);
digitalWrite(out2,HIGH);
digitalWrite(out3,LOW);
digitalWrite(out4,LOW);
delay(t);
//(0110)
digitalWrite(out1,LOW);
digitalWrite(out2,HIGH);
digitalWrite(out3,HIGH);
digitalWrite(out4,LOW);
delay(t);
//(0010)
digitalWrite(out1,LOW);
digitalWrite(out2,LOW);
digitalWrite(out3,HIGH);
digitalWrite(out4,LOW);
delay(t);
//(0011)
digitalWrite(out1,LOW);
digitalWrite(out2,LOW);
digitalWrite(out3,HIGH);
digitalWrite(out4,HIGH);
delay(t);
//(0001)对应8拍不同的输出值。
digitalWrite(out1,LOW);
digitalWrite(out2,LOW);
digitalWrite(out3,LOW);
digitalWrite(out4,HIGH);
delay(t);
}
}
void wait() {
digitalWrite(out1,LOW);
digitalWrite(out2,LOW);
digitalWrite(out3,LOW);
digitalWrite(out4,LOW);
//delay(10);
}
页:
[1]