HI
I am having problems with the ofArduino library too.
this is what is printed out:
OF_ERROR: ofSerial: trouble reading from port
the program does not really do anything other than trying to start communications with the arduino (duemilanove).
i am using the the StandardFirmata that came with arduino 016.
i tried both baurates 115200 and 57600. i am running of006.
what can it be.
thanks,
stephan.
testApp.h
#ifndef _TEST_APP
#define _TEST_APP
#include "ofMain.h"
#include "ofAddons.h"
class testApp : public ofSimpleApp{
public:
void setup();
void update();
void draw();
void keyPressed(int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased();
void setupArduino();
void updateArduino();
ofArduino ard;
bool bSetupArduino; // flag variable for setting up arduino once
int data;
long timer;
};
#endif
testApp.cpp
#include "testApp.h"
#include "ofMain.h"
//--------------------------------------------------------------
void testApp::setup(){
ofSetVerticalSync(true);
ofBackground(255,0,130);
ard.connect("/dev/cu.usbserial-A9005ddA", 115200); //57600);
bSetupArduino = false; // flag so we setup arduino when its ready, you don't need to touch this :)
}
//--------------------------------------------------------------
void testApp::update(){
if ( ard.isArduinoReady()){
// 1st: setup the arduino if haven't already:
if (bSetupArduino == false){
setupArduino();
bSetupArduino = true; // only do this once
}
// 2nd do the update of the arduino
updateArduino();
}
}
//--------------------------------------------------------------
void testApp::setupArduino(){
// this is where you setup all the pins and pin modes, etc
// it's a good idea to set all pins to output, to avoid noise
for (int i = 0; i < 13; i++){
ard.sendDigitalPinMode(i, ARD_OUTPUT);
}
}
//--------------------------------------------------------------
void testApp::updateArduino(){
// update the arduino, get any data or messages:
ard.update();
}
//--------------------------------------------------------------
void testApp::draw(){
}
the error seems to come from here int the ofSerial.cpp file:
int ofSerial::readByte(){
if (!bInited){
ofLog(OF_LOG_ERROR,"ofSerial: serial not inited");
return OF_SERIAL_ERROR;
}
unsigned char tmpByte[1];
memset(tmpByte, 0, 1);
//---------------------------------------------
#if defined( TARGET_OSX ) || defined( TARGET_LINUX )
int nRead = read(fd, tmpByte, 1);
if(nRead < 0){
ofLog(OF_LOG_ERROR,"ofSerial: trouble reading from port");
return OF_SERIAL_ERROR;
}
if(nRead == 0)
return OF_SERIAL_NO_DATA;
#endif
//---------------------------------------------
//---------------------------------------------
#ifdef TARGET_WIN32
DWORD nRead;
if (!ReadFile(hComm, tmpByte, 1, &nRead, 0)){
ofLog(OF_LOG_ERROR,"ofSerial: trouble reading from port");
return OF_SERIAL_ERROR;
}
#endif
//---------------------------------------------
return (int)(tmpByte[0]);
}