For context: I'm working on a project where I need to use sensors to figure out the current state of the environment. This process is done using an Arduino UNO and a RPi. The easiest way that I found to perform communication between both boards is by uploading Standard Firmata and reading the code from RPi using Serial communication. I'm using pyfirmata to write the code in Python on the RPI side. Also, the Arduino is powered by the RPi using the USB port.

My problem was: The ADC component in the Arduino uses as the analog reference the 5V provided by the USB. When I tested the integration, I was using my laptop. So, the computer was providing 5V to the Arduino. So far so good. When I integrated the Arduino board to the RPi, I got some problems related to the precision of the sensor. I figured out that the RPi was only giving 4.75 V to the Arduino Board. This was messing with my readings since the ADC was using 4.75V while my code had 5V to compute things. After adjusting the code, everything proceeded as planned. Both 4.75 V and 5 V were hardcoded in my code.

So, these are my questions:

  • Is there a way to read the Vcc using pyfirmata to figure out the correct voltage without having this hardcoded?
  • Is there a way to modify the analog reference to use the INTERNAL reference of 1.1V?

About the analog reference, I found this: https://github.com/firmata/arduino/issues/39 . So, pyfirmata implements send_sysex method, I just have to execute these steps, but I still don't know how.


It does not appear that Firmata has proceeded with the ability to change the analog reference source. You referenced one of the issues opened for it, but I don't see anywhere where it committed to the current master branch.

There's no way for an Arduino to read a voltage without some reference, and as you are experiencing, the default reference is Vcc. That means everything must be compared to Vcc, and if you compare Vcc to itself, you will always find out that Vcc is equal to Vcc.

The pull request to implement is here, so you could play around with it yourself.

  • So, you are saying that even if I use the send_sysex method (which I'm still not sure that can solve my problem), it wouldn't matter since the analog reference modification is not implemented in the current Firmata version?
    – coelhudo
    Mar 13 '18 at 20:00
  • 1
    I'm not an expert on Firmata, but I searched through the source code for the firmata code that would run on an Arduino and no were in there does it implement anything that sets the analog reference. Mar 13 '18 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.