B4R Question ESP8266 Wemos Mini and MCP4251 SPI ?

Discussion in 'B4R Questions' started by KiloBravo, Feb 22, 2019.

  1. KiloBravo

    KiloBravo Member

    Hi, I am trying to use the Library in this post ...

    I cannot figure out how he defined the Chip Select Pin.
    In this line of code he has "10" for the csPin ?

    mcp.Initialize(10, mcp.POT_0, mcp.RES8BIT, mcp.POTENTIOMETER)

    Initialize(csPin As Byte, pot As B4R::pot, res As B4R::Resolution, config As B4R::WiperConfiguration)
    As B4R::void

    The Standard Pins for Wemos D1 Mini are D8-SS, D7-MOSI, D6-MISO, and D5-SCK.
    The defines above are from the Wemos D1 mini PCB. (I am sure everyone knows this !)

    I looked thru the code and h files, but I am not sure where pin defines get pulled from or defined.

    Any help would be appreciated. I am new to this but I did get a DHT11 working with I2C and a few of the Wifi examples as well. Thanks !
  2. thetahsk

    thetahsk Active Member Licensed User

    The default SS/CS (Slave Select/Chip Select) pin for your Wemos D1 is GPIO15 or D8.
  3. KiloBravo

    KiloBravo Member

    So I changed this mcp.Initialize(10, mcp.POT_0, mcp.RES8BIT, mcp.POTENTIOMETER) line to be

    mcp.Initialize(dp.D8, mcp.POT_0, mcp.RES8BIT, mcp.POTENTIOMETER)

    It still did not work.

    So after spending time pouring thru header and driver files, I realized I had the wires crossed ! LOL !!!
    I had reversed MISO and MOSI from the MCP4251 to the ESP8266 board. Doh !!!

    But to answer my question "10" is defined in Arduino\Libraries\WiFi\src\utility spi_drv.cpp

    #define SLAVESELECT 10 // ss

    Live and Learn !!!
  4. kolbe

    kolbe Active Member Licensed User

    The first value is the CS/SS pin. In the example it is 10. The other pins are taken from the defines depending on the board selected. This is all done in the original library that the one I posted wraps. Look at the constructor of the original cpp. The defines are pulled in by the Arduino IDE and not by the libraries. Search for "pins_arduino.h" in your arduino variants folder. Sorry don't have a Wemos D1 to test.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice