Finally managed to get my yun to save and run python scripts. So, thanks!
Now trying to get my arduino sketch to be sent through the python script. I can't get it to send over.
Arduino code.
// Setup pin locations
int flexPin0 = A0; //analog pin 0
int flexPin1 = A1; //analog pin 1
int flexPin2 = A2; //analog pin 2
int flexPin3 = A3; //analog pin 3
int inByte = 0;
void setup(){
Serial1.begin(9600);
while (!Serial) {
;
}
establishContact();
}
void loop(){
// Read values
// if we get a valid byte, read analog ins:
if (Serial.available() > 0) {
// get incoming byte:
inByte = Serial.read();
int flexSensorReading0 = analogRead(flexPin0);
delay(20);
int flexSensorReading1 = analogRead(flexPin1);
int flexSensorReading2 = analogRead(flexPin2);
int flexSensorReading3 = analogRead(flexPin3);
// Scaling section
int scale0 = map(flexSensorReading0, 128, 256, 0, 100);
int scale1 = map(flexSensorReading1, 128, 256, 0, 100);
int scale2 = map(flexSensorReading2, 128, 256, 0, 100);
int scale3 = map(flexSensorReading3, 128, 256, 0, 100);
// Output results to serialon one line and spaces
Serial.write(flexSensorReading0);
Serial.write(flexSensorReading1);
Serial.write(flexSensorReading2);
Serial.write(flexSensorReading3);
delay(500); //just here to slow down the output for easier reading
}
}
void establishContact() {
while (Serial.available() <= 0) {
Serial.print('A'); // send a capital A
delay(300);
}
}
Python script
#!/usr/bin/python
import socket
import serial
ser = serial.Serial('/dev/ttyATH0', 9600)
while 1:
data_raw = ser.readline()
UDP_IP = "192.168.1.242" #Uno IP address
UDP_PORT = 8888
MESSAGE = data_raw
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
sock.sendto(bytes(MESSAGE), (UDP_IP, UDP_PORT))
recvmsg=sock.recv(1024)
print recvmsg
sock.close()
Was hoping I could just use that, but I think I'm not sure how to get the python script to read the serial correctly, and send that out.
Thanks!