Hi! I’m developing a project on the Raspberry Pi which works with the GPIO pins. There are two apps, one of them is doing the hardware interfacing and sending the values over OSC. The second app is doing some visuals with the values received over OSC. 4 of these are float values from an ADC and 8 of them are ints (technically bools) sending 1s or 0s depending on whether the gate is one or off.
Now, when these two apps the running, the OSC messages received by the second apps, for the gates that are 1, seem to quit often keep flickering between 1 and 0, and I’m trying to figure out why. When I run just the first app to check, it’s rock steady on the readings that it’s getting - so I’m a bit confused what’s going on.
Here’s some of the code,
App 1/HW
for(int i = 0; i < chip; i++){
if(i<4){
analogIn[i] = 1023 - a2d.getValueAllChannel(chip)[i]; //fix potentiometer wired the wrong way by inverting the value :P
} else {
analogIn[i] = a2d.getValueAllChannel(chip)[i];
}
usleep(100);
}
int r0 [] = {0, 1, 0, 1, 0, 1, 0, 1};
int r1 [] = {0, 0, 1, 1, 0, 0, 1, 1};
int r2 [] = {0, 0, 0, 0, 1, 1, 1, 1};
for(int i = 0; i< mux.size(); i++){
gpio14.setval_gpio(ofToString(r0[i]));
gpio15.setval_gpio(ofToString(r1[i]));
gpio18.setval_gpio(ofToString(r2[i]));
gpio17.getval_gpio(mux[i]);
usleep(100);
}
//sending CVs packed in one OSC message.
//......................................
int max = 1023 * 1023;
ofxOscMessage cv;
cv.setAddress("/cv");
for(int i = 0; i < o_cv.size(); i++){
o_cv[i] = ofMap(analogIn[i] * analogIn[i+4], 0, max, 0, 1.0f);
cv.addFloatArg(o_cv[i]);
}
sender.sendMessage(cv, false);
//sending gate/triggers in one OSC message.
//.........................................
ofxOscMessage gates;
gates.setAddress("/gates");
for(int i = 0; i < mux.size(); i++){
int value = ofToInt(mux[i]);
gates.addIntArg(value);
}
sender.sendMessage(gates, false);
Briefly, first I’m reading the 8 channels of the MCP3008 ADC, then I’m reading the 8 gates connected to a multiplexer, mapping the ADC values to 4 channels and then sending them over via OSC.
In the second app, this is how I’m receiving the OSC messages.
while(receiver.hasWaitingMessages()){
ofxOscMessage m;
receiver.getNextMessage(m);
if(m.getAddress() == "/cv"){
for(int i = 0; i<CV.size(); i++){
CV[i] = m.getArgAsFloat(i);
}
}
else if (m.getAddress() == "/gates"){
for(int i = 0; i<gateIn.size(); i++){
gateIn[i] = m.getArgAsInt(i);
}
}
}
The gateIn[] values seem to be not stable, what am I doing wrong, should I be doing something differently? As I said earlier, when I just run the first app and draw the values to screen, everything is steady, no flickering of any sort, it’s only when I’m getting them from the second app through OSC the values are jumping around a bit… Also, the /cv values seem steady enough, they’re mapped to be between 0-1 so there’s some flickering in the .000xxx ranges but that’s too minor to worry about.