bromagosa / Snap4Arduino

Binding Snap! and Arduino together
http://snap4arduino.rocks
GNU Affero General Public License v3.0
133 stars 85 forks source link

BT module - COM-port random disconnects #160

Closed DenysZaytsev closed 1 year ago

DenysZaytsev commented 7 years ago

BT module HC-05/HC-06 disconnects randomly when script is running. Usually disconnects when no interaction from user, script is running and waiting for keys to be pressed. Then suddenly COM port disconnects. Tried HC-05/HC-06 modules and also SPP-CA module. Baud rate is set to 57600 on BT and on Arduino UNO board. No such issues when connected via USB cable. Also checked power. It is good, not related to this issue.

DenysZaytsev commented 7 years ago

Tried to power up BT module with stand alone power source. Same issues. Script is actively running (switching to different blocks via broadcast command). Tried connecting an Arduino without anything there (just arduino and BT). Tried Firmata, S5A and Firmata Plus) - same issues. Tried different BT modules. Nothing helps. Tried with Arduino Mega - same behavior

Is this an issue with BT modules (which are not supported) or Snap itself?

bromagosa commented 7 years ago

Hi!

There must be something different on your side, we can't reproduce the problem here. Can you specify your OS, Snap4Arduino version, Arduino model (is it an original one?) and send us your Snap! project too?

Just for the record, I've had Snap4Arduino running over Bluetooth for a whole day uninterruptedly, so it's most probably not a Snap! issue :)

DenysZaytsev commented 7 years ago

Hi bromagosa!

Thank you for quick reply. I'll let you know my configuration shortly. Briefly it's laptop Acer Nitro with build-in bluetooth module and Windows 10 with all latest Microsoft's updates installed. I also tried to use USB Dlink DBT-122 adapter. Arduino is chineese clone from Aliexpress (Arduino Uno R3, also tried the same clone of Mega 2560). BT module I used was HC-05 (changed speed to 57600 and name, haven't touched any other settings ). I thought it might be happening due to a bad HC-05, but I tried a couple of them.

Can we troubleshoot this somehow, as I need to make a lot of such sets for children learning?

I'll let you know more details shortly. I can either record a short video and post it somewhere.

For some reason I was unable to attach ZIP with XML, so I've just posted it here. Please copy it into an empty XML file. The script is made for an RC car. Arduino controls the motors via H-bridge and BT-module. Also there is a Voltmeter (made with resistors voltage devider) and the logic is to stop motors when there is an overload and general voltage goes lower then some value.

Thanks in advance, Denys.

chrisclaynz commented 7 years ago

hey mate - Are you using DC motors?

On Mon, May 29, 2017 9:35 PM, DenysZaytsev notifications@github.com wrote: Hi bromagosa!

Thank you for quick reply. I'll let you know my configuration shortly. Briefly it's laptop Acer Nitro with build-in bluetooth module and Windows 10 with all latest Microsoft's updates installed. I also tried to use USB Dlink DBT-122 adapter. Arduino is chineese clone from Aliexpress (Arduino Uno R3, also tried the same clone of Mega 2560). BT module I used was HC-05 (changed speed to 57600 and name, haven't touched any other settings ). I thought it might be happening due to a bad HC-05, but I tried a couple of them.

Can we troubleshoot this somehow, as I need to make a lot of such sets for children learning?

I'll let you know more details shortly. I can either record a short video and post it somewhere.

My script is attached.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

Chris ClayIndependent Education Consultant@chrisclaynz
Chris Clay | LEARNING TO THINK DIFFERENTLYChris Clay | LEARNING TO THINK DIFFERENTLY While many are trying to encourage students to continue studying STEM subjects it seems that the content of these courses remains unchanged. chrisclay.org

DenysZaytsev commented 7 years ago

Hello there. I've managed to figure out exactly when disconnects happens.

So BT is being disconnected permanently only when there is an intensive data exchange between PC (host) and BT. When I'm turning ON/OFF PINs many times in the loop. As you can see from the screenshot - I'm just turning some PINs off in the EVER cycle. In this case LED on my BT module blinks all the time and after 10-30 seconds it disconnects from the host. https://www.dropbox.com/s/s5usqygn73jc6xc/ScreenHunter_05%20Jun.%2006%2009.57.jpg?dl=0

But I need to change the PIN state all the time. The project is RC Car and motor should only run when you press the key (i.e. up arrow) and HOLD it. When you release the key - motors should STOP. Please note that disconnects happens EVEN when MOTORS ARE NOT running (when motors are stopped)! Please see example of my script (see picture): https://www.dropbox.com/s/6h3ti9hwn7xbevv/ScreenHunter_07%20Jun.%2006%2010.02.jpg?dl=0

The logic is to set motor PINS to 0, when nothing is pressed in the ever cycle. But when arrow up is pressed - motors PINs sould be set to 1 in order to run the motors.

Yesterday I've even flashed RN-42 firmware to my HC-05 module, re-configured it from HID to SPP and tried again, but got the same behavior as before.

Please someone help me with it.

bromagosa commented 7 years ago

Good that you figured this out, now it all makes sense! :)

You need to power the board and the motors using different sources. Otherwise the current drop when stopping the motor or the excessive current draw when starting it up will cause the BT module to disconnect. This has nothing to do with Snap4Arduino, it's all in the electronics :)

DenysZaytsev commented 7 years ago

Hi bromagosa!

Can you share pls your IM (skype, viber, facebook...), I can share my screen for you, so you could take a look.

The issue is not sticked to DC motors, as MOTORS are STOPPED when disconnect happens. It just disconnects when I'm setting PINs in the cycle.

Also everything works perfect when Arduino is connected to the host via USB cable!

DenysZaytsev commented 7 years ago

I even tried to disconnect MOTORS physically from Arduino and still got disconnects when running the same script. So it's not related to power problems (I know about those, DC motor makes voltage to drop down for few miliseconds when they starts and also when there is some more load on them). But my problem is something else.

DenysZaytsev commented 7 years ago

Guys, another question - is there a way to change communication speed between Arduino(I can change it in the Firmata sketch) and Snap4Arduino (at least Windows desktop application) ? I tried to set baud rate in Firmata to 9600, but it was unable to connect after, obviously because desktop app (Snap4Arduino) is set to use 57600 baud rate.

bromagosa, please let me know how to change the baud rate in the desktop App! I wan't to try running on lower speeds.

Also would it work if I set the parity bit on the BT module to 1 or 2 (odd/even) instead of 0 (none) ? I think the problem migh occure due to a high speed. BT can't send correct values on 57600 baud. I might be wrong, but I want to try lower it down.

jguille2 commented 7 years ago

Hi @DenysZaytsev, As @bromagosa said, power source and electronics configuration is important, and this is causing the annoying disconnections (as you said, with USB connection all is right). But also, you can reduce easily your board request!

You can use a 'wait' block to reduce these connections or, in the case you are commenting, you can avoid requesting when the state is not changing. Something like this: reducingconnections

DenysZaytsev commented 7 years ago

power source and electronics configuration is important

sure it is, but I tried to power up arduino and BT module from a power bank, when DC motors were powered with completely different power source (2 li-ion 18650 batteries) and behaviour was the same. Of cause I'll try to reduce connections, but it's weird that it works okay with the USB cord (Arduino and BT powered via USB and Serial link over USB cable as well), but doesn't work good with BT module (also powered separately from the motors).

How about changing the baud rate of Snap4Arduino for Windows ? How can I do it, I want to try

DenysZaytsev commented 7 years ago

I think the problem is deeper - in the BT connection itself. I believe that 57600 baud rate is not good for Bluetooth to work without errors, so that's why I want to try 9600baud rate, but don't know how to configure the desktop application to work with this speed.

jguille2 commented 7 years ago

Or more elegant (and also natural): reducingconnections2

And about changing baud rate... the only way is hacking Snap4Arduino. We are using Firmata protocol. You saw the config into the Arduino sketch and the server side is firmata.js int Snap4Arduino. I think you don't need to make this change.

DenysZaytsev commented 7 years ago

Thank you, jguille2

That's exactly what I need. I'm gonna change the value in firmata.js and recompile Desktop app for Windows ... we'll seen then if that would make a trick.

Thanks a lot!

DenysZaytsev commented 7 years ago

Eventually I was unable to use BT, so we decided to move onto the ESP8266 module. I've flashed it with esp-link firmware which does a transparent UART bridge, so it works good. No disconnect issues since.

However BT connectivity issues are still NOT solved. Perhaps it depends on BT controller/drivers on the PC side, anyway it's still there.