I2C communication : Picaxe 40x2(Master) with ESP8266(slave) unsuccesfull

klaasje

Member
Dear,

The past week i have been putting my head arround the following question: " Can i prepare I2C communication between the ESP8266 and Picaxe 40x2 "
I have succesfully got communication working when using the ESP8266 as a Master with the following code


ESP8266- MASTER CODE
Code:
#include <Wire.h>
int i = 0;
boolean message = true;

void setup()
{
  Wire.pins(4,5);
  Wire.begin();  
  Serial.begin(9600);
  Serial.println("\nI2C Scanner");
}


void loop()
{
  Wire.beginTransmission(14);
 Wire.write(1); // Adress to write to
  Wire.write(i); // data to write
 Wire.write(0); // Extra no clue why but it makes it work stable 
Wire.endTransmission();

Wire.beginTransmission(14);
Wire.write(2); // address to read from 
Wire.endTransmission();
Wire.requestFrom(14, 1); // request one byte from address 14
  while (Wire.available() > 0 )
  {
    byte c;
    c = Wire.read();
    Serial.print(c);
    message = true;
  }

  
  if (i >= 255)
  {
    i = 0;

  }
  i++ ;
delay(100); 
}
PICAXE 40x2 SLAVE CODE

Code:
hi2csetup i2cslave, 14

do
     get 2 , b2 
     put 1 , b2 
     pause 100

debug 

loop

However for my research i require the PICAXE to be master and the ESP8266 to be slave
I tried in several ways but until i was unsuccesfull in getting any comminication. I could not find any info on I2C communication with the PICAXE as master to any other chip but another PICAXE

I tried the following codes
PICAXE_MASTER
Code:
hi2csetup i2cmaster, %10000000, i2cfast, i2cbyte

do
	hi2cin [14],1,(b2)
	pause 100
	debug
	
loop
AND USED
Code:
hi2csetup i2cmaster, %10000000, i2cfast, i2cbyte

do
	hi2cout[14],1
	pause 100
	debug
	
loop
WITH ESP(slave) CODE
Code:
#include <Wire.h>
int i = 0;
boolean message = true;

void setup()
{
  Wire.pins(4,5);
  Wire.begin(14);
  Wire.onRequest(requestEvent); // register event
  Serial.begin(9600);
  Serial.println("\nI2C Scanner");
}


void loop()
{
  while (Wire.available() > 0 )
  {
    byte c;
    c = Wire.read();
    Serial.print(c);
    message = true;
  }

  
  if (i >= 255)
  {
    i = 0;

  }
  i++ ;
delay(100); 
}
void requestEvent() {
  Serial.println("EVENT"); 
  Wire.write(25); 
}
both unsuccesfull, are there any suggestions on this matter?, Any ideas on i2C communication with PICAXE as master to either ESP(ARDUINO BASED) or ATMEGA328p(ARDUINO BASED) would be very appreciated !

Kind Regards,
 

hippy

Technical Support
Staff member
I tried the following codes ... both unsuccesfull
It might be helpful to indicate how it was unsuccessful. I don't know the ESP8266 so have no idea if your code for it being an I2C Slave is correct or not.

In the PICAXE code it is probably best to use I2CSLOW rather than I2CFAST to start with. Rather than put the device address in square brackets, put it in the I2CSETUP ...

Code:
hi2csetup i2cmaster, [b]14[/b], [b]i2cslow[/b], i2cbyte
do
	hi2cin 1,(b2)
	pause 100
	debug
loop
Likewise in your write to ESP8266 code. And note that you are not writing any value to the ESP8266. You probably want something like ...

Code:
hi2csetup i2cmaster, [b]14[/b], [b]i2cslow[/b], i2cbyte
do
	hi2cout 1, (123)
	pause 100
loop
 

hippy

Technical Support
Staff member
As I said; I am not familiar with ESP8266, nor the programming language and libraries it uses, however, looking at documentation for the Wire library, that suggests it uses 7-bit I2C Device Addresses. The PICAXE uses 8-bit I2C Device Addresses.

If that is the case it is hard to see how using "14" on both the PICAXE side and ESP8266 side could have worked when you were using the PICAXE as a Slave and the ESP8266 as the master.

It might be worth double-checking that this does actually work.
 

PhilHornby

Senior Member
ESP8266 as I2C slave ... is it possible?

However for my research i require the PICAXE to be master and the ESP8266 to be slave
I tried in several ways but until i was unsuccesfull in getting any comminication. I could not find any info on I2C communication with the PICAXE as master to any other chip but another PICAXE
The last time I looked into this (using an ESP8266 as an I2C Slave), it didn't seem to be currently possible.

A quick Google Search seems to suggest that this is still the case, apart from this result:


(which I'm really not convinced by ... You have to click "Show More" to get any sort of explanation...)

If you figure it out, let me know, it's something I'd like to do too.
 
Last edited:

AllyCat

Senior Member
Hi,

I could not find any info on I2C communication with the PICAXE as master to any other chip but another PICAXE
Being the Master on an I2C bus is "easy"; it can be done by M2s and even by "bit banging" software. There are examples on this forum of the PICaxe being used as a Master to external EEPROMs, RTCs, Temperature/Humidity sensors, etc, etc.

Being an I2C Slave is much more difficult, that's why it's only supported by PICaxe X2s. So I suspect that your problem is with the "ESP/Arduino" Slave program code.

Cheers, Alan.
 

eggdweather

Senior Member
The Espressif web site says 'the ESP currently only support I2C master mode you can not run it in slave mode.' there are some beta versions in development, but not yet released.

The ESP8266 uses a 7-bit I2C device address range.
 

klaasje

Member
Dear all,

Thanks for all the responds,
i am aware of the fact that the ESP currently does not support I2C slave by its own however i found a working version which works between two ESP's and or ESP and Arduino
The ESP does not really act as a slave as the picaxes does but it is capable of reading from the i2C bus.

I tried the suggestions you all gave , no succes still ( no communication recieved or send between ESP and picaxe) . The bus is running and i can see messages being send on my ocsilloscope
I will be starting to write my own i2c libary for the ESP to comunicate with picaxe . If i have any progress you will hear back from me .


Kind Regards,

Ralf Smit
 
Top