B4R Question ESP8266 Wemos Mini and MCP4251 SPI ?

KiloBravo

Active Member
Licensed User
Hi, I am trying to use the Library in this post ...
https://www.b4x.com/android/forum/threads/mcp4xxx.101935/

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 !
 

KiloBravo

Active Member
Licensed User
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 !!!
 
Upvote 0

kolbe

Active Member
Licensed User
Longtime 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.
 
Upvote 0
Top