BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Joystick's code for nodejs

nodejs
#1

Good day. I have a chassis, about the same as in the picture. I want to control these motors with the widget joystick on the application. But I can’t find sample code for NodeJs. Can you tell me where to get a ready-made example, or write an example.
P.S.
Motors are simple. Not stepper.

0 Likes

#2

I have this example with servos… just replace the servo commands with the appropriate JS based h-bridge motor controller commands… You have the controller and it’s JS code already?.. If not Google is your friend :wink:

0 Likes

#3

Thank you for help. I did everything as you said. The blynk server starts, but as soon as I click on the joystick widget, the server receives a command and crashes.
my code:

const Blynk = require(‘blynk-library’);
const Gpio = require (‘onoff’).Gpio;
const AUTH = ‘****************************’;
const blynk = new Blynk.Blynk(AUTH);

const PAN_PORT = 110;
const TILT_PORT = 8;
const pan = new Gpio(PAN_PORT, {mode: Gpio.OUTPUT});
const tilt = new Gpio(TILT_PORT, {mode: Gpio.OUTPUT});

var JoyX = new blynk.VirtualPin(4);
var JoyY = new blynk.VirtualPin(3);

JoyX.on(‘write’, function(panValue) {
pan.servoWrite(panValue);
});

JoyY.on(‘write’, function(tiltValue) {
tilt.servoWrite(tiltValue);
});

0 Likes

#4

I use an orange pi board, not a raspberry. Maybe the problem is this?

0 Likes

#5

Read, and if necessary Google, the first line in the error… it is your best clue.

In your case… I was using the pigpio library for GPIO control in my example and it includes the servo control, onoff doesn’t.

0 Likes