Beaglebone Black's Bonescript problem is causing headaches

I am currently running a script on a Beaglebone Black that controls a motor based on input from a thermocouple. Everything was working perfectly until I enclosed everything in a box, and now an error keeps popping up:

4:4:91-ti-r133
/usr/local/lib/node_modules/bonescript/src/index.js:234
    if(typeof pin.ain != 'undefined') {
                 ^

TypeError: Cannot read property 'ain' of undefined
  at Object.f.digitalRead (/usr/local/lib/node_modules/bonescript/src/index.js:234:18)
  at Object.<anonymous> (/var/lib/cloud9/Relays/Relays.js:9:16)
  at Module._compile (module.js:570:32)
  at Object.Module._extensions..js (module.js:579:10)
  at Module.load (module.js:487:32)
  at tryModuleLoad (module.js:446:12)
  at Function.Module._load (module.js:438:3)
  at Timeout.Module.runMain [as _onTimeout] (module.js:604:10)
  at ontimeout (timers.js:386:11)
  at tryOnTimeout (timers.js:250:5)
  at Timer.listOnTimeout (timers.js:214:5)

I have double-checked all the connections, resistances, and voltages, and they all seem to be properly connected. Understanding this error message would greatly assist me in diagnosing the issue. Here is the code snippet:

var b = require('bonescript');
var c = require('bonescript');
var d = require('bonescript');
var e = require('bonescript');
var f = require('bonescript');

var state1 = b.low;
var state2 = c.low;
var state3 = e.digitalRead('P9.23', e.INPUT)
var state4 = f.digitalRead('P9.25', f.INPUT)

var temp = d.analogRead('P9_37');

d.analogRead('P9_37', printStatus);
function printStatus(x) {
    console.log('temp = ' + x.value);
}

b.pinMode("P9_15", b.OUTPUT);
b.digitalWrite("P9_15", b.LOW);
c.pinMode("P9_12", b.OUTPUT);
c.digitalWrite("P9_12", b.LOW);
e.pinMode("P8_7", b.OUTPUT);
e.digitalWrite("P8_7", b.LOW);

setInterval(toggle1, 10000);
setInterval(toggle2, 200);
setInterval(toggle3, 1000);

function toggle3() {
    temp = d.analogRead('P9_37');
    d.analogRead('P9_37', printStatus);
}

function toggle1() {
    if(temp<0.74 && temp>0.01 && state3 == c.HIGH) {
        state1 = b.HIGH;
        state2 = c.LOW; //If temp is LT 1190 C
        b.digitalWrite("P9_15", state1);
        b.digitalWrite("P9_12", state2);
    }
    else if(temp>0.76 && state3 == c.HIGH) {//If temp is GT 1210 C
        state1 = b.LOW;
        state2 = c.HIGH;
        b.digitalWrite("P9_15", state1);
        b.digitalWrite("P9_12", state2);
    }
    else if(temp<0.74 && temp>0.01 && state4 == c.HIGH) {
        state1 = b.LOW;
        state2 = c.HIGH; //If temp is LT 1190 C
        b.digitalWrite("P9_15", state1);
        b.digitalWrite("P9_12", state2);
    }
    else if(temp>0.76 && state4 == c.HIGH) {//If temp is GT 1210 C
        state1 = b.HIGH;
        state2 = c.LOW;
        b.digitalWrite("P9_15", state1);
        b.digitalWrite("P9_12", state2);
    }
    else {//Else do nothing
        state2 = c.LOW;
        b.digitalWrite("P9_15", state2);
    }

}

function toggle2() {
    if(state1 == b.HIGH) { //If Temp was LT 1190 C
        state1 = b.LOW;
        state2 = c.LOW;
        b.digitalWrite("P9_15", state1);
        b.digitalWrite("P9_12", state2);
    }
    else if(state1 == b.LOW) { //If temp was GT 1210 C
        state2 = c.LOW;
        state1 = b.LOW;
        b.digitalWrite("P9_15", state1);
        b.digitalWrite("P9_12", state2);
    }
    else { //Else do nothing
        state1 = b.LOW;
        state2 = c.LOW;
        b.digitalWrite("P9_15", state1);
        b.digitalWrite("P9_12", state2);

    }

}

return 0;

If anyone has any advice or suggestions, it would be greatly appreciated. I have not been able to find any reference to this specific error elsewhere, and similar errors appear to be unrelated. Thank you for your help!

Answer №1

After some troubleshooting, it was discovered that the issue was related to syntax. Below is the corrected code snippet:

var initialState1 = board.low;
var initialState2 = controller.low;

setInterval(checkStatus,1000);

function checkStatus(){
    hardwareIO1.digitalRead('P8_13');
    hardwareIO2.digitalRead('P8_19');
}

var temperatureSensorValue = sensor.analogRead('P9_37');

sensor.analogRead('P9_37', displayTemperature);
function displayTemperature(data) {
    console.log('Current temperature: ' + data.value);
}

board.pinMode("P9_15", board.OUTPUT);
board.digitalWrite("P9_15", board.LOW);
controller.pinMode("P9_12", board.OUTPUT);
controller.digitalWrite("P9_12", board.LOW);
outputDevice.pinMode("P8_7", board.OUTPUT);
outputDevice.digitalWrite("P8_7", board.LOW);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Generating a fresh array based on the size of its existing elements is the key feature of the ForEach method

When running this forEach loop in the console, it extracts the property "monto_gasto" from an array of objects in the firebase database. Here's how it looks: something.subscribe(res => { this.ingresos = res; ...

"Endless loop error in Three.js causing a system crash

I'm currently in the process of developing a library that consists of 'letter' functions responsible for generating letters in vertex coordinates. The main objective here is to allow users to create words or sentences using an interactive Po ...

Different results are being obtained when destructuring props in a component

Just diving into the world of React and trying to grasp destructuring. I've been doing some reading on it, but I'm currently stuck. When I try to destructure like this function MList({action}) { // const data = [action];}, I only get 'camera ...

Enhance your JQuery skills by implementing variables within the .css() function

Attempting to randomly assign values to an image's left and right properties using JQuery. Here is the code snippet: var sides = ["left", "right"] var currentSide = sides[Math.floor(Math.random() * sides.length)]; $("#"+currentImage).css({currentSide ...

Issue with Vue.js v-for not displaying component

Hello, I am facing an issue with the v-for feature as it is not rendering at all. You can view the fiddle by clicking on this link https://jsfiddle.net/tadeyemi/k6s4gv85/. I am puzzled as to why it's not working. Can anyone provide some insight? < ...

Are you utilizing Google Chrome extensions for importing and exporting JSON files?

Currently, I am in the process of developing a Google Chrome extension and I have a question regarding its capabilities. Is it possible for the extension to generate JSON files for users to download (export) as well as implementing a button that allows use ...

Encountering an 'uncaught promise rejections' error in express due to a problem with the catch() statement

I encountered a problem where I keep getting an error message 'Unhandled promise rejections' every time I try to execute the following code: app.get('/standings/:tableId', async (req, res) => { const tableId = req.params.table ...

Using AngularJS to encapsulate the JSON response received from the server

Currently, I have a basic CRUD application that is operational. However, I am looking to enhance every response received from the server by adding two additional parameters: 'error' => boolean, 'errorMessage' => string, 'dat ...

Regular expression for identifying script tags containing a particular phrase

Looking to extract specific script tags containing a push() method call from an HTML file using Node.js. The file contains multiple script tags, but only some of them have the push() method call that I want to target. A simplified example Regexr has been p ...

What is the best way to show nested objects in JavaScript?

let paragraph = document.createElement('p'); document.body.appendChild(paragraph) const fruit = { type: 'Apple', properties: { color: 'Green', price: { bulk: '$3/kg', smallQty: '$4/kg' ...

Leveraging promises to make Ajax calls without repeating code

Would it be possible to create an ajax function without duplicating it? Passing different parameters, which are locations to various files. Then utilizing the promise to combine them into a single object, possibly incorporating the spread operator. Is th ...

What steps do I need to take in order to establish a connection to a GridFS bucket

I have successfully implemented file uploads using a gridfs bucket. However, I am facing challenges with downloading files. For retrieving files, I need to access the bucket instance that I created within the database connection function: const connectDB ...

Setting variables in AngularJS services without encountering JavaScript undefined errors

After developing an AngularJS module, I attempted to link a service and use it to share variables across the application. While most things are functioning properly, I encountered an issue when trying to set submenu[1] to an object. The error message sta ...

Accessing the element within an ion-tab using document.getElementById

Within my ion-view, I have ion-tabs containing a canvas element. However, when attempting to retrieve the canvas using document.getElementById('photoCanvas'); I receive 'undefined'. Here is the code snippet: HTML: <ion-view ...

You cannot reassign NodeJS global variables

Currently, I am in the process of writing unit tests for code that utilizes a JavaScript library. This particular library sets a global variable if it does not already exist using the following pattern: var GLOBAL_VAR = GLOBAL_VAR || {} While this method ...

Increment your ids automatically for bootstrap collapse components

To utilize Bootstrap's Collapse components effectively, it is necessary to have sections (or cards) with unique IDs assigned to allow for independent collapsing and expanding. My challenge lies in creating multiple sections, each representing a data p ...

Utilizing Angular 5: Enhancing ngFor with a Pipe and a Click Event

Iterating through an array of objects using *ngFor, I apply various filters via pipes to manipulate the resulting list. One of these pipes relies on a user input from a search field. Upon clicking on one of the ngFor elements, the corresponding object is p ...

Different Ways to Access a C# Enumeration in Javascript

I'm trying to retrieve an enum from my C# code and implement it in javascript. Is there a method to accomplish this without relying on hardcoded values? ...

Blending the power of google-maps-react with the versatility of react-router

While working on my project, I encountered an issue with google-maps-react. It seems that when I try to include a <Link /> from react-router-dom alongside multiple <Marker />, there is a conflict. This is the structure of my code: render() { ...

Exploring the focus() method of refs in Vue 3

I'm struggling to comprehend why my straightforward test case keeps failing. As I delve into the world of testing in Vue, I've created a simple test where the element.focus() is triggered onMount(() => /* see implementation ...