0

I want to read out data from a load cell, for this I seem to need 2 analog input pins, the Wemos doesn't have this. In the Arduino I was also able to use the digital pint with PWM, there are also Wemos pins who have that. Is it possible to use them to read the data from the load cell?

1
  • 1
    You need to clarify what are you talking about. How did you manage to use digital pins in Arduino Uno to read analog data? And what does PWM have to do with it? Commented Apr 30, 2019 at 16:41

3 Answers 3

1

PWM is quasi-analog output, and they have no symmetric analog read function.

The ESP8266 that is the heart of the Wemos D1 Mini has only 1 analog input.

If you need to read 2 analog signals, you can use an analog switch/multiplexer to read one value, and then the other value in quick succession. Or you can purchase an external ADC with multiple inputs -- these often communicate with a host by SPI or I2C connection, which the Wemos supports.

1

There is one way you could measure analogue voltages using a PWM output: Use it as a DAC to build your own Successive Approximation ADC:

  • The PWM is filtered through a low-pass filter to create an analogue voltage
  • That is compared to an incoming voltage using a comparator
  • The output of the comparator is recorded for different reference voltages using a "divide and conquer" method.

You can read more about how Successive Approximation works here.

However, doing that would be overly complex and needlessly expensive. It is far better to just add an ADC chip using I2C or SPI. It's cheaper, easier, and the results will be far superior.

But as a learning exercise to discover how ADCs work, it could be kind of fun.

1

You can use a capacitor and resistor to build a simple circuit to turn a voltage into a time duration, then precisely measure the timing to get a voltage. This isn't as fast as a direct read, but it can be more precise in some cases, and the sampling might be fast enough for your needs. The cost is great compared with external or home-brew ADCs. I once used this method to build an ohmmeter with an ESP-01, which had a much greater range than a naive voltage divider would have provided.

You feed your voltage through a resistor into a capacitor, and have a digital input pin watching the resistor-cap voltage. You'll need to be generous with the timing because you want the cap to fully drain, and you can't tell from the MCU when that's completed, but a few preliminary DMM measurements will give you that info.

To measure voltage, you switch the GPIO from OUTPUT/low to to INPUT-PULLUP and wait for it to go HIGH. By measuring the time it takes before the pin goes high, you can calculate the voltage expected to fill the cap to the trigger threshold in that amount of time. You will need to do some manual measurements to calibrate it up-front, as different pins have different pull-up values and slightly different schmitt trigger voltage thresholds. Once setup, it can be repeatable to about +/- 5%, maybe more with slower sampling.

ascii schematic: (vSensor) --- [R1] --- (GPIO) --- [C1] --- GND

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.