SoundSensor with node.js

Hello,

first, i like the GrovePi very much, it simplifies a lot.

I have tried to write a class consuming the lightsensor, as there is currently no class in lib for it.
But it always returns 0.

I call the AnalogSensor the following way:

var method = SoundSensor.prototype;

var AnalogSensor = require('./base/analogSensor')
var commands     = require('../commands')

function SoundSensor() 
{
}

var analogSensor = new AnalogSensor(2);

method.read = function()
{
	return analogSensor.read(); 
}

module.exports = SoundSensor

I have installed 5 more Sensors that currently not supported by node.js library.

Thanks a lot…

Hey,
Di you have a look at the Node.JS code here: https://github.com/DexterInd/GrovePi/blob/master/Software/NodeJS/libs/sensors/lightAnalogSensor.js .

It would be great if you send us a pull request for the other sensors that are working for you. We’ll be glad to merge them in our repo.

-Karan

Hi s0h0,
as pointed out by Karan there is actually an analog light sensor class in the current library, did it help? Let me know.

Marcello

Hello,

sorry didnt got time to try it out.
Yes i had a look at the the AnalogLightSensor and the dhtDigitalSensor which i have both already running.
I have tried now two ways but both return always 0 for the first three bytes and 255 for the fourth byte.
SoundSensor is connected to A1 port.

First approach using the AnalogSensor and adding as a new defualt sensor class to the index.js (in analogSensor.js i can see the returned bytes are always 0 and 255):

var AnalogSensor = require('./base/analogSensor')
var commands     = require('../commands')
function SoundAnalogSensor(pin) {
  AnalogSensor.apply(this, Array.prototype.slice.call(arguments))
}
SoundAnalogSensor.prototype = new AnalogSensor()
SoundAnalogSensor.prototype.read = function() {
  this.board.pinMode(this.board.INPUT)
  var res = AnalogSensor.prototype.read.call(this)
  var number = parseInt(res)
 console.log('SOUND value: ' + number);
  return number;
}
module.exports = SoundAnalogSensor

Second approach with a custom function as descriped in readme and basicTest.js files. (Also always returns 0 for first three bytes and 255 for third byte)

function customAccelerationReading()
{ 
var write = board.writeBytes(commands.aRead.concat([1, commands.unused, commands.unused]))
  if (write) {
    board.wait(2000)
    board.readByte();
    var bytes = board.readBytes()
    if (bytes instanceof Buffer)
    {
      console.log('byte0' + bytes[0]);   //returns 0
      console.log('byte1' + bytes[1]);   //returns 0
      console.log('byte2' + bytes[2]);   //returns 0
      console.log('byte3' + bytes[3]);   //returns 255
      return bytes[0];
    } else {
      return false
    }
  } else {
    return false
  }
}

Really appreciate any help. If it will work i can of couse check it in as a pull request.

Thank you.

Hi s0h0,
could you please tell me more about the environment? Which version of Node.js are you running? Which is the firmware version of your GrovePi? Which model of Rpi do you have?

Thanks in advance

EDIT:
It’s not clear to me if you are facing issues with the AnalogLightSensor and the DHTDigitalSensor or if they are working fine for you. Please, let me know :slight_smile:

The AnalogLightSensor and the DHTDigitalSensor are working really fine for me.

The other Infos as following.
Sensor: SoundSensor v1.1
Node Version: v0.12.6
GrovePi Version :: 255.255.255
Linux Kernel: Linux raspberrypi 3.18.11+ #781 PREEMPT Tue Apr 21 18:02:18 BST 2015 armv6l GNU/Linux
RaspPiFirmware: Apr 21 2015 14:40:08, Copyright © 2012 Broadcom, version 2d5ad04b63af4233440c3f7c8587108223201102 (clean) (release)
RaspPiHardware: 0010, Model B+

Hey s0h0, thanks for the detailed informations.
The GrovePi version looks strange to me; I already saw that kind of response with old firmwares. Do you already know how to update your GrovePi’s firmware? Plus, do you have a GrovePi or a GrovePi+?

Thanks, M.

EDIT: Did you already try to read data from the Sound sensor with anything else attached to the GrovePi?

I bought it from here on 29.12.2014


As far as i can see its the GrovePi, NOT the GrovePi+.

I didnt have done a FW update so far, as the other sensors (Light, DHT, LED, SoundBuzzer) are working.
Would you recommend to do a FW update of the GRovePi Shield as descriped here?
http://www.dexterindustries.com/GrovePi/get-started-with-the-grovepi/updating-firmware/

Thanks so far!

Yep, it’s a GrovePi. An update would be fine in any case (the link you have posted is OK for your GrovePi model) but probably it will not fix the issue with the Sound sensor which is, at this point, more likely related to the way to access to the bytes. Is this your sensor: http://www.seeedstudio.com/wiki/Grove_-_Sound_Sensor?

Thanks for the informations.

No the layout looks exactly like the Loudness Sensor, but “Sound Sensor v1.1” is written on it
http://www.seeedstudio.com/wiki/Grove_-_Loudness_Sensor

Okay, I need to read the specs. and then come back to you :slight_smile:

Please dont slap me, i have already done it…

“Lastly, there is a screw potentiometer that enables manual adjustments to the output gain.!”

When i have moved the screw a little bit its now receiving signals… First i had read the spec of the soundSensor instead of the LoudnessSensor so i didnt got it…
Thank you very much for your support!

awesome! Don’t worry, the most important thing is that it’s working now :slight_smile:

Enjoy!
M.