|
Fall07Shakar Links: |
Toms Note About SerialAn important message from Tom Igoe about the Serial Lab: The two most common sources of error that might lead to this that I have seen this week: 1 Make sure you've run the Processing macosx_setup.command if you're on a mac, which is in the Applications/Processing/libraries/serial/ directory. Quit Processing, double click the command file, restart the machine, and restart Processing. That gives Processing rights to open the serial port. I thought it was automated in Processing 0125, but maybe not. 2 If you're using a Diecimila, there's an arcane bug that can pop up. The Arduino Diecimila has an auto-reset capability. Every time the serial port it's connected to opens, the diecimila automatically resets. This means that when you start your Processing sketch that opens the serial port, the Diecimila resets. Not a major problem, because a couple seconds later, it starts sending data and Processing's happy. HOWEVER: If the Diecimila gets a byte of data RIGHT AFTER IT RESETS, it thinks it's getting a new program upload, and stops and waits for the upload instead of restarting. If you're using my call-and-response code from the lab (and most of you are), you'll notice that Processing sends a byte right after it opens the serial port in the setup(). This will cause the Diecimila to wait, as described above. This ONLY happens with the Diecimila and with NG's where you've added that special capacitor for auto-reset like I mentioned on this list a few weeks ago. If you've never soldered to your board, and you have an Arduino NG or NG rev. C,you can ignore this. Your problem is elsewhere. But if you have a Diecimila, here's how to solve it. In the final piece of Processing code found in the lab (http://itp.nyu.edu/physcomp/Labs/Serial), you need to make the following change: comment out this line in the setup: // port.write(65); // Send a capital A to start the microcontroller sending } Then change this block in the draw routine: if (firstContact == false) { delay(300);
port.write(65);
}
Change the delay to something like 10000 or higher. This change will make Processing not ask for any data for ten seconds. That gives the Arduino plenty of time to reset after the serial port opens. The Diecimilas need only a second or two, so you can lower it once you see the program work. The NG's need about eight seconds, so ten is safe. The point of Processing sending a byte at the beginning of the code is so that the Arduino will start sending code in response. One side or the other has to start the conversation, and in this case it's Processing. However, if you know the Arduino's going to reset when the serial port opens, you could change the whole program so that the Arduino starts the conversation. If you're interested in that solution, let me know and I'll work up an example of it. t. |