Serial Lab 1
Or sometimes I think there is a phantom living in my Arduino board
Since I plan to use either video or the Kinect as part of my final projects, and definitely intend to stay away from Max/MSP, I started to use openFrameworks for this week's labs instead of Processing. I've been taking an intensive workshop series on openFrameworks and have just been interested in the toolkit for a while.
I made the mistake of overestimating openFrameworks' documentation, and so ended up using the Processing IDE. Of course, my results for the Serial Lab were dissimilar to the results on the wiki.
My accelerometer hasn't yet arrived, and I still have no idea what I am doing so I just messed around with the first lab for a while.
Before opening either openFrameworks or Processing, I tested my board with example code I found either on the wiki or within the program's folder. When I replaced the println() function with the write() function, the serial monitor printed gobbledy-gook.
I spent the week reading through an openFrameworks tutorial using OpenCV and Arduino. I did not intend to use OpenCV for this week's assignment, but it was the only one I found on Creative Applications.
There are two libraries that simplify the communication between the Arduino board and openFrameworks. The first is ofSerial and the second is ofArduino.
With the ofSerial library, the process of bridging communication from one program to another was the same as Processing. I initialized a new ofSerial object named serial; I asked the program to list the available ports; I specified the port name of the usb port that the Arduino uses.
serialA.getDeviceList(); //serial.setup("/dev/tty.usbmodemfa131",9600); // mac osx looks like this serialA.setup(0, 9600); //I am providing the deviceNumber instead of the portName like above
The ofArduino library was different.
serialB.connect("/dev/tty.usbmodemfd121", 9600); // listen for EInitialized notification. this indicates that // the arduino is ready to receive commands and it is safe to // call setupArduino() ofAddListener(ard.EInitialized, this, &testApp::setupArduino); bSetupArduino = false; // flag so we setup arduino when its ready
I found the ofSerial library easier to implement because the tutorial used the library. Also, the ofSerial class methods were nearly the same as the Processing examples provided on the course wiki. For the ofArduino library, I need to upload the Firmata library onto the Arduino board and then write some code to see if a function returns true.
Do I need to run the Arduino and the Processing code at the same time? I didn't include that in my notes from office hours.