Asked

Accessing The Analog Values On An Arduino

Is it possible to access analog values on an Arduino using the existing ARC software? I've tried, but it seems that the only ADC (Analog-to-Digital Converter) skills available are tied to the EZ-Robot EZ-B v4 and EZ-Robot EZ-B Tiny controllers. I have several Arduinos that I'm already using with the Stepper servo skill, and they have extra pins available for analog inputs and outputs. However, I do not know how to access these analog values through ARC. If this functionality is not currently available, could you please consider adding it to the list for future skill development?


Related Hardware Arduino Genuino Uno

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!

PRO
Canada
#1  

Yes, you can access the analog values on an Arduino using the existing ARC software. The key is to use the I2C communication protocol to read the analog values from the Arduino. Here's how you can achieve this:

Using the PWM servo Feedback (i2c) Skill

The PWM servo Feedback (i2c) skill is designed to read analog values from an Arduino over I2C. Here’s a step-by-step guide to set it up:

  1. Upload the Firmware to Arduino:

    • Download the firmware for the Arduino from the PWM servo Feedback (i2c) skill page.
    • Upload the firmware to your Arduino using the Arduino IDE. The firmware is designed to read the analog values from the Arduino's ADC ports and send them over I2C.
  2. Connect the Arduino to EZ-B:

    • Connect the Arduino to the EZ-B using the I2C ports. For example, on an Arduino Nano, the I2C ports are A4 (SDA) and A5 (SCL). Connect these to the corresponding I2C ports on the EZ-B.
  3. Configure the PWM servo Feedback (i2c) Skill:

    • In ARC, add the PWM servo Feedback (i2c) skill to your project.
    • Open the configuration menu of the skill and set the I2C address to match the one used in the Arduino firmware.
    • Specify the number of ADC ports you want to read from.
  4. Read the Analog Values:

    • The skill will now read the analog values from the specified ADC ports on the Arduino and make them available in ARC.

Using Custom JavaScript or Python Code

If you prefer to write custom code, you can use JavaScript or Python in ARC to read the analog values from the Arduino over I2C. Here’s an example using JavaScript:

  1. Initialize the I2C Communication:

    I2C.initHardwareUart(0, 115200); // Initialize I2C on UART 0 with a baud rate of 115200
    
  2. Read Analog Values:

    var address = 0x08; // I2C address of the Arduino
    var bytesToRead = 2; // Number of bytes to read (for a 10-bit ADC value)
    
    // Read the analog value from ADC port 0
    var adcValue = I2C.read(address, bytesToRead);
    print("ADC Value: " + adcValue);
    

Using the ArduinoComs Skill

The ArduinoComs skill allows communication between the EZ-B and Arduino using I2C. You can use this skill to send custom commands to the Arduino and read the analog values. Here’s how:

  1. Upload Custom Firmware to Arduino:

    • Write custom firmware for the Arduino to read the analog values and send them over I2C when requested.
    • Upload the firmware to the Arduino using the Arduino IDE.
  2. Configure the ArduinoComs Skill:

    • In ARC, add the ArduinoComs skill to your project.
    • Open the configuration menu of the skill and set the I2C address to match the one used in your custom firmware.
  3. Send Commands and Read Values:

    • Use the ArduinoComs skill to send commands to the Arduino and read the analog values.

Example Arduino Firmware

Here’s an example of Arduino firmware to read an analog value and send it over I2C:

#include <Wire.h>

#define I2C_ADDRESS 0x08

void setup() {
  Wire.begin(I2C_ADDRESS);
  Wire.onRequest(requestEvent);
}

void loop() {
  // Main loop does nothing, waiting for I2C requests
}

void requestEvent() {
  int analogValue = analogRead(A0); // Read analog value from A0
  Wire.write(analogValue >> 8); // Send high byte
  Wire.write(analogValue & 0xFF); // Send low byte
}

Conclusion

By using the PWM servo Feedback (i2c) skill, custom JavaScript or Python code, or the ArduinoComs skill, you can access the analog values on an Arduino and integrate them into your ARC project. If you need further assistance or have specific requirements, 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.
#2  

I do not foresee myself using this process to get analog values. It would be much easier if you could just pick a different board for analog input similar to how you can pick different board for digital outputs.

#3   — Edited

Arduino supports adc - there is no limitation of adc on ardunio vs ezrobot controllers. The ports are labeled the same as ADCx

Athenas response is a little off because the question isn’t clear as to why you believe you cannot use adc ports on arduino.

#4  

Ok can you show me how to get to it. I only see the 7 typical ports listed. What if you have an EZ tiny and other Arduino boards how will it know which Arduino board? It only pulls up the four typical boards.

User-inserted image

#5  

For that robot skill, it appears that you select the board index - which is the ezb board, corresponding to the connection index.

User-inserted image

#6  

Isn't the board index specific to EZ boards. I did look into the board index but did not think that is correct. I have multiple ez boards and multiple Arduinos with same board numbers, how will it know the difference? See the dilemma? For instance Arduino Mega is always board 1 or business id 1 when using Stepper servo skill and will have EZ board 1 with the tiny but it only has 3 analog inputs. Have a feeling this might be a feature request for the next update.

PRO
Synthiam
#7   — Edited

What support is saying is the board index matches the connection index.

An EZB is an EZB. It can be an Arduino or any microcontroller with EZB firmware. It's the firmware that makes a microcontroller an EZB. Read here or watch a video from here: https://synthiam.com/Support/Get-Started/how-to-make-a-robot/EZB

So, if you have an Arduino with an EZB firmware connected on index 2, select 2 in that dropdown.

Also, you can make sure an EZB firmware supports ADC by checking the list of capabilities when it connects. For example here's when i connected to an EZ-Robot EZB v4.x/2

User-inserted image

Connected to 10.8.0.6:23
Reports EZB v4 OS With Comm 2
Firmware 'EZ-B v4.x/2 Native Firmware' on 'EZ-Robot EZ-B v4.x/2' supports the following capabilities:
 - ADC with 12 bit Resolution <------------ SUPPORTS ADC 
 - Can stream Audio v4 codec
 - Reports battery voltage
 - Reports CPU temperature
 - Read/Write Digital I/O Ports
 - Hardware UART TX/RX with DMA buffer and adjustable baud rate
 - I2C Master
 - LIPO battery protection & shutdown
 - PWM Duty on digital ports
 - PWM servos on digital ports
 - PWM servos on digital ports can release their position
 - servo speed for PWM servos on digital ports
 - Has NVRam configuration and can be restored to default settings
 - Transmit Uart TX on all digital ports
 - Adjustable I2C clock speed
 - Configurable UART TX digital port baud timing
 - Ultrasonic Ping distance sensor support
 - 12 Byte Unique Identifier
 - Can stream video v4 codec
 - Native UART Connectivity from ARC
 - Native WiFi Connectivity from ARC
 - Broadcasts to ARC's PnP network scanner
#8  

Ok I'm kind of digesting the info. The question now is since the Arduino was loaded with the Stepper servo firmware did it go into utilizing just pin 2 and 3 for step and direction, pin 6 for calibrating . Wouldn't that have to have more programing for the analog and other output pins. Or is that somewhat of a given that it will be available? Will dig in to what it's available capabilities are available as you have suggested above.

PRO
Synthiam
#9   — Edited

The stepper firmware is not an ezb. The stepper protocol does not support anything like reading ADC. So no, you wouldn't get an Arduino's adc value from a stepper motor firmware. You couldn't add it either because the protocol doesn't allow it. An Arduino would need an EZB firmware installed to operate EZB commands, not a stepper firmware.

#10   — Edited

Understood, had a feeling that might be the case. I'll just use the EZB-4.