#### robotDR

Joined Mar 17, 2020
60
I am using pin 3 from the data sheet. 47ohm resistors. VDD=3.3v

If I pull pin 3 down to gnd with 47ohm resistor, I get ~320.
If I pull pin 3 up to VDD with 47ohm, I get ~810
If I put a divider from VDD to gnd, pin 3 is output of divider (47ohm high and low dividers) I get 512 which I expect.

But why wont pulling down to gnd read 0, or up to VDD read 1023?

Code:
Code:
#include <Wire.h>

#define pot  2     // LED1 for Configure command communication indication
#define batt_fb  3     // LED2 for READ command communication indication

#define MySerial Serial

// Constants
byte bright1 = 0x3C;
byte bright2 = 0x78;
byte bright3 = 0xFF;

// Variables
int battV = 0;
int battV1 = 0;
int battV2 = 0;
int battV3 = 0;
int battVavg = 0;

void setup() {

Wire.begin();
MySerial.begin(9600);
MySerial.println("IS323FL3238 Driver");
MySerial.println(bright1);

analogReference(VDD);  //Sets up ADC reference to VDD

pinMode(batt_fb,INPUT);

// ***Initialize I2C communications:
int nDevices;                             // number of devices on circuit

MySerial.println("IS323FL3238 Control");

nDevices = 0;
{
error = Wire.endTransmission();

if (error == 0)
{
MySerial.print("I2C device found at address 0x");
MySerial.print("0");
MySerial.println("  !");

nDevices++;
}
else if (error == 4)
{
MySerial.print("0");
}
}
if (nDevices == 0)
MySerial.println("No I2C devices found\n");
else
MySerial.println("done\n");

delay(500);

}

void loop() {

delay(10);
delay(10);
delay(10);
battVavg = battV1 + battV2 + battV3;
delay(10);
battV = battVavg/3;
MySerial.println("battery voltage (V):");
MySerial.println(battV);

#### Ian0

Joined Aug 7, 2020
6,293
What voltage is on the pin?

#### robotDR

Joined Mar 17, 2020
60
What voltage is on the pin?
I am sorry. I checked the pinout of the megatinycore from spencer and he changed the pins on me!
The voltage was what i expected. 3.3 high, 0 low, and 1.65 with equal divider.

weird thing was that i should have been using pin 4 from the data sheet for pin 2 on the core. however I was using pin 2 from the datasheet and calling pin 2 on the IDE. weird thing is that since my input was floating (calling 2 on IDE corrosponds to pin 4 from datasheet) my values were changing when i went high or low. Just not correct. What is up with that? Shouldn't it had just remained floating while I manipulated another pin?

#### WBahn

Joined Mar 31, 2012
27,392
I am sorry. I checked the pinout of the megatinycore from spencer and he changed the pins on me!
The voltage was what i expected. 3.3 high, 0 low, and 1.65 with equal divider.

weird thing was that i should have been using pin 4 from the data sheet for pin 2 on the core. however I was using pin 2 from the datasheet and calling pin 2 on the IDE. weird thing is that since my input was floating (calling 2 on IDE corrosponds to pin 4 from datasheet) my values were changing when i went high or low. Just not correct. What is up with that? Shouldn't it had just remained floating while I manipulated another pin?
Not following. Are you saying that the input pin was floating when you were trying to take the measurements? If so, pretty much all bets are off as far as what you will get. Since the results are going to be largely determined by the leakage currents on the pad, and since leakage currents tend to be sensitive to lots of things, including the state of other pads, it's not surprising that your values would change. What is perplexing is why you got a solid result when you put the voltage divider output on the other pin.

#### robotDR

Joined Mar 17, 2020
60
Yeah, I was using pin 2 on the datasheet, and calling pin 2 on the IDE. However the core maps 'pin 2' to pin 4 on the chip package.

So it was floating while I was using pin 2. however I got solid 512 readings when I had an equal divider on pin 2. I got solid ~800 when I pulled pin 2 high, and solid ~300 when pin2 pulled to ground. all the while, pin 4 is floating and that is what the IDE core calls 'pin 2'. now that I am actually putting the signals (divider, vdd, gnd, etc) to pin 4 on the package, i am getting perfect results that match my dmm. I change the divider and I get perfect results.

Weird that the floating pin is locked down when other pins are used.

#### Papabravo

Joined Feb 24, 2006
19,284
The other thing to remember is that an ADC has a defined input impedance. When you use a resistor to pull that input up or down or somewhere in the middle, those resistors are acting in combination with the impedance of the ADC input and may not produce the results you expect. You would be better off using a unity gain buffer on the on the ADC inputs with resistor networks on the input side of the unity gain buffer.