Temporary docs/notes (and small change to systemctl service)
This commit is contained in:
61
docs/noxbox-phase-1.2-GPIO.md
Normal file
61
docs/noxbox-phase-1.2-GPIO.md
Normal file
@@ -0,0 +1,61 @@
|
||||
# This describes how to use GPIO pins````
|
||||
#
|
||||
#
|
||||
|
||||
Follow wiring guide from sparkfun
|
||||
Dont install python
|
||||
install nodejs and npm instead
|
||||
then install
|
||||
npm i -g onoff
|
||||
Enable i2c
|
||||
https://github.com/fivdi/i2c-bus/blob/master/doc/raspberry-pi-i2c.md
|
||||
|
||||
New boot config, when also enabling pull-up for GPIO17 and 27:
|
||||
````
|
||||
# See /boot/overlays/README for all available options
|
||||
dtparam=i2c_arm=on
|
||||
dtparam=audio=on
|
||||
gpio=17=pu
|
||||
gpio=27=pu
|
||||
|
||||
dtoverlay=vc4-kms-v3d
|
||||
dtparam=krnbt=on
|
||||
initramfs initramfs-linux.img followkernel
|
||||
````
|
||||
|
||||
Using it in as NodeJS project to control amp volume using up/down buttons:
|
||||
````
|
||||
const i2c = require('i2c-bus');
|
||||
const Gpio = require('onoff').Gpio;
|
||||
|
||||
const MAX9744_ADDR = 0x4B;
|
||||
|
||||
let curVolume = 20;
|
||||
|
||||
async function setVolume(v){
|
||||
const bus = await i2c.openPromisified(1);
|
||||
const wbuf = Buffer.from([v]);
|
||||
bus.i2cWrite(MAX9744_ADDR,wbuf.length,wbuf);
|
||||
bus.close()
|
||||
}
|
||||
|
||||
setVolume(30);
|
||||
|
||||
const upButton = new Gpio(17, 'in', 'both', {activeLow: true});
|
||||
const downButton = new Gpio(27, 'in', 'both', {activeLow: true});
|
||||
|
||||
upButton.watch((err,value) => {
|
||||
if(value && curVolume < 63){
|
||||
console.log('UP');
|
||||
setVolume(++curVolume);
|
||||
}
|
||||
});
|
||||
downButton.watch((err,value) => {
|
||||
if(value && curVolume > 0){
|
||||
console.log('DOWN');
|
||||
setVolume(--curVolume);
|
||||
}
|
||||
});
|
||||
|
||||
console.log("Watching");
|
||||
````
|
||||
Reference in New Issue
Block a user