Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By johntech2014
#28739 [/quote]
You should look at ESP8266WebServer example.
You can then use some URL for buttons like "/led_on?led_no=5", then in an handler "handleLEDOn()" function, you will received the argument "led_no" with value "5" and doing the call to mcp.digitalWrite(5, HIGH) accordingly. Same thing with "handleLEDOff()" function.[/quote]

I am looking at this now! I didn't READ the information in the heading of the sketch to see what it was actually doing....DAH :oops: !!!Still learning . Thanks for point that out !!! Now time to experiment....

John
User avatar
By Samighi11
#28746
Samighi11 wrote:
johntech2014 wrote:

A friend of mine has let me borrow a Sparkfun ESP8266 WiFi shield that looks like it has about 8 I/O pins on it which I haven't tried yet. I just got the Adafruit sketch to run on the 01 with the help from martinayotte. I only use pins 0 and 2. I have another sketch from another site that is a little more involved that I can turn on multiple LED's through the 23017 at once but still no web interface. I would be interested to see what you have done ! Thank you!

John[/color]


i will get it running tonight and upload code and pictures.



I have uploaded my code that I just tested to https://github.com/samighi/ESP8266-sample-23017-support

Please note that it uses GPIO4 and 5 to avoid any issues with GPIO 0/2/15. I assume you can flash the device with Arduino IDE 1.6.5 (see github readme). The only issue I have is after initial flash, I need to restart the board once or twice. I use the FTDI power to power the chip. Ensuring i used 3.3v FTDI.

the code is copied from somewhere else (probably the example set) and I added /ledtest to it. you can use /ledtest?A=anyvalue to set the binary value of the 8 LEDs.

Note that 23017 requires one extra byte to be sent so it know which A or B register to work with. PCF8574 doesn't.

key points in the code are

Code: Select all// 23017 setup
 Wire.begin(5, 4); // note this could be swapped on some boards

and

Code: Select allvoid ledtest( void ) {
char dataA = server.arg ( 0).toInt() ;
char dataB =  server.arg ( 1).toInt() ;
Wire.beginTransmission(mcp_address);
  Wire.write(GPIOA);
  Wire.write(dataA);         
  Wire.endTransmission();         

  Wire.beginTransmission(mcp_address);
  Wire.write(GPIOB);
  Wire.write(dataB);         
  Wire.endTransmission();         


this is made for my kids Lego City to light up 10s of lights. I personally did 10 LEDs per 23017 just due to cabling issues. I could obviously run 16 LEDs per setup.

The only trick to 23017 setup is simply holding the RESET high. Also, ensure you set A0,A1,A2 properly. It defines the address.

Lastly before I didn't any LED work at all, I ran the Arduino standard I2C scanner code first. That way I could at least know the 23017 was working. Once done, I wrote this code.

Good luck and keep me posted.
User avatar
By johntech2014
#28754
Samighi11 wrote:
IMG_0370.JPG
pictures


WOW !! The code for setting up the 23017, was the other code I had mentioned I found on another site. You just figure out what LED's you want on and punch in that corresponding number. All I had to do was change the Wire.begin(0,2) for the 8266-01 and it works great. I still would like to know how all the code above the " //23017 setup " line works.

Thanks for sharing!!

John