Hello
My initial project is to build a wireless sensor interface for me and for friends of mine musician/dance/circus artists.
Considering the purpose is to use the data with Max/MSP or alike i wanted an OSC format for the raw data to be sent
So the idea was to get the raw values from sensor from Arduino side to YUN side, then to send thoses values with a Python script (I don't know Python I just learned right there for the purpose of the project)
I tried quite a lot of things and figured out 2 possibility to get the data from Arduino to YUN with the help of the forum :
- To use the (key,value) communication with Bridge.put
- To use serial transfer with serial module in Python, and use the following code to get it
serialConnection = serial.Serial("/dev/ttyATH0", 115200, timeout=1)
So far I chose the Bridge.put approach considering I didn't have to disabled the console that way ans it seemed easier.
Here are my codes
Arduino : this one juste read a potentiometer input that i use for testing everything
#include<Bridge.h>
int potPin = 2; // select the input pin for the potentiometer
int val;
void setup() {
Serial.begin(115200); //opens serial port, sets data rate to 115200 bps
while (!Serial) {
}; //gives time to serial to open
// Bridge startup
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
Bridge.begin();
digitalWrite(13, HIGH);
}
void loop() {
val = analogRead(potPin); // read the value from the sensor
Serial.println(val);
Bridge.put("Pot", String(val));
delay(50);
}
Python Script : The script get the value from the 'Pot' and send it thru OSC.
At first I did put it within the Arduino sketch with a Process call after each Begin.put but it was really very slow (1s to enter the process and give the value). So I took the script out and I run it wiht an SSH command (I could do it at Linino Startup within Luci maybe ?)
#!/usr/bin/python
import OSC
import sys
sys.path.insert(0, '/usr/lib/python2.7/bridge/')
from bridgeclient import BridgeClient as bridgeclient
sensorsRawData = bridgeclient()
# Init OSC
client = OSC.OSCClient()
msg = OSC.OSCMessage()
msg.setAddress("/Pot")
# To be looped infinitly
while True:
msg.append(sensorsRawData.get('Pot'))
client.sendto(msg, ('192.168.1.42', 9001))
msg.clearData()
Doing that way i can make the transmission BUT it's still too slow (about 5/6Hz, so a value every 166/200ms which isn't enough for a lot of purpose)
Now I'm gonna start to investigate the "serial connection approach", but maybe i'm just missing something somethin that might improve the "Bridge.put() approch" ?