I understand that Serial.write writes binary data to the serial port.
Is there a way to view what has been written?
You can read/capture the data on a PC using Processing or another language able to use a COM port.
Processing is Java based, free, and it is what Arduino IDE was made to mesh with.
The original model is Processing and Wiring. Arduino is an application of Wiring.
You'll need to include and use the Serial library to read COM.
You should notice the similarities between Arduino and Processing which is good and not so good (keeping which syntax is which straight) at the same time.
I'm no expert at Processing. I've used it enough to make sure it works to get at Arduino.
Try in Java with my open source library Ardulink.
I wrote the following example code without testing it but should be almost complete.
Link link = Link.getDefaultInstance();
link.connect(connectionPort); // connectionPort is a String, for example COM19 in windows
link.addRawDataListener(new RawDataListener() {
@Override
public void parseInput(String id, int numBytes, int[] message) {
// Write your code here
}
});
Let me know if you have some trouble.
This could be made to do what Firmata does pretty easily?
wengzhe:
I understand that Serial.write writes binary data to the serial port.
Is there a way to view what has been written?
Serial monitor. Click the icon in the upper right of the IDE.
Serial monitor displays ASCII, not binary.
If you wanted to you could pipe the Arduino output straight to file and then read that with a hex editor.
Using Arduino write to transfer values as binary saves cycles and buffer by not text-translating to ASCII.
16 bits unsigned.can be 0 to 65536. That's 6 bytes with terminating NULL for what 2 bytes can transfer.
But it's a good idea to CRC binary serial message strings. Check is good.
wengzhe:
I understand that Serial.write writes binary data to the serial port.
Is there a way to view what has been written?
You might try printing the bytes to the serial monitor in hex format to see what they are. Below is some test code for the serial monitor.
// zoomkat 5-28-13 serial I/O string test
// type a string in serial monitor. then send or enter
// for IDE 0019 and later
String readString;
void setup() {
Serial.begin(9600);
Serial.println("serial test 0021"); // so I can keep track of what is loaded
}
void loop() {
while (Serial.available()) {
delay(2); //delay to allow byte to arrive in input buffer
byte c = Serial.read();
//char c = Serial.read();
// print it out in many formats:
//Serial.println(c); // print as an ASCII-encoded decimal
Serial.println(c, DEC); // print as an ASCII-encoded decimal
Serial.println(c, HEX); // print as an ASCII-encoded hexadecimal
Serial.println(c, OCT); // print as an ASCII-encoded octal
Serial.println(c, BIN); // print as an ASCII-encoded binary
Serial.println();
readString += c;
}
if (readString.length() >0) {
Serial.println("Decimal values of bytes sent");
Serial.println(readString);
Serial.println("Done!");
Serial.println();
readString="";
}
}
GoForSmoke:
Serial monitor displays ASCII, not binary.
void setup() {
Serial.begin(115200);
char x = 'A';
Serial.println(x);
Serial.println(x, DEC);
Serial.println(x, HEX);
Serial.println(x, BIN);
}
void loop() {
}
And if you change the binary then it's not the binary but you'll be able to read it without a hex editor.
Learning to capture binary on the PC is a useful personal skill/tool and hex editors do write as well as read.
Compare changing your code to produce debug text to capturing what you have and viewing with a hex editor?
Which is easier, not forgetting to make it able to output binary values?
What are you doing with the data and how fast is the data flow?
Do you have SD support? You could write the data to the SD card and read that card on your PC.