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?
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.
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.
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.
(vSensor) --- [R1] --- (GPIO) --- [C1] --- GND