AcceleroMMA7361 ski;
int x;
int y;
int z;
void setup(){
Serial.begin(115200);
ski.begin(13, 12,11,10, A0, A1, A2);
ski.setARefVoltage(3.3);
ski.setSensitivity(HIGH);
ski.calibrate();
}
void loop(){
x = ski.getXRaw();
y = ski.getYRaw();
z = ski.getZRaw();
Serial.print("\nx: ");
Serial.println(x);
Serial.print("\ty: ");
Serial.print(y);
Serial.print("\tz: ");
Serial.print(z);
delay(10); //(make it readable)
}//End of Arduino Sketch
from Tkinter import *
import serial #import Serial Library
import numpy as np # Import numpy
ardoData = serial.Serial('COM4', 115200)
accelX1 = [] #to hold the incoming axis data from the arduino
accelY1 = []
accelZ1 = []
class GraphException(Exception):
def __init__(self, string):
Exception.__init__(self, string)
class Smoking(Canvas):
def __init__(self, master, FrameTitle, Col, Row, Height):
Canvas.__init__(self, master)
self.FrameTitle = FrameTitle
self.x1Axis = range(1001)
self.y1Axis = range(1001)
self.z1Axis = range(1001)
self.Line1 = range(1001)
self.Line2 = range(1001)
self.Line3 = range(1001)
self.configure(height=Height, width=750, bg='grey', bd=3, relief=GROOVE)
self.grid()
self.grid_propagate(0)
self.Col = Col
self.Row = Row
self.place(y=Col, x=Row)
self.create_text(380, 20, text=self.FrameTitle, fill = 'black')
for i in range(0, 1001):
self.Line1[i] = self.create_line(-13+10+(i*13i*10), 90, 0+(i*13i*10), 90, fill='blue', width=0)
self.Line2[i] = self.create_line(-13+10+(i*13i*10), 90, 0+(i*13i*10), 90, fill='red', width=0)
self.Line3[i] = self.create_line(-13+10+(i*13i*10), 90, 0+(i*13i*10), 90, fill='yellow', width=0)
def LiveValues(self,accelX1, accelY1, accelZ1, Centerline = False, Dritter = False):
for x in range(1, 59):
for i in np.arange(1, 1001, 1):
while(ardoData.inWaiting() == 0):
pass #do nothing
ardoString = ardoData.readline()
dataArray = ardoString.strip().strip('\n') #Split into an array called dataArray and strip off any spaces
# Ensure that you are not working on empty line
if ardoString:
dataArray = ardoString.split(",")
if len(dataArray) > 1:
self.x1Axis = int(dataArray[0])
self.y1Axis = int(dataArray[1])
self.z1Axis = int(dataArray[2])
accelX1.append(self.x1Axis)
accelY1.append(self.y1Axis)
accelZ1.append(self.z1Axis)
for x in range(0, 1001):
self.coords(self.Line1[x], -13+10+(x*10), self.accelX1[x], (x*10), self.accelX1[x+1])
self.coords(self.Line2[x], -13+10+(x*10), self.accelY1[x], (x*10), self.accelY1[x+1])
self.coords(self.Line3[x], -13+10+(x*10), self.accelZ1[x], (x*10), self.accelZ1[x+1])
# Create and run the GUI
root = Tk()
app = Smoking(root, "Smooth Sailing", 1000, 1000, 1000)
app.mainloop()