Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

[Unable to run demo] - Firmata closes serial connection... #53

Closed
stevenrace opened this Issue · 29 comments

9 participants

@stevenrace

First off, rad project. I'm hoping someone can steer me towards the light...

Attempting to run the demo code: (

var five = require("johnny-five"),
    board = new five.Board();

board.on("ready", function() {
  (new five.Led(13)).strobe();
});

Which fails with:

Connecting...�
Serial� Found possible serial port� ttyACM0
Board -> Serialport� connected�
Board <- Serialport ready�
Repl� Successfully Connected�
firmata > �Board� Closing connection to board, serialport
/home/usernamehere/projects/johnny-five/node_modules/firmata/lib/firmata.js:13341: Uncaught TypeError: Cannot set property 'mode' of undefined

ArchLinux
NPM version 1.1.46
Node version v.0.8.5
Arduino Uno via USB

thanks in advance...

@rwaldron
Owner

Thanks, I'm going to cross-file this with Firmata

@rwaldron
Owner

Follow here: jgautier/firmata#13

@stevenrace

Thanks.

I spent the afternoon tracking down another Arduino Uno, loading an Ubuntu VM, and swapping various cables - but while I didn't get dumped into a Firmata prompt, I couldn't get the demo examples (or REPL) to work... it just lights up TX on the Arduino.

Bummer.

I'm going to retry later with a Macbook and my multimeter.

  • Are non-Uno Arduinos supported?
@rwaldron
Owner

Have you loaded StandardFirmata onto the board?

@stevenrace

In short, after a fresh install of Mountain Lion it works on my Macbook.

However, on various Linux machines it fails with the same error above. Details in the Firmata link, as I suspect it's the problem too.

:(

@rwaldron
Owner

Thanks for the update—I'm moving from Boston to New York over the next few days, but once I'm settled in I'll commit to working through the installation process on Linux.

@paultag
Collaborator

I'm interested to know what's up with this. Is the VM handling USB correctly? I have no issues with Johnny-Five on any of my GNU/Linux machines

@stevenrace

Paul, thanks for the feedback. It's good to know it's possible :).

The VM Host is set to pass through a USB Bus and specified devices (in this case an Arduino Uno as /dev/ttyASM0). And I can now get Firmata to work on both Ubuntu and ArchLinux VMs.

For Arch it was a matter of not being in the 'uucp' group:

$ echo "foobar" > /dev/ttyACM0
permissions error (too lazy to cut+paste) 
$ sudo gpasswd -a <user> uucp #(and then reboot)

Ubuntu:

  • I had to remove Nodejs which was installed via the unofficial repo
  • Compiled from source (using v0.8.8, as v0.9-pre broke 'npm install')
  • changed permissions with:
$ sudo usermod -a -G dialout myusername
$ sudo chmod a+rw /dev/ttyACM0
# steps via: http://blog.markloiseau.com/2012/05/install-arduino-ubuntu/

Ok, that said it still fails.

Within ArchLinux it really doesn't post an error.

screenshot

Occasionally, I get dumped to a firmata prompt. But trying to pass led.on() or similar didn't work as I had hoped
screenshot #2

Trying Johnny-five on Ubuntu now results in the same thing as ArchLinux... the TX light stays lit but pin13 doesn't cycle...

screenshot

$ cat /dev/ttyACM0

screen
So you can see the serial connection is made and something is going across the wire...

Also I was able to get another project, Duino (https://github.com/ecto/duino), to work on both Arch and Ubuntu. It doesn't use Firmata as the Arduino sketch, but it's own. Not sure if that helps pinpoint the issue...

Thanks for the help so far.

@stevenrace stevenrace closed this
@stevenrace stevenrace reopened this
@rwaldron
Owner

Re: the repl missing led: eg/led-on-off.js Doesn't have any code that injects the led instance into the repl: https://github.com/rwldrn/johnny-five/blob/master/eg/led-on-off.js

Which version of the IDE are you using? Which version of Firmata? if it's 2.3, switch to 2.2

@soundanalogous

Not sure if this will fix your issue or not: https://github.com/soundanalogous/AdvancedFirmata. If it doesn't file an issue there and/or fork and submit a pull request. The official Firmata library is not going to move forward anytime soon (if ever for reasons other than bug fixes).

@m-mujica

Hi guys, I'm running into the same issue here :'(

I'm running Ubuntu 12.10. At this time I'm testing with Arduino 0023 because I'm sure that it has Firmata 2.2. ( I've tried with Arduino 1.0.x and got the same error ). I've loaded Standard Firmata from File/Examples/Firmata/StandardFirmata and when I try to run the led-strobe example I get the following:

$ node led-strobe.js

1355586587821 Board Connecting...
1355586587827 Serial Found possible serial port ttyACM0
1355586587833 Board -> Serialport connected ttyACM0
1355586587833 Board

1355586587834 Repl Successfully Connected

.../johnny-five/node_modules/firmata/lib/firmata.js:13341: Uncaught TypeError: Cannot set property 'mode' of undefined

What can I do?
Thanks

@louisremi

I had the exact same problem and today I successfully got the LED to cycle. I used the standardFirmata shipped with the version 1.0.3 of the IDE, then just after clicking "upload", I execute the following command:

$ sudo chmod a+rw /dev/ttyACM0

This is the only Johnny-Five example I have tested so far. I'll let you know if I run into other problems.

@louisremi

hum, very strange, I just tried the potentiometer example and couldn't get it to work. Then I tried the cycling LED again and can't get it to work anymore :-(
I rebooted, tried to do everything like I did the first time, to no avail. Everything seems to run fine, the command line displays Board -> Serialport connected ttyACM0 but the LED doesn't strobe.
This is rather annoying.

@rwaldron
Owner

Unfortunately, these reports have been impossible to reproduce :(

@louisremi

Yep. I'm using the AMD64 variant of Ubuntu 12.10, and I've tried every version of standardFirmata out there.
I think the one time when the cycling led worked was a false positive: is it still supposed to blink after the node program has been shutdown? If not, then it was only me not properly resetting the card after uploading the built-in Blink example.

I'm gonna try Ubuntu 32 to see if it helps. Has anyone tried Johnny-Five with the RaspberrPi and its default OS? If it works, this could be an expensive but relatively easy fix (I've ordered mine yesterday).

@louisremi

I've created live USBs of Ubuntu 12.10 in 32b and 64b then booted them and installed Java, g++, node+npm, the Arduino IDE v1.0.3 and then downloaded Johnny-five. I have successfully uploaded standardFirmata 2.2 and the version shipped with the IDE (not at the same time of course) but I haven't been able to execute the demo code, it never goes further than Board -> Serialport connected ttyACM0. Sketches written in processing are uploaded and run successfully on the board, though.
So it probably doesn't have to do with 64b nor software configuration. I still have to try previous versions of Ubuntu and different hardware. I'll keep posting in this bug if it doesn't bother anyone.

For the record, the easiest way to upload firmata or any other arduino code to the board is to start the IDE with $ sudo ./arduino and reset the board right after clicking the upload button.

@rwaldron
Owner

Do you mean hitting the actual reset button on the board?

Doing that will reset the board, which erases the compiled and uploaded Standard Firmata... which is why Johnny-Five can't make a connection.

@m-mujica

Rick, I'm definitely not doing hard testing like Louis, but I can tell you I do not hit the reset button after upload the Firmata but get the same error "Cannot set property 'mode' of undefined"

@louisremi

@rwldrn The need to reset the board might depend on the type of board actually. I'm using Leonardo and uploading new sketches often fails if I don't press the reset button of the board right after clicking the upload button of the IDE.
(I forgot to mention in my previous post that Processing sketches were successfully uploaded and run using that procedure, with both live USBs).

@evilsaurer The "Cannot set property 'mode' of undefined" error often has to do with permissions to read/write the USB port. You should try @stevenrace advice of doing $ sudo chmod a+rw /dev/ttyACM0 before executing your node app or running it with $ sudo node <name of your app>.

EDIT: I can confirm that Firmata is not to blame, having played with the Firmata Test Program (again, ran with sudo).

@soundanalogous

In order to use StandardFirmata with Arduino Leonardo you have to replace the version of Firmata included in the Arduino IDE with version 2.3.2 or higher: https://github.com/firmata/arduino/downloads. This will ensure that all of the pins are mapped correctly. Leonardo was not added to Boards.h of the Firmata library until version 2.3.2.

@louisremi

[Oops, I inadvertently deleted my last post, here it is, sorry]

I have a version of firmata.js that works with my configuration: https://github.com/louisremi/firmata

I read a little bit of the docs of SerialPort and the Firmata protocol and noticed that the current firmata.js doesn't wait for the "open" event of SerialPort and doesn't send requests for REPORT_VERSION and QUERY_FIRMWARE characters. So I fixed that and was able to run my first Johnny-five demo, this time for real!

I just don't know why everything works fine for others... I need those who don't have problems to make sure my fix doesn't break anything, and I need @stevenrace to tell me if my version of the file fixes his problems.

Thank you in advance!

PS: @soundanalogous I have been able to run the basic Johnny-Five example on a Leonardo using both Firmata 2.2 and Firmata 2.3. But you're right, Firmata 2.3 is required to get all pins properly mapped on that card.

@soundanalogous

It will work, but your pins will not all be mapped correctly. Firmata (the Arduino library, not the node.js library... confusing... should have been named "node-firmata" or something like that) detects the ATmega32u4 on the Leonardo, but thinks it's a Teensy 2.0 board. The pinout is different on the Teensy 2.0 and Leonardo. Here is the Leonardo board definition from Boards.h (which was added in Firmata v2.3.2):

// Leonardo
#elif defined(AVR_ATmega32U4)
#define TOTAL_ANALOG_PINS 12
#define TOTAL_PINS 30 // 14 digital + 12 analog + 4 SPI (D14-D17 on ISP header)
#define VERSION_BLINK_PIN 13
#define IS_PIN_DIGITAL(p) ((p) >= 0 && (p) < TOTAL_PINS)
#define IS_PIN_ANALOG(p) ((p) >= 18 && (p) < TOTAL_PINS)
#define IS_PIN_PWM(p) ((p) == 3 || (p) == 5 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 11 || (p) == 13)
#define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
#define IS_PIN_I2C(p) ((p) == 2 || (p) == 3)
#define PIN_TO_DIGITAL(p) (p)
#define PIN_TO_ANALOG(p) (p) - 18
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
#define PIN_TO_SERVO(p) (p)

And this is the board definition for the Teensy 2.0 board (for version of Firmata earlier than 2.3.2)

// Teensy 2.0
#elif defined(AVR_ATmega32U4)
#define TOTAL_ANALOG_PINS 12
#define TOTAL_PINS 25 // 11 digital + 12 analog
#define VERSION_BLINK_PIN 11
#define IS_PIN_DIGITAL(p) ((p) >= 0 && (p) < TOTAL_PINS)
#define IS_PIN_ANALOG(p) ((p) >= 11 && (p) <= 22)
#define IS_PIN_PWM(p) digitalPinHasPWM(p)
#define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
#define IS_PIN_I2C(p) ((p) == 5 || (p) == 6)
#define PIN_TO_DIGITAL(p) (p)
#define PIN_TO_ANALOG(p) (((p)<22)?21-(p):11)
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
#define PIN_TO_SERVO(p) (p)

This means that I2C pins and analog pins will not map properly and that not all of the digital pins will be available if you are using a Leonardo with an older version of Firmata. The latest version of Firmata supports both Leonardo and Teensy 2.0 boards.

@kingcoyote

I was running into the same bug but made a few changes and got past it.

First off, I'm running an Arduino Uno on an Ubuntu 12.04 VM inside a Windows 7 host. I'm using the 1.0.3 IDE and node v0.8.7 and johhny-five v0.5.14.

When I originally set up Firmata, I did it through Windows 7, and then switch to Ubuntu to do the JS work and got this error. I then installed Arduino IDE into Ubuntu and re-uploaded Firmata to the Arduino from there, and changed permissions on /dev/ttyACM0 to 0777. I'm not sure which of these changes fixed it, but either way the error stopped happening.

@louisremi

@kingcoyote that is surprising, but interesting. I'm still very interested to know if my modified firmata.js fixes the problem for @stevenrace

@agentsmith2

I experienced a very similar bug. First setup was Arduino Uno with Firmata 2.2 uploaded via Arduino 0023 running on Windows 8 x64. Things got stuck on

1359288784867 Board Connecting...
1359288784984 Serial Found possible serial port ttyACM0
1359288784995 Board -> Serialport connected ttyACM0

when running Johnny Five from Raspberry Pi with Node.js compiled from source and Johnny Five installed locally via npm package. Strange thing is that everything worked flawlessly with same setup except running J-5 from a Linux Mint 14 laptop.

According to @kingcoyote i tried uploading Firmata 2.2 from Arduino 0023 on Linux machine. Now things got even more strange. I could not get the LED Fade example to work but LED Strobe example works a litte. LED Turns on and off once and then get stuck again at this point:

1359288784867 Board Connecting...
1359288784984 Serial Found possible serial port ttyACM0
1359288784995 Board -> Serialport connected ttyACM0
1359288790443 Board <- Serialport ready ttyACM0
1359288790451 Repl Successfully Connected

Repl does not take any commands (not even ^C) until i pull the Arduinos USB off the Pi.
I checked the modified firmata.js lib from @louisremi but that did not change anything for me. The "stuck situation" is similar to the one others described here. Notably the TX LED on the Ardunio is strobing and data is coming in on the serial line as cat proved.

The best output i could get is the following when i ran the LED Fade example (LED didn't do anything) then typing led.on() while repl got stuck, so i didn't see the actual text i was writing and finally pulling the USB plug.

1359286779541 Board Connecting...
1359286779658 Serial Found possible serial port ttyACM0
1359286779668 Board -> Serialport connected ttyACM0
1359286785279 Board <- Serialport ready ttyACM0
1359286785287 Repl Successfully Connected

led.on()
{ board:
{ ready: true,
firmata:
{ domain: null,
_events: {},
_maxListeners: 10,
MODES: [Object],
I2C_MODES: [Object],
HIGH: 1,
LOW: 0,
pins: [Object],
analogPins: [Object],
version: [Object],
firmware: [Object],
currentBuffer: [Object],
versionReceived: true,
sp: [Object] },
id: '2163B859-1FE1-44BF-B7BB-EA0D91279021',
debug: true,
repl: { context: [Object], ready: false },
_events: { ready: [Function] },
port: 'ttyACM0' },
firmata:
{ domain: null,
_events: {},
_maxListeners: 10,
MODES:
{ INPUT: 0,
OUTPUT: 1,
ANALOG: 2,
PWM: 3,
SERVO: 4 },
I2C_MODES:
{ WRITE: 0,
READ: 1,
CONTINUOUS_READ: 2,
STOP_READING: 3 },
HIGH: 1,
LOW: 0,
pins:
[ ...many [Object] here ...],
analogPins:
[ 16,
17,
18,
19,
20,
21,
22,
23 ],
version: { major: 2, minor: 2 },
firmware:
{ version: [Object],
name: 'StandardFirmata' },
currentBuffer:
[ ... many analog read values here... ],
versionReceived: true,
sp:
{ domain: null,
_events: [Object],
_maxListeners: 10,
fd: 0,
readStream: [Object],
closing: false } },
value: [Getter],
interval: { ontimeout: [Function] },
pin: 3,
mode: 1 }

(^C again to quit)

1359286823364 Board Closing: firmata, serialport

Maybe this is somewhat useful to you.

@rwaldron
Owner

Sorry, I've been warning people away from the npm package... it's severely out of date and has bugs, but I haven't been ready or comfortable with releasing a new version, but it looks like I may have to...

@agentsmith2

Well thats a nice hint. I'll check that later.

Edit: Cloned a fresh johnny-five version from github and required that via an absolute path. But that did not change anything for me :(

@rwaldron rwaldron closed this
@Athuli7

Guys, i'm a noob in linux (so don't scream if this is some obvious thing or something), but this worked for me. I tried all of the above stuff, about permissions and all, but they did nothing by themselves, I had to change ttyACM0 to ttyUSB0. Vola, works beautifully..

@rwaldron
Owner

The port detection should match that:

var rport = /usb|acm|^com/i;
@scazan scazan referenced this issue in netlabtoolkit/ntk
Closed

Pin mode switching from front-end #48

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.