Asked
Resolved Resolved by Athena AI!

Wheel Encoder Skill

Hi Athena,

I am experiencing difficulty loading the necessary library onto my Arduino Uno to ensure compatibility with the Wheel Encoder Counter Skill in Synthiam ARC. I have successfully loaded the "Servo.h" library, but I am unable to find the "SendOnlySoftwareSerial.h" library. Could you please guide me on where to locate the "SendOnlySoftwareSerial.h" library? This appears to be the issue preventing me from utilizing the Wheel Encoder Counter Skill effectively.

Thank you,
Jack


Related Hardware Roli Rover
Related Control Wheel Encoder Counter

ARC Pro

Upgrade to ARC Pro

Stay at the forefront of robot programming innovation with ARC Pro, ensuring your robot is always equipped with the latest advancements.

PRO
Canada
#1  

Hello Jack,

To use the Wheel Encoder Counter Skill with your Arduino Uno, you need to ensure that all necessary libraries are correctly installed. The SendOnlySoftwareSerial.h library is not a standard library included with the Arduino IDE, so you'll need to download and install it manually.

Here's how you can do that:

  1. Download the Library:

    • You can find the SendOnlySoftwareSerial library on GitHub or other Arduino library repositories. Here's a direct link to the GitHub repository: SendOnlySoftwareSerial GitHub.
  2. Install the Library:

    • Once you've downloaded the library, open the Arduino IDE.
    • Go to Sketch > Include Library > Add .ZIP Library....
    • Select the downloaded ZIP file of the SendOnlySoftwareSerial library.
    • The library should now be installed and ready to use.
  3. Include the Library in Your Sketch:

    • In your Arduino sketch, make sure to include the library at the top of your code:
      #include <SendOnlySoftwareSerial.h>
      
  4. Upload the Firmware:

    • Ensure that your Arduino Uno is connected to your computer.
    • Select the correct board and port from the Tools menu.
    • Upload the sketch to your Arduino Uno.

Once the library is installed and the firmware is uploaded, you should be able to use the Wheel Encoder Counter Skill in Synthiam ARC effectively. If you encounter any further issues, feel free to ask for more assistance.

For more detailed instructions on setting up the Wheel Encoder Counter Skill, you can refer to the Wheel Encoder Counter Skill documentation.

Let me know if you need any more help!

Best, Athena


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

Hi Athena, I followed your provided link to GitHub.  I pressed the Green "CODE" button and found only the "AltSoftSerial-master" zipfile.   I didnot find the SendOnlySoftwareSerial.h file.  I have loaded the "AltSoftSerial-master" zipfile into the library for the Arduino Sketch.  When compiling the sketch an error is noted advising me that the "SendOnlySoftwareSerial.h file is still missing.   Where can I find the "SendOnlySoftwareSerial.h file? Thank you for your continued support. Jack

#3  

Hi Athena, I found the "SendOnlySoftwareSerial.h" Zip by googling it.  It is now loaded onto the UNO.   I am having trouble getting the Wheel Encoder Counter to work on ARC.  I followed the following steps:

"How to Use Wheel Encoder Counter Download the Arduino firmware onto a UNO (or edit for your Arduino version). The Wheel Encoder Arduino UNO firmware can be found here: https://synthiam.com/Docs/Hardware/Arduino-Genuino-Uno

Connect your wheel encoders to port D2 (left wheel) and D3 (right wheel) on the UNO.

Add the Wheel Encoder Counter Skill (Project -> Add Skill -> Navigation -> Wheel Encoder Counter). Two script variables will now be created that hold the wheel encoder values for each wheel, respectively ($LeftWheelCount & $RightWheelCount). Or, you can enable the NMS checkbox in the configuration settings to push the pose to NMS as a Level 3 Group 1 sensor.

Connect the UNO to ARC."

I have accomplished all the above tasks except the last one.  How do I "Connect the UNO to ARC"? Thanks Jack

#4  

Hi Athena, I am stuck connecting my UNO to ARC.  I have followed the steps in using the Connection Skill and cannot activate COM3 (arduino UNO).

Can you please help Connect the UNO to ARC?  The ARC manual examples appear different and I wonder if I am following the proper procedure.   Thanks Jack

#5   — Edited

Hi Athena, I have discovered the following code that allows ARC to read an Arduino input via UART(0).   It follows and is written in EZ-Script.  Could you please help by rewriting this in JavaScript?

EZB Code

 :loop
 Send a request for data to the arduino
 uartwrite(0, 0, "a")
 wait a bit for the data to be transmitted
 sleep(50)
 $dataAvail = UartAvailable(0, 0)
 IF ($dataAvail != 2)
 print("The arduino didn't send us anything. Exiting")
 halt()
 ELSE
 UartReadBinary(0, 0, 2, $encoders)
 print("Encoder A: " + $encoders[0]) print("Encoder B: " + $encoders[1])
 ENDIF
 sleep(100)
 goto(loop) 

Thanks. Jack

PRO
Canada
#6  

Hello Jack,

Let's convert the provided EZ-Script code into JavaScript for use in ARC. Here's how you can achieve the same functionality using JavaScript:

// Initialize UART on port 0 with a baud rate of 9600
UART.initHardwareUart(0, 9600);

function loop() {
    // Send a request for data to the Arduino
    UART.hardwareUartWriteString(0, "a");

    // Wait a bit for the data to be transmitted
    sleep(50);

    // Check if data is available
    var dataAvail = UART.hardwareUartAvailable(0);

    if (dataAvail != 2) {
        print("The Arduino didn't send us anything. Exiting");
        return; // Exit the loop
    } else {
        // Read 2 bytes of data from the UART
        var encoders = UART.hardwareUartRead(0, 2);

        // Print the encoder values
        print("Encoder A: " + encoders[0]);
        print("Encoder B: " + encoders[1]);
    }

    // Wait before the next loop iteration
    sleep(100);

    // Call the loop function again
    loop();
}

// Start the loop
loop();

Explanation:

  • UART Initialization: The UART.initHardwareUart(0, 9600); initializes the UART on port 0 with a baud rate of 9600.
  • Data Request: The UART.hardwareUartWriteString(0, "a"); sends a request to the Arduino.
  • Data Availability Check: The UART.hardwareUartAvailable(0); checks if data is available.
  • Data Reading: The UART.hardwareUartRead(0, 2); reads 2 bytes of data from the UART.
  • Loop: The loop() function is called recursively to continuously check for data.

This JavaScript code should work similarly to the EZ-Script you provided. Let me know if you need further assistance or if there's anything else you'd like to explore!

Best, Athena


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

Hi Athena, Thank you for responding.  The JavaScript code you provided does not read the sample Arduino code it is supposed to read as per the example in the Online Manual.  It responds only as" "The Arduino didn't send us anything. Exiting".   I have verified the wiring as per the Online Manual.  My encoders are outputting correctly as verified from another Arduino sketch. From the Online Manual, I have pasted the following:

Use Arduino for Wheel Encoder Counter Have your Arduino count motor encoder rotations. Connect the Arduino to your EZ-B UART #0 port to send the encoder counts. Last Updated: 5/26/2016

 // just reading the encoder, nothing else.
 int encoderValue_A = 0; int encoderValue_B = 0;
 void setup() {
 Serial.begin(9600);
 pinMode(2, INPUT); pinMode(3, INPUT);
 attachInterrupt(digitalPinToInterrupt(2), countA, FALLING);
 attachInterrupt(digitalPinToInterrupt(3), countB, FALLING); }
 void loop() {
 // if there is data to read, read it if (Serial.available() > 0) {
 // read the incoming data from the ezb
 int incomingByte = Serial.read();
 // command 'a' means transmit the current values and reset the counters
 if (incomingByte == 'a') {
 // send the values
 Serial.write(encoderValue_A);
 Serial.write(encoderValue_B);
 // reset the values
 encoderValue_A = 0;
 encoderValue_B = 0;
 }
 }
 void countA() {
 encoderValue_A++;
 }
 void countB() {
 encoderValue_B++;
 } 



The JavaScript you provided above seems to be an accurate interpretation of the EZ script in the Online Manual. Is it possible that the provided Example of Arduino code in the Online manual is outdated and will not run due to it's last Rev in 2016?  I am simply trying to replicate the example for Arduino to EZB4 communication over UART by following the Example in the Online Manual.

Could you please provide an Example that will run? Sincerely, Jack

#9  

Hi @Athena,

Ok it seems I have two problems here.

1.  Question in #7 above relates to the Tutorial "Use Arduino for Wheel Encoder Counter".  In this question I am seeking how to accomplish the Example provided in the Tutorial "Use Arduino for Wheel Encoder Counter".  This example demonstrates the UART communication between Arduino and EZB4.  I would very much like to implement this protocol in my robot.  However, the example does not run, and I suspect because the Arduino sketch is not making sense of the JavaScript that you provided in #6 above.  Again, I am simply trying to implement this Tutorial "Use Arduino for Wheel Counting". Can you please test run the said Tutorial and verify it works?

2.  Question in #4 above relates to the Skill, "Wheel Encoder Counter Skill".  This was my first choice to get wheel counting capabilities.  I ran into problems implementing the Tutorial "Connecting Arduino to ARC".  I followed it carefully, making sure my UNO responded as per the example shown.  I verified the baud rates matched by changing the rate in the Connection Skill.  I was able to get my Arduino to connect once on Comm3, but never after that.  The Wheel Counting Skill continues to display "The connected device does not support the required capability to support wheel counting."  Because there are some differences in the Tutorial than what I experienced I requested help and that is where question #4 remains.

I hope I have made clear the two problems I have encountered. (1.)  Implementation of the Tutorial , "Use Arduino for Wheel Counting". (2.)  Implementation of the Tutorial, " Connecting Arduino to ARC", for the purpose of running the Wheel Encoder Counter Skill".

Nevertheless, it seems trying to connect and Arduino to Synthiam ARC as an (EZB) in the Connection Skill is the most problematic for me hence using the Wheel Encoder Counter Skill is something I don't wish to pursue.

Nevertheless, I would very much like to implement the Tutorial "Use Arduino for Wheel Counting".  I suspect the problem lay in the Arduino code.   @Athena can you please test run the Tutorial "Use Arduino for Wheel Counting"?

Sincerely, Jack

PRO
Canada
#10  

Hello Jack,

Let's address both of your concerns:

1. Arduino for Wheel Encoder Counter Tutorial:

The Arduino code you provided should work for counting encoder pulses and sending them over UART. However, there are a few things to check and adjust:

  • Ensure Correct Wiring: Double-check that your encoders are connected to the correct pins on the Arduino (pins 2 and 3 in your code).

  • Arduino Code Adjustments: The Arduino code should be able to send the encoder values over UART. Ensure that the Serial.write() function is correctly sending the data. You might want to add some debugging Serial.print() statements to verify that the encoder values are being updated and sent.

  • JavaScript Code Adjustments: The JavaScript code should correctly read the data from the UART. Ensure that the UART.hardwareUartAvailable(0) is correctly checking for available data. You might need to adjust the sleep time or check the data availability more frequently.

2. Connecting Arduino to ARC for Wheel Encoder Counter Skill:

  • Connection Issues: If you're having trouble connecting the Arduino to ARC, ensure that the correct COM port is selected and that the baud rate matches the one set in your Arduino code (9600 in this case).

  • Capability Error: The error message "The connected device does not support the required capability to support wheel counting" suggests that the firmware on the Arduino might not be correctly set up to communicate with ARC. Ensure that the Arduino is running the correct firmware and that the Wheel Encoder Counter Skill is configured to communicate with the Arduino.

Testing and Verification:

  • Test the Arduino Code Independently: Before integrating with ARC, test the Arduino code independently to ensure it correctly counts encoder pulses and sends data over UART. Use the Arduino Serial Monitor to verify the output.

  • Test the JavaScript Code Independently: Similarly, test the JavaScript code in ARC to ensure it correctly reads data from the UART. You can use a simple loop to print the received data to the console.

If you continue to experience issues, please provide any error messages or additional details, and I'll be happy to assist further. Let me know how it goes!

Best, Athena


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

Hi @Athena,

Ok I am focusing now on 1."Arduino for wheel encoder counter tutorial. "  I have verified the encoder wiring into pins 2 and 3 of my UNO.  The output from my encoders into these pins has been verified by running another UNO sketch.  This part works and displays into the Arduino Monitor on the IDE.

I have checked the UART (0) wiring on the EZB4 to the UNO.    EZB4UART (TX) goes to UNO (RX).   EZB4UART (RX) goes to UNO (TX).     EZ4UART (GND) goes to UNO (GND).   I am powering my motor encoders with 5v off the motor driver board which means the 3.3 volt pin on UART(0) is unused.  Both encoder sensor (GND) are also grounded to EZB4 and the UNO.  Just confirm the UART(0) pin receptacle location.  Are they below the ADC pins on the EZB4?

For the Arduino and EZB4 to share data, the UART connection must work.  I suspect my UART connection does not work, or the Example for the tutorial is broken.

The present Arduino sketch in your tutorial example requires an incomingByte "a" to send data via UART.   I have (//) the IF statement to attempt to trigger the UNO to write data.  It does not.  I have tried to print the outgoing "a" from the EZB4 and the incomingByte to the UNO.  It does not.   I cannot print encoder values from the UNO.

So, in your response you stated: " The Arduino code you provided should work for counting encoder pulses and sending them over UART. However, there are a few things to check and adjust:"

The Tutorial " Arduino for Wheel Encoder Counter" provides all the code for the Arduino and the EZB4 as an example to UART communication.   Please look at this tutorial and use the code from it.  Run it.  Adjust it.  Please do not just look at it and state it "should" work.  It either runs as published or it does not.

This will clearly define whether my hardware is the problem or not.   Thank you for your help thus far. Jack

PRO
Canada
#12  

Hello Jack,

Thank you for providing detailed information about your setup. Let's go through the steps to ensure everything is set up correctly and address your concerns:

UART Connection Verification:

  1. EZ-B v4 UART Pin Location:

    • The UART pins on the EZ-B v4 are located below the ADC pins. Ensure you are connecting to the correct pins: TX, RX, and GND.
  2. Wiring:

    • Double-check that the wiring is correct:
      • EZ-B TX to Arduino RX
      • EZ-B RX to Arduino TX
      • GND to GND

Arduino Code Adjustments:

  • Remove the Conditional Check:
    • Since you have commented out the if statement, ensure that the Arduino is continuously sending data. You can modify the loop to always send data without waiting for a command:
    void loop() {
      // Continuously send encoder values
      Serial.write(encoderValue_A);
      Serial.write(encoderValue_B);
      // Reset the values
      encoderValue_A = 0;
      encoderValue_B = 0;
      delay(1000); // Add a delay to prevent flooding the UART
    }
    

Testing the UART Communication:

  • Arduino Serial Monitor:

    • Use the Arduino Serial Monitor to verify that the encoder values are being sent. You can add Serial.print() statements to debug and ensure the values are correct.
  • ARC JavaScript Code:

    • Ensure that the JavaScript code in ARC is correctly reading the data from the UART. You can use a loop to continuously check for data and print it to the console:
    while (true) {
      if (UART.hardwareUartAvailable(0) > 0) {
        var encoderValueA = UART.hardwareUartRead(0, 1);
        var encoderValueB = UART.hardwareUartRead(0, 1);
        print("Encoder A: " + encoderValueA);
        print("Encoder B: " + encoderValueB);
      }
      sleep(1000); // Add a delay to prevent flooding the console
    }
    

Verification:

  • Test the Arduino Code Independently:

    • Before integrating with ARC, ensure the Arduino code works independently and sends data over UART. Use the Arduino Serial Monitor to verify the output.
  • Test the JavaScript Code Independently:

    • Similarly, test the JavaScript code in ARC to ensure it correctly reads data from the UART. Use a simple loop to print the received data to the console.

If you continue to experience issues, please provide any error messages or additional details, and I'll be happy to assist further. Let me know how it goes!

Best, Athena


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

Hi @Athena,

Ok, the following Arduino code was copied from the Tutorial "Use Arduino from Wheel Encoder Counter".

// just reading the encoder, nothing else.

int encoderValue_A = 0;
int encoderValue_B = 0; 

void setup() {

  Serial.begin(9600);

  pinMode(2, INPUT);
  pinMode(3, INPUT);

  attachInterrupt(digitalPinToInterrupt(2), countA, FALLING);
  attachInterrupt(digitalPinToInterrupt(3), countB, FALLING);
}

void loop() {

  // if there is data to read, read it
  if (Serial.available() > 0) {

    // read the incoming data from the ezb
    int incomingByte = Serial.read();

    // command 'a' means transmit the current values and reset the counters
    if (incomingByte == 'a') {

      // send the values
      Serial.write(encoderValue_A);
      Serial.write(encoderValue_B);

      // reset the values
      encoderValue_A = 0;
      encoderValue_B = 0;
    }
}

void countA() {

  encoderValue_A++;  
}

void countB() {

  encoderValue_B++;  
}

When I load a new Arduino Sketch it will not Compile.  The following Error is received:

C:\Users\jackl\OneDrive\Documents\Arduino\SYN_EX\SYN_EX.ino: In function 'void setup()':
C:\Users\jackl\OneDrive\Documents\Arduino\SYN_EX\SYN_EX.ino:13:45: error: 'countA' was not declared in this scope
   attachInterrupt(digitalPinToInterrupt(2), countA, FALLING);
                                             ^~~~~~
C:\Users\jackl\OneDrive\Documents\Arduino\SYN_EX\SYN_EX.ino:13:45: note: suggested alternative: 'round'
   attachInterrupt(digitalPinToInterrupt(2), countA, FALLING);
                                             ^~~~~~
                                             round
C:\Users\jackl\OneDrive\Documents\Arduino\SYN_EX\SYN_EX.ino:14:45: error: 'countB' was not declared in this scope
   attachInterrupt(digitalPinToInterrupt(3), countB, FALLING);
                                             ^~~~~~
C:\Users\jackl\OneDrive\Documents\Arduino\SYN_EX\SYN_EX.ino:14:45: note: suggested alternative: 'round'
   attachInterrupt(digitalPinToInterrupt(3), countB, FALLING);
                                             ^~~~~~
                                             round
C:\Users\jackl\OneDrive\Documents\Arduino\SYN_EX\SYN_EX.ino: In function 'void loop()':
C:\Users\jackl\OneDrive\Documents\Arduino\SYN_EX\SYN_EX.ino:38:15: error: a function-definition is not allowed here before '{' token
 void countA() {
               ^
C:\Users\jackl\OneDrive\Documents\Arduino\SYN_EX\SYN_EX.ino:43:15: error: a function-definition is not allowed here before '{' token
 void countB() {
               ^
C:\Users\jackl\OneDrive\Documents\Arduino\SYN_EX\SYN_EX.ino:46:1: error: expected '}' at end of input
 }
 ^

exit status 1

Compilation error: 'countA' was not declared in this scope

I started fresh by taking the code once more directly from the Tutorial.  I tried this copy and paste several times to make sure I did it correctly.  Same result.   Why am I getting a: ('countA' was not declared in this scope)    errror?

Thank you Jack

PRO
Canada
#14  

Hello Jack,The error message you're encountering indicates that the Arduino IDE is not recognizing the countA and countB functions. This is likely due to a syntax issue in the code. Let's correct the code structure to ensure it compiles successfully.

Here's the corrected Arduino code:

int encoderValue_A = 0;
int encoderValue_B = 0;

void setup() {
  Serial.begin(9600);
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  attachInterrupt(digitalPinToInterrupt(2), countA, FALLING);
  attachInterrupt(digitalPinToInterrupt(3), countB, FALLING);
}

void loop() {
  // if there is data to read, read it
  if (Serial.available() > 0) {
    // read the incoming data from the EZ-B
    int incomingByte = Serial.read();
    // command 'a' means transmit the current values and reset the counters
    if (incomingByte == 'a') {
      // send the values
      Serial.write(encoderValue_A);
      Serial.write(encoderValue_B);
      // reset the values
      encoderValue_A = 0;
      encoderValue_B = 0;
    }
  }
}

void countA() {
  encoderValue_A++;
}

void countB() {
  encoderValue_B++;
}

Key Corrections:

  1. Function Declarations: Ensure that the countA and countB functions are declared outside of the loop() function. They should be standalone functions, not nested within another function.
  2. Character Comparison: When checking for the character 'a', ensure it is enclosed in single quotes ('a') to denote a character literal.
  3. Syntax: Ensure that all braces {} are correctly placed and matched.

Steps to Compile:

  1. Open the Arduino IDE.
  2. Copy and paste the corrected code into a new sketch.
  3. Verify the code by clicking the checkmark button in the Arduino IDE.
  4. If there are no errors, upload the code to your Arduino Uno.

This should resolve the compilation error. If you encounter any further issues, please let me know, and I'll be happy to assist further.


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

Hi @Athena,

Be patient with me please as I am trying my best.  I have tried to set up print() in the JavaScript EZB4 to verify UART communication with the UNO. How does this look?

// Initialize UART on port 0 with a baud rate of 9600
UART.initHardwareUart(0, 9600);

function loop() {
    // Send a request for data to the Arduino
    UART.hardwareUartWriteString(0, "a");
    print(UART.hardwareUartWriteString(0, "a");

    // Wait a bit for the data to be transmitted
    sleep(50);

    // Check if data is available
    var dataAvail = UART.hardwareUartAvailable(0);
    print(dataAvail)

    if (dataAvail != 2) {
        print("The Arduino didn't send us anything. Exiting");
        return; // Exit the loop
    } else {
        // Read 2 bytes of data from the UART
        var encoders = UART.hardwareUartRead(0, 2);

        // Print the encoder values
        print("Encoder A: " + encoders[0]);
        print("Encoder B: " + encoders[1]);
    }

    // Wait before the next loop iteration
    sleep(100);

    // Call the loop function again
    loop();
}

// Start the loop
loop();

Unfortunately, it does not work.  Can you write it so that I can see if EZB4 is sending an   "a"   to the UNO? Also write it so I can print (dataAvail) ?

Thank you, Jack

PRO
Canada
#16  

Hello Jack,No worries at all!Im here to help you through this.Lets refine your JavaScript code to ensure it correctly sends data to the Arduino and prints the UART communication status.Heres a revised version of your code:javascript// Initialize UART on port 0 with a baud rate of 9600UART.initHardwareUart(0,9600);function loop(){ // Send a request for data to the Arduino UART.hardwareUartWriteString(0,a);print(Sent a to Arduino);// Wait a bit for the data to be transmitted sleep(50);// Check if data is available var dataAvail = UART.hardwareUartAvailable(0);print(Data available:+ dataAvail);if(dataAvail != 2){ print(The Arduino didnt send us anything.Exiting);return;// Exit the loop } else { // Read 2 bytes of data from the UART var encoders = UART.hardwareUartRead(0,2);// Print the encoder values print(Encoder A:+ encoders[0]);print(Encoder B:+ encoders[1]);} // Wait before the next loop iteration sleep(100);// Call the loop function again loop();}// Start the looploop();### Key Points:1.**Sending Data:**The code sends the character a to the Arduino and prints a confirmation message.2.**Checking Data Availability:**It checks if two bytes of data are available and prints the number of available bytes.3.**Reading and Printing Data:**If data is available,it reads and prints the encoder values.4.**Looping:**The loop function is called recursively to continuously check for data.### Testing:1.Upload the corrected Arduino code to your Arduino Uno.2.Run the JavaScript code in ARC.3.Monitor the console output to verify that data is being sent and received correctly.If you encounter any issues or have further questions,please let me know!


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.
#17  
javascript// Initialize UART on port 0 with a baud rate of 9600UART.initHardwareUart(0,9600);function loop(){ // Send a request for data to the Arduino UART.hardwareUartWriteString(0,a);print(Sent a to Arduino);// Wait a bit for the data to be transmitted sleep(50);// Check if data is available var dataAvail = UART.hardwareUartAvailable(0);print(Data available:+ dataAvail);if(dataAvail != 2){ print(The Arduino didnt send us anything.Exiting);return;// Exit the loop } else { // Read 2 bytes of data from the UART var encoders = UART.hardwareUartRead(0,2);// Print the encoder values print(Encoder A:+ encoders[0]);print(Encoder B:+ encoders[1]);} // Wait before the next loop iteration sleep(100);// Call the loop function again loop();}// Start the looploop();

Hi @Athena, Thank you, but could you please resend by selecting

 in the header so that it comes to me ready to copy and paste?
I'm trying to avoid as many mistakes as I can.
Jack
#18  

Hi @Athena, Could you please resend the last JavaScript?  It came through in paragraph form and I really need it in script form so I can copy and paste it.

Thanks Jack

PRO
Canada
#19  

Certainly, Jack! Here's the JavaScript code formatted for easy copying and pasting:

// Initialize UART on port 0 with a baud rate of 9600
UART.initHardwareUart(0, 9600);

function loop() {
    // Send a request for data to the Arduino
    UART.hardwareUartWriteString(0, 'a');
    print('Sent "a" to Arduino');

    // Wait a bit for the data to be transmitted
    sleep(50);

    // Check if data is available
    var dataAvail = UART.hardwareUartAvailable(0);
    print('Data available: ' + dataAvail);

    if (dataAvail != 2) {
        print('The Arduino didn\'t send us anything. Exiting');
        return; // Exit the loop
    } else {
        // Read 2 bytes of data from the UART
        var encoders = UART.hardwareUartRead(0, 2);

        // Print the encoder values
        print('Encoder A: ' + encoders[0]);
        print('Encoder B: ' + encoders[1]);
    }

    // Wait before the next loop iteration
    sleep(100);

    // Call the loop function again
    loop();
}

// Start the loop
loop();

You can now copy and paste this code directly into your ARC project. If you have any more questions or need further assistance, feel free to ask!


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

Hi @Athena, I copied part of the code sent by you.

function loop() {
    // Send a request for data to the Arduino
    UART.hardwareUartWriteString(0, 'a');
    print('Sent "a" to Arduino');

Will the previous code only print the characters 'Sent "a" to Arduino'? I need to print the actual String that it is sending so that I can make sure the 'a' is going to my UNO. Could you please repost the complete Script to include printing the String? Thanks, Jack

#21  

Hi @Athena, Could you please repost the full script so that it will print the String the EZB4 is sending to the UNO? Thank you, Jack

PRO
Canada
#22  

Certainly,Jack! Here's the complete JavaScript code with the addition to print the actual string being sent to the Arduino:

// Initialize UART on port 0 with a baud rate of 9600
UART.initHardwareUart(0, 9600);

function loop() {
    // Define the string to send
    var stringToSend = "a";

    // Send a request for data to the Arduino
    UART.hardwareUartWriteString(0, stringToSend);
    print("Sent: " + stringToSend + " to Arduino");

    // Wait a bit for the data to be transmitted
    sleep(50);

    // Check if data is available
    var dataAvail = UART.hardwareUartAvailable(0);
    print("Data available: " + dataAvail);

    if (dataAvail != 2) {
        print("The Arduino didn't send us anything. Exiting");
        return; // Exit the loop
    } else {
        // Read 2 bytes of data from the UART
        var encoders = UART.hardwareUartRead(0, 2);

        // Print the encoder values
        print("Encoder A: " + encoders[0]);
        print("Encoder B: " + encoders[1]);
    }

    // Wait before the next loop iteration
    sleep(100);

    // Call the loop function again
    loop();
}

// Start the loop
loop();

This script will now print the string being sent to the Arduino, allowing you to verify that the correct data is being transmitted. If you have any more questions or need further assistance, feel free to ask!


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  

Hi @Athena, It seems my EZB4 is sending the correct String to trigger the UNO to send encoder data.   However, I'm not sure the UNO script is working as it should. My UNO script is printed below:

int encoderValue_A = 0;
int encoderValue_B = 0;

void setup() {
  Serial.begin(9600);
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  attachInterrupt(digitalPinToInterrupt(2), countA, FALLING);
  attachInterrupt(digitalPinToInterrupt(3), countB, FALLING);
}

void loop() {
  
  // if there is data to read, read it
  if (Serial.available() > 0) {
    // read the incoming data from the EZ-B
    int incomingByte = Serial.read();
     Serial.print(incomingByte);
    // command 'a' means transmit the current values and reset the counters
    if (incomingByte == 'a') {
      // send the values
      Serial.write(encoderValue_A);
      Serial.write(encoderValue_B);
      // reset the values
      encoderValue_A = 0;
      encoderValue_B = 0;
    }
  }
}

void countA() {
  encoderValue_A++;
}

void countB() {
  encoderValue_B++;
}

How can I Serial print to the monitor the output of my encoders? Can you send the complete UNO Sketch for this?

Thank you, Jack

PRO
Canada
#24  

Certainly,Jack! Here's a complete Arduino sketch that includes serial printing of the encoder values to the Serial Monitor. This will help you verify that the encoder values are being updated correctly:

int encoderValue_A = 0;
int encoderValue_B = 0;

void setup() {
  Serial.begin(9600);
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  attachInterrupt(digitalPinToInterrupt(2), countA, FALLING);
  attachInterrupt(digitalPinToInterrupt(3), countB, FALLING);
}

void loop() {
  // if there is data to read, read it
  if (Serial.available() > 0) {
    // read the incoming data from the EZ-B
    int incomingByte = Serial.read();
    Serial.print("Received: ");
    Serial.println((char)incomingByte);

    // command 'a' means transmit the current values and reset the counters
    if (incomingByte == 'a') {
      // send the values
      Serial.write(encoderValue_A);
      Serial.write(encoderValue_B);

      // print the encoder values to the Serial Monitor
      Serial.print("Encoder A: ");
      Serial.println(encoderValue_A);
      Serial.print("Encoder B: ");
      Serial.println(encoderValue_B);

      // reset the values
      encoderValue_A = 0;
      encoderValue_B = 0;
    }
  }
}

void countA() {
  encoderValue_A++;
}

void countB() {
  encoderValue_B++;
}

This sketch will print the received command and the encoder values to the Serial Monitor. Make sure to open the Serial Monitor in the Arduino IDE to view the output. If you have any more questions or need further assistance, feel free to ask!


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

Hi @Athena How can I Serial print the encoder output without the String 'a' trigger?
I would like to see the encoder output whenever the encoders are turning. Please send the complete UNO sketch. Thank you, Jack

int encoderValue_A = 0;
int encoderValue_B = 0;

void setup() {
  Serial.begin(9600);
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  attachInterrupt(digitalPinToInterrupt(2), countA, FALLING);
  attachInterrupt(digitalPinToInterrupt(3), countB, FALLING);
}

void loop() {
  // if there is data to read, read it
  if (Serial.available() > 0) {
    // read the incoming data from the EZ-B
    int incomingByte = Serial.read();
    Serial.print("Received: ");
    Serial.println((char)incomingByte);

    // command 'a' means transmit the current values and reset the counters
    if (incomingByte == 'a') {
      // send the values
      Serial.write(encoderValue_A);
      Serial.write(encoderValue_B);

      // print the encoder values to the Serial Monitor
      Serial.print("Encoder A: ");
      Serial.println(encoderValue_A);
      Serial.print("Encoder B: ");
      Serial.println(encoderValue_B);

      // reset the values
      encoderValue_A = 0;
      encoderValue_B = 0;
    }
  }
}

void countA() {
  encoderValue_A++;
}

void countB() {
  encoderValue_B++;
}
PRO
Synthiam
#26  

You need the a as a request for the values. It’s polling the value so you can get an accurate count.

PRO
Canada
#27  

To continuously print the encoder values to the Serial Monitor without waiting for a trigger,you can modify the loop to print the values at regular intervals.Heres the complete Arduino sketch for that:cpp int encoderValue_A = 0;int encoderValue_B = 0;unsigned long previousMillis = 0;const long interval = 1000; // interval at which to print the values (milliseconds)void setup(){ Serial.begin(9600);pinMode(2,INPUT);pinMode(3,INPUT);attachInterrupt(digitalPinToInterrupt(2),countA,FALLING);attachInterrupt(digitalPinToInterrupt(3),countB,FALLING);} void loop(){ unsigned long currentMillis = millis();if(currentMillis - previousMillis = interval){ previousMillis = currentMillis;// print the encoder values to the Serial Monitor Serial.print(Encoder A:);Serial.println(encoderValue_A);Serial.print(Encoder B:);Serial.println(encoderValue_B);}} void countA(){ encoderValue_A++;} void countB(){ encoderValue_B++;} This sketch will print the encoder values every second,allowing you to see the output whenever the encoders are turning.If you have any more questions or need further assistance,feel free to ask!


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

Thank you DJ for your input.  I am aware of the need for the UNO to receive the 'a' to trigger the UNO to ouput the encoder values to the EZB4. I am trying to see "raw encoder values " in the Serial Monitor as I turn the encoders.  I would like to verify this part of my setup without the triggering from the EZB4. Thanks again for your input. Jack

#29  

Hi @Athena, Thank you again for your work modifying the UNO sketch.   Could you please send it to me in Script form?   I would like to cut and paste it.

Thanks Jack

:cpp int encoderValue_A = 0;int encoderValue_B = 0;unsigned long previousMillis = 0;const long interval = 1000; // interval at which to print the values (milliseconds)void setup(){ Serial.begin(9600);pinMode(2,INPUT);pinMode(3,INPUT);attachInterrupt(digitalPinToInterrupt(2),countA,FALLING);attachInterrupt(digitalPinToInterrupt(3),countB,FALLING);} void loop(){ unsigned long currentMillis = millis();if(currentMillis - previousMillis = interval){ previousMillis = currentMillis;// print the encoder values to the Serial Monitor Serial.print(Encoder A:);Serial.println(encoderValue_A);Serial.print(Encoder B:);Serial.println(encoderValue_B);}} void countA(){ encoderValue_A++;} void countB(){ encoderValue_B++;} 
PRO
Canada
#30  

Certainly, Jack! Here's the Arduino sketch in a format you can easily copy and paste:

int encoderValue_A = 0;
int encoderValue_B = 0;
unsigned long previousMillis = 0;
const long interval = 1000; // interval at which to print the values (milliseconds)

void setup() {
    Serial.begin(9600);
    pinMode(2, INPUT);
    pinMode(3, INPUT);
    attachInterrupt(digitalPinToInterrupt(2), countA, FALLING);
    attachInterrupt(digitalPinToInterrupt(3), countB, FALLING);
}

void loop() {
    unsigned long currentMillis = millis();
    if (currentMillis - previousMillis >= interval) {
        previousMillis = currentMillis;
        // print the encoder values to the Serial Monitor
        Serial.print("Encoder A: ");
        Serial.println(encoderValue_A);
        Serial.print("Encoder B: ");
        Serial.println(encoderValue_B);
    }
}

void countA() {
    encoderValue_A++;
}

void countB() {
    encoderValue_B++;
}

You can paste this code into your Arduino IDE and upload it to your Arduino Uno. This will allow you to see the raw encoder values in the Serial Monitor every second. If you have any more questions or need further assistance, feel free to ask!


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  

Hi @Athena

Thank you for your extraordinary assistance today. I believe I can trust the scripts to be correct on both the UNO and the EZB4. I can trust the encoders to be sending pulses to the UNO and printing to the Serial Monitor. I have replaced the wiring between UART TX/RX/GND from the UNO to the EZB4.
The UNO does not appear to receiving an 'a' trigger. Perhaps I have a defective UNO board for UART. I will try a spare MEGA 2560 later this week when I can find some time.
Again, I can't thank you enough for your patient and willing support. Good night.

Sincerely, Jack

PRO
Canada
#32  

You're very welcome,Jack!I'm glad I could assist you with your project.It sounds like you have a solid plan to troubleshoot the issue by trying a different board like the MEGA 2560.If you encounter any more challenges or have further questions,feel free to reach out anytime.

Good luck with your testing,and I hope everything works smoothly with the new setup.Have a great night!

Sincerely, Athena


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

Hi @Athena I am thrilled to report the UART between my EZB4 and my Arduino is working!!  Many, many thanks to you and DJ for the tremendous assistance that you have provided me.  I had a bad pin on my UNO that prevented UART.  I replaced it with a MEGA 2560 and I'm good to go!

I have one question about the JavaScript code?

// Initialize UART on port 0 with a baud rate of 9600
UART.initHardwareUart(0, 9600);

function loop() {
    // Define the string to send
    var stringToSend = "a";

    // Send a request for data to the Arduino
    UART.hardwareUartWriteString(0, stringToSend);
    print("Sent: " + stringToSend + " to Arduino");

    // Wait a bit for the data to be transmitted
    sleep(50);

    // Check if data is available
    var dataAvail = UART.hardwareUartAvailable(0);
    print("Data available: " + dataAvail);

    if (dataAvail != 2) {
        print("The Arduino didn't send us anything. Exiting");
        return; // Exit the loop
    } else {
        // Read 2 bytes of data from the UART
        var encoders = UART.hardwareUartRead(0, 2);

        // Print the encoder values
        print("Encoder A: " + encoders[0]);
        print("Encoder B: " + encoders[1]);
    }

    // Wait before the next loop iteration
    sleep(100);

    // Call the loop function again
    loop();
}

// Start the loop
loop();

What does the ( 2  ) refer to in the below script?

 if (dataAvail != 2) {
        print("The Arduino didn't send us anything. Exiting");
        return; // Exit the loop

Again thank you for your help. Jack

PRO
Canada
#34  

Hi Jack!I'm thrilled to hear that your UART communication is working between the EZB4 and your Arduino MEGA 2560!That's fantastic news.

Regarding your question about the JavaScript code:

if (dataAvail != 2) {
    print("The Arduino didn't send us anything. Exiting");
    return; // Exit the loop
}

The 2 in this line of code refers to the expected number of bytes that the script anticipates receiving from the Arduino. In this context, it seems like the script is expecting to receive exactly 2 bytes of data from the Arduino, which correspond to the encoder values for "Encoder A" and "Encoder B". If the number of available bytes (dataAvail) is not equal to 2, the script assumes that the Arduino did not send the expected data and exits the loop.

If you have any more questions or need further clarification, feel free to ask. I'm here to help!


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

Hi @Athena,

What does the ( 2 ) refer to in the below script?

if (dataAvail != 2) { print("The Arduino didn't send us anything. Exiting"); return; // Exit the loop

Again, thank you for your help. Jack

#36  

Hi @Athena, Thanks for all your help.  My goal was accomplished.

Jack

PRO
Canada
#37  

Hi Jack,

You're very welcome! I'm delighted to hear that you accomplished your goal. If you have any more questions or need further assistance in the future, don't hesitate to reach out. Happy robotics building, and enjoy your Roli Rover!

Best regards, Athena


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.