Closed austinsk8s closed 7 years ago
The problem is that StandardFirmataYun uses Serial1 to communicate with Linino so it's possible this may lead to issues (but I've never tried). You don't need ConfigurableFirmata at all, that's just to add Stepper support, but the Yun doesn't have enough flash and RAM to include both stepper and serial.
If you want to try it, all you need to do is copy StandardFirmataPlus.ino then replace this block of code with this block of code and add this line right after it.
Then attempt to compile, if you get a warning about RAM size, it's probably not safe to use and then you'd have to revert to using ConfigurableFirmata with some features you don't need stripped out.
No changes are required on the Linino side or the Breakout.js side.
Thanks for the tips! I've had success sending and receiving data over hardware serial RX/TX, but I'm having data loss issues, and with more complex message content I'm having issues where the data is corrupted and changed (english characters turning to chinese, for instance).
Here is a gist with modifications and output.
You're seeing data that appears corrupted because you're trying to send Firmata serial over the same serial transport you're using for the connection to Linino. The "corrupted" data you are seeing is probably from the Sysex framing.
Can you explain exactly what you're trying to accomplish in more detail?
Ahh I see. I created a more detailed test output.
What I'm trying to accomplish is:
A way to send long strings of data to and from a javascript user interface, where the data is being sent to/from some pin or pins on the Yun.
An Arduino Mega sends a string of data to a pin on the yun, and that string is displayed in a javascript UI.
A javascript UI sends a very long string of data to a pin on the Yun to be sent over wire to a pin on an Arduino Mega.
You should use SW_SERIAL0 rather than HW_SERIAL1 for the connection between the Yun and the Mega. You may also need to buffer data in small batches. You can only send or receive about 28 chars max at a time (since with Firmata it takes 2 bytes to send a single char).
Also note that you can only use these pins for SoftwareSerial on the Yun: 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI)
I did try that, but I was never able to receive any response over SW_Serial0. I actually receive data over HW_SERIAL1, although it is garbled (Hello! turned into ÷ðHll! elo! ).
I didn't use the correct pins for software serial on my first go. I will attempt SW_Serial0 again using the proper pins this time.
I attempted SoftwareSerial with various arrangements of the pins you mentioned, but I still haven't been able to read any data sent.
Is there any other means of sending string data in this manner? I2C or disabling communications that conflict with Hardware Serial?
Maybe I need to dig deeper into why SoftwareSerial isn't working for me...
There is no way to get it to work properly with Hardware serial. I don't know why Arduino chose to use an ATMega32u4 for the Yun as it's very limited. SoftwareSerial should work unless you are seeing RAM usage over 90% (check the output when compiling). Otherwise I2C is a good option. You'd need to setup the Mega as an I2C slave device and define a simple protocol for sending and receiving strings over I2C. Then you can use the I2C interface Breakout.js provides.
Also, with SoftwareSerial you can't use a baud higher than 57600. I'd suggest 9600 or 19200.
I lowered the baud rate to 19200, but still no response via SoftwareSerial, only HardwareSerial is responsive.
To attempt the I2C route, I can extend the Breakout.js I2CBase class to send and receive strings over I2C pins?
HW_Serial1 is responsive because it's the the transport used to communicate with Linino.
For I2C, extend I2C base just like in many of the Breakout io modules. If you're familiar with the I2C protocol, this should be trivial, if not you'll probably need to read up on I2C first.
Also, regarding your SoftwareSerial attempts, what does your Mega code look like?
You should have something like this running on your Mega: https://gist.github.com/soundanalogous/3c21496ce3f1a1af2235. However it would be more efficient to use HW Serial on the Mega (Serial1, Serial2 or Serial3) while using SW serial on the Yun. Just make sure the baud rate matches.
Thanks for the tips! I still haven't gotten software serial working, but I'll spend a bit more time with it.
If I don't figure out my issue with software serial today, then I'll move on to I2C.
Using this SoftwareSerialExample, I have been able to send strings from one Arduino (Uno or Mega) to a Yun running slightly modified StandardFirmataPlus.
I haven't succeeded in sending a long string of data from a javascript UI to pin on the Yun over SoftwareSerial to a pin on another Arduino, but I'm sure I'm not too far from getting that working.
If I get small chunks of data to send from Yun to Uno or Mega using SoftwareSerial, I'll try and buffer longer strings of data across in 28 character chunks.
If I choose to go with I2C for sending string data from Yun to Uno/Mega, will it have the same 28 character limitation as SoftwareSerial?
Actually I2C is worse. It has a 28 or 29 character hard limit. There is currently no way to buffer with I2C in Firmata.
Well you could but you'd need to define a subprotocol within I2C in order to frame packets and identify them as part of a series of packets, that you then need to reassemble.
I think SoftwareSerial can be used for sending the long strings from Yun to Mega as well as the Mega to Yun example I gave above. I'll just stick with SoftwareSerial for sending and receiving on the Yun side, and I'll buffer the data into 28 character pieces for sending the long stuff.
As for this github issue, should I submit a pull request for adding Breakout.js 0.4.0 and the modified StandardFirmataPlus?
For the price of a bit of direction, I would love to help with this.
I would like to be able to utilize the new serial features of Breakout.js on the Yun using the yunBreakout configuration.
I don't mind doing the work, I would just need some direction on the best way to go about this.
I know Breakout is now using configurable firmata, but I'm unsure how to integrate configurable firmata into this project. I'm assuming there will need to be some modifications to the Arduino side and the Linino/Python side, but I'm unsure as to what modifications are needed.