Running math equations in Python to save sketch space


i'm trying python script write value bridge, run equations, , put bridge arduino, reason, keep returning blank values in console until execute script manually in putty.  i can see sketch executing mathtest.py in top.

what doing wrong?

in sketch:
code: [select]

#include <bridge.h>
char ppmco[10];
int valsamp = 292;

void setup() {;
 bridge.begin();
 delay(2000);
 console.begin();
 console.println("you're connected console!!!!");
 console.buffer(64);
}

void loop() {
 bridge.put("valsampcoput", string(valsamp));
 console.println("sending");
 delay(1000);
 process p;        // create process , call "p"
 p.runshellcommand("python mathtest.py"); // add url parameter "curl"
 console.println("processing");
 delay(1000);
bridge.get("valsampcolin",ppmco,10);
console.println("getting");
console.println(ppmco);


in python:
code: [select]

#!/usr/bin/python

import math
import sys    

sys.path.insert(0, '/usr/lib/python2.7/bridge/')
                                               
from bridgeclient import bridgeclient bridgeclient

valsampco = bridgeclient()
val = int(valsampco.get('valsampcoput'));
vrl = val * ( 5.000 / 1024.000  );
rs = 5300.000 * ( 5.000 - vrl) / vrl;
ratio =  (rs/ 3100.140)
ppm = str(round(666.340 * math.pow (ratio, -3105.000/1000.000),4));
valsampco.put('valsampcolin',ppm)
print valsampco.get('valsampcolin')

code: [select]
nano /mnt/sda1/mathtest.py

code: [select]
#!/usr/bin/python
# -*- coding: utf-8 -*-
import math
import sys    
valsampcoput=sys.argv[1]
val = int(valsampcoput)
vrl = val * ( 5.0 / 1024.0  )
rs = 5300.000 * ( 5.0 - vrl) / vrl
ratio =  (rs/ 3100.14)
ppm = int(round(666.34 * math.pow (ratio, -3105.0/1000.0),4))
print ppm


code: [select]
chmod 755 /mnt/sda1/mathtest.py

test code:

code: [select]
/mnt/sda1/mathtest.py 292
7


code: [select]
#include <process.h>
int valsamp = 292;
void setup() {
 // initialize bridge
 bridge.begin();
 // initialize serial
 serial.begin(9600);
 // wait until serial monitor connected.
 while (!serial);
}

void loop() {
 process p;        // create process , call "p"
 p.begin("/mnt/sda1/mathtest.py");  // process launch "mathtest.py" command
 p.addparameter(string(valsamp)); // add url parameter "mathtest.py"
 p.run();      // run process , wait termination
 while (p.running()); // nothing until process finishes, whole output
 int result = p.parseint();
 serial.println((result));
 delay(1000);
}




Arduino Forum > Products > Arduino Yún (Moderator: fabioc84) > Running math equations in Python to save sketch space


arduino

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support