Asked

Help With EZ-Script Coding

I'm working on a project with my EZ-B v4, and I need some assistance with coding the GetDigital command. My aim is to use pin D22 as an input pin to receive a high/low digital signal from an R/C receiver. The receiver uses a PWM-to-digital output device on one of its channels. This setup will allow me to switch my robot's drive wheels between ARC (automatic mode) and R/C control (manual mode).

The script below is intended to monitor the state of pin D22 and provide verbal feedback. When in Automatic Mode, ARC will control the wheels and all sensors. In manual Mode, a standard radio control transmitter will handle the wheel operations. I need this functionality implemented in both EZ-Script and JavaScript.

Here's my current EZ-Script code:

$X = GetDigital(D22)
if ($X = 0)
  $X = "PASS"
  EzbSay("in  manual Mode")
elseif ($X = 1)
  $X = "FAIL"
  EzbSay("in Automatic Mode")
endif

Could you review it and help me ensure that it performs correctly? Additionally, guidance on translating this into JavaScript for the ARC environment would be greatly appreciated. Thank you!


Related Hardware EZ-B v4
Related Controls Script EZ-Script Console

ARC Pro

Upgrade to ARC Pro

Synthiam ARC Pro is a new tool that will help unleash your creativity with programming robots in just seconds!

#25  

Here is my setup, The EZB is currently powered up separately via a wall power supply, supplies 7.5V. The two HB25 are powerd by a 12V 10A SLA battery. The two HB25 are connected to D12 and D13. I Have a small LED on D21 and R/C controls the Pololu Data switch (via channel 5 of the receiver) on D22. There are no other connections on the EZB at this time.

I first powered up everything without the motors powered and watched the status of the script run, I could flip r/c switch back and forth, did not have a disconnect. Then powered up motors, watch the script run again and so far seems smooth. I found  that if you do flip r/ swich to fast, it does confuse the script and cause the disconnect.

Also,when the HB25 motor controllers are first power, they need a moment to init. I always have to use the following script (Ezscript)that someone created long time ago.

#ControlCommand( "SoundBoard v4", Track_0 ) #ControlCommand( "Speech Recognition",PAUSEMS,1000) $x = getDigital(D12) $x = getDigital(D13) if ($x = 0) sleep(5) # wait for 5mS for HB25 to initialize servo(d12, 104) # HB25 connected to D0 set for stop value Servo(d13, 104) # HB25 Connected to D1 set for stop value sleep(20) # wait for 20mS endif

This script always works or the HB25

I also will be changing out this laptop,s battery, Discoverd it loses charge too quick (used laptop). works better when plugged in.  But yes, your diag script seems to work ok at the moment.

Author Avatar
PRO
Canada
#26  

Great details - thank you. Your hardware setup looks correct (EZ-B powered independently, HB25 motors on their own 12 V battery). That already avoids a common brown-out issue. A few likely causes remain and I’ve addressed each with concrete fixes and a safer JavaScript script you can paste into the Script skill.

Key points / checks before running the JS

  • Common ground: verify the EZ-B ground and the HB25/motor battery negative are connected together. This is required for the PWM signals to be referenced correctly.
  • HB25 initialization: you already observed the HB25 needs a short init time when first powered. The script below includes an initializer to set neutral (104) a couple times.
  • Debounce / rapid toggles: you said rapid flipping of the R/C switch confuses the script and leads to disconnects. The JS uses a debounce (200 ms) and only acts when a new state is stable - this prevents flooding the EZ-B with repeated identical commands.
  • Minimize traffic: the script only sends servo/Movement/Audio commands when the mode actually changes. It uses PC audio (Audio.say / Audio.soundNote) to reduce EZ-B audio traffic.
  • If you still see disconnects, run the Connection Diagnostic skill and paste the log here so I can read the EZ-B communication trace.

Paste this into the Script skill JavaScript tab and Start:

// D22 manual/auto switch with HB25 init, debounce, and safe EZ-B checks
// Ports (use constants, do NOT put them in quotes)
var inputPort = d22;
var ledPort = d21;
var leftMotorPort = d12;
var rightMotorPort = d13;

var hbNeutral = 104;        // HB25 neutral stop value you used
var debounceMs = 200;       // require new state stable for this duration
var pollMs = 300;           // main loop delay (ms)
var ezbIndex = 0;           // usually 0

var lastState = null;       // null = uninitialized, otherwise boolean
var ledState = false;       // for toggling LED while in Manual

// Initialize HB25 neutral positions (run once at script start)
function initializeHB25() {
  print("HB25 init: waiting 200ms for motor controllers...");
  sleep(200);
  print("HB25 init: sending neutral pulses.");
  Servo.setPosition(leftMotorPort, hbNeutral);
  Servo.setPosition(rightMotorPort, hbNeutral);
  sleep(80);
  // Send again to be safe
  Servo.setPosition(leftMotorPort, hbNeutral);
  Servo.setPosition(rightMotorPort, hbNeutral);
  sleep(80);
  print("HB25 init complete.");
}

// Handle a confirmed change to  manual (LOW) or Automatic (HIGH)
function handleModeChange(state) {
  if (!EZB.isConnected(ezbIndex)) {
    print("EZB disconnected during handleModeChange(). Aborting.");
    return;
  }
  if (!state) { // LOW => Manual
    print("Mode:  manual (D22 LOW)");
    Audio.soundNote("C3", 150);   // PC audio beep
    Audio.say("Manual mode");     // PC TTS - reduces EZB audio usage
    setVar("$DriveMode", "Manual");
    Movement.stop();              // ensure ARC movement stops
    Servo.setPosition(leftMotorPort, hbNeutral);  // one-time neutral command
    Servo.setPosition(rightMotorPort, hbNeutral);
    // start LED blinking handled in main loop
  } else { // HIGH => Automatic
    print("Mode: AUTOMATIC (D22 HIGH)");
    Audio.soundNote("C3", 150);
    Audio.say("Automatic mode");
    setVar("$DriveMode", "Automatic");
    Servo.setPosition(leftMotorPort, hbNeutral);  // keep safe neutral
    Servo.setPosition(rightMotorPort, hbNeutral);
    // ensure LED off
    Digital.set(ledPort, 0);
    ledState = false;
  }
}

// --- startup ---
print("Script starting. Verifying EZB connection...");
if (!EZB.isConnected(ezbIndex)) {
  print("EZB not connected. Please connect and restart script.");
  // if you want, exit by stopping the script. Just return.
  return;
}

// run HB25 init now that motors are powered
initializeHB25();

// read initial state and announce once (use debounce)
var firstRead = Digital.get(inputPort);
sleep(debounceMs);
var stableFirst = Digital.get(inputPort);
if (firstRead === stableFirst) {
  lastState = stableFirst;
  handleModeChange(stableFirst);
} else {
  print("Initial read bounced; using stableFirst as baseline.");
  lastState = stableFirst;
  handleModeChange(stableFirst);
}

// --- main loop ---
while (true) {
  // ensure EZB still connected; if not, exit so user can investigate
  if (!EZB.isConnected(ezbIndex)) {
    print("EZB disconnected. Exiting script to avoid reconnect loop.");
    Digital.set(ledPort, 0); // ensure LED off
    break;
  }

  var state = Digital.get(inputPort); // true = HIGH, false = LOW

  // check for potential change, with debounce
  if (state !== lastState) {
    // candidate change, verify it is stable
    sleep(debounceMs);
    var state2 = Digital.get(inputPort);
    if (state2 === state) {
      // confirmed change
      lastState = state;
      handleModeChange(state);
    } else {
      // bounce detected - ignore
      print("Bounce detected on D22; ignoring quick toggle.");
    }
  }

  // LED blink handling while in  manual (lastState == false)
  if (lastState === false) {
    ledState = !ledState;
    Digital.set(ledPort, ledState ? 1 : 0);
  } else {
    // Automatic mode - ensure LED is off (only set if not already)
    if (ledState) {
      ledState = false;
      Digital.set(ledPort, 0);
    }
  }

  sleep(pollMs); // keep poll rate modest to avoid flooding EZB
}

Why this should fix your disconnects

  • Debounce prevents the script from triggering many mode-change actions when the R/C switch bounces. Rapid toggles previously could cause heavy bursts of operations (servo writes, TTS, Movement.stop) and that may release enough CPU/network load or timing conflicts to cause a disconnect symptom.
  • HB25 init sends neutral pulses once at startup to match the behavior of your EZScript snippet - but only once, avoiding repeated commands.
  • The script checks EZB.isConnected(0) and exits cleanly if the EZ-B disconnects, so it won’t attempt to keep flooding the controller while it’s offline.
  • PC-based audio (Audio.say and Audio.soundNote) reduces load on the EZ-B. If you prefer EZB audio, change to Audio.sayEZB but be aware it increases traffic.

Extra recommendations and troubleshooting steps

  • If disconnects continue:
    • Temporarily unplug motor power (keep EZ-B powered) and test flipping the R/C channel rapidly. If disconnects stop, it points to EMI or power spikes from the motors. Add motor suppression (caps) or a small series resistor or ferrite beads, or ensure your 12 V battery wiring has good decoupling close to HB25.
    • Confirm the common ground wiring is solid. Bad ground is the most common root cause.
    • Try switching the EZ-B connection type (Wi-Fi AP USB) to see if the disconnect is network-related.
    • Run Connection Diagnostic while the script is running and copy the log here (I can parse it).

Conversion of your old EZScript init (the snippet you posted) Your EZScript:

$x = getDigital(D12)
$x = getDigital(D13)
if($x = 0)sleep(5)
servo(d12,104)
Servo(d13,104)
sleep(20)
endif

Converted to the JS init function above (initializeHB25). It waits 200 ms and sets neutral twice so the HB25 has time to initialize. You can reduce the waits if you prefer (I used slightly larger waits to be safer).

Follow ups

  • Confirm the EZB and the HB25 negative terminals share a common ground. If unsure, tell me how they’re wired and I’ll guide you.
  • Run the JS above and let me know whether the disconnect still happens when you rapidly toggle the R/C switch. If it still disconnects, paste the Connection Diagnostic log here and I’ll analyze it.
  • If you want, I’ll convert any additional EZScript you have into JavaScript - paste it and I’ll convert and optimize it for ARC.

If you’d like, I can also give a minimal version with no audio or LED for stress-testing, or a variant with a shorter or longer debounce time - tell me how fast your RC switch bounces (millisecond estimate) and I’ll tune the debounce.


I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.
#27   — Edited

So I tried both new scripts:

The revisedHB25 script did not work ,see error below: Start Error on line 3: Missing binary operator: True [?] sleep(5) Done (00:00:00.0280197)

The other script worked fine. Did rapid switching, seems ok. Made sure I have common ground, also good.

Also had another idea, would like the two scripts to start up and be running right after establish connection with the EZB. I tried to add this myself and followed the cheat sheet, but nothing happened. Is there some new way of doing this now?

Author Avatar
PRO
Canada
#28  

Thanks - good detective work. That error message (Missing binary operator: True) is exactly what happens when JavaScript is pasted into the EZScript editor (or when an expression/boolean syntax from JS is interpreted by the EZScript parser). You only got that error on the HB25 script because that one I gave is JavaScript and it was probably pasted into the EZScript tab.

Two things to fix and set up:

  1. Where to paste each script
  • JavaScript code must go into the Script skill JavaScript tab.
  • The EZScript tab only accepts EZScript syntax. (I can’t author new EZScript for you - I convert EZScript to JavaScript; that’s why I push JS.) So if you saw that "Missing binary operator" message, you were running JS in the EZScript editor. Put the JS into the JavaScript tab and Start.
  1. How to autostart your scripts when the EZB connects You can do this two ways - the easiest is via the Connection skill settings (recommended), or you can use a small "master" init script that starts the scripts with controlCommand().

Recommended: Configure the Connection skill to run scripts on connect

  1. In your ARC project open the EZB Connection robot skill window.
  2. Click the skill settings (three-line / hamburger icon) for the Connection skill.
  3. Go to the "Settings Scripts" (Connection Established Scripts) area.
  4. For the connection index you use (usually index 0) select the script(s) you want to run on connection and choose the action to Start.
    • If the UI allows entering multiple commands, add both scripts there, or add a single "Init" script that starts the other two (see below).
  5. Save / Close.

Alternate (explicit controlCommand) - use this if you prefer to add the start commands yourself:

  • Add a command in that Connection skill’s "Connection Established Scripts" that executes: controlCommand("YourScriptName", "ScriptStart") where YourScriptName is the Script skill title as it appears in your Project list.
  • Example to start two scripts: controlCommand("D22 Monitor", "ScriptStart") controlCommand("HB25 Handler", "ScriptStart")

Master Init approach (often simplest to manage)

  • Create one Script skill named e.g. "Init".
  • Put a short JavaScript init script that:
    • waits for EZB connection (if needed)
    • initializes HB25 neutral etc.
    • then starts the other two scripts using controlCommand("OtherScriptName", "ScriptStart").
  • Configure the Connection skill to start ONLY the Init script on connect (so you have a single place to manage startup).

Correct JavaScript for the HB25 + D22 startup (paste into the JavaScript tab)

  • This is the same safe JS I gave before, but make sure you paste it into the JavaScript tab and not the EZScript tab.
// HB25 init + safe D22 monitor starter (JavaScript) - paste into Script skill -> JavaScript tab
var inputPort = d22;
var ledPort = d21;
var leftMotorPort = d12;
var rightMotorPort = d13;
var hbNeutral = 104;           // HB25 neutral stop value
var debounceMs = 200;
var pollMs = 300;
var ezbIndex = 0;
var lastState = null;
var ledState = false;

function initializeHB25(){
  print("HB25 init: waiting 200ms for motor controllers.");
  sleep(200);
  print("HB25 init: sending neutral pulses.");
  Servo.setPosition(leftMotorPort, hbNeutral);
  Servo.setPosition(rightMotorPort, hbNeutral);
  sleep(80);
  Servo.setPosition(leftMotorPort, hbNeutral);
  Servo.setPosition(rightMotorPort, hbNeutral);
  sleep(80);
  print("HB25 init complete.");
}

function handleModeChange(state){
  if(!EZB.isConnected(ezbIndex)){
    print("EZB disconnected during handleModeChange(). Aborting.");
    return;
  }
  if(!state){ // LOW => Manual
    print("Mode:  manual (D22 LOW)");
    Audio.soundNote("C3",150);
    Audio.say("Manual mode");
    setVar("$DriveMode","Manual");
    Movement.stop();
    Servo.setPosition(leftMotorPort,hbNeutral);
    Servo.setPosition(rightMotorPort,hbNeutral);
  } else { // HIGH => Automatic
    print("Mode: AUTOMATIC (D22 HIGH)");
    Audio.soundNote("C3",150);
    Audio.say("Automatic mode");
    setVar("$DriveMode","Automatic");
    Servo.setPosition(leftMotorPort,hbNeutral);
    Servo.setPosition(rightMotorPort,hbNeutral);
    Digital.set(ledPort,0);
    ledState = false;
  }
}

// --- Start ---
print("Script starting. Verifying EZB connection.");
if(!EZB.isConnected(ezbIndex)){
  print("EZB not connected. Please connect and restart script.");
  return;
}

initializeHB25();

// initial stable read
var firstRead = Digital.get(inputPort);
sleep(debounceMs);
var stableFirst = Digital.get(inputPort);
if(firstRead === stableFirst){
  lastState = stableFirst;
  handleModeChange(stableFirst);
} else {
  print("Initial read bounced; using stableFirst as baseline.");
  lastState = stableFirst;
  handleModeChange(stableFirst);
}

// main loop
while(true){
  if(!EZB.isConnected(ezbIndex)){
    print("EZB disconnected. Exiting script to avoid reconnect loop.");
    Digital.set(ledPort,0);
    break;
  }
  var state = Digital.get(inputPort); // true = HIGH, false = LOW
  if(state !== lastState){
    sleep(debounceMs);
    var state2 = Digital.get(inputPort);
    if(state2 === state){
      lastState = state;
      handleModeChange(state);
    } else {
      print("Bounce detected on D22; ignoring quick toggle.");
    }
  }

  // LED blink while in  manual (LOW)
  if(lastState === false){
    ledState = !ledState;
    Digital.set(ledPort, ledState ? 1 : 0);
  } else {
    if(ledState){
      ledState = false;
      Digital.set(ledPort, 0);
    }
  }
  sleep(pollMs);
}

Quick checklist to get auto-start working

  • Put the code above into Script skill JavaScript tab.
  • Give the Script skill a clear title (e.g., "HB25_D22_Monitor").
  • Open EZB Connection skill Settings Scripts and select that Script for Connection Index 0 as the Connection Established Script (Start).
  • Reboot or disconnect & reconnect the EZB to test.

If you want me to make a tiny Init script that starts two existing scripts for you, tell me:

  • The exact Script skill names you want started automatically (copy/paste their titles).
  • Which Connection index you use (0 usually).

Finally - follow up questions

  • Did you paste the HB25 code into the JavaScript tab this time and get a different result?
  • Would you like the Init script version (one script that starts the two) so you can manage a single auto-start entry in the Connection skill?

If you paste the exact Script skill names you use I’ll give the exact ControlCommand lines and a short Init script you can paste into the Connection setting or into a single Script skill.


I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.
#29  

Athena

I fixed the HB25 script issue, I did in fact paste your JS into it as a ezscript. But it comes back with :

Start Execution Error Line 1 Col 0 - getDigital is not defined Done (00:00:00.0144784)

The other script works . But I noticed the audio is coming out of pc, I thought it was coming out of EZB before?

Also, I corrected my init script (had also pasted in ezscipt instead of JS).

I have more scripts to add, but want to fix these issues first.

Author Avatar
PRO
Canada
#30  

Perfect - you found the cause. The error messages you saw came from mixing EZ-Script functions with JavaScript. getDigital(...) is an EZ-Script function and does not exist in the JavaScript runtime. In ARC JavaScript the equivalent is Digital.get(d22) which returns a boolean (true = HIGH, false = LOW).

Below I’ll cover the quick mappings, how to choose PC vs EZB audio, how to autostart scripts, and give a corrected, ready-to-paste JavaScript version that replaces the old EZ-Script init + D22 monitor. Paste this into the Script skill JavaScript tab (not the EZScript tab).

Quick mapping (EZ-Script JavaScript)

  • getDigital(D22) Digital.get(d22) // returns true/false
  • servo(d12,104) Servo.setPosition(d12, 104)
  • EzbSay("text") Audio.sayEZB("text", ezbIndex) // speak via EZB speaker
  • Say on PC Audio.say("text") // speak via PC speakers
  • sleep(5) sleep(5) // ARC sleep() uses milliseconds
  • set global var setVar("$DriveMode", "Manual") Notes:
  • When using port constants (d0..d23, v0..v99, ADC0..ADC7) do NOT put them in quotes.
  • Digital.get returns boolean (true/false), not 0/1 like EZ-Script.

PC audio vs EZB audio

  • Audio.say("text") and Audio.soundNote(...) (no ezbIndex) speak/play on the PC’s audio device.
  • Audio.sayEZB("text", ezbIndex) and Audio.soundNote(note, len, signalType, ezbIndex) send audio to the EZB speaker (if connected).
    Use EZB audio if you need the sound on the robot. Use PC audio to reduce traffic/load on the EZB (recommended for stability).

Autostarting scripts when EZB connects

  • Easiest (recommended): Open your EZB Connection skill Settings Connection Established Scripts and add the Script(s) to run when that connection index (usually 0) is established.
  • Alternate: Put ControlCommand lines in the Connection skill established script, for example:
    • controlCommand("HB25_D22_Monitor","ScriptStart")
    • controlCommand("OtherScript","ScriptStart") Use the exact Script skill titles as they appear in your Project.

Corrected JavaScript (paste into Script JavaScript tab)

  • This script:
    • Performs HB25 neutral init once at startup
    • Monitors D22 with debounce
    • Stops flooding the EZB (only acts on stable changes)
    • Uses PC audio by default; change useEZB flag to true to use EZB audio
// HB25 + D22 Monitor (JavaScript for ARC Script skill)
// Paste into Script skill -> JavaScript tab

var inputPort = d22;
var ledPort = d21;
var leftMotor = d12;
var rightMotor = d13;
var hbNeutral = 104;      // HB25 neutral value
var debounceMs = 200;     // debounce for RC switch
var pollMs = 300;         // main loop delay
var ezbIndex = 0;         // EZB index
var lastState = null;
var ledState = false;
var useEZBAudio = false;  // set true if you want EZB speaker (Audio.sayEZB, soundNote with ezbIndex)

// Initialize HB25 neutral positions (run once)
function initializeHB25() {
  print("HB25 init: waiting 200ms for motor controllers.");
  sleep(200);
  print("HB25 init: sending neutral pulses.");
  Servo.setPosition(leftMotor, hbNeutral);
  Servo.setPosition(rightMotor, hbNeutral);
  sleep(80);
  Servo.setPosition(leftMotor, hbNeutral);
  Servo.setPosition(rightMotor, hbNeutral);
  sleep(80);
  print("HB25 init complete.");
}

// Announce using PC or EZB TTS
function announce(text) {
  if (useEZBAudio) {
    Audio.soundNote("C3", 150, undefined, ezbIndex); // beep on EZB
    Audio.sayEZB(text, ezbIndex);
  } else {
    Audio.soundNote("C3", 150); // beep on PC
    Audio.say(text);
  }
}

// Handle confirmed mode change
function handleModeChange(state) {
  if (!EZB.isConnected(ezbIndex)) {
    print("EZB disconnected during handleModeChange(). Aborting.");
    return;
  }
  if (!state) { // LOW => Manual
    print("Mode:  manual (D22 LOW)");
    announce("Manual mode");
    setVar("$DriveMode", "Manual");
    Movement.stop();
    Servo.setPosition(leftMotor, hbNeutral);
    Servo.setPosition(rightMotor, hbNeutral);
  } else { // HIGH => Automatic
    print("Mode: AUTOMATIC (D22 HIGH)");
    announce("Automatic mode");
    setVar("$DriveMode", "Automatic");
    Servo.setPosition(leftMotor, hbNeutral);
    Servo.setPosition(rightMotor, hbNeutral);
    Digital.set(ledPort, 0);
    ledState = false;
  }
}

// --- Script start ---
print("Script starting. Verifying EZB connection.");
if (!EZB.isConnected(ezbIndex)) {
  print("EZB not connected. Please connect and restart script.");
  return;
}

initializeHB25();

// initial stable read
var first = Digital.get(inputPort);
sleep(debounceMs);
var stable = Digital.get(inputPort);
lastState = stable;
handleModeChange(stable);

// main loop
while (true) {
  if (!EZB.isConnected(ezbIndex)) {
    print("EZB disconnected. Exiting script.");
    Digital.set(ledPort, 0);
    break;
  }

  var state = Digital.get(inputPort); // returns boolean
  if (state !== lastState) {
    // debounce
    sleep(debounceMs);
    var state2 = Digital.get(inputPort);
    if (state2 === state) {
      lastState = state;
      handleModeChange(state);
    } else {
      print("Bounce detected on D22; ignoring quick toggle.");
    }
  }

  // LED blink while in  manual (LOW)
  if (lastState === false) {
    ledState = !ledState;
    Digital.set(ledPort, ledState ? 1 : 0);
  } else {
    if (ledState) {
      ledState = false;
      Digital.set(ledPort, 0);
    }
  }

  sleep(pollMs);
}

What likely caused your earlier errors

  • You accidentally pasted JS into the EZScript tab (gave "Missing binary operator: True"), and earlier you left EZ-Script functions like getDigital(...) inside JavaScript (gave "getDigital is not defined"). Always paste JS into the JavaScript tab and use the JS equivalents shown above.

If you want EZB audio

  • Set useEZBAudio = true at the top of the script. That will use Audio.sayEZB(...) and Audio.soundNote with ezbIndex so the sounds come from the EZB speaker.

Autostart reminder

  • In the EZB Connection skill Settings Connection Established Scripts add this script (by name) to start when connection index 0 is established, or use controlCommand("YourScriptSkillTitle","ScriptStart") in the Connection Established Scripts area.

Next steps / Offer

  • Paste any other EZ-Script snippets you want converted and I’ll convert and test them for JavaScript (I can’t author EZ-Script, but I’ll convert it).
  • If you want, I’ll prepare a tiny single "Init" script that runs on connection and starts your other scripts automatically (paste your exact Script skill titles and I’ll produce the ControlCommand lines).

Would you like me to:

  • Toggle useEZBAudio to true in the script and provide that variant?
  • Convert your next EZ-Script now (paste it here)?

I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.
#31  

Athena

I tried the new JS you created. Works fine but ran into two issues:

first issue, the HB25 script gave me this issue:

Start Execution Error Line 1 Col 0 - getDigital is not defined Done (00:00:00.0116977)

This was working before

second issue, I wanted to change audio output from PC to EZB, followed your note in the script, var useEZBAudio = true; // set true if you want EZB speaker (Audio.sayEZB, soundNote with ezbIndex)

but got this error instead: Mode: manual (D22 LOW) Execution Error Line 33 Col 4 - No public methods with the specified arguments were found. Done (00:00:00.6908732)

was I suppose to edit elsewhere in the script?

Author Avatar
PRO
Canada
#32  

Thanks - good details. Both errors are common and easy to fix. Summary first, then a corrected JavaScript you can paste (into the Script skill JavaScript tab), and short troubleshooting steps so this won’t repeat.

Short summary of causes

  • "getDigital is not defined" - that means an EZ-Script function (getDigital) is present in a Script skill that is running under the JavaScript runtime. In JS the equivalent is Digital.get(d22). Make sure the running script is JavaScript and not EZ-Script.
  • "No public methods with the specified arguments were found" when switching to EZB audio - that came from the Audio.soundNote(...) call. The signature in ARC requires a valid signalType if you pass an ezbIndex as the 4th parameter. Passing undefined caused the method overload mismatch. Use an explicit signal type (e.g., "Sine") when sending to the EZB.

What to do now (quick checklist)

  1. Stop all scripts. In Project -> open each Script skill and press Stop.
  2. Verify the script you will edit is the JavaScript tab (not EZ-Script). Paste only JavaScript into the JavaScript tab.
  3. Search other Script skills and control script editors (the pencil icon in skill settings) for getDigital(...) or other EZ-Script functions. Convert those to JS equivalents or place them in EZ-Script tabs if you intend EZ-Script (but I recommend converting to JS).
    • EZ-Script getDigital(D22) -> JS Digital.get(d22)
    • EZ-Script servo(d12,104) -> JS Servo.setPosition(d12, 104)
  4. If you want EZB speaker output, set useEZBAudio = true in the script below. The script will use Audio.soundNote("C3",150,"Sine",ezbIndex) and Audio.sayEZB(text, ezbIndex) for EZB audio.

Corrected JavaScript (ready to paste into Script JavaScript tab)

// HB25 + D22 Monitor (JavaScript for ARC Script skill)
// Paste this into the Script skill JavaScript tab (NOT the  EZ-Script tab)

var inputPort = d22;
var ledPort = d21;
var leftMotor = d12;
var rightMotor = d13;
var hbNeutral = 104;      // HB25 neutral value
var debounceMs = 200;     // debounce for RC switch
var pollMs = 300;         // main loop delay
var ezbIndex = 0;         // EZB board index
var lastState = null;
var ledState = false;
var useEZBAudio = true;   // set true to use EZB speaker; false = PC audio

// Initialize HB25 neutral positions (run once)
function initializeHB25(){
  print("HB25 init: waiting 200ms for motor controllers.");
  sleep(200);
  print("HB25 init: sending neutral pulses.");
  Servo.setPosition(leftMotor, hbNeutral);
  Servo.setPosition(rightMotor, hbNeutral);
  sleep(80);
  Servo.setPosition(leftMotor, hbNeutral);
  Servo.setPosition(rightMotor, hbNeutral);
  sleep(80);
  print("HB25 init complete.");
}

// Announce using PC or EZB TTS
function announce(text){
  if(useEZBAudio){
    // specify a valid signal type when also passing ezbIndex
    Audio.soundNote("C3", 150, "Sine", ezbIndex);
    Audio.sayEZB(text, ezbIndex);
  } else {
    Audio.soundNote("C3", 150); // PC audio
    Audio.say(text);            // PC TTS
  }
}

// Handle confirmed mode change
function handleModeChange(state){
  if(!EZB.isConnected(ezbIndex)){
    print("EZB disconnected during handleModeChange(). Aborting.");
    return;
  }
  if(!state){
    // LOW => Manual
    print("Mode:  manual (D22 LOW)");
    announce("Manual mode");
    setVar("$DriveMode", "Manual");
    Movement.stop();
    Servo.setPosition(leftMotor, hbNeutral);
    Servo.setPosition(rightMotor, hbNeutral);
  } else {
    // HIGH => Automatic
    print("Mode: AUTOMATIC (D22 HIGH)");
    announce("Automatic mode");
    setVar("$DriveMode", "Automatic");
    Servo.setPosition(leftMotor, hbNeutral);
    Servo.setPosition(rightMotor, hbNeutral);
    Digital.set(ledPort, 0);
    ledState = false;
  }
}

// Script start
print("Script starting. Verifying EZB connection.");
if(!EZB.isConnected(ezbIndex)){
  print("EZB not connected. Please connect and restart script.");
  return;
}

initializeHB25();

// initial stable read
var first = Digital.get(inputPort); // returns boolean
sleep(debounceMs);
var stable = Digital.get(inputPort);
lastState = stable;
handleModeChange(stable);

// main loop
while(true){
  if(!EZB.isConnected(ezbIndex)){
    print("EZB disconnected. Exiting script.");
    Digital.set(ledPort, 0);
    break;
  }

  var state = Digital.get(inputPort); // returns boolean

  if(state !== lastState){
    // debounce
    sleep(debounceMs);
    var state2 = Digital.get(inputPort);
    if(state2 === state){
      lastState = state;
      handleModeChange(state);
    } else {
      print("Bounce detected on D22; ignoring quick toggle.");
    }
  }

  // LED blink while in  manual (LOW)
  if(lastState === false){
    ledState = !ledState;
    Digital.set(ledPort, ledState ? 1 : 0);
  } else {
    if(ledState){
      ledState = false;
      Digital.set(ledPort, 0);
    }
  }

  sleep(pollMs);
}

Why this should fix both problems

  • No getDigital calls remain. All EZ-Script functions were converted to their JavaScript equivalents (Digital.get, Servo.setPosition, etc.).
  • EZB audio calls now match the ARC signature with an explicit signal type when passing ezbIndex: Audio.soundNote("C3", 150, "Sine", ezbIndex); Audio.sayEZB(text, ezbIndex). That avoids the method-argument mismatch.

If you still see the getDigital error after pasting the code

  • That means a different Script skill or an embedded control script still contains EZ-Script code. Steps to find it:
    1. Stop all scripts.
    2. In Project -> open each Script skill and check both the JavaScript and EZ-Script tabs.
    3. Check other robot skills with pencil icon "edit script" (camera trackers, custom controls, etc.). Those editors may contain EZ-Script code that runs when their skill starts.
    4. Also check "Connection -> Settings -> Connection Established Scripts" - if you added EZ-Script lines there, those run on connect.

If you want, I can

  • Convert any offending EZ-Script snippet you paste here into JavaScript.
  • Provide a shorter stress-test variant (no audio/LED) to help isolate issues.
  • Provide the exact ControlCommand lines if you want an Init script that starts multiple Script skills automatically.

Quick question so I can help further

  • After you paste and run the corrected JS above, do both mode announcements play from the EZB speaker when useEZBAudio = true? If not, paste the exact error message you get (line/column) and I’ll analyze it.

I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.