After installing the requisite packages on my Raspberry pi from the johnny-five.io website and reviewing examples, I realized one small oversight on my part. The "typical" use for johnny-five appears to be the ability to control a board (like an Arduino or Raspberry Pi) from a computer over a USB cable. You can install johnny-five on a Raspberry Pi itself, but then the use case is that the Rpi is the master and the board you connect (like an Arduino) is the slave. That's all well and good and part of what I wanted to do, but I *also* want to be able to control things *on* the Rpi at the same time.
I have googled all over and did not see examples of anyone saying that this could be done or had been done. Examples were either for the Rpi *or* the arduino. I find this shocking because it seems like the perfect robotic use case. Sure, there's piduino5, but again, that's just an Rpi controlling an Arduino without any specific control on the Rpi in addition.
I did find out how to set up multiple boards. With some digging I found out how to set up both types of boards and made adjustments for using the multi-board setup. I tinkered with the setup of LEDs and I found that I could blink LEDs on the Rpi AND the Arduino in the same script!
Below is my script. Very plain, it only tests with LEDs. I would consider this a "bilingual Hello World" for johnny-five. I hope this helps someone else scratching their head over the same dilemma,
/*
** Control Raspi AND Arduino
** (C) Dan Shaurette; licensed as CC-BY.
** http://creativecommons.org/licenses/by/4.0/
** March 17, 2017
** Using johnny-five.io
*/
var five = require("johnny-five");
var Raspi = require("raspi-io");
var ports = [
{ id: "mega", port: "/dev/ttyACM0" },
{ id: "rpi3", io: new Raspi() }
];
new five.Boards(ports).on("ready", function() {
var aled = new five.Led({
pin: 13,
board: this.byId("mega")
});
var pled = new five.Led({
pin: "P1-13",
board: this.byId("rpi3")
});
aled.blink();
pled.blink();
this.on("exit", function() {
aled.off();
pled.off();
});
});
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.