3

I'm having some technical problems... I'm trying to use Firmata for arduino but over nrf24, not over Serial interface. I have tested nRF24 communication and it's fine. I have also tested Firmata over Serial and it works.

Base device is simple "serial relay". When it has data available on Serial, read it and send it over nRF24 network. If there is data available from network, read it and send it through Serial.

Node device is a bit complex. It has custom Standard Firmata where I have just added write and read override.

Diagram

Read override id handeled in loop method in this way:

while(Firmata.available())
    Firmata.processInput();

// Handle network data and send it to Firmata process method
while(network.available()) {
    RF24NetworkHeader header;
    uint8_t data;
    network.read(header, &data, sizeof(uint8_t));
    Serial.print(data, DEC); Serial.print(" ");
    Firmata.processInputOverride(data);
    BlinkOnBoard(50);
}

currentMillis = millis();

Firmata processInputOverrride is little changed method of processInput where processInput reads data directly from FirmataSerial, and in this method we pass data down to method from network. This was tested and it should work fine.

Write method is overloaded in a different way. In Firmata.cpp I have added an method pointer that can be set to a custom method and used to send data using that custom method. I have then added custom method call after each of the FirmataSerial.write() call:

Firmata.h
...
size_t (*firmataSerialWriteOverride)(uint8_t);
...

void FirmataClass::printVersion(void) {
  FirmataSerial.write(REPORT_VERSION);
  FirmataSerial.write(FIRMATA_MAJOR_VERSION);
  FirmataSerial.write(FIRMATA_MINOR_VERSION);
  Firmata.firmataSerialWriteOverride(REPORT_VERSION);
  Firmata.firmataSerialWriteOverride(FIRMATA_MAJOR_VERSION);
  Firmata.firmataSerialWriteOverride(FIRMATA_MINOR_VERSION);
}

I have then set the overrided write method to a custom method that just writes byte to network instead of Serial.

size_t ssignal(uint8_t data) {
    RF24NetworkHeader header(BaseDevice);
    network.write(header, &data, sizeof(uint8_t));
}

void setup() {
...
Firmata.firmataSerialWriteOverride = ssignal;
...
}

Everything seems to be working fine, it's just that some data seems to be inverted or something. I'm using sharpduino (C#) to do some simple digital pin toggle. Here's how output looks like: (< came from BASE, > sent to BASE)

> 208 0
> 209 0
...
> 223 0
> 249
< 4 2 249 
and here communication stops...

That last line came inverted. So i tough that I only need to invert received bytes. And it worked for that first command. But then something happens and communication stops again.

> 208 0
> 209 0
...
> 223 0
> 249 // Report firmware version request
< 249 2 4
> 240 121 247 // 240 is sysex begin and 247 is systex end
< 240 121
< 101 0 67 0 0 1 69 0 118
< 117 0 115 0
< 0 70 0 105 0 116 0 111 0 109
< 0 97 0
< 0 109
< 116 0 97 0 247
> 240 107 247

So what could be the problem here? It seems that communication with Firmata works but something isn't right...

-- EDIT --

I solved that issue. The problem was that I didn't see Serial.write() calls in sysex callback. Now that that is solved, I came up to another problem... All stages pass right (I guess) and then I dont get any response from Node when I request pin states

...
< f0 6a 7f 7f 7f ... 7f 0 1 2 3 4 5 6 7 8 9 a b c d e f f7 // analog mapping
> f0 6d 0 f7 // sysex request pin 0 state and value
> f0 6d 1 f7 
> f0 6d 2 f7
...
> f0 6d 45 f7
// And I wait for response...

There is no response. Any ideas why would that happen? Node receive all messages correctly and code for handling pin states exist.

4

0 回答 0