the challenge: FIRMATA over Ethernet Shield w MultiSerialMega and SPI

I decided to repost this as a new topic because I’ve found very little on using Firmata over Ethernet, so hopefully this will help someone -
… if not at least I will be able to find it. see the original topic here for reference http://arduino.cc/forum/index.php/topic,116816.msg1192129.html#msg1192129>

Basically what I want to do is control two boards - both running the Firmata Library - using one Ethernet shield.

My setup is>

|A|- ArduinoMega 2560 + Seeed Ethernet Shield (v1) + [sketch1]
|
pins[17,18][5v,grd] tied to
X
pins[1,0][vin,grnd] on
|
|B|ArduinoUno R3 + Arduino Motor Shield(external power supply) + [sketch2]

Im able to connect board A no problem but can’t seem to ping or connect to board B

My Sketches are based on the ‘StandardFirmataEthernet’ sketch which can be found here>

it requires you to overwrite the current Ethernet library - but it works great with just one device.

On the host side(PC) Im using the PyFirmata library for Python>

Im also using HW VSP3 - Virtual Serial Port to create my socket for PySerial, but Id like to get that written into my code >
http://www.hw-group.com/products/hw_vsp/index_en.html

first let me show you my code…

Here is my Python code for the client/controller, which is currently being run from a Windows PC

Keep in mind that the "COM#" - is a Virtual Serial Port mapped to the ip address of my Arduino.

Nothing real special here, just for testing a few pins. I have not written in my attempt to establish a second connection yet, but it should be no different than the first.


# -*- coding: utf-8 -*-
"""
#==============================================================================
                #                .~- monster.py ~-.
                #
                #                 Created on 1/7/13
                #
                #                   @author: paul
                #
                #                 ~ Monster Project ~
#==============================================================================

"""
from pyfirmata import *

# try: board = Arduino('/dev/ttyACM1')
# except: board = Arduino('/dev/ttyACM0')
#     except:

try:
    board = ArduinoMega('COM3')
except:
    print '''
    lights are on but nobodys home
            CONN FAILED
    '''

motora = 11
motorb = 3
temp1 = 5
light = 13

board.digital[motora]._set_mode(PWM)
board.digital[motorb]._set_mode(PWM)
board.digital[light]._set_mode(PWM)

board.analog[temp1].enable_reporting()

it = util.Iterator(board)
it.start()

def lspd(x):
    board.digital[motora].write(x)

def rspd(x):
    board.digital[motorb].write(x)

def readtemp():
    return board.analog[temp1].read()

def setlight(x):
    board.digital[light].write(x)

that together with > https://github.com/paulakg4/ArduinoCommander-ethernet/blob/master/Firmata/examples/StandardFirmataEthernet/StandardFirmataEthernet.ino and one device should work just fine..

My thought is to sort of splice together StandardFirmataEthernet with MultiSerialMega.ino

/*
  Mega multple serial test

 Receives from the main serial port, sends to the others. 
 Receives from serial port 1, sends to the main serial (Serial 0).

 This example works only on the Arduino Mega

 The circuit: 
 * Any serial device attached to Serial port 1
 * Serial monitor open on Serial port 0:

 created 30 Dec. 2008
 modified 20 May 2012
 by Tom Igoe & Jed Roach

 This example code is in the public domain.

 */


void setup() {
  // initialize both serial ports:
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop() {
  // read from port 1, send to port 0:
  if (Serial1.available()) {
    int inByte = Serial1.read();
    Serial.write(inByte); 
  }
  
  // read from port 0, send to port 1:
  if (Serial.available()) {
    int inByte = Serial.read();
    Serial1.write(inByte); 
  }
}

..which would be run on the ArduinoMega

then on the connected ArduinoUno I would be running an unmodified copy of the FirmataEthernet (with diff IP)

So the Mega would first act as sort of a 'dumb hub' passing along all ethernet data to Serial1 before looking at it itself.

I guess my first question is regarding the MultiSerial bit - I wonder should I change >

FirmataClass firmata(ethernet);

to> FirmataClass firmata(serial);

then move everything out of the main loop and just do something like>

void setup() {
  // initialize both serial ports:
  Serial.begin(57600);
  Serial1.begin(57600);
}

void loop() {
  // read from port 1, send to port 0:

  ser = [Serial,Serial1]

  if (ethernet.available()) {
    int inByte = ethernet.read();
    ser.write(inByte); 
  }
  
  if (ser.available()) {
    int inByte = ser.read();
    ethernet.write(inByte); 
  }

...fooTheRest()