Quantcast
Viewing all articles
Browse latest Browse all 40524

[ error ] ofSerial: writeByte(): serial not inited

Hi, everyone!

I am currently trying to build simple connection between TouchOsc, Openframeworks and Arduino. And I met with the problem sending data from OF to Arduino. So I tried to write the simple code example in book: Programming Interactivity. it appears the problem of [ error ] ofSerial: writeByte(): serial not inited, and there is no reaction or feedback from arduino side.

Can anyone help me out of this? Thank you!

in OF, ofApp.h:

#pragma once
#ifndef OFSEND_SERIAL
#define OFSEND_SERIAL
#include "ofMain.h"

class ofApp : public ofBaseApp{

public:
	void setup();
	void update();
	void keyPressed(int key);
	void keyReleased(int key);

    ofSerial serial;    // here's our ofSerial object that we'll use;

};
#endif

in OF, ofApp.h:

#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
serial.setup("/dev/tty.usbmodem411", 115200);
}

void ofApp::keyPressed(int key){
serial.writeByte(key);
}

in Arduino:
int message = 0; // for incoming serial data
int ledPin = 13;

void setup(){
pinMode(ledPin, OUTPUT);
Serial.begin(115200); // opens serial port, sets data rate to 9600 bps
}
void loop() {
// do something only when we receive data:
if (Serial.available() > 0) {// read the incoming byte:
message = Serial.read();
if(message == '!') {
digitalWrite(ledPin, HIGH);
}
if(message == '?') {
digitalWrite(ledPin, LOW);
}
}
}


Viewing all articles
Browse latest Browse all 40524

Trending Articles