Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
mg-snake
@mg-snake
this is in my PATH
Joshua Scott Oxner
@Bohemus307
Is there a way to access a ph sensor that is connected via usb to a rpi3 with Johnny-five?
Vini Dalvino
@ViniDalvino
I know it sound stupid to say but would it be possible to use the johnny five library and express js on a Espduino board to make a web server?
markirgang
@markirgang
I tried running the Phoenix.js program from the Javascript Robotics book. I received multiple errors running the code:

Running the Phoenix.js the errors were Microsoft Windows [Version 10.0.18363.1256]
(c) 2019 Microsoft Corporation. All rights reserved.

C:\Users\HP>node phoenix.js
1609566836800 Available COM7
1609566836806 Connected COM7
1609566837872 Repl Initialized

The 'isInverted' property has been renamed 'invert'
C:\Users\HP\phoenix.js:99
phoenix.r1 = new five.Servo.Array([ phoenix.r1c, phoenix.r1f, phoenix.r1t ]);
^

TypeError: five.Servo.Array is not a constructor
at Board.<anonymous> (C:\Users\HP\phoenix.js:99:16)
at Board.emit (events.js:323:22)
at Board.EventEmitter.emit (domain.js:482:12)
at C:\Users\HP\node_modules\johnny-five\lib\board.js:428:39
at processTicksAndRejections (internal/process/task_queues.js:79:11)

C:\Users\HP>

C:\Users\HP>

C:\Users\HP>

Donovan Buck
@dtex
Try ‘new five.Servos’ instead of ‘new five.Servo.Array’
markirgang
@markirgang
Ok,thanks. What about the The 'isInverted' property has been renamed 'invert'
C:\Users\HP\phoenix.js:99
phoenix.r1 = new five.Servo.Array([ phoenix.r1c, phoenix.r1f, phoenix.r1t ]);
Is that 'isInverted' property has been renamed 'invert' a warning or a critical error that will stop the program from executing?
Donovan Buck
@dtex
Yes
markirgang
@markirgang
Ok,thanks!
markirgang
@markirgang
Getting closer! The Phoenix code compiles now with no errors or warnings and the Raspberry Pi running Node 14 and Johnny-five connects to the Arduino Mega flashed with standard Plus Firmata and connected directly to the servos w/no sensor shield When I type ph.walk or ph.sleep through he REPL it says it's running the function but yet the servos don't move. Any idea what could be wrong? As a test I tried flashing "sweep" in the Arduino IDE ID and the servo worked fine.
markirgang
@markirgang
I also tried running a simple servo sweep program in node.js/Johnny-5 on the raspberry Pi connected by USB to the Arduino Mega. The simple sweep program worked fine and the receive light on the Mega flickered as the servo swept. Yet, nothing is received by the Mega when I tried the Phoenix program.
markirgang
@markirgang
I even tried as a test inserting code for a servo sweep on pin 10. The receive light on the Mega flickered and the servo swept. Yet, the Phoenix code doesn't seem to send an commands to the servos.
Donovan Buck
@dtex
Hmmm, I'll take a look. Were talking about the Phoenix code in the J5 repo, correct?
Not from the Javascript Robotics book repo.
markirgang
@markirgang
It's from that excellent Make: Javascript Robotics book. The code is on GitHub at https://github.com/rwaldron/javascript-robotics. I used to read that book to my son several years ago. Now he is an engineering student at RPI.
Sorry, I meant Drexel. My daughter did RPI engineering.
Donovan Buck
@dtex
First, I'd try switching to the code in the J5 repo. It's a couple of years more up to date. I know the Servo.Array collection constructor was deprecated a while back. That could be the culprit.
markirgang
@markirgang

pi@raspberrypi:~ $ node phoenix
node:internal/modules/cjs/loader:928
throw err;
^

Error: Cannot find module '../lib/johnny-five.js'
Require stack:

  • /home/pi/phoenix.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:925:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Module.require (node:internal/modules/cjs/loader:997:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.<anonymous> (/home/pi/phoenix.js:17:12)
    at Module._compile (node:internal/modules/cjs/loader:1108:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:973:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12) {
    code: 'MODULE_NOT_FOUND',
    requireStack: [ '/home/pi/phoenix.js' ]
    }
Sorry, the preceeding was the error I got trying to run the newer J5 code
Donovan Buck
@dtex
It assumes it's in the eg folder. Just change the require statement for J5 so that it doesn't use a relative path:
var five = require("johnny-five"),
markirgang
@markirgang
Yes. The errors are gone. Still not sending servo messages to the mega,though
Donovan Buck
@dtex
I'm at the day job right now so I can't test, but I'm thinking that maybe the 'degrees' property name isn't being converted to 'value'. This means the servo value never changes. J5 won't try to update the servo if the value doesn't change so no command is sent to the mega. I'll try after work.
markirgang
@markirgang
Interesting!- I tried inserting function calls like "ph.walk();" from inside the code itself instead of trying to call the "ph.walk(); function by typing the commands into the command window as follows:>>ph.walk();. The board is now receiving data and moving the servos! Is it possible I'm not using the command window correctly?
Donovan Buck
@dtex
Hmm... there’s no magic in using the repl. What do you get if you just type ‘ph’?
markirgang
@markirgang

just prints out stuff like this:pwmRange: [Array],
range: [Array],
deadband: [Array],
fps: 100,
offset: 0,
mode: 4,
interval: null,
value: 103.29333333333332,
type: 'standard',
invert: true,
startAt: 180,

  [Symbol(kCapture)]: false
},
length: 6

},
coxa: Servos {
'0': Servo {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
board: [Board],
io: [Firmata],
id: 'FC0C1A77-1F7F-4726-8419-90C6BF96E894',
custom: {},
pin: 23,
degreeRange: [Array],
pwmRange: [Array],
range: [Array],
deadband: [Array],
fps: 100,
offset: 10,
mode: 4,
interval: null,
value: 56.80000000000001,
type: 'standard',
invert: false,
startAt: 45,

  [Symbol(kCapture)]: false
},

...etc etc

Interestingly, one side's legs don't move at all while the other side's legs move normally when calling ph.walk();. Is something wrong with the "invert" function?
markirgang
@markirgang
Sorry!My mistake. I connected the servos to the pins specified in the Javascript Robotics book. I should have verified that the pins specified in the phoenix.js code match the pins specified in the book. I hooked up the pins to match the code and it worked! Should teach me to never assume anything.Now I will trim the servos and repair the stripped joints w/ epoxy and I should be good to go. Thanks for this amazing animation code!
Where does the Sparkfun Joystick shield and UNO get connected here?
RYeah Sh
@pantchox
Hi everyone, how do you get real time push notification from your devices? I am asking for development research - ANY input will be great! thanks
reconbot
@reconbot:matrix.org
[m]
wohh gitter is matrix?
@pantchox: mqtt is a common protocol, but even an HTTP get request to a server that does the "push" will work
onesocialinbox
@onesocialinbox
Can Johnny-Five library run on browser DOM? When I browserify/webpack it has some problems running in browser... Any hints??
Lucas Sanz Gorostiaga
@lucas-sg

Hi everyone, I'm desperately looking for help with the Proximity class. I'm trying to read data from a HCRS-04 proximity sensor and then stop after I say so (with the click of a button). The thing is, there is no "disable" method or anything similar to make it stop. So I tried to pass a React state so that when the state changes, the callback function that is associated to the proximity.on("data", callback) method stops processing the data. The Proximity object would still be reading but there would be nothing going on since the state changed.

The problem is that the callback function won't change accordingly. The state is initiated with a "true" value, but when it changes to false the callback function doesn't notice. It's the same as if I had passed a function that said if (true) {...}.
I don't know what to do anymore, I really need this to work for my college thesis.

reconbot
@reconbot:matrix.org
[m]
Got any example code?
Lucas Sanz Gorostiaga
@lucas-sg

Sure, sorry for the delay, but here it is:

const proximityCallback = (centimeters: number) => {
    if (reactStateIsTrue) {
        console.log(centimeters);
    }
};
plotArduinoData(750, proximityCallback);

and the plotArduinoData function being:

export function plotArduinoData(freq: number, callback: (centimeters: number) => void) {
    if (board == null)
        board = new Board({
            repl: false,
            debug: false
        });

    board = board.on("ready", () => {
        const proximity = new Proximity({
            controller: "HCSR04",
            pin: 10,
            freq: freq
        });

        proximity.on("data", (data) => callback(data.cm));
    });
}
Like I said before, the callback function that is being bound to the proximity object in the on method is not changing according to the react state that is being passed on
I got a recommendation to use proximity.removeAllListeners("data"); to make it stop but since I'm using Typescript I don't have the inheritance relationship between
Proximity < Withinable < EventEmitter
reconbot
@reconbot:matrix.org
[m]
How are you getting this to run in the browser?
Lucas Sanz Gorostiaga
@lucas-sg
I'm running it as an Electron application
reconbot
@reconbot:matrix.org
[m]
Ahh
Lucas Sanz Gorostiaga
@lucas-sg
If you have any idea of how to overcome the Typescript problem of not recognizing Proximity's ascendants or if you have another approach to make the callback take the cue from React's state it would be really appreciated :pray:
reconbot
@reconbot:matrix.org
[m]
Is all this in a useEffect?
You probably got to share the react example too as this code looks ok but isn’t the full
Story
Rick Waldron
@rwaldron
I think the best we can do is a "pause/resume", which would "pause" the emitters from emitting until you call "resume"
Lucas Sanz Gorostiaga
@lucas-sg
@rwaldron that would be splendid!
@reconbot:matrix.org no, the first code fragment is part of a functional component that sets the layout for a chart to be plotted out. I didn't put the rest of the component because it's irrelevant to the problem. The component receives the reactStateIsTrue flag as part of props and uses it to tell the Proximity object whether or not to log the cm read (if only the Proximity object would actually listen to the state's changes).
The state (reactStateIsTrue) flag is a boolean that was initiated as:
    const [reactStateIsTrue, stop] = useState(true);
Lucas Sanz Gorostiaga
@lucas-sg

I think the best we can do is a "pause/resume", which would "pause" the emitters from emitting until you call "resume"

Would this be something that could be solved by myself with your advice/guidance or is this something that could be implemented eventually in the project?

Rick Waldron
@rwaldron
I meant, J5 can/should do that