Bluetooth HC-06 LED is solid but keep getting Error 516: Unable to write. Broken Pipe

Hello Forum,

I am relatively new to MIT App Inventor. I have spent nearly 60 hours over the past 2 weeks trying to learn how to use this awesome tool, and I have only scratched the surface. I have viewed hundreds of videos on YouTube, and I have looked at hundreds of posts on this Forum.

I am getting this error while connected via Bluetooth between an Arduino Pro Mini and Android smartphone with an HC-06 Bluetooth module:

Error 516: Unable to write. Broken Pipe.

I am getting this error non-stop. I have used the protocol to connect to Bluetooth as shown in literally 100's if not 1000's of postings.

I transmit a few bytes. Then I receive a few bytes. And all of the sudden I see the error. And the red LED on the HC-06 remains solid (meaning that it is connected). But it is not connected.

I have searched the forum and see no one item that causes this error...seems like there are infinite causes.

Any advice would be greatly appreciated.

TIA,
--Neal

Hello Neal.
Have you tried using a BT serial terminal app? Always a good tool to have on hand when building a BT app.

The app from Kai Morich is popular. Just search on "Bluetooth Serial Terminal app".
John.

Dear John,

How do you connect the Bluetooth Serial Terminal App to a smartphone? I have an FTDI module for connecting and Arduino to my PC via USB cable. I have no idea how to connect the smartphone. I have searched for Bluetooth connection. The list will not refresh. I have no clue. Is there a tutorial for this? I have Googled this and cannot find anything other than the download.

TIA,
--Neal

I'm a bit confused re what you have already achieved. I get the Broken Pipe message when the phone's BT service is not enabled, so just use the phone settings to enable BT.

Are you sure solid LED means connected? With my HC-05 it flashes twice every 5 secs when connected.

Do you know how to install an app from Google Store? Please have a look at this url:
BT Ser Term App

Dear John,
I already did this. I open the app, configure 9600 8N1 and I cannot see the BT connection. Shouldn't the BT connection be in a list?
--Neal

Only if the phone and yr HC-06 have been paired. Pairing is "permanent", connection is done when you use an app.

Dear John,
I have paired the phone with the HC-06 module under the phone's settings. When I open the BT Ser Term App, the HC-06 is not listed. In fact, nothing is listed.

My AI2 project was working this morning and then it stopped. I have struggled to get this working all day. The Bluetooth keeps quitting. I even swapped out the "old" HC-06 for a new module. This did not correct the problem. Maybe the phone has an issue? I do not know. It it strange that the HC-06 doesn't even show up in the list for the BT Ser Term App.
--Neal

And the phone does show the HC-06 in its list of paired devices?

Swapping components out is a good tactic. So you've swapped the HC-06. How about the phone? Have another or a tablet?

Dear John,

I just dug up an old Android phone out of my desk drawer and I am charging it up. I will test it out in the AM and I will let you know what happens.

Thank You,
--Neal

Dear John,

I just finished installing AI2 on another Android smartphone and I have the same "Error 516 Unable to write. Broken Pipe". So I have swapped out both HC-06 module and smartphone and still have this error.

--Neal

Do you mean you have installed the app you built on the second phone? Is the HC-06 appearing in the phone's list of paired devices? Is it appearing in the Terminal app's list of devices?

If you search the AppInvr and Arduino forums for your error message there are some similar experiences from others. One cause seems to be voltage drop at the HC-05 cos devices attached to the Arduino causing a power drain. A sketch of your wiring setup might offer some clues.

Have you tried a different Arduino board such as a UNO?
John.

Don't forget your PC or laptop most likely has BT capability. You could test the comms b/w the HC-06 & the PC/laptop.

Do you have a GPS module? That is a convenient source of continuous serial data that can be sent to the HC-06 without any programming effort.

Good morning John. So I charged up the "old" Android phone and installed AI2 and BT Ser Term apps.

I first tried running my AI2 project and it behaved just the same. I received Error 516 several times.

Per your mention of voltage issues, I am using a voltage regulator (LM7805) to power the HC-06 with 5V (Vin is 3.6-6V). I monitored the voltage supply to the HC-06 with my scope and see no dips in voltage as I use the use the BT connection with my smartphone to turn a solenoid valve on and off. The solenoid valve opens based upon an accelerometer reading. I am not using a flyback diode on the solenoid valve because this created some very erratic behavior when I connected it. I do however have a capacitor in parallel with the solenoid valve. I believe that this somewhat helps.

The HC-06 DOES show up in the BT Ser Term app list on my "old" smartphone. I was able to connect and see the data stream. I am using AltSoftSerial with the Arduino Pro Mini and have been using mySerial.write() commands instead of mySerial.print() commands. The "write" commands showed up as diamonds on the BT Ser Term app. So I changed to "print" commands and the numbers show up correctly on the BT Ser Term app. But of course I will have to parse out the data on the AI2 end. I am not sure whether the write commands are the problem. What I do know is that I am able to see the accelerometer values changing on the BT Ser Term app as I move the accelerometer around, but the AI2 project does not see the numbers changing. I have to do some work with the parsing of the received data on the AI2 side.

So I do not believe that I have solved any problems at this time. I have only eliminated a few potential culprits. Hopefully I will now be able to parse out the received data. All of the data received is formatted to be 3 digits. I do not have to add any leading zeros. That being said, I saw an excellent tutorial on adding digits about a week ago...I will have to find the link.

Thank You,
--Neal

I think instead of writing and writing and writing you should put the faulty design here so that someone can see where you made the mistake.

I typically get that when the phone is not connected. So i would check that the Phone is paired to the HC-06 using the BT settings and you enter the 1234 as the passcode, then in the MIT code ensure you are connecting to the right MAC address, if after you connect to the HC-06 and the light is blinking slowly (2 sec intervals). Then you should check the potential divider resistors for the RX pin. I found that only having a 1k ohm in series to the pin worked and the potential divider stopped it working...

One thing I learned is that pairing (using phone settings and entering passcode 1234) is telling the phone that it is an allowed trusted device, then in the app you must get the list of allowed paired devises that the phone has ever connected to and choose the HC-06 as the one you want to control/ communicate with. As when you call if "bluetoothClient1. isConneced" it says yes as it is on the trust list but it dosent mean you have started a communication session with that device.

Its either a bug or a feature, no one knows...