-
Notifications
You must be signed in to change notification settings - Fork 516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
initial implementation of Serial protocol #205
Conversation
serialPort = NULL; | ||
} | ||
} | ||
serialIndex = -1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this line outside of the directive block since it applies to HW serial as well
Wow, will dig in this week :D |
Turns out Arduino doesn't declare constants like RX, TX, RX1, TX1, etc so there is no easy way to provide this info in a configuration query response. Looks like I'll have to add constants to Boards.h per arch. For identifying pins that are SW serial capable is another matter since not all pins work on some boards. For now for HW Serial, I could map the UART pins in Boards.h by adding a |
I had to remove all occurrences of |
That is strange you got an error on that define. It is necessary because SoftwareSerial is only compatible with AVR micros. It will fail to compile if you include SoftwareSerial with a non-AVR board. What board are you using and which version of the Arduino IDE? |
Can you also copy the Arduino log output from a version with those defines in place? |
Sure thing.. I'm using an Arduino Uno. Here's the output from the first issue I encounter:
So I replaced the ifdef from the top:
With
Error is gone, but there is no reply delivered to |
As of Arduino 1.6.4 you should be able to clone Firmata directly into ~/Documents/Arduino/libraries/ rather than installing into the Arduino application directory. |
continue; | ||
} | ||
// only the SoftwareSerial port that is "listening" can read data | ||
if (portId > 7 && !((SoftwareSerial*)serialPort)->isListening()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rwaldron this appears to be the source of the error. Lines 218 - 220 should also be wrapped by:
#if defined(ARDUINO_ARCH_AVR)
...
#endif
Without those defines if you tried to compile on an ARM board like a Due or a Teensy, compilation would fail. There could be an additional issue of ARDUINO_ARCH_AVR not being included in Arduino 1.0.6. I need to verify later when I get home.
@rwaldron with the latest commit, it should work now in both Arduino 1.0.6 and Arduino 1.6.5. Haven't tested with 1.6.4 to see if that has other issues. It also appears that the preprocessor is handled differently in Arduino 1.0.x vs 1.6.x. I had no errors in 1.6.5 (even though there was clearly an error in the code) while 1.0.6 reported the same error you encountered. |
Didn't try that, so I will.
I will confirm both and report back! |
Actually it doesn't work in Arduino 1.0.6 (when I tested I had compiled from 1.6.5 after proving that compilation succeeded in 1.0.6). #if !defined(ARDUINO_ARCH_SAM) This will prevent official arduino ARM boards from trying to include SoftwareSerial (which would fail because the library is not in the compile path for non AVR boards). |
Ok, I will focus on >=1.5.x for now |
Testing with IDE 1.6.4...
#include <SoftwareSerial.h>
SoftwareSerial s(10, 11); // RX, TX
void setup() {
s.begin(9600);
}
void loop() {
s.write(1);
s.write(2);
s.write(3);
s.write(4);
delay(20);
}
|
Next thing I'm going to work on:
|
I'm considering a couple of changes:
These 2 changes would update the Serial ConfigConfigures the specified hardware or software serial port. The format options (bytes 6 and 7) are
Serial ReadBoard -> Firmata client Read contents of serial buffer and send to Firmata client (send with
|
An alternative approach to Serial Read Interval[Optional] Set the
This could be extended (simply by ORing the 3rd byte) to specify the interval by individual port if necessary in the future, however at the cost of added memory usage. Contrast with the proposal in my previous comment in which it would be difficult to extend the protocol (if |
I'm declaring the Firmata serial message protocol as final. Punted:
Last step is to incorporate the serial code (or a subset of it) into the StandardFirmataEthernet example. |
*/ | ||
|
||
#include <Servo.h> | ||
#include <Wire.h> | ||
#include <ArduinoUnit.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO - remove this include as it's no longer needed
Adding Firmata serial support to StandardFirmataEthernet consumes 99% of available program memory on a Leonardo or Yun. We have reached the limit here. Options:
The second one may be better although it adds complexity in maintaining an additional StandardFirmata variant (a change in one must be manually propagated to all unless I get creative with some scripting). |
This is also why I was previously pushing ConfigurableFirmata for new features, but it seems the consensus is users want an all-in-one approach rather than a build your own for your setup approach (considering the limitations of any given setup). |
I think I have a plan: Keep StandardFirmata as it was in Firmata 2.4.4 and create a new version StandardFirmataPlus, StandardFirmataEthernetPlus, will not be guaranteed to run on boards with <= 32K for Flash and < 3k of RAM (so Uno, Leonardo, etc will be use at your risk and in some cases it won't even compile... you'll get a Flash memory exceeded error). They will run better on newer architectures such as Due, Zero, Teensy 3.x series, etc and will also still run on Mega since it has much more Flash and RAM than the ATMega328p and ATMega32u4 based boards. |
Revert StandardFirmata to 2.4.4. StandardFirmataPlus will be used for new features. StandardFirmata will be maintained and minor features may still be added as long as Flash, RAM and performance of lower memory boards (Uno, Leonardo, etc) is not affected.
StandardFirmataPlus and StandardFirmataEthernetPlus have been added. I had to strip out the Yun code from StandardFirmataEthernetPlus since the sketch is too large to run on the ATMega32u4 of the Yun. Going to run tests on a few more boards and then merge this early this week. |
Successfully tested:
I think this is good to go! Merging... |
initial implementation of Serial protocol
Somehow I missed that this landed—this is really exciting. Thanks for all your work @soundanalogous!! |
This is a great plan and great work! I'm sorry I missed this too, glad you kept such good notes! |
Adds support for using Hardware and Software serial ports. See the protocol here.
All hardware ports except the default (Serial) port are supported. So you can use Serial1 on a Leonardo or Serial1, Serial2, or Serial3 on an Arduino Mega or Due.
Up to 4 SoftwareSerial instances can be used. Only one instance can read at a time however. Send the SERIAL_LISTEN message to set the current reading port.
Baud rates up to 115200 seem to work for reading using HW serial. Baud rates up to 57600 seem to work for reading using SW serial. When using a board that has additional HW serial ports (RX1, TX1, etc), using those ports will be more efficient than creating SoftwareSerial Instances.
Has been tested successfully with the following boards:
This is a work in progress. Please test and report any bugs. This sketch can be used for testing. Even better would be to test against actual serial devices.
A client implementation and example are available here:
To do:
SERIAL_MESSAGE
constant to Firmata.hINPUT
when SerialN.begin is called (fixes a bug with Due)