Hi,
I’m at a loss setting up communication between Arduino Pro Mini and an Imp (Breakout board). The strange thing is: this has been working the last couple weeks. Since today: nothing.
I have added a logic level converter, my code is as follows:
`// Assign hardware
serial <- hardware.uart12;
function readSerial() {
local byte = serial.read();
local data = “”;
while (byte != -1) {
// read repeatedly, we want just the last value.
data += format("%c", byte);
byte = serial.read(); // read next byte.
}
if (data.len()) {
server.log(data);
agent.send(“data”, data);
} else {
server.log("Got nothing - " + data.len());
}
}
function executeTask() {
server.log(“Sending command!”);
// query Arduino
//serial.write(0xB0); // tried this too, no difference.
serial.write('p');
serial.flush();
//readSerial(); // now handling in callback when configuring serial.
}
// After wake-up and idle after startup do:
imp.onidle(function() {
// wait 1 more sec before going to deep sleep, making sure we have no
// unfinished business.
imp.sleep(1); // Do I need this??
//wake up every 5 mins (on the minute)
server.sleepfor(300 - (time() % 300));
});
serial.configure(9600, 8, PARITY_NONE, 1, NO_CTSRTS, readSerial);
executeTask();`
On the Arduino I have this:
`
const byte STAT1 = 7;
const byte STAT2 = 8;
const byte ARDLED = 13;
void setup()
{
Serial.begin(9600);
}
void loop()
{
// respond to imp requests.
while (Serial.available()) {
digitalWrite(STAT2, HIGH); //Blink stat LED
char command = Serial.read();
// allow imp to reset timers at midnight (to sync with real time)
if (command == 'x' || command == 0xFFFFFFA0) {
Serial.print("%reset#");
Serial.flush();
}
if (command == 'p' || command == 0xFFFFFFB0) {
Serial.print("%pong#");
Serial.flush();
for(int i=0; i < 4; i++) {
digitalWrite(STAT2, LOW); //Blink stat LED
delay(50);
digitalWrite(STAT2, HIGH); //Blink stat LED
delay(25);
}
if (command == 'd' || command == 0xFFFFFFD0) {
impDebug(); // Send debug to imp %.....#
}
digitalWrite(STAT2, LOW); //Blink stat LED
}
delay(150); // do this every 150 ms
}
`
I can see using the LED’s that the command from the imp arrives on the Arduino. They flash every 5 mins. But nothing is getting back to the imp: the serial callback is never triggered.
To troubleshoot, I ended up soldering a wire to PIN2 on the imp board and connected that to the RXI of an FTDI board. I can actually see the desired serial data in the terminal screen monitoring the FTDI! So the data makes its way all the way back to the imp card… but nothing in the code.
Any thoughts?
Thanks!
Tom.