arduinowifipinsarduino-uno-wifi

Read analog input from Arduino Uno Wifi Wire/TWI/I2C pins (A4 & A5)


I recently got an Arduino Uno Wifi (flashed it with the Wifilink firmware to support UDP) and I have created a simple sketch to read analog values from a flex sensor.

I am using the code below (copy paste from the official website)

const int FLEX_PIN = A4; // Pin connected to voltage divider output

// Measure the voltage at 5V and the actual resistance of your
// 47k resistor, and enter them below:
const float VCC = 4.98; // Measured voltage of Ardunio 5V line
const float R_DIV = 47500.0; // Measured resistance of 3.3k resistor

// Upload the code, then try to adjust these values to more
// accurately calculate bend degree.
const float STRAIGHT_RESISTANCE = 37300.0; // resistance when straight
const float BEND_RESISTANCE = 90000.0; // resistance at 90 deg

void setup() {
  Serial.begin(9600);
  pinMode(FLEX_PIN, INPUT);
}

void loop() {
  // Read the ADC, and calculate voltage and resistance from it
  int flexADC = analogRead(FLEX_PIN);
  float flexV = flexADC * VCC / 1023.0;
  float flexR = R_DIV * (VCC / flexV - 1.0);
  Serial.println("Resistance: " + String(flexR) + " ohms");
  // Use the calculated resistance to estimate the sensor's
  // bend angle:
  float angle = map(flexR, STRAIGHT_RESISTANCE, BEND_RESISTANCE, 0, 90.0);
  Serial.println("Bend: " + String(angle) + " degrees");
  Serial.println();
  delay(500);
}

The code does not work in the Arduino Uno Wifi: it does not show any change in the bend degrees. However, it works in another Arduino Uno I have for testing.

Also I made a test and I found out that pins 4 and 5 in Arduino Uno Wifi produce current for some reason even with an empty script, capable of lighting a LED (while pins 0,1,2,3 do not light it up).

The same applies for the values for the sensors. For example if I put the flex sensor in analog pin 0 then the values change when I bend it (e.g. 362 read not bend and 600 bend, which is fine).

On the other hand when I put the pin of the sensor in A4 or A5 there is a change from 1023 (starting value) to 982 and it won't change no matter if I bend the sensor.

I was recently informed that those pins are Wire/TWI/I2C pins. Is there any way i can read analog input from those pins?

Also posted in Arduino forums link


Solution

  • 'WiFi' is connected to those pins.

    pins A4 and A5 are Wire/TWI/I2C pins and there is the additional UART SC16IS750 connected to which the esp8266 is connected on Uno WiFi