Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

Measuring Current and Voltage of Servo with Arduino Nano 33
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Measuring Current and Voltage of Servo with Arduino Nano 33

by mawen on Mon Oct 18, 2021 9:26 am

Hello,

I designed a circuit containing an Arudino nan 33 BLE powered by two 18650, connected in series by a BMS, and a HS 646WP Hitec Servo. I attached a simple schematic.

I fried quite a few Arduinos and have now included diodes, resistor and capacitors to protect the Vin port, which seems to work stable now.

I would like to measure the current and voltage of the servo. I ordered INA260 Adafruit breakout board. Can someone confirm this is suitable for my setup?

May I also kindly ask for suggestions on where to best include it in my circuit and how to wire it? I read about inductive kickback, is this something in need to take into considerations?

Many thanks in advance
Attachments
cabling.png
cabling.png (72.1 KiB) Viewed 110 times

mawen
 
Posts: 9
Joined: Mon Oct 18, 2021 9:17 am

Re: Measuring Current and Voltage of Servo with Arduino Nano

by adafruit_support_bill on Mon Oct 18, 2021 10:36 am

I'd put it on the positive power feed between your diode and the servo.
See the guide here for instructions: https://learn.adafruit.com/adafruit-ina ... -3024022-1

The servo control board will have diode protections on each leg of the H-bridge, so inductive kickback will not be an issue. Do note however that servo current draw tends to be rather spiky, and instantaneous readings may not be representative of the overall current draw. So you may want to add some low-pass filtering (basically a short-term running average) in your code.

adafruit_support_bill
 
Posts: 82437
Joined: Sat Feb 07, 2009 10:11 am

Re: Measuring Current and Voltage of Servo with Arduino Nano

by mawen on Wed Oct 20, 2021 11:14 am

adafruit_support_bill wrote:I'd put it on the positive power feed between your diode and the servo.
See the guide here for instructions: https://learn.adafruit.com/adafruit-ina ... -3024022-1

The servo control board will have diode protections on each leg of the H-bridge, so inductive kickback will not be an issue. Do note however that servo current draw tends to be rather spiky, and instantaneous readings may not be representative of the overall current draw. So you may want to add some low-pass filtering (basically a short-term running average) in your code.


Thank you very much for the reply!

I will place it, as suggested, between servo and diode. Did I understand correctly that I need to power the INA260 via the 3.3V pin on the Arduino? Then connect INA260 GND to Arduino GND and also connect SCL and SDA on both?

Attached an updated schematic

Many thanks again
Attachments
cabling2.png
cabling2.png (51.64 KiB) Viewed 91 times

mawen
 
Posts: 9
Joined: Mon Oct 18, 2021 9:17 am

Re: Measuring Current and Voltage of Servo with Arduino Nano

by adafruit_support_bill on Wed Oct 20, 2021 1:31 pm

Yes. Those connections look correct for a Nano 33.

adafruit_support_bill
 
Posts: 82437
Joined: Sat Feb 07, 2009 10:11 am

Re: Measuring Current and Voltage of Servo with Arduino Nano

by mawen on Wed Oct 20, 2021 3:07 pm

Thank you again.

Another question to clarify, does the above setup give me a measurement of Battery Voltage and Servo Current?

Or would the attached update would do that?
Attachments
cabling3.png
cabling3.png (75.17 KiB) Viewed 86 times

mawen
 
Posts: 9
Joined: Mon Oct 18, 2021 9:17 am

Re: Measuring Current and Voltage of Servo with Arduino Nano

by adafruit_support_bill on Wed Oct 20, 2021 3:51 pm

Wiring as in the first diagram will give you bus voltage as well as current.

Wired as in the second diagram is likely to cause damage to your Nano.

adafruit_support_bill
 
Posts: 82437
Joined: Sat Feb 07, 2009 10:11 am

Re: Measuring Current and Voltage of Servo with Arduino Nano

by mawen on Thu Oct 21, 2021 7:35 am

adafruit_support_bill wrote:Wiring as in the first diagram will give you bus voltage as well as current.

Wired as in the second diagram is likely to cause damage to your Nano.



Thank you. Hope its OK to ask further questions.

I solder the INA260 in as per the correct drawing, VCC and GND to 3.3V pin and GND pin on the Arduino.
The board in general is amazing, works all in first try. However, my readings currently seem to not be correct.

I attached an image of graph of a reading for Current and Voltage. No cycle averaging applied, but results are similiar with the cycle averaging loop in the code. Also the magnitude is not close to the measured voltage across the BMS port is 7.9V.
My current understand is that the INA260 would measure that value when cabled as above?

I am using the following code, where I send the data via BLE to my PC (note that I multiply and divide by factor 1000, to send values as integer) readings are the same when following the provided example, yet the servo is not powered in that case, as I keep the switch switched OFF.

Many thanks again

Code: Select all | TOGGLE FULL SIZE

#include <ArduinoBLE.h>
#include <Adafruit_INA260.h>




//Adafruitboard
Adafruit_INA260 ina260 = Adafruit_INA260();

int VolINT;
int CurrINT;

int ic;
int j;
int ic_max = 200;
int CycMC [200];
int AveC;


int iv;
int k;
int iv_max = 200;
int CycMV [200];
int AveV;


Servo hitec;

time_t t = now();

BLEService MService("1101");
BLEUnsignedCharCharacteristic voltageChar("2201", BLERead | BLENotify);
BLEUnsignedCharCharacteristic currentChar("2101", BLERead | BLENotify);

void setup()
{

  Serial.begin(115200);


  Serial.println("Adafruit INA260 Test");

  if (!ina260.begin()) {
    Serial.println("Couldn't find INA260 chip");
    while (1);
  }
  Serial.println("Found INA260 chip");

  if (!BLE.begin()) {
    Serial.println("starting BLE failed!");
    while (1);
  }
 
  // set advertised local name and service UUID:

  BLE.setAdvertisedService(MService);

  // add the characteristic to the service
  MService.addCharacteristic(voltageChar);
  MService.addCharacteristic(currentChar);

 
  // add service
  BLE.addService(MService);
 
  // set the initial value for the characeristic:
  voltageChar.writeValue(0);
  currentChar.writeValue(0);

  // start advertising
  BLE.advertise();
}

void loop()
{
  BLEDevice central = BLE.central();

  if (central)\
  {
    Serial.print("Connected to central: ");
    Serial.println(central.address());
     
     while (central.connected())
       { 

        //VOLTAGE READING
        VolINT = int(ina260.readBusVoltage()*1000);
       
        // cycle averaging
        iv++;
        if (iv >= iv_max)
         {
         iv = 0; 
         }
        CycMV[iv] = VolINT;
        AveV = 0;
        for (k=0;k<ic_max;k++)
        {
          AveV = AveV + CycMV[k]; 
        }

       //SEND VOLTAGE VALUE
       voltageChar.writeValue(VolINT);
       //voltageChar.writeValue(AveV); 

//CURRENT READING
        CurrINT = int (ina260.readCurrent()*1000);
        //cycle averaging
        ic++;

        if (ic >= ic_max)
        {
        ic = 0; 
        }
       
        CycMC[ic] = CurrINT;
        AveC = 0;
        for (j=0;j<ic_max;j++)
        {
          AveC = AveC + CycMC[j]; 
        }

      //SEND VOLTAGE VALUE
      currentChar.writeValue(CurrINT);
      currentChar.writeValue(AveC);
       
   
      }
  }

}

Attachments
ada260.png
ada260.png (110.05 KiB) Viewed 67 times
Last edited by mawen on Thu Oct 21, 2021 7:52 am, edited 1 time in total.

mawen
 
Posts: 9
Joined: Mon Oct 18, 2021 9:17 am

Re: Measuring Current and Voltage of Servo with Arduino Nano

by adafruit_support_bill on Thu Oct 21, 2021 7:51 am

Please post some photos showing all of your connections.

adafruit_support_bill
 
Posts: 82437
Joined: Sat Feb 07, 2009 10:11 am

Re: Measuring Current and Voltage of Servo with Arduino Nano

by mawen on Thu Oct 21, 2021 7:56 am

adafruit_support_bill wrote:Please post some photos showing all of your connections.


It is soldered like this. Do you mean actual photos? I will share one in another photo yet I think they might not be very clear.
Attachments
cabling2.png
cabling2.png (51.64 KiB) Viewed 66 times

mawen
 
Posts: 9
Joined: Mon Oct 18, 2021 9:17 am

Re: Measuring Current and Voltage of Servo with Arduino Nano

by mawen on Thu Oct 21, 2021 8:00 am

Please let me know if you would like a more clear image
Attachments
IMG_2803-min.jpg
IMG_2803-min.jpg (491.77 KiB) Viewed 66 times

mawen
 
Posts: 9
Joined: Mon Oct 18, 2021 9:17 am

Re: Measuring Current and Voltage of Servo with Arduino Nano

by adafruit_support_bill on Thu Oct 21, 2021 8:06 am

We can't follow where any of the wires go from that photo.

adafruit_support_bill
 
Posts: 82437
Joined: Sat Feb 07, 2009 10:11 am

Re: Measuring Current and Voltage of Servo with Arduino Nano

by mawen on Thu Oct 21, 2021 8:12 am

adafruit_support_bill wrote:We can't follow where any of the wires go from that photo.


My apologies. I am not using a breadboard for this project.

I can confirm that from all cables are connected according to the above schematic.

mawen
 
Posts: 9
Joined: Mon Oct 18, 2021 9:17 am

Re: Measuring Current and Voltage of Servo with Arduino Nano

by mawen on Thu Oct 21, 2021 8:20 am

Please find this photo, which is hopefully more clear.
Attachments
IMG_2805-min.jpg
IMG_2805-min.jpg (949.98 KiB) Viewed 63 times

mawen
 
Posts: 9
Joined: Mon Oct 18, 2021 9:17 am

Re: Measuring Current and Voltage of Servo with Arduino Nano

by adafruit_support_bill on Thu Oct 21, 2021 8:45 am

First measure the voltage between the Vin+ screw terminal and the ground pin in the INA260 and verify that it matches the output of your battery (minus the diode drop of course).

Then run the example code from the library and post the output from that: https://github.com/adafruit/Adafruit_IN ... 0_test.ino

adafruit_support_bill
 
Posts: 82437
Joined: Sat Feb 07, 2009 10:11 am

Re: Measuring Current and Voltage of Servo with Arduino Nano

by mawen on Thu Oct 21, 2021 9:07 am

adafruit_support_bill wrote:First measure the voltage between the Vin+ screw terminal and the ground pin in the INA260 and verify that it matches the output of your battery (minus the diode drop of course).

Then run the example code from the library and post the output from that: https://github.com/adafruit/Adafruit_IN ... 0_test.ino


Battery voltage 7.89V

Voltage on INA260 V+ to INA GND 7.24V.

Results measure the 7.24V look good when running the example code.

This would mean the error is within my code. I will have a look.

Many thanks!
Attachments
ada260_2.png
ada260_2.png (13.24 KiB) Viewed 59 times

mawen
 
Posts: 9
Joined: Mon Oct 18, 2021 9:17 am

Please be positive and constructive with your questions and comments.