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

Your robot can be more than a simple automated machine with the power of ARC Pro!

#17  

I trid the new ezscript, this is the error message I get :

Start Error on line 8: Missing String Quotes or Invalid Expression at index 4: > Done (00:00:00.0156305)

it never goes beyond that point

Author Avatar
PRO
Canada
#18  

Thanks - that error came from an invalid comparison expression. The line If($Last 0) is missing a comparison operator, which causes the "Missing String Quotes or Invalid Expression" error.

EZScript implementations differ slightly on the notequal operator. Try the corrected script below - first with the VB-style operator <> (most common in ARC EZScript). If your ARC version still errors, try the second variant using != (C-style).

Paste one of these into the Script skill EZScript tab and Start.

  1. EZScript (use <> for not-equal - try this first)
#  EZ-Script - Monitor D22: LOW = Manual, HIGH = Automatic
# Left/Right HB-25 on D12 and D13, LED on D21
$Last = -1

:Loop
  $X = GetDigital(D22)    # returns 0 or 1

  If($X = 0)              # D22 LOW -> Manual
    If($Last <> 0)        # announce only on change (not-equal)
      SoundNote("C3",150) # short safety beep
      EzbSay("Manual mode")
      SetVar("$DriveMode","Manual")
      Movement.stop()
      Servo.setPosition(D12,104) # neutral for HB-25
      Servo.setPosition(D13,104) # neutral for HB-25
    EndIf

    # Blink LED while  manual (continuous)
    Digital.set(D21,1)
    Sleep(200)
    Digital.set(D21,0)
    Sleep(200)

    $Last = 0

  ElseIf($X = 1)          # D22 HIGH -> Automatic
    If($Last <> 1)        # announce only on change (not-equal)
      SoundNote("C3",150) # short safety beep
      EzbSay("Automatic mode")
      SetVar("$DriveMode","Automatic")
      Servo.setPosition(D12,104) # neutral for HB-25
      Servo.setPosition(D13,104) # neutral for HB-25
    EndIf

    # Ensure LED is off in Automatic
    Digital.set(D21,0)
    Sleep(250)

    $Last = 1
  EndIf

Goto(Loop)
  1. EZScript alternative (if your environment expects !=)
#  EZ-Script - alternate not-equal using !=
$Last = -1

:Loop
  $X = GetDigital(D22)

  If($X = 0)
    If($Last != 0)
      SoundNote("C3",150)
      EzbSay("Manual mode")
      SetVar("$DriveMode","Manual")
      Movement.stop()
      Servo.setPosition(D12,104)
      Servo.setPosition(D13,104)
    EndIf

    Digital.set(D21,1)
    Sleep(200)
    Digital.set(D21,0)
    Sleep(200)

    $Last = 0

  ElseIf($X = 1)
    If($Last != 1)
      SoundNote("C3",150)
      EzbSay("Automatic mode")
      SetVar("$DriveMode","Automatic")
      Servo.setPosition(D12,104)
      Servo.setPosition(D13,104)
    EndIf

    Digital.set(D21,0)
    Sleep(250)

    $Last = 1
  EndIf

Goto(Loop)

Notes & troubleshooting:

  • You already confirmed SoundNote("C3",150) works in JS. This same call should work in EZScript.
  • Make sure you paste exactly (no hidden characters), and use the Script skill EZScript tab.
  • If you still get an error, copy/paste the exact error text and tell me which variant you tried and your ARC version. If needed I’ll provide a simpler fallback that avoids the notequal operator entirely (e.g., always announce but add a short suppression timer), but the above should give you the desired transition-only announcements.

Would you like me to:

  • Convert this corrected EZScript into a tiny JS snippet that runs inside the Script skill (to keep everything in JS)?
  • Add the Movement Panel auto-resume on Automatic mode now?

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.
Author Avatar
PRO
Synthiam
#19  

just as an fyi, athena doesn't know ezscript - which is why she will keep pushing javascript or python onto you:). So unless you enjoy talking to her like this, she'll keep making mistakes for ever haha

Author Avatar
PRO
Canada
#20  

Thanks - good point, DJ_Sures. Appreciate the callout.

A few clarifications for everyone here:

  • EZ-Script is legacy and kept for backward compatibility. I cannot create EZ-Script from scratch (I don’t know it well enough), so I guide users toward JavaScript or Python instead.
  • I can, however, convert existing EZ-Script into JavaScript (recommended) or Python and help you maintain everything in one language inside the Script skill.
  • RoboHappy - since your JavaScript version is already working and you like the tone/beep behavior, I recommend dropping the EZ-Script and using the JavaScript-only solution (less fragmentation, easier debugging and maintenance).

If you want, I can:

  • Paste the final, cleaned JS version again (ready-to-paste into Project Add Skill Script JavaScript tab).
  • Convert your exact EZ-Script into a JS equivalent (if you prefer me to reproduce the exact EZ-Script behavior).
  • Provide a compact JS debug helper using print() and setVar() so you can monitor D22 and mode changes during testing.

Helpful links:

RoboHappy - which would you like now?

  • A final cleaned JS file to replace the EZ-Script entirely?
  • Or a conversion of your exact EZ-Script into JS while keeping the EZ-Script as-is?

If you want the JS again, I’ll paste the tested version (with the C3 beep) ready to paste into the 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.
#21  

DJ,

Thats too bad, She should learn it, it would be helpful for some of us that are old school:) Ive never liked java or python. Im still a fan of BASIC any day of the week lol. That said, I do like how she was able to create the java version so fast, and it does work. I have another ezscript id like to see it converted to JC, just curious to see what happens:)

Athena I am happy with your last JS, it works, so I am deciding to use it as is. This will be used as part of an update process im doing of an old robot I posted on long time ago. Id like to post a small video of the script in action if I can here.

Author Avatar
PRO
Canada
#22  

Nice - glad the JS is working well and you’re happy with the tone. Posting a short demo video is a great idea. Below I’ll give clear, practical steps for recording, uploading, and sharing your clip on the Synthiam Community (and best-practices so viewers quickly see the important bits). When you’re ready, paste the next EZScript you want converted and I’ll convert it to JavaScript for you.

How to record a short demo

  • Keep it short: 30-90 seconds. Show each key step once (mode toggle, LED blink, speech/beep, joystick/R/C control and ARC movement stop/resume).
  • What to show:
    • The robot in view (wheels off the ground or on blocks for safety).
    • The Script skill window (so viewers see the code running).
    • The Read Digital skill or a console/debug output (print()) showing D22 state.
    • The LED on D21 blinking and audio beep + spoken announcement.
    • Motors being neutral/controlled (HB25 neutral behavior).
  • Recommended file format & size:
    • MP4 (H.264), 720p or 1080p, 30 fps. Aim under ~50-100 MB for easy upload.
    • Short clips are easier for others to watch and comment on.

Quick recording tools

  • Windows (quick):
    • Xbox Game Bar: press Win + G press the record button. Good for screen + microphone.
  • Windows (more control):
    • OBS Studio (free) - lets you capture both screen and a webcam for robot view.
  • Mac:
    • QuickTime Player File New Screen Recording (or use OBS).
  • iPhone / Android:
    • Use built-in Screen Recording (for mobile control UIs) or phone camera to capture the robot.
  • Tip: record the robot and the PC screen side-by-side if possible (or do two short clips and combine).

Uploading the video

  • Easiest (recommended): Upload to YouTube as Unlisted and paste the link into a forum post.
    • YouTube steps: Upload Visibility choose Unlisted copy link paste in the forum post.
  • Alternatives:
    • Vimeo or other hosting.
    • If Synthiam Community supports attachments in your account, you may attach the MP4 directly in the post (file size limits may apply).

How to post on Synthiam Community

  1. Go to https://synthiam.com/Community and log in.
  2. Click "New Topic" (or the forum category relevant to your robot / project).
  3. Choose a category / subforum (e.g., "Projects" or the platform you used).
  4. Title the post (e.g., "EZB v4: D22 Manual/Auto switch demo - short video").
  5. In the body:
    • Briefly describe what the clip shows (JS script running, D22 toggles, LED + beep, HB25 neutral).
    • Paste the YouTube/Vimeo link or attach your MP4 (if supported).
    • Optionally paste the JS snippet (or attach the project file) so others can try it.
  6. Click Submit / Post.

Helpful debugging & posting tips

  • Include the short JS snippet or a pastebin link in the post so people can copy the script.
  • If you want me to tidy the JS into a project file (or a clean, commented version) I can paste it ready to paste into your Script skill.
  • If you want a visible console output during the demo, add a couple of print() calls to the JS (preferred over console.log()):
    • Example debug lines:
      print("D22 state: " + (state ? "HIGH" : "LOW"));
      print("DriveMode: " + getVar("$DriveMode", "unknown"));
      
  • Consider exporting the ARC project (File Save Project As) and attach it so others can load and test.

Would you like:

  • Step-by-step OBS settings (scene layout, bitrate, audio) for best quality?
  • A copy of the final cleaned JS again (ready to paste) and a compact debug snippet to show on video?
  • To paste the other EZScript now so I can convert it to JavaScript?

I’m ready to convert your next EZScript whenever you paste it here - and I can even prepare a short "what to show" checklist tailored to your robot for the video.


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.
#23  

athena Im suddenly having an odd issue with the JC. Once I click on START, the EZB will disconnect a few moments later. It happens so fast,the program hardly has time to announce which mode it is in.  I then try to reconnect to the EZB, script still running, switch mode on transmitter, still disconnects. Does not seem to disconnect EZB if I dont run the script. Very odd all of the sudden. I may have ti go back to a previous SC you created and see if this still happens.

Author Avatar
PRO
Canada
#24  

Thanks - that’s a useful symptom. When a script causes an EZ-B to disconnect shortly after Start, it’s almost always one of a few common problems (power draw / brown-out, WiFi instability, or the script flooding the EZB with too many commands). Let’s go through a targeted troubleshooting checklist and a safer JavaScript you can run that minimizes traffic to the EZB and detects disconnects.

First, quick checklist (try in this order)

  1. Connection type

    • Are you connected via WiFi (AP or router) or USB serial? If WiFi, try USB (or viceversa) to isolate network vs hardware power issues.
  2. Power / brownout check

    • Are servos or motors powered from the EZB power pins? Those pins are convenient but can brownout when heavy motor/servo current flows. If so, temporarily disconnect motors/servos from the EZB power pins and power them from a separate battery/UBEC to test.
    • If using a battery, ensure it can provide the peak current of the motors/servos.
  3. Camera / other devices

    • Is camera streaming enabled? Video + script + servo commands can increase traffic and power usage. Temporarily disable camera streaming.
  4. I2C and peripherals

    • Do you have any I2C devices connected? Bad I2C wiring can lock up microcontrollers and can look like disconnects.
  5. Script behavior to review

    • Does the script send continuous commands each loop (servo.setPosition, Movement.stop, Audio.sayEZB)? Sending the same commands rapidly every loop can flood the EZB and cause instability. Commands should be sent only on change.
  6. Connection diagnostics / logs

    • Add the Connection Diagnostic skill (Project -> Add robot skill -> Communication -> Connection Diagnostic) and run it while starting your script. Copy the log and look for any EZB connection errors, or ping failures. The diagnostic view will show verbose comms info.

Useful docs

Safer JavaScript to run now

  • This version:
    • Checks EZB.isConnected(0) and stops if disconnected.
    • Only sends servo, Movement, or setVar when D22 actually changes.
    • Uses PC TTS (Audio.say) instead of Audio.sayEZB to reduce EZB load.
    • Prints state so you can monitor behavior in the Script skill status.
    • Increased sleep interval to reduce traffic. Paste this into the Script skill (JavaScript tab) and Start:
// Safer D22 monitor - reduces EZ-B traffic and checks connection
// Ports: change as needed
var inputPort = d22;
var ledPort = d21;
var leftMotorPort = d12;
var rightMotorPort = d13;
var lastState = null;
var ledState = false;
var ezbIndex = 0; // typically 0

while (true) {
  // If EZ-B disconnected, stop script cleanly
  if (!EZB.isConnected(ezbIndex)) {
    print("EZB not connected. Exiting script to avoid reconnect loop.");
    // Ensure LED off
    Digital.set(ledPort, 0);
    break;
  }

  var state = Digital.get(inputPort); // true = HIGH, false = LOW
  print("D22 state: " + (state ? "HIGH" : "LOW") + "  last: " + (lastState === null ? "null" : (lastState ? "HIGH" : "LOW")));

  // Only act on state changes (prevents flooding the EZB)
  if (lastState === null || state !== lastState) {
    if (!state) { // LOW => Manual
      print("Switching to  manual mode");
      Audio.soundNote("C3", 150); // plays on PC audio by default
      Audio.say("Manual mode");   // PC TTS - reduces EZB audio traffic
      setVar("$DriveMode", "Manual");
      Movement.stop();            // request movement stop (ARC)
      // Send neutral to motors once
      Servo.setPosition(leftMotorPort, 104);
      Servo.setPosition(rightMotorPort, 104);
      // start LED blink cycle for  manual (initial toggle)
      ledState = true;
      Digital.set(ledPort, 1);
    } else { // HIGH => Automatic
      print("Switching to AUTOMATIC mode");
      Audio.soundNote("C3", 150);
      Audio.say("Automatic mode");
      setVar("$DriveMode", "Automatic");
      // Keep motors neutral until  Movement Panel or other resumes
      Servo.setPosition(leftMotorPort, 104);
      Servo.setPosition(rightMotorPort, 104);
      ledState = false;
      Digital.set(ledPort, 0);
    }
    lastState = state;
  }

  // Blink LED only while  manual (LOW)
  if (lastState === false) {
    // toggle every 400ms to be visible but not flood
    ledState = !ledState;
    Digital.set(ledPort, ledState ? 1 : 0);
    sleep(400);
    // continue loop - next iteration checks EZB.isConnected again
    continue;
  }

  // In Automatic ensure LED off and poll slower
  if (lastState === true) {
    Digital.set(ledPort, 0);
  }

  // Main poll delay - keep it reasonable to avoid flooding
  sleep(500);
}

Testing steps with this code

  1. Run the code with servos/motors disconnected (or motor power removed) - if it no longer disconnects, it points to power/brownout.
  2. If still disconnecting: switch from WiFi to USB (or from USB to WiFi) and test. If USB is stable, it points to WiFi instability.
  3. If disconnect only occurs when camera streaming is active, disable camera and test.
  4. If still disconnects quickly while the script is running even with motors/power disconnected, run the Connection Diagnostic skill and post the log output here (paste into a code block). The diagnostic log will show ping failures / error messages I can interpret.

Extra safety options I can add

  • A script that measures EZB input voltage periodically and prints it (if you want to see brownouts).
  • A fallback that automatically restarts the connection loop (I don’t recommend automatic reconnect without solving root cause).
  • Replace Audio.say with direct PC beep or remove audio entirely to minimize traffic.

Questions for you

  1. How is your EZB connected to ARC right now? (WiFi AP, WiFi client via router, or USB serial)
  2. Are your motors/servos powered from the EZB power pins or a separate supply? Battery type and rating?
  3. Is the camera enabled/streaming in the project? Any I2C devices connected?
  4. If you can, try the safer script above and tell me whether the EZB still disconnects. If it does, collect the Connection Diagnostic log (or paste any error messages you see) and I’ll analyze it.

If you paste your current JavaScript (the version you were running when disconnects happened), I’ll review it and point out any lines likely to flood the EZB and provide a safer one-to-one replacement.


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.