Fun, Learning, Friendship and Mutual Respect START  HERE


Unregistered
Go Back   HeliFreak > R/C Electronics Support > OpenTX Radios


OpenTX Radios OpenTX Radios Discussion and Support Forum


Reply
 
LinkBack Thread Tools Display Modes
Old 09-14-2016, 09:25 AM   #1 (permalink)
Registered Users
 
Posts: 3,090
 

Join Date: Mar 2012
Default Arduino current sensor - How To

There is another thread about this, but I thought that since I asked a bunch of questions and worked through it that I'd put a step by step set of instructions on how to do this.

I'm assuming the following
  • You know how to program OpenTX
  • You understand how to load software and drivers using Windows.
  • That you understand that this is build at your own risk and learn about some of this stuff before blindly following things

First of all, thank you to the help that I received from Trebb & Raleighcopter

What you need
  • Arduino Nano Get the Atmega 328 16MHz processor. I got mine from Amazon.
  • ACS758 100U current sensor. I got mine from eBay. There are 50, 100, 150 and 200A sizes, so select what you want for your application. Unidirectional ones will work and are more accurate than bidirectional sensors.
  • .1uF Capacitor Had one laying around or you can get them from eBay
Download Arduino tools https://www.arduino.cc/en/Main/Software
Download OpenXSensor library - https://github.com/openXsensor/openX...ensor_v2.5.zip
Do not use OpenXSensor Config

Wiring
Note that the following wiring needs to match the configuration setup in oXs_config.h
Here is a diagram of what my wiring is. The example oXs_config.h file excerpts below match it.


Note that you will want to unplug from the receiver when you plug in the USB. The power on the board is not isolated and you will power up your FBL and servos from Arduino board which is not really setup to supply that much power.

Editing oXs_config.h
Open the OpenXSensor project in the Arduino software.

In the oXs_config.h file near the middle. You will need to set the pin that is the input from the current sensor. I used A6. See below. You will also need to adjust how many mvolts are being output from the sensor for both at 0 amps and per amp. The per amp voltage is in the data sheet for the 758. To measure at 0 amps, I simply measured the voltage across VIOUT and GND on the 758 when the Arduino was being powered by the USB. This way the flight pack is not hooked up and 0 current is flowing across the 758.
The 758 data sheet can be found here. http://www.allegromicro.com/~/media/...eet.ashx?la=en
This site also has information as well as starting points for offsets at 0 current in case you have no way of measuring. http://henrysbench.capnfatz.com/henr...nsor-tutorial/
Here are the parameters I set for my 758 100A unidirectional current sensor wired to Pin A6 on the Arduino. I did not use any resistors, so I set those value to 0.
// ***** 6.4 - Current parameters *****
#define PIN_CURRENTSENSOR 6
#define MVOLT_AT_ZERO_AMP 589 // in millivolt
#define MVOLT_PER_AMP 36 // in milliVolt per Amp
#define RESISTOR_TO_GROUND_FOR_CURRENT 0 // put as comment or set to 0 if no divider is used
#define RESISTOR_TO_CURRENT_SENSOR 0 // put as comment or set to 0 if no divider is used
If you want to change the pin that outputs to the S.Port, then you will need to change the following line to what you want.
// --------- 2 - Serial data pin choice ---------
#define PIN_SERIALTX 4 // The pin which transmits the serial data to the telemetry receiver, Usually pin 4
Connecting Arduino to PC
Warning Do not plug Arduino into a BEC and USB at the same time. It will not end well for your board.
When you install the Arduino IDE (Integrated Design Environment) it should give you the option of installing the drivers. Do this.

Plug in the Arduino to the USB and then look in Device Manager to see where it connected. If it does not show up, then your driver did not install properly and you need to fix that. Otherwise, note the COM port used. The Arduino tools do not automatically find it.

Setting up Arduino Studio
First you need to set up the type and processor being used. There are several options. I used a Nano 16MHz with the built in USB port.

Your config should look similar to the following.


Before you go with OpenXSensor, you might want to try the sample project called Blink to make sure that everything works. The Arduino tools have it under the example projects. It's a bit counter intuitive, but you upload a project to your Arduino. Just make sure the LED blinks when you upload that example file. If it does, then you have just run your first project. Congratulations.

Once you've done that, open the OpenXSensor project in the Arduino tools and upload it to the Nano.

Configuring the Taranis
Once you plug in everything, power up the model and scan for new telemetry sensors. Curr should show up. You can then create a new telemetry variable for mAh that is calculated.


Calibration
Finally, you need to calibrate your sensor. My method was to fully charge a battery on the charger. Fly your model for a couple of minutes. Write down the mAh from the telemetry screen on the transmitter, then compare it to how many mAh need to be put back into the battery to fully charge it. Then calculate what percentage you are off by. Once you have that, then adjust the value of MVOLT_PER_AMP in oXs_config.h accordingly.

As an example, I was reading about 10% lower in the TX than what my charger was telling me. I have MVOLT_PER_AMP set to 40, so I lowered it by 10% to 36 so that it would calculate a higher usage of current per mV. I saved the file and then uploaded the project into the Arduino again and I was within 1% of the charger reading. I'm sure that's within the tolerances of my measuring equipment and close enough that I won't overdischarge my pack if I fly it to 25% left.

Here is my first ugly setup. The next one I build will have custom wire lengths for model I'm building it on and I'll heat shrink the components to avoid shorting things.



More information:
https://www.arduino.cc
https://github.com/openXsensor/openX..._Documentation
http://henrysbench.capnfatz.com/henr...nsor-tutorial/
Attached Thumbnails
Click image for larger version

Name:	oXs Current Wiring.jpg
Views:	5292
Size:	62.2 KB
ID:	671562   Click image for larger version

Name:	Arduino type.jpg
Views:	2262
Size:	71.2 KB
ID:	671563  
__________________
P Max v2, G570, S516, P380, XK K110, Open-TX
JWeber is online now        Reply With Quote Quick reply to this message
Sponsored Links
Advertisement
 
Old 09-15-2016, 01:42 PM   #2 (permalink)
Registered Users
 
Posts: 5,921
 
My HF Map location
Join Date: Jul 2006
Default

That is wicked cool! Thanks for taking the time to lay it out for us dummies who may want to try making one.
__________________
Chris Boultinghouse
JustPlaneChris is offline        Reply With Quote Quick reply to this message
Old 09-15-2016, 07:14 PM   #3 (permalink)
 

Join Date: Jan 2016
Default

Great write-up. You can also use an acs712 sensor in 5, 20, and 30 amps. Get them on ebay for 2 bucks.
Raleighcopter is offline        Reply With Quote Quick reply to this message
Old 09-15-2016, 08:30 PM   #4 (permalink)
Registered Users
 
Posts: 3,090
Thread Starter Thread Starter
 

Join Date: Mar 2012
Default

Thanks guys.

For that 712 sensor, the link to Henry's Bench has info on that one as well. It's a link at the bottom of the article.

Also, Chris, are you still flying OpenTX? I thought you wen to the dark side.
__________________
P Max v2, G570, S516, P380, XK K110, Open-TX
JWeber is online now        Reply With Quote Quick reply to this message
Old 09-16-2016, 11:38 AM   #5 (permalink)
Registered Users
 
Posts: 2,474
 
My HF Map location
Join Date: Feb 2013
Default

I was going to ask that same question Chris. I was there when you won that "other" radio. LOL. Don't get me wrong, it's good to see your posts.
__________________
George - Goblin700(iKon2), Trex550e(iKon), Oxy3(microiKon), Taranis
gstoneberg is offline        Reply With Quote Quick reply to this message
Old 09-17-2016, 10:22 PM   #6 (permalink)
Registered Users
 
Posts: 5,921
 
My HF Map location
Join Date: Jul 2006
Default

Oh yes, I still have my Taranis! I use it for DLG and multicopters. I do currently fly all my helis with the "other" radio, but if I end up getting a Protos 380 I'll likely give the Brain2 a try with the Taranis and one of the new XSR receivers.
__________________
Chris Boultinghouse
JustPlaneChris is offline        Reply With Quote Quick reply to this message
Old 09-19-2016, 03:36 PM   #7 (permalink)
Registered Users
 
Posts: 4,709
 

Join Date: Jan 2009
Default

thanks for doing this. Last night i weighed my frsky 40a and my 150a current sensor to see which one i wanted to put on my protos 380. I'm going to hopefully wedge the 150 in there. Both the packages are a pain.

Now i'll order one of these current sensors, i think have a couple of arduinos laying around.
__________________
XK K110 - BLheli
TX: Fr-Sky X9 Lite
P.I.Engineer is offline        Reply With Quote Quick reply to this message
Old 09-19-2016, 03:43 PM   #8 (permalink)
Registered Users
 
Posts: 3,090
Thread Starter Thread Starter
 

Join Date: Mar 2012
Default

I actually didn't weigh mine. I should.

My issue with the 40A isn't the physical size, but it's really only applicable for my Oxy from an amperage size. And as you know the 150A is a monster and overkill on the P380.

For my next one, I'm going to try and bend the tabs on the current sensor backwards, for XT60 mounting, or just cut the pins shorter and solder them directly in line with the positive wire and then skip the extra connection points. That would make it more difficult to remove however. Decisions, decisions.
__________________
P Max v2, G570, S516, P380, XK K110, Open-TX
JWeber is online now        Reply With Quote Quick reply to this message
Old 09-19-2016, 05:56 PM   #9 (permalink)
Registered Users
 
Posts: 4,709
 

Join Date: Jan 2009
Default

yeah, i know 150 is overkill, and the 40a might clip the data.

i repackaged my 40 awhile ago, to make it a little smaller.
https://www.helifreak.com/showthread.php?t=656049

for your current sensor, i was thinking to solder the leads in line with the signal wires, and clip off the bends. Make it a small package.
__________________
XK K110 - BLheli
TX: Fr-Sky X9 Lite
P.I.Engineer is offline        Reply With Quote Quick reply to this message
Old 09-22-2016, 11:49 PM   #10 (permalink)
Registered Users
 
Posts: 142
 

Join Date: Jan 2014
Default Arduino current sensor - How To

Great write-up JWeber! This is just what was needed.

I got my acs758's in the post yesterday. So now I can finally try this too.


Sent from my iPhone using Tapatalk
__________________
Gaui X3 - KST cyclics, MKS tail, YEP esc, Align motor, 6s Gens ace
Goblin 570 - Mks, Kde motor, 12s Gens ace
...and some planks too!
Trebb is online now        Reply With Quote Quick reply to this message
Old 09-25-2016, 03:10 PM   #11 (permalink)
Registered Users
 
Posts: 142
 

Join Date: Jan 2014
Default Arduino current sensor - How To

Here's first attempt with the acs758.



Same as JWebber's with a 0.1uf capacitor from vcc to ground. It is the 150A bidirectional version so Vout gives 13.3mV for every 1 Amp so it might not be very accurate but should give a good idea. The dean plugs obviously won't handle 150A but this version I will put on my X3. I will make another with EC5 connectors for my G570.

Initial test show everything seems to be working fine.

This is a neat little chip! These things are supposed to handle over 200A the amp rating is just its measuring range. With the arduino mini pro, wires and connectors I'm still expecting this to come well under 20 grams.

Any reason why frsky and others are not using these for their high amp sensors?


Sent from my iPhone using Tapatalk
__________________
Gaui X3 - KST cyclics, MKS tail, YEP esc, Align motor, 6s Gens ace
Goblin 570 - Mks, Kde motor, 12s Gens ace
...and some planks too!
Trebb is online now        Reply With Quote Quick reply to this message
Old 09-26-2016, 08:43 AM   #12 (permalink)
Registered Users
 
Posts: 3,090
Thread Starter Thread Starter
 

Join Date: Mar 2012
Default

Quote:
Originally Posted by Trebb View Post
Any reason why frsky and others are not using these for their high amp sensors?
No idea, but I was part of the Horus beta program and at the end, FrSky asked me what other products I'd like to see from them.

I asked for a current sensor in the 100A range that I could solder in line myself. That should cover all the way up to most 500 size helis and be much smaller than the 150A sensor that we currently have. I also asked for a telemetry device that could read the telemetry output from either Castle or HobbyWing and send it to the S.Port on the RX.

I think that we can do it for the latter ourselves if we can just get the format for the ESC output. I'm more interested in the HobbyWings. The V3's have the needed info in the user manual, but the v4's do not. I've reached out to HobbyWing about getting it and they said that they are thinking internally about it. So, we'll see. I have a HW 50A v3 extra, so I'm going to play with it. I'm also using this project as a way to help teach my son about programming.
__________________
P Max v2, G570, S516, P380, XK K110, Open-TX
JWeber is online now        Reply With Quote Quick reply to this message
Old 09-28-2016, 03:12 PM   #13 (permalink)
Registered Users
 
Posts: 142
 

Join Date: Jan 2014
Default Arduino current sensor - How To

Yeah that would save a lot of hassle getting the info direct from the esc...

I built an ec5 version now. This weighs 40g with arduino and cables:





Do you have any suggestions on how to calibrate the current sensors? I don't have a multimeter that goes very high.

Is it best to use a power resistor and measure the voltage and calculate the current (using V=IR) and compare to s.port value?


Sent from my iPhone using Tapatalk
__________________
Gaui X3 - KST cyclics, MKS tail, YEP esc, Align motor, 6s Gens ace
Goblin 570 - Mks, Kde motor, 12s Gens ace
...and some planks too!
Trebb is online now        Reply With Quote Quick reply to this message
Old 09-28-2016, 03:26 PM   #14 (permalink)
Registered Users
 
Posts: 3,090
Thread Starter Thread Starter
 

Join Date: Mar 2012
Default

Quote:
Originally Posted by Trebb View Post
Do you have any suggestions on how to calibrate the current sensors? I don't have a multimeter that goes very high.
I only used the multimeter for testing the voltage at 0 current.

For the current usage, I started with the data sheet values on the particular 758 I used, then I charged a battery fully. Went out and flew until the timer went off, then let the battery settle for a bit (15 minutes or so) and charged it back up on the exact same charger. After that I looked at what was reported on the Taranis and compared it to what the charger put back in and adjusted my mV per Amp value until I got it as close as I could. I don't fly till only 20% left usually I land at about 30% as a safety net.
__________________
P Max v2, G570, S516, P380, XK K110, Open-TX
JWeber is online now        Reply With Quote Quick reply to this message
Old 09-28-2016, 03:30 PM   #15 (permalink)
 

Join Date: Jan 2016
Default

Put a 1 ohm resistor across a 2s battery. Measure the voltage across the 1 ohm resistor and it should be the same as the current in amps.
Raleighcopter is offline        Reply With Quote Quick reply to this message
Old 09-29-2016, 10:22 AM   #16 (permalink)
Registered Users
 
Posts: 3,090
Thread Starter Thread Starter
 

Join Date: Mar 2012
Default

So I asked the question the the Brain forum about splitting the RPM output from the ESC so that I can use it as both an input for the Brain governor and the Arduino. They said it shouldn't be a problem. I'm going to test tonight if I have time.

https://www.helifreak.com/showthread...55#post7139155

Ideally though if I can get the format of the HW v4 ESC telemetry output and be able to read that, I can get rid of all other inputs to the Arduino and just use that for everything I need and more (except for the 60A ESC which has no internal current senor)
__________________
P Max v2, G570, S516, P380, XK K110, Open-TX
JWeber is online now        Reply With Quote Quick reply to this message
Old 12-23-2016, 09:05 PM   #17 (permalink)
Registered Users
 
Posts: 5,863
 
My HF Map location
Join Date: Sep 2010
Default

Well, wire mine up finally to test. Wire into a foamy plank for testing. Straight between Batt and ESC. Sensors are discovered in TX. But Nothing when running motor. BUT, Doing Ailerons back and forth, the current jumps, so does temp and Alt on the TX. I don't even have Temp or Alt. But I guess forgot to comment those lines? But why I get readings servo movement, but nothing on motor.
__________________
Dan Pesonen
FBL, Don't think about it, DO IT.
mCX2, nCPX, mCP X, Blade 400, MSH PRTOS, T-700N
"Tri-Flow"
I put that S*** on everything!"
banditpowdercoat is offline        Reply With Quote Quick reply to this message
Old 12-26-2016, 06:02 AM   #18 (permalink)
Registered Users
 
Posts: 3,090
Thread Starter Thread Starter
 

Join Date: Mar 2012
Default

The only thing I can think of is a wiring issue of some sort. Dbl check everything.

Since the correct telemetry sensors show up in discovery, odds are your programming is correct.
__________________
P Max v2, G570, S516, P380, XK K110, Open-TX
JWeber is online now        Reply With Quote Quick reply to this message
Old 12-29-2016, 09:38 PM   #19 (permalink)
Registered Users
 

Join Date: Mar 2014
Default

I've got all the parts coming to make one hopefully they will be here in a week or so as I ordered them a few weeks ago from China. I may have a question or two but your write up is pretty good so maybe not.
__________________
KDS Agile 5.5, Ikon, KST, KDE motor/Gaui X4ii, BK servos, Brain / Gaui X3, Ikon, KST, Scorpion 1580Kv
Frsky Taranis plus
PhoenixRC upgraded to wireless
Larryu is offline        Reply With Quote Quick reply to this message
Old 01-27-2017, 09:50 PM   #20 (permalink)
Registered Users
 
Posts: 5,863
 
My HF Map location
Join Date: Sep 2010
Default

Looks like I might have a faulty ACS712 seems like +V out. approx 4v to ground in. Audrino is getting 5v

from Aurduino to sensor
+ to Gnd 4.13v
+ to Sig .304v
Sig to Gnd 0v

Nothing changes when motor power is varied
__________________
Dan Pesonen
FBL, Don't think about it, DO IT.
mCX2, nCPX, mCP X, Blade 400, MSH PRTOS, T-700N
"Tri-Flow"
I put that S*** on everything!"
banditpowdercoat is offline        Reply With Quote Quick reply to this message
Reply




Quick Reply
Message:
Options

Register Now

In order to be able to post messages on the HeliFreak forums, you must first register.
Please enter your desired user name, your REAL and WORKING email address and other required details in the form below.
User Name:
Password
Please enter a password for your user account. Note that passwords are case-sensitive.
Password:
Confirm Password:
Email Address
Please enter a valid email address for yourself. Use a real email address or you will not be granted access to the site. Thank you.
Email Address:
Location
Where do you live? ie: Country, State, City or General Geographic Location please.
Name and Lastname
Enter name and last name here. (This information is not shown to the general public. Optional)
Helicopter #1
Enter Helicopter #1 type and equipment.
Helicopter #2
Enter Helicopter #2 type and equipment.
Helicopter #3
Enter Helicopter #3 type and equipment.
Helicopter #4
Enter Helicopter #4 type and equipment.

Log-in


Thread Tools
Display Modes

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




Copyright © Website Acquisitions Inc. All rights reserved.
vBulletin Security provided by vBSecurity v2.2.2 (Pro) - vBulletin Mods & Addons Copyright © 2019 DragonByte Technologies Ltd.

SEO by vBSEO 3.6.1