[solved] Particle Photon not receiving i2c transmission

Does your i2c master ever send 0x00 to the Photon, especially as the first byte? Doing the append to String with 0x00 will just terminate the string.

Well, If It did send 0x00 then the string would be terminated when I tested it on my Arduino. I don’t think it’s the problem here, as far as I can see, the receiveEvent function never gets called on the Photon.

Update
I have tried sending the transmission using an Arduino with the same 4.7k resistors and the Photon is still not calling the receiveEvent function.

Hello,

Do you have any other tips @bko? Just to get another set of eyes on this too, @BDub are you able to help with this?

Kyle

Hi @kaydend

I will try to duplicate your setup with two photons but it will take a bit to set up since they are busy right now.

Can you post of photo of your setup with the Photon? Do you have three wires between the boards–SDA, SCL and GND?

1 Like

Hi @kaydend

OK, the following code works for me! First the transmitter sending one incrementing byte to address 8 and blinking the D7 LED to show that it is sending:

uint8_t val = 0;

void setup() {
    Wire.begin();
    pinMode(D7,OUTPUT);
}

void loop() {
    delay(1000);
    digitalWrite(D7,HIGH);
    Wire.beginTransmission(8);
    Wire.write(&val,1);
    Wire.endTransmission();
    val++;
    delay(20);
    digitalWrite(D7,LOW);
}

Now the receive side using onReceive:

uint8_t data[8];
int idx;

void receiveEvent(int numOfBytes) {
    idx = 0;
    while (Wire.available()) { 
        data[idx++] = (uint8_t)Wire.read();       
  } 
}


void setup() {
    Serial.begin(9600);
    Wire.begin(8);
    Wire.onReceive(receiveEvent);
    pinMode(D7,OUTPUT);

}

void loop() {
    if (idx != 0) {
        digitalWrite(D7,HIGH);
        Serial.print("RX (");
        Serial.print(idx);
        Serial.print("): ");
        for(int i=0;i<idx;i++) {
            Serial.println(data[i],HEX);  
        }
        idx = 0;
        digitalWrite(D7,LOW);
    }

}

I let this run for several minutes with no problems. Here’s a copy of the serial output.

RX (1): F9
RX (1): FA
RX (1): FB
RX (1): FC
RX (1): FD
RX (1): FE
RX (1): FF
RX (1): 0
RX (1): 1
RX (1): 2
RX (1): 3
RX (1): 4
RX (1): 5
RX (1): 6
RX (1): 7
1 Like

Hmm, I see you got is working. I’ll post some picture of the photon setup and my working Arduino setup. Maybe you can shed some light on what I’m doing wrong. Sorry about the bad lighting if it’s not good enough, I can find some more light and take better ones.

Here the Arduino setup






Oh, and by the way, this is the data being printed to the serial monitor on the Arduino with the code in the original post. This is exactly what I wanted. {"sensor":0,"state":0} {"sensor":0,"state":1}

Hi @kaydend

You seem to be showing the case where the Photon is the slave in the first 3 photos (that’s great) but then the UNO swapped in for the Photon also as slave. Where is the master?

Your wiring is not easy to follow–I would try having just three wires between master and slave: SDA, SCL and GND.

Where does the multicolor ribbon cable with SDA and SCL off to the right? To the master?

1 Like

Yeah sorry about that I have taken some new pictures. Indeed the ribbon cable goes off to the master, Which is an esp8266 being used as a “Gateway” for my wifi mesh network of esp8266 powered garage door sensors. I have simplified the cables down to a Red SDA wire, Orange SCL wire, and a Yellow GND wire. After the red and orange wire come off the ribbon cable they are in pulled to 3.3v and they head off to white and blue jumpers that go to D0 and D1 respectively.

They rest of the wires on the original picture was just the 3.3v regulator as the esp8266 only accept 3.3v.
I have also just tested the Photon as a slave with an Arduino UNO as the master, with the same 4.7k resistors and that didn’t even work. This one has really stumped me.

Hi @kaydend

Much better photos and test setup. I can’t see how your pull-ups are connected to +3.3V–where does that happen?

If you have two Photons, you could try my code–it is really simple. Or set up the ESP to transmit a byte every second and try just my receive code.

1 Like

My pullups are connected to 3.3v in the part of the breadboard my hand was covering up which contained a 3.3v regulator. If you go look at the original pictures, you can kinda see how that regulator is hooked to the power rail on the breadboard. Unfortunately, I don’t have two Photons and my FTDI cable broke that I used to program the esp8266s but I have a new one coming tomorrow so, I’ll try that when it arrives. Anyway, I have to get off for the night so I won’t reply until the morning.

1 Like

Looks like @bko has you well covered. Something to note which shouldn’t really matter much, you mentioned 4.7k ohm pullups and I’m pretty sure I see 10k ohm pull ups in your pictures. They should work, but maybe try 4.7k or even 2.2k ohm.

2 Likes

@BDub

You are correct, I measured those pull-ups and indeed they were 10k. So I took those out and got some real 4.7k resistors (I made sure to measure them), but these still didn’t work. I also tried the pull-ups as 2.2k (confirmed by my multimeter), but those didn’t work either. I also tried those two pull-up values with the Arduino UNO and they worked perfectly.

I would clean up your wiring as @bko suggested, and use as little jumpers as possible. That should be a quick process.

Also check your jumpers and make sure they are not open inside the black rubber part. That style of jumper has the wire soldered to a pin, and they are notorious for breaking and opening inside the rubber part. The rubber part will hold the wire and pin seemingly connected, but they are deceiving.

When in doubt, rip it all apart and rebuild it :slight_smile:

2 Likes

@BDub

I have rebuilt it again with no jumpers and simplified as much as possible. The reason I’m using the ribbon cable to go from my ESP8266 to the Photon is that the ESP8266 pins don’t fit on the breadboard. This setup still doesn’t work. I’ll attach some pictures of this re-organized setup. Later today I will try this with @bko receive code on the Photon and the transmit code on the ESP8266 running https://github.com/esp8266/Arduino which is what I was already using.

@kaydend, pull-ups only go on one side so you should remove a set.

@peekay123 what line should it be on?

@kaydend, on both SDA and SCL but not at both end of the wires.

@peekay123 It is not on both ends of the wires. Those are not two different Photons, It’s just two pictures from slightly different angles. Sorry for the confusion.

@kaydend, stereo!! Can you confirm that those are 3.3K ohm resistors? Do you have a picture of your whole setup?