TypeError: SoundAnalogSensor is not a constructor


#1

running node.js on pi3, we got the following error, any advice would be appreciated:

info GrovePi.board GrovePi is initing
/home/pi/workspace/rapiro-iotf/robot_main.js:165
soundSensor = new SoundAnalogSensor(2)
^

TypeError: SoundAnalogSensor is not a constructor
at onInit (/home/pi/workspace/rapiro-iotf/robot_main.js:165:16)
at GrovePi.init (/home/pi/workspace/rapiro-iotf/node_modules/node-grovepi/grovepi.js:73:9)
at start (/home/pi/workspace/rapiro-iotf/robot_main.js:268:9)
at Object. (/home/pi/workspace/rapiro-iotf/robot_main.js:315:1)
at Module._compile (internal/modules/cjs/loader.js:654:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:665:10)
at Module.load (internal/modules/cjs/loader.js:566:32)
at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
at Function.Module._load (internal/modules/cjs/loader.js:498:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:695:10)
at startup (internal/bootstrap/node.js:201:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:516:3)


#2

our node.js code:

function start() {
console.log(‘starting’)

board = new Board({
debug: true,
onError: function(err) {
console.log(‘TEST ERROR’)
console.log(err)
},
onInit: function(res) {
if (res) {
ultrasonicSensor = new UltrasonicDigitalSensor(2)
lightSensor = new LightAnalogSensor(1)
soundSensor = new SoundAnalogSensor(2)
var buttonSensor = new ButtonDigitalSensor(5)

             buttonSensor.stream(100,function(res){
             if(res==1){
             processing_music.stop();
            trigger=false;
            can_record=true;
            speaker_using=false;
             sp.write("#M00\n");

             }
             }
            );

#3

ok, solved , new version of grovepi is as follows, our code is too old to running on pi3:


#4

Hi @joeyangx,

Glad to hear it worked out for you. As a suggestion for future readers of this forum, using formatting quotes might prove to be useful - it’s far easier to understand a code when it’s properly formatted.

Thank you!