# Boron GPIO provides less current than Electron's GPIO?

**URL:** <https://community.particle.io/t/boron-gpio-provides-less-current-than-electrons-gpio/46647>\
**Category:** Hardware\
**Tags:** boron\
**Created:** [December 30, 2018, 5:31pm UTC](https://community.particle.io/t/boron-gpio-provides-less-current-than-electrons-gpio/46647 "2018-12-30T17:31:03Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![blub](https://avatars.discourse-cdn.com/v4/letter/b/9d8465/32.png) [@blub](https://community.particle.io/u/blub)\
**Post date:** [June 22, 2019, 9:47pm UTC](https://community.particle.io/t/boron-gpio-provides-less-current-than-electrons-gpio/46647/13 "2019-06-22T21:47:35Z")

</div>

@Acrop, I actually had such spiky data already with the Electron, but not as many as with the Boron. After removing the outliers, I managed to get down to about 2 g scale reading precision.

In my case, the HX711ADC is creating many outliers which will bias an average value greatly. I can’t tell if this is due to the quality of its power supply or electrical noise in the amplifier or by bad shielded cables to the load cells. Anyway, I think it is pretty common to apply filters in digital signal processing, and I did this by using a median instead of just using an average. A median nicely gets rid of extreme values and therefore delivers pretty stable scale readings. I am actually surprised, that the HX711ADC library only provides an average and not a median function.

Therefore, I had to add myself a median function, as described in below code snippet. In this example, the median is calculated based on 100 instantaneous scale readings. Much less readings may also get already a stable result.

Below the wiring of the HX711 to the Boron (actually not really Boron, but the pins are the same) as well as a code snippet. I am using here the library HX711ADC (0.0.3).

I hope this helps.

 ![boron_HX711](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/4/f/4f249589bc9f54c000a3812442553aeeba58cea4.jpeg)

```auto
#include <HX711ADC.h> //scale amplifier
#include <Arduino.h>
#include "math.h"

// HX711.DOUT	- pin #A1
// HX711.PD_SCK	- pin #A0
HX711ADC scale(A1, A0); // parameter "gain" is ommited; the default value 128 is used by the library
float scale_weight = 0;
  
int const num_scale_readings = 100; //number of instantaneous scale readings to calculate the median
float readings[num_scale_readings]; // create arry to hold readings

void setup() {

  scale.begin();

}
void loop() {

  scale.power_up();

  delay(100);

  scale.set_scale(22); //gain: this value is obtained by calibrating the scale with known weights
  scale.set_offset(100000); //offset: this value is obtained by calibrating the scale with known weights
  
  for (int i = 0; i < num_scale_readings; i++) {
    readings[i] = scale.get_units(1); // fill the array with instantaneous readings from the scale
  }
  
  delay(100);
  
  scale_weight = median(readings,num_scale_readings); //calculate median 
 
  Serial.println(scale_weight);
  
  scale.power_down();
  
  delay(10000);
}

//Following functions are based on "https://github.com/dndubins/QuickStats", by David Dubins  

float median(float samples[],int m) //calculate the median
{
  //First bubble sort the values: https://en.wikipedia.org/wiki/Bubble_sort
  float sorted[m]; //Define and initialize sorted array.
  float temp=0.0; //Temporary float for swapping elements
  
  for(int i=0;i<m;i++){
    sorted[i]=samples[i];
  }
  bubbleSort(sorted,m); // Sort the values
  
  if (bitRead(m,0)==1) { //If the last bit of a number is 1, it's odd. This is equivalent to "TRUE". Also use if m%2!=0.
    return sorted[m/2]; //If the number of data points is odd, return middle number.
  } else {    
    return (sorted[(m/2)-1]+sorted[m/2])/2; //If the number of data points is even, return avg of the middle two numbers.
  }
}

void bubbleSort(float A[],int len) {
  unsigned long newn;
  unsigned long n=len;
  float temp=0.0;
  do {
    newn=1;
    for(int p=1;p<len;p++){
      if(A[p-1]>A[p]){
        temp=A[p]; //swap places in array
        A[p]=A[p-1];
        A[p-1]=temp;
        newn=p;
      } //end if
    } //end for
    n=newn;
  } while(n>1);
}

```

---

_[View the full topic](https://community.particle.io/t/boron-gpio-provides-less-current-than-electrons-gpio/46647)._
