I am trying to make a 'Coocking-aid'. I am using a Raspberry Pi 4B with the official 7" touchscreen and an active piezo buzzer. The 'program' should run in Chromium (the RPi's webbrowser) and I write it in HTML, CSS and Javascript. I can do some tricks in Javascript but lack a lot of knowledge there. I try to sound the buzzer with Javascript, but so far without success.
The buzzer is connected between GPIO-pin 17 and Ground (connector-pins 11 and 9). When GPIO 17 is made high (+3V) the buzzer will sound. I have tested this 'circuit' with a small Python program, which successfully turned the buzzer on:
1. from gpiozero import Buzzer
2. buzzer = Buzzer(17)
3. buzzer.on()
To do the same with Javascript I learned that I needed to install Node.js and its module 'onoff'.
From this web-post 1 I learned how to install node.js, by typing the following commands in the terminal:
curl -sL https://deb.nodesource.com/setup_15.x | sudo -E bash -
sudo apt install -y nodejs
I checked the installation by typing: "node -v". The response was: "v15.12.0" I also checked the version of Node's package manager by typing: "npm -v". The response was: "7.7.5"
From this web-post 2 I learned how to install "onoff" by typing the following command in the terminal:
npm install onoff
I checked the installation by typing: "node -v". The response was "v15.12.0"
In the RPi directory "/home/pi/node_modules/onoff/examples" is a file called: "blink-led.js" which I used as an example to create (in the same directory) a file called: "test.js" with the following code:
'use strict';
const Gpio = require('../onoff').Gpio; // Gpio class
const buzzer = new Gpio(17, 'out'); // Export GPIO17 as an output
buzzer.writeSync(17); // Make GPIO-pin 17 high
In the terminaI I moved to the same directory by typing:
cd /home/pi/node_modules/onoff/examples
and then executed "test.js" file by typing:
node test.js
Unfortunately the buzzer was not activated and a comprehensive error message was shown (see under). I get the impression that the numbers are program line numbers and I had a look here and there, but I can't figure out what is wrong. Any help would be much appreciated!.
The error message was:
/home/pi/node_modules/bindings/bindings.js:121
throw e;
^
Error: libnode.so.64: cannot open shared object file: No such file or directory
at Object.Module._extensions..node (node:internal/modules/cjs/loader:1151:18)
at Module.load (node:internal/modules/cjs/loader:972:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Module.require (node:internal/modules/cjs/loader:996:19)
at require (node:internal/modules/cjs/helpers:92:18)
at bindings (/home/pi/node_modules/bindings/bindings.js:112:48)
at /home/pi/node_modules/epoll/epoll.js:7:31
at Object.<anonymous> (/home/pi/node_modules/epoll/epoll.js:15:3)
at Module._compile (node:internal/modules/cjs/loader:1092:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10) {
code: 'ERR_DLOPEN_FAILED'
}