Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By Sunspot
#21125 Some progress
knightrider is working on PCF8574 8 IO expander (I only tested with 1 LED)

-----------------------------------------------------------------------
/*--------------------------------------------------------------
Program: two_wire_knight_rider

Description: Uses a PCF8574 IO Expander IC on the Arduino
TWI bus to interface 8 LEDs. A "knight
rider" display is shown on the LEDs.

Date: 25 April 2012

Author: W.A. Smith, http://startingelectronics.org
--------------------------------------------------------------*/
#include <Wire.h>

// address of PCF8574 IC on TWI bus
//#define IO_ADDR (0x38 >> 1)
#define IO_ADDR (0x38)

void setup() {
Wire.begin(0, 2); // initialize the I2C/TWI interface
Wire.setClock(50000); //this does nothing !!!! - it runs at 100000
Serial.begin(9600);
}
void loop() {
Serial.println("looping");
static unsigned char data = 0x01; // data to display on LEDs
static unsigned char direc = 1; // direction of knight rider display

// send the data to the LEDs
Wire.beginTransmission(IO_ADDR);
Wire.write(~data);
Wire.endTransmission();
delay(70); // speed of display

// shift the on LED in the specified direction
if (direc) {
data <<= 1;
}
else {
data >>= 1;
}
// see if a direction change is needed
if (data == 0x80) {
direc = 0;
}
if (data == 0x01) {
direc = 1;
}
}

------------------------------------------------------------------------------------------------

note the
//#define IO_ADDR (0x38 >> 1)
#define IO_ADDR (0x38)
0x38 is as found by the scanner program seems there is no need to remove a bit off the end

So my esp01 is working fine on SDA 2 and SCL 0 for both the scanner and the knightrider PCF8574

The Adafruit MCP23017 is more complex and I see that the cpp file contains
#include <avr/pgmspace.h>

So I think that means a special compile for the esp8266 is needed?
But I guess it ran in the Sketch Buffet?

I have yet to learn how to compile my own IDE - perhaps that was done for the Buffet?
User avatar
By martinayotte
#21131
The Adafruit MCP23017 is more complex and I see that the cpp file contains
#include <avr/pgmspace.h>

So I think that means a special compile for the esp8266 is needed?
But I guess it ran in the Sketch Buffet?


The include above is in a #ifdef __AVR__, so it should not be included at all, if it is, it should pick the on for ESP :
hardware/esp8266com/esp8266/cores/esp8266/pgmspace.h

For the Sketch_Buffet, I suggest to strip down to the only things you need.

For IDE, I'm still using 1.6.1, so nothing special needed for the Sketch_Buffet.
User avatar
By Sunspot
#21204 First - in Sketch Buffet
I had put the Adafruit_MCP23017.h in the .ino folder since I thought it was a modified version.
When all includes are in the main library it compiles and runs a bit even without the eeprom - I see time etc.
THANKS!

However the MCP23017 is dead even though I can see it's address in the scan

So I went fully basic with :-
-----------------------------
#include "Wire.h"
void setup()
{
Serial.begin(9600);
Wire.begin(); // wake up I2C bus
// set I/O pins to outputs
Wire.beginTransmission(0x20);
Wire.write(0x00); // IODIRA register
Wire.write(0x00); // set all of port A to outputs
Wire.endTransmission();

void loop()
{
Serial.println("looping");

Wire.beginTransmission(0x20);
Wire.write(0x12); // GPIOA
Wire.write(0xFF); // port A
Wire.endTransmission();
delay(100);

Wire.beginTransmission(0x20);
Wire.write(0x12); // GPIOA
Wire.write(0x00); // port A
Wire.endTransmission();
delay(100);
}
--------------------------------------

Still nothing on IO :(
- surely wired OK if I can scan the address??
User avatar
By martinayotte
#21217 BTW, according to your code shown above, you'are talking directly to the MCP, so, there are no needs for the Adafruit library.

Quick question : do you have pullup resistors on both SDA and SCL lines ?