arduino / YunBridge

72 stars 32 forks source link

Run the Bridge on (USB CDC) Serial rather than (hardware) Serial1 #17

Open probonopd opened 10 years ago

probonopd commented 10 years ago

I have an Arduino Leonardo connected to my OpenWrt-based router via USB. On the OpenWrt router, I have installed the Arduino-related components of Linino as documented on https://gist.github.com/probonopd/9594775 - this setup works for other Arduinos but not for the Leonardo so far, since the Bridge library is using Serial1 rather than Serial (which I would want) on the Leonardo.

I would like to use the Arduino Yun's Bridge library and run it on an Arduino Leonardo, but rather than using the hardware serial RX/TX pins I would like to communicate over the USB CDC serial connection.

Please also see http://forum.arduino.cc/index.php?topic=229643.0 where I have asked for help regarding this question.

ffissore commented 10 years ago

Thank you for your suggestion. We currently have no plans of porting the Bridge library to run on a non-Yun environment. I'll leave the issue open as enhancement. ps: your gist is quite accurate. I've added a comment about why we need gpg keys

probonopd commented 10 years ago

Thanks ffissore. I understand that you have no plans of porting the Bridge library to run on a non-Yun environment, but can you give me some hints what I would have to do in order to make it work with Serial rather than Serial1 on the Leonardo? Thanks.

ffissore commented 10 years ago

I think you'll need to customize the gcc call. You could pass in a parameter that disables the default behaviour. ATM choice is made using the MCU type. You could override that with some BRIDGE_SERIAL_NAME var

probonopd commented 10 years ago

If I change to "SerialBridgeClass Bridge(SERIAL_PORTMONITOR);" then I get libraries/Bridge/src/Bridge.cpp:244: error: no matching function for call to 'SerialBridgeClass::SerialBridgeClass(Serial&)' libraries/Bridge/src/Bridge.h:94: note: candidates are: SerialBridgeClass::SerialBridgeClass(HardwareSerial&) libraries/Bridge/src/Bridge.h:92: note: SerialBridgeClass::SerialBridgeClass(const SerialBridgeClass&)

cmaglie commented 10 years ago

@probonopd

SerialBridgeClass is a specialization of BridgeClass and it expects a real UART (so an HardwareSerial instance) connected to the OpenWRT console. If you use SERIAL_PORTMONITOR on the Leonardo instead you are trying to instantiate SerialBridgeClass with a USB-CDC (Serial) object.

You may try to use BridgeClass directly instead that accepts any type of Stream:

on Bridge.h:

...
extern BridgeClass Bridge;
...

on Bridge.cpp

...
// Bridge instance
BridgeClass Bridge(SERIAL_PORT_MONITOR); // or directly Serial
...
probonopd commented 10 years ago

Thanks cmaglie for the hint. This does compile, but I do not get a connection. I also tried this in Bridge.h:


// This subclass uses a serial port Stream
class SerialBridgeClass : public BridgeClass {
  public:
    SerialBridgeClass(Serial_ &_serial)
      : BridgeClass(_serial), serial(_serial) {
      // Empty
    }
    void begin(unsigned long baudrate = 115200) {
      serial.begin(baudrate);
      BridgeClass::begin();
    }
  private:
    Serial_ &serial;
};
extern SerialBridgeClass Bridge;

And in bridge.cpp: SerialBridgeClass Bridge(SERIAL_PORT_MONITOR); But wasn't a success either.

PaulStoffregen commented 9 years ago

I've been working on a patch that adds a pair of alternate begin functions:

    Bridge.begin(serial, baud);  // lets Bridge begin on any hardware serial port

    nonserial.begin();
    Bridge.begin(nonserial);     // lets Bridge begin on any Stream

I'm still working on the code and testing. If there's interest, I'd be happy to prepare a pull request for the 1.5.x branch.

This work only addresses the Arduino side. You still have to get the Linux side talking on other ports (that's the part holding up testing.....)

probonopd commented 9 years ago

PaulStoffregen, I am very interested in your work, did you have a look at my scripts on https://gist.github.com/probonopd/9594775 - especially run-avrdude?

PaulStoffregen commented 9 years ago

Yes, I looked at that script. I do not believe this is a good way:

    /sbin/askfirst ttyACM0 /bin/ash --login

This sort of thing works for a fixed serial device. But ttyACM0 can come and go as the USB device is plugged.