Analog Pins
-
- Posts: 36
- Joined: Wed Sep 27, 2017 1:42 pm
- Location: Louisville Ky
Analog Pins
What is the best way to increase the number of analog pins on an esp8266. I need 4 more Analog pins for sensors. Thank You in advance
Re: Analog Pins
Sounds like you're after an I2C ADC. eg. ADS1115.
https://www.adafruit.com/product/1085
https://www.aliexpress.com/item/I2C-ADS ... 56200.html
$2-15 USD
A few people have written drivers:
* https://bitbucket.org/thesheep/micropython-ads1015/src
* https://github.com/adafruit/micropython ... it-ads1015
* https://github.com/AnthonyKNorman/Micropython_ADS1115
* https://github.com/robert-hh/ads1x15
* https://github.com/coylen/BatteryMonitor
https://www.adafruit.com/product/1085
https://www.aliexpress.com/item/I2C-ADS ... 56200.html
$2-15 USD
A few people have written drivers:
* https://bitbucket.org/thesheep/micropython-ads1015/src
* https://github.com/adafruit/micropython ... it-ads1015
* https://github.com/AnthonyKNorman/Micropython_ADS1115
* https://github.com/robert-hh/ads1x15
* https://github.com/coylen/BatteryMonitor
-
- Posts: 36
- Joined: Wed Sep 27, 2017 1:42 pm
- Location: Louisville Ky
Re: Analog Pins
Can multiplexer like the 74hc4051 be used?
Re: Analog Pins
And if you are using a Wemos D1 Mini, by total coincidence I just started selling my homebrew analog shield: https://www.tindie.com/products/deshipu ... r-d1-mini/
-
- Posts: 36
- Joined: Wed Sep 27, 2017 1:42 pm
- Location: Louisville Ky
Re: Analog Pins
I have a D1 not the mini. But i might be getting one to try out. Your board looks solid.
Re: Analog Pins
Judging by this page, yes you can use a 74hc4051 multiplexer:
https://internetofhomethings.com/homethings/?p=530
https://internetofhomethings.com/homethings/?p=530
-
- Posts: 36
- Joined: Wed Sep 27, 2017 1:42 pm
- Location: Louisville Ky
Re: Analog Pins
Thats an Arduino hook up. I wonder if someone has hook it up with Micropython???
Re: Analog Pins
I am using the MCP3008, which works perfectly for up to 8 analog inputs using the SPI pins (~2$). You could also use the MCP3004, I think, but it only has 4 analog inputs. I wrote a simple driver (mcp3008.py):
The layout of the MCP3008 can be found on the internet (e. g. here).
You will have to make the follwing connections (MCP3004/8 <-> ESP8266):
You can change the pins in the constructor if you like (e. g. CS pin can be any pin you like). If you need more than 8 extra ADC inputs, you can probably (not tested) simply connect multiple MCP3008 (on the same three SPI pins), but use a different CS pin for each MCP.
Code: Select all
from machine import Pin
class MCP3008:
def __init__(self, clk=14, mosi=13, miso=12, cs=15):
self._clk = Pin(clk, Pin.OUT)
self._mosi = Pin(mosi, Pin.OUT)
self._miso = Pin(miso, Pin.IN)
self._cs = Pin(cs, Pin.OUT)
def read(self, channel):
# """ Reads an analog value from the given channel (0-7) and returns it. """
if channel not in range(0, 8):
raise ValueError("channel must be 0-7")
self._cs(1) # negative edge
self._cs(0)
self._clk(0)
send_cmd = channel
send_cmd |= 0b00011000 # 0x18 (start bit + single/ended)
# send bits (only 5 bits considered)
for i in range(5):
self._mosi(bool(send_cmd & 0x10)) # check bit on index 4
self._clk(1) # negative edge
self._clk(0)
send_cmd <<= 1
# receive value from MCP
v = 0
for i in range(11):
self._clk(1) # negative edge
self._clk(0)
v <<= 1
if self._miso():
v |= 0x01
return v
You will have to make the follwing connections (MCP3004/8 <-> ESP8266):
- V_dd <-> 3.3V
- V_ref <-> 3.3V
- AGND <-> GND
- CLK <-> SCK (14)
- D_out <-> MISO (12)
- D_in <-> MOSI (13)
- CS <-> 15
- DGND <-> GND
Code: Select all
from mcp3008 import MCP3008
mcp = MCP3008()
print("Value on CH0:", mcp.read(0))
-
- Posts: 36
- Joined: Wed Sep 27, 2017 1:42 pm
- Location: Louisville Ky
Re: Analog Pins
Thank You for all the info. That helps out a-lot. Great Forum!!!! Thanks again
-
- Posts: 36
- Joined: Wed Sep 27, 2017 1:42 pm
- Location: Louisville Ky
Re: Analog Pins
Now that work with the MCP3008. Thank You