rwaldron / johnny-five

JavaScript Robotics and IoT programming framework, developed at Bocoup.
http://johnny-five.io
Other
13.26k stars 1.76k forks source link

PingFirmata not found #1020

Closed mulderp closed 8 years ago

mulderp commented 8 years ago

Hi,

I am playing with a small robot with HSR04 sensor.

Flashing the PingFirmata looked successfull, but I get an error when I start up the HSR04 example:

pm:vehicle pmu$ node proximity_hello.js
1453638857437 Device(s) /dev/cu.usbserial-AL01TQ76
1453638857447 Connected /dev/cu.usbserial-AL01TQ76
1453638860882 Repl Initialized
>> { supportedModes: [],
  mode: undefined,
  value: 0,
  report: 1,
  analogChannel: 127 }
/Users/pmu/projects/embedded/book/ch_9_making_robots_with_nodejs/vehicle/node_modules/johnny-five/node_modules/firmata/lib/firmata.js:1321
    throw new Error("Please upload PingFirmata to the board");
          ^
Error: Please upload PingFirmata to the board
    at Board.pingRead (/Users/pmu/projects/embedded/book/ch_9_making_robots_with_nodejs/vehicle/node_modules/johnny-five/node_modules/firmata/lib/firmata.js:1321:11)
    at Proximity.<anonymous> (/Users/pmu/projects/embedded/book/ch_9_making_robots_with_nodejs/vehicle/node_modules/johnny-five/lib/proximity.js:176:19)
mulderp commented 8 years ago

Btw, I am trying to make this small robot work with Johnny-5: http://hackarobot.com/fabric-shield-monthly-giveaway/

Based on Arduino Nano, L293D to drive motors, and HC SR04 for proximity, some Arduino examples are here: https://github.com/ThomasCLee/funnyvale/tree/master/hackabot_nano ) The proximity sensor is wired to A0 and A1. Arduino Code for this is:

float getDistance() {
   digitalWrite(TRIGGER_PIN, LOW); 
   delayMicroseconds(2); 
   digitalWrite(TRIGGER_PIN, HIGH);
   delayMicroseconds(10); 
   digitalWrite(TRIGGER_PIN, LOW);
   return (  pulseIn(ECHO_PIN, HIGH) *0.017);
}

(/cc @ThomasCLee )

mulderp commented 8 years ago

Can pulseIn() be written with JavaScript ?

ThomasCLee commented 8 years ago

I am not familiar with JavaScript, but in theory, it should be doable.

You need to monitor the echo pin when it goes low, you store the current time. It then goes into a while loop. When the echo pin goes high, it exits. You compare the time when it exits verses the time you stored earlier. The difference is the pulse width.

You may need to add a timeout check for the while loop just in case.

On Sunday, January 24, 2016, Patrick Mulder notifications@github.com wrote:

Can pulseIn() be written with JavaScript ?

— Reply to this email directly or view it on GitHub https://github.com/rwaldron/johnny-five/issues/1020#issuecomment-174294531 .

rwaldron commented 8 years ago

HCSR04 won't work when attached to analog inputs, it needs to be attached to a digital input.

Can pulseIn() be written with JavaScript ?

No, but that's not really the issue here.

ThomasCLee commented 8 years ago

A0 and A1 pins could be analog as well as digital inputs (not just analog).

On Tue, Jan 26, 2016 at 11:12 AM, Rick Waldron notifications@github.com wrote:

HCSR04 won't work when attached to analog inputs, it needs to be attached to a digital input.

Can pulseIn() be written with JavaScript ?

No, but that's not really the issue here.

— Reply to this email directly or view it on GitHub https://github.com/rwaldron/johnny-five/issues/1020#issuecomment-175184964 .

rwaldron commented 8 years ago

A0 and A1 pins could be analog as well as digital inputs (not just analog).

Yes, I'm aware of this, but Johnny-Five has always used the user provided pin name value to infer user intent. Using the literal "A0" is assumed to mean: "I want this pin treated as an analog input pin, because that's a precedent that I learned from using Arduino". That being said, Proximity w/ HCSR04 can be updated to accept "A0" and do the right thing.

mulderp commented 8 years ago

(Interesting discussion, I was not aware that A0/A1 are GPIOs as well, but indeed it makes sense. Arduino mentions it too "The analog input pins can be used as digital pins, referred to as A0, A1, etc." see https://www.arduino.cc/en/Reference/DigitalRead )

rwaldron commented 8 years ago

@mulderp thanks for the report! v0.9.19 is on npm now. This was tested using:

And an example + diagram here: https://github.com/rwaldron/johnny-five/blob/master/docs/proximity-hcsr04-analog.md

mulderp commented 8 years ago

Thanks! Indeed, now it works great! To make the example work with @ThomasCLee hackarobot, one need to add a jumper between A0 and A1. Next up, I'll check the combination with an MPU-6050 to read the bot's position. But was working earlier already.