I’ve been playing around with the SX1509 library for the last day or so. I gave myself a small week-end challenge which consisted of reading as much HC-SR04 sonars as I can through I2C using the SX1509 as an intermediary. (using this breakout board.)
So far I:
- Configured half the SX1509 as the HC-SR04 trigger pins
- Configured the rest as my echo pins.
- Enabled an interrupt on the echo pin of the sonar I want to read.
- Use the active-low output interrupt pin of the SX1509 and the pulseIn() function of the Photon to capture the delay/distance of the sonar.
I’ve just started troubleshooting my circuit, however it seems like I’m not getting any echo back from the HC-SR04.
Using a small testbench program, I confirmed the sonar itself works well which means I most likely made a few mistakes along the way.
I’m not too familiar with the I2C protocol and quite unsure about the proper way to drill down to the root cause. I was thinking perhaps the digitalWrite() commands sent through I2C are too slow for the HC SR04 trig signal to properly work? Or maybe I’m not going the right way about reading the SX1509 interrupt with pulseIn()?
SX1509 io; // Creation of a an SX1509 object /* setup(), loop(), etc... */ io.digitalWrite(trig_pin, HIGH); delayMicroseconds(10); io.digitalWrite(trig_pin, LOW); duration = pulseIn(D2, LOW); //Particle's D2 configured as INPUT_PULLUP connected to the SX1509 active-low INT