rwaldron / particle-io

Particle/Spark Core/Photon IO Plugin for Johnny-Five
http://johnny-five.io
MIT License
173 stars 31 forks source link

Reality Check: use Spark-IO with Johnny-Five to identify issues/bugs #9

Open rwaldron opened 10 years ago

rwaldron commented 10 years ago

Need to...

voodootikigod commented 10 years ago

I can rock on this! I have some time this week. Anyway to get some fritzing diagrams (will gladly help) for the breadboard layouts. Also will be a very awesome "getting started" guide for johnny-five in general.

rwaldron commented 10 years ago

@voodootikigod there are tons of them in Johnny-Five repo: https://github.com/rwaldron/johnny-five/tree/master/docs/breadboard

voodootikigod commented 10 years ago

I had no idea this existed...!!!! omg happiness

Chris Williams

@voodootikigod http://twitter.com/voodootikigod | GitHubhttp://github.com/voodootikigod

The things I make that you should check out: SaferAging http://www.saferaging.com/ | JSConf http://jsconf.com/ | RobotsConf http://robotsconf.com/ | RobotsWeeklyhttp://robotsweekly.com/

Help me end the negativity on the internet, share thishttp://jsconf.eu/2011/an_end_to_negativity.html .

On Sun, May 18, 2014 at 8:43 PM, Rick Waldron notifications@github.comwrote:

@voodootikigod https://github.com/voodootikigod there are tons of them in Johnny-Five repo: https://github.com/rwaldron/johnny-five/tree/master/docs/breadboard

— Reply to this email directly or view it on GitHubhttps://github.com/rwaldron/spark-io/issues/9#issuecomment-43458651 .

Resseguie commented 10 years ago

I can work on this too.

Resseguie commented 10 years ago

What's the best pattern for referencing J5 in these examples? Add it as a dependency (dev dependency?) or manually copy it to /lib?

var five = require("../lib/johnny-five.js"); // this ?
var five = require("johnny-five"); // or this?
// or something else?

Do you want J5 examples mixed in with vanilla spark-io ones? Or separate subdirectory under /eg?

Use same file names as J5 examples (eg. board.js)? Or prefix them somehow such as j5-board.js?

Resseguie commented 10 years ago

So before I go too far, is this what you had in mind for the original request? I basically just copied over files from the J5 eg/ folder and modified them to use spark-io (and tweaked to take advantage of things like the D7 LED).

https://github.com/Resseguie/spark-io/tree/j5-examples/eg

These are completely untested as of yet, but wanted to make sure I was on the right track before doing too many. I can also rename and reorganize per my previous comment before doing a pull request.

rwaldron commented 10 years ago

This is what example files that are local to the repo look like:

var five = require("../lib/johnny-five.js"); // this ?

This is what is used when you've installed Johnny-Five via npm install johnny-five:

var five = require("johnny-five"); // or this?
rwaldron commented 10 years ago

Do you want J5 examples mixed in with vanilla spark-io ones? Or separate subdirectory under /eg?

Mixed is fine

rwaldron commented 10 years ago

So before I go too far, is this what you had in mind for the original request? I basically just copied over files from the J5 eg/ folder and modified them to use spark-io

That's what I would've done

Resseguie commented 10 years ago

As far as referencing J5, I just wasn't sure if you wanted to check in a snapshot of johnny-five.js under lib/ or depend on using npm to install (my personal preference but don't feel strongly either way). And if we go the npm route, should it be listed under devDependencies?

rwaldron commented 10 years ago

In this case devDependencies would be fine

Resseguie commented 10 years ago

In converting a few of the examples for J5, I'm getting a similar error to what's described in this gist: https://gist.github.com/Resseguie/21d83c60511789f51a23 (Gist is a direct copy of J5's led.js but using the spark-io plugin for creating the board.)

Basically, it's assuming pin is a string, but it's still a number at spark.js:276 and thus replace() isn't defined.

pinInt = (pin.replace(/A|D/, "") | 0) + offset; 

TypeError: Object 13 has no method 'replace'

Been spinning my tires a bit trying to figure out what's going on. Have a quick pointer to keep me rolling?

rwaldron commented 10 years ago

You'll need to change the pins from the numeric pins of an Arduino to the string pins of a Spark. The gist errors because 13 is an invalid pin for Spark, valid pins are: "D0-D7" and "A0-A7".

Change this:

var led = new five.Led(process.argv[2] || 13);

to this:

var led = new five.Led(process.argv[2] || "D7");

And it will be fine

Resseguie commented 10 years ago

Shoot, I copied over an old version by mistake in that gist. (It's been updated.)

Yes, the following works (using digital pin):

var led = new five.Led(process.argv[2] || "D7");

but not if you specify an analog one. The "A" gets stripped somewhere:

var led = new five.Led(process.argv[2] || "A1");
$ node led.js "A1"
1400642280013 Device(s) spark-io 
1400642280386 Connected spark-io 
1400642280387 Repl Initialized 
>> 
/Users/Resseguie/Dropbox/work/spark-io/lib/spark.js:276
  pinInt = (pin.replace(/A|D/, "") | 0) + offset;
                ^
TypeError: Object 1 has no method 'replace'
    at Spark.pinMode (/Users/Resseguie/Dropbox/work/spark-io/lib/spark.js:276:17)
    at Led.Object.defineProperties.mode.set (/Users/Resseguie/Dropbox/work/spark-io/node_modules/johnny-five/lib/led.js:83:19)
    at new Led (/Users/Resseguie/Dropbox/work/spark-io/node_modules/johnny-five/lib/led.js:94:15)
    at Board.<anonymous> (/Users/Resseguie/Dropbox/work/spark-io/eg/led.js:13:13)
    at Board.EventEmitter.emit (events.js:95:17)
    at Board.broadcast (/Users/Resseguie/Dropbox/work/spark-io/node_modules/johnny-five/lib/board.js:384:8)
    at Board.<anonymous> (/Users/Resseguie/Dropbox/work/spark-io/node_modules/johnny-five/lib/board.js:298:23)
    at Spark.g (events.js:180:16)
    at Spark.EventEmitter.emit (events.js:92:17)
    at Socket.<anonymous> (/Users/Resseguie/Dropbox/work/spark-io/lib/spark.js:183:13)
rwaldron commented 10 years ago

but not if you specify an analog one. The "A" gets stripped somewhere:

That's an awesome bug you found—great work!

rwaldron commented 10 years ago

https://github.com/rwaldron/spark-io/issues/17

Resseguie commented 10 years ago

Not ready to do a PR until I've better tested all these, but if anyone is interested in tracking progress of the examples I've added so far, you can see them in this branch off my fork: https://github.com/Resseguie/spark-io/tree/j5-examples/eg

voodootikigod commented 10 years ago

Awesome work!!!

I disappear for two days and you two rock the heck out of it!!! Thank you!

Chris Williams

@voodootikigod http://twitter.com/voodootikigod | GitHubhttp://github.com/voodootikigod

The things I make that you should check out: SaferAging http://www.saferaging.com/ | JSConf http://jsconf.com/ | RobotsConf http://robotsconf.com/ | RobotsWeeklyhttp://robotsweekly.com/

Help me end the negativity on the internet, share thishttp://jsconf.eu/2011/an_end_to_negativity.html .

On Wed, May 21, 2014 at 11:32 PM, David Resseguie notifications@github.comwrote:

Not ready to do a PR until I've better tested all these, but if anyone is interested in tracking progress of the examples I've added so far, you can see them in this branch off my fork: https://github.com/Resseguie/spark-io/tree/j5-examples/eg

— Reply to this email directly or view it on GitHubhttps://github.com/rwaldron/spark-io/issues/9#issuecomment-43845328 .

Resseguie commented 10 years ago

Question: In Johnny-Five examples, we have pairs like button.js and button-options.js that are basically identical but the second demonstrates passing multiple options to constructor. Do we really need both those when refactoring for spark-io, or can I just include a comment in button.js that demonstrates the other options? Feels redundant to have both almost identical examples.

rwaldron commented 10 years ago

can I just include a comment in button.js that demonstrates the other options?

That sounds good to me :)