Hi All, I’m currently trying to update some code and get my firmata2.2 and OF talking to each other nicely.
In previous versions, ( 060 I think) I was able to control the servos in OF using the advice and firmata version in this thread: http://forum.openframeworks.cc/t/ofarduino-and-servo/2950/4). However in 062, I can’t make my servos move, and get random crashes. However, when I don’t access the servo pins, it is stable.
can’t think of nothing that changed from 0061 to 0062 for firmata, so i guess the problem is that the software was changed in the arduino side and we haven’t kept it up to date. About the crashes, can you debug your application and post in which line is it crashing?
I think that the servo code in oF is not in line with the latest firmata protocol. I recall having to change the oF code to get servos to work a while ago. I’ll look into it tonight. Need to do this anyway because I’m using the code in a class I’m teaching on HW/SW integration starting in a couple of weeks.
I’ve looked into this further and have a fix. The issue was as I suspected that the way servo is handled in firmata 2.2 is different than in ofArduino.
I have pasted a temporary fix below. Replace the following in ofArduino.cpp. Please note that this will break backwards compatibility so it should only be used as a temporary solution. I hope to have time this weekend to properly update the file in my oF fork and will submit a pull request at that time.
Note the use of the EInitialized event in the setup() method of the example rather than polling isArduinoReady. You will need to use the event rather than polling for servo to work properly with Firmata 2.2. This is also better practice in general since isArduinoReady() was based on an arbitrary delay period rather than the actual initialization event.
Regarding the crash you’ve been experiencing. I have also noticed this and think it may be a timing issue either in firmata running on the arduino or somewhere in ofArduino. What’s happening is on startup an event indicating that firmata on the Arduino has acknowledged the connection to the oF application is sending incomplete data so during the read, the pointer increments and there is nothing stored at the address (this where you see the code stopping in the debugger). I intend to look into this.