hybridgroup / gobot

Golang framework for robotics, drones, and the Internet of Things (IoT)
https://gobot.io
Other
8.95k stars 1.04k forks source link

Stuck at starting connection (with Firmata) #421

Closed conejoninja closed 7 years ago

conejoninja commented 7 years ago

I'm trying to connect to an Arduino Uno with Standard Firmata running on it, tried 3 different USB-cables and two different USB ports. Debian Jesie and user is on dialout group if that helps.

This issue happens most of the time, but not always. It just hangs at

➜  examples go run examplebot.go               
2017/05/18 09:39:17 Initializing connections...
2017/05/18 09:39:17 Initializing connection Firmata-5721E10BB1A30F02 ...
2017/05/18 09:39:17 Initializing devices...
2017/05/18 09:39:17 Initializing device LED-77F786BE130713F4 ...
2017/05/18 09:39:17 Robot sensorBot initialized.
2017/05/18 09:39:17 Starting Robot sensorBot ...
2017/05/18 09:39:17 Starting connections...
2017/05/18 09:39:17 Starting connection Firmata-5721E10BB1A30F02 on port /dev/ttyUSB0...

And that's it, it stays there, nothing more.

More information, I'm working on a driver for a sensor, maybe the code crash or exits without closing properly the connection to /dev/ttyUSB0 (as an idea). But If I disconnect/re-connect the arduino, the problem is still there. Arduino IDE is able to flash the board without any problem, it only happens with gobot's code. Also, once it start happening, no matter what I run (my code, or gobot's examples), it's stuck there.

Probably it's a configuration issue of my setup, but not sure how to identify what is wrong

deadprogram commented 7 years ago

The easy way to establish if it is permissions related, is to run your program under sudo.

If it runs correctly, it is permissions related. If not, it is something else.

Please give that a try.

Also, from where did you obtain your Firmata? Try using the Firmata that is uploaded using Gort (http://gort.io/) it was created using ConfigurableFirmata and includes all the needed capabilities.

conejoninja commented 7 years ago

Same results with sudo and chmod the file, sometime it works, sometime it doesn't. I tried with both, installing firmata from gort and from the IDE.

I will try with a different board, in case something is wrong with this one, since it works at times, it may be the problem. I'm running out of ideas.

deadprogram commented 7 years ago

Did you try switching to the dev branch of Gobot? There are some important Firmata/serial related changes in that branch.

conejoninja commented 7 years ago

Yes, I'm using dev branch, last commit 4e05c7f2c60604ae6f67ac4ae8f69378f6616d32

Even if this is a hardware problem, I think there could be some timeout, or at least some verbose option, that will help sort this out.

conejoninja commented 7 years ago

I close this issue, I used a different board and so far so good, no problems for now. Looked like a hardware problem.

half2me commented 7 years ago

I have the same problem with Arduino UNO and OSX 10.12.4

2017/05/23 15:51:22 Initializing connections...
2017/05/23 15:51:22 Initializing connection Firmata-A283223A5671633 ...
2017/05/23 15:51:22 Initializing devices...
2017/05/23 15:51:22 Initializing device LED-62505DE4731EE1DF ...
2017/05/23 15:51:22 Robot bot initialized.
2017/05/23 15:51:22 Starting Robot bot ...
2017/05/23 15:51:22 Starting connections...
2017/05/23 15:51:22 Starting connection Firmata-A283223A5671633 on port /dev/cu.usbmodem1421...

It just hangs here, and the program doesn't get loaded onto the Arduino

deadprogram commented 7 years ago

Hi @half2me did you try the dev branch as I had suggested?

half2me commented 7 years ago

@deadprogram I'm just starting to learn go, so I'm not sure how I would go about doing that :) Searching on the net is giving me forums where they say its not possible with go get ... wha?

conejoninja commented 7 years ago

@half2me go to your GOPATH/src/gobot.io/x/gobot/ and there just change the git branch with

git checkout dev && git pull origin dev

git checkout dev will change the branch to "dev" git pull origin dev will download latest updates of said branch

deadprogram commented 7 years ago

We will release an update with these fixes once we have confirmation from someone else that this issue and https://github.com/hybridgroup/gobot/issues/376 have been addressed in the dev branch.

We've tested on OSX El Capitan, just need testing on some more recent OSX versions.

half2me commented 7 years ago

@deadprogram @conejoninja I just tested with dev branch... same problem :(

deadprogram commented 7 years ago

@half2me did you flash the Arduino with Firmata first?

half2me commented 7 years ago

@deadprogram nope :/ I was under the impression that gobot would handle flashing that, but I'll try now.

deadprogram commented 7 years ago

https://gobot.io/documentation/platforms/arduino/ first paragraph in "How to install" documents this.

deadprogram commented 7 years ago

@half2me I added some code to the firmata.Connect() to some ideas that have emerged from this issue. The new code is much cleaner, and provides a new ConnectTimeout field that defaults to 15 seconds.

In the case that Gobot is unable to connect, the updated Firmata "blink" example will display any connection errors: https://github.com/hybridgroup/gobot/blob/dev/examples/firmata_blink.go#L32

Also, the error displayed in the case of a timeout, suggests flashing Firmata on your Arduino, for people who might not realize that requirement.

I am going to reopen this issue until the new code makes it into a Gobot release. In the meantime, anyone who can test the dev branch, your feedback in appreciated.

conejoninja commented 7 years ago

Nice, I can confirm the timeout is working properly, much better than before. In my case, it was a faulty hardware issue, that sometimes worked, sometimes not.

half2me commented 7 years ago

@deadprogram Awesome work, thank you! I will test the dev branch as much as possible and report any bugs I might find. 👍

JDogHerman commented 7 years ago

Seems to be working for me also, The dev branch let me know I was having a permissions error. After running ln -s /usr/local/go/bin/go /usr/bin/go I was able to run sudo go run blink.go without issue.

deadprogram commented 7 years ago

Version 1.6.0 is now out, and includes all these fixes. Now closing, please reopen if needed. Thank you everyone!