Pocket Beagle index.js issue?

Forwarded on Jason’s request.

Forwarded on Jason’s request.

From: Fred Kerr <fekerr@gmail.com>
Date: Wed, Feb 28, 2018 at 2:41 PM
Subject: Pocket Beagle index.js issue?
To: Jason Kridner <jkridner@beagleboard.org>

Hello Jason,

I’m new to Pocket Beagle but I have other low-level experience (mainly x86 pre-boot firmware, 16-bit and UEFI 32, 64).

This is likely to be a known issue but I don’t know where to look yet. I’m sure I need to get some versions and other information for you, or just find how to get the latest code.

Latest BoneScript? You can install the latest via

TERM=none npm install -g —unsafe-perm bonescript

Am I correct that this “b.” should apparently be “g.”? Based on context from the file, it seems so, and fixed the issue I had.

I’d need to see the source. It is a variable.

/usr/local/lib/node_modules/bonescript/src/index.js:325
if(bitOrder == b.LSBFIRST) {

Also, I get this when I run a simple script that resets some GPIO values. (I’m playing with a 44-LED light bar with serial input.)

debian@beaglebone:~/src/node$ node reset.js

What is the source to reset.js?

Exiting Cleanly
Unable to open /dev/mem
Unable to open /dev/mem
ERROR: trying to disable motors before they have been initialized
Unable to open /dev/mem
Unable to open /dev/mem
Unable to open /dev/mem

I need to clean this up. It is harmless.

Most likely, I just need to look around for the libraries to use with C/C++ development on Pocket Beagle.

Depending. Do you have a reason to use JavaScript other than the BoneScript examples?

Thanks Jason,

I don’t currently need javascript; I’m just exploring the examples. I may need it in the future for some things, TBD. :slight_smile:

reset.js just contains this:

//# fekerr 20180227
//# System Reference Manual · beagleboard/pocketbeagle Wiki · GitHub

var b = require(‘bonescript’);

var LE = “P2_33” ; // GPIO45
var SPI = “P2_25”; // MOSI
var CLK = “P2_29”; // CLK

var chip = [0, 0, 0, 0, 0, 0]; // 44 outputs, 5 1/2 chips

// Configure pins as outputs
b.pinMode(LE, b.OUTPUT);
b.pinMode(SPI, b.OUTPUT);
b.pinMode(CLK, b.OUTPUT);

// initial states
b.digitalWrite(LE, b.LOW);
b.digitalWrite(SPI, b.LOW);
b.digitalWrite(CLK, b.LOW);

doUpdate();

function doUpdate()
{
var i;
b.digitalWrite(LE, b.LOW);
for(i=0; i<6; ++i)
{
b.shiftOut(SPI, CLK, b.MSBFIRST, chip[i]);
}
b.digitalWrite(LE, b.HIGH);
}

debian@beaglebone:/usr/local/lib/node_modules/bonescript/src$ ls -rtl
total 232
-rw-r–r-- 1 debian debian 6000 Jan 12 21:11 socket_handlers.js
-rw-r–r-- 1 debian debian 2190 Jan 12 21:11 server.js
-rw-r–r-- 1 debian debian 680 Jan 12 21:11 serial.js
-rw-r–r-- 1 debian debian 1639 Jan 12 21:11 rc.js
-rw-r–r-- 1 debian debian 3777 Jan 12 21:11 parse.js
-rw-r–r-- 1 debian debian 17253 Jan 12 21:11 my.js
-rw-r–r-- 1 debian debian 1063 Jan 12 21:11 iic.js
-rw-r–r-- 1 debian debian 9873 Jan 12 21:11 hw_universal.js
-rw-r–r-- 1 debian debian 2940 Jan 12 21:11 hw_simulator.js
-rw-r–r-- 1 debian debian 6039 Jan 12 21:11 hw_oldkernel.js
-rw-r–r-- 1 debian debian 13019 Jan 12 21:11 hw_mainline.js
-rw-r–r-- 1 debian debian 14571 Jan 12 21:11 hw_capemgr.js
-rw-r–r-- 1 debian debian 4349 Jan 12 21:11 functions.js
-rw-r–r-- 1 debian debian 11980 Jan 12 21:11 eeprom.js
-rw-r–r-- 1 debian debian 393 Jan 12 21:11 constants.js
-rw-r–r-- 1 debian debian 4596 Jan 12 21:11 bonescript.js
-rw-r–r-- 1 debian debian 69177 Jan 12 21:11 bone.js
-rw-r–r-- 1 debian debian 4394 Jan 12 21:11 autorun.js
-rw-r–r-- 1 debian debian 19763 Feb 28 00:26 index.js

index.js, lines 1-5:

// Copyright (C) 2011 - Texas Instruments, Jason Kridner
2 //
3 //
4 var fs = require(‘fs’);
5 var child_process = require(‘child_process’);

lines pi-hundred to 333:

} else if(clock == 2) {
315 i++;
316 clock = 0;
317 f.digitalWrite(clockPin, g.LOW, next);
318 }
319 }
320
321 if(callback) {
322 next();
323 } else {
324 for(i = 0; i < 8; i++) {
325 //fekerr 20180227 if(bitOrder == b.LSBFIRST) {
326 if(bitOrder == g.LSBFIRST) {
327 bit = val & (1 << i);
328 } else {
329 bit = val & (1 << (7 - i));
330 }
331
332 if(bit) {
333 f.digitalWrite(dataPin, g.HIGH);

Thanks for the issue report and test code. It helped me verify the fix for shiftOut.js. Indeed it got broken some time back and it seems no one tried using the function.

Anyway, it is now fixed in 0.6.3.

Install via ‘sudo npm install -g --unsafe-perm bonescript’.

I tested with the BaconBits PocketCape on PocketBeagle:
https://plus.google.com/u/1/+JasonKridner/posts/14ij5UkGLwY
https://gist.github.com/jadonk/4557087c543e2ba29ca824badd1d4aa8

I adjusted your code a bit for the BaconBits hardware:

  • nCS was on a different pin
  • Addressing was a bit different than you seem to have planned

It starts up a bit slow, but it works.

Great, thanks! I was just choosing some pins to connect to the light bar. I had initially wired it up to an Arduino101 to amuse my ~4 - year old son.

I’m just grabbing things out of my parts that I have available and as time permits.

I started playing with a small solar cell as an input to 1.8v analog input.

I don’t have enough fluency in javascript right now so I should probably switch to python. I will eventually want to use a c/c++ library.

I just found the reference to the Cape last night.

When I get to my laptop or desktop I plan to check on something. I think P2_36 has a P2_35 typo in one of the tables.

Fred Kerr (mobile)

Responding to a query you made privately…

Try clearing the npm cache and setting the install path. The root user environment doesn’t seem quite right.

TERM=none sudo npm cache clear
TERM=none sudo npm install -g --prefix /usr/local --unsafe-perm bonescript

Thanks, it reports 0.6.3 now.

What pins should I be using? I don’t know the conventions and expected usages. I’m wiring OE to ground, and driving SDI, CLK, and LE.

44 LED light bar:
Based on the STP08CL596 chip made by ST.
There are six IC’s. Five control forty LED’s(eight each…) and one IC controls a group of four.
Serial data goes to the first chip’s SDI pin then it outputs serial data to the next chip via the SDO pin.

Pin out:
J1 Connector Pin Out (Pin 6 is on the ond of the bar)
1: SDI (to the first chip)
2: CLK (to all chips)
3: /LE (to all chips)
4: /OE (to all chips)
5: Ground (to all chips)
6: 3.3vDC (to all chips)

debian@beaglebone:~/update$ node -pe “require(‘bonescript’).getPlatform().bonescript”
0.6.3