Python to plot graph of serial data from Arduino Uno analog input

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Раза с 3го запустилось, спасибо за рабочую схему бро!

leshgabes
Автор

I need to find a way to capture the oscillation point or peak data of a moving object and use that data for a trigger.
To visualize this, Picture a rail with a distance sensor at each end. The target would oscillate between the 2 end points with the center being 180. To the left the max measurement would be 270 and max 90 to the right. When the target moves to the right then switches direction I want to capture the farthest measurement lowest number serial data to trigger a device when the target is at a certain point on the left. Then I want to capture the oscillation point highest number on the left to in turn trigger the device at a certain point on the right. Due to changing loads on the device being triggered the oscillation points will change randomly.

Can this be done?

Below is a rough draft of comments without any code.

//Arduino uno

// vl53l0x sensors
// distance sensor1 value 181 to 270 degrees
//distance sensor2 value 179 to 90 degrees


//1 stepper Nemo 17 or 23
//Stepper full rotation 0-359 steps (clock wise count 0 north)
//Home 180, max rotation from 270 to 90 degrees.
// orientations. 270 right, 90 left.
//sensors placed at the ends of a rail with oscillating target.

//if sensor1 value oscillates set sensor1 to highvalue of oscillation
Oscillation at 172-173-172 would set value at 173

// if sensor2 lowalue is = 178
// run stepper to 183 when sensor1 reaches 182 //1degrees
// if sensor2 lowalue is =177
// run stepper to 184 when sensor1 reaches 183
// if sensor2 lowalue is =176
// run stepper to 185 when sensor1 reaches 184
// if sensor2 lowalue is = 175
// run stepper to 186 when sensor1 reaches 185
// if sensor2 lowalue is =174
// run stepper to 187 when sensor1 reaches 186
// if sensor2 lowalue is =173
// run stepper to 188 when sensor1 reaches 187
// if sensor2 lowalue is = 172
// run stepper to 189 when sensor1 reaches 188
// if sensor2 lowalue is =171
// run stepper to 189 when sensor1 reaches 188
to lowvalue of 90
//use < at end max run to 270

//If sensor 2 value oscillates set sensor2 to lowvalue of oscillation
Ocilation at 186 - 185 - 186 would set value at 185

// if sensor1 highvalue is 182
// run stepper to 177 when sensor2 reaches 178
// if sensor1 highvalue is 183
// run stepper to 176 when sensor2 reaches 177
// if sensor1 highvalue is 184
// run stepper to 175 when sensor2 reaches 176
// if sensor1 highvalue is 185
// run stepper to 174 when sensor2 reaches 175
highvalue of
//use > at end max run to 90.

jameselliott
Автор

Any thoughts on using github ballbotCommander for plotting? This example seems to use matplotlib (instead of pyqtgraph).. not sure the difference!

import serial
import matplotlib.pyplot as plt
from drawnow import *
import atexit

values = []

plt.ion()
cnt=0

serialArduino = serial.Serial('/dev/ttyACM0', 9600)

def plotValues():
plt.title('Serial value from Arduino')
plt.grid(True)
plt.ylabel('Values')
plt.plot(values, 'rx-', label='values')
plt.legend(loc='upper right')

def doAtExit():
serialArduino.close()
print("Close serial")
print("serialArduino.isOpen() = " + str(serialArduino.isOpen()))

atexit.register(doAtExit)

print("serialArduino.isOpen() = " + str(serialArduino.isOpen()))

#pre-load dummy data
for i in range(0, 26):
values.append(0)

while True:
while
pass
print("readline()")
valueRead = serialArduino.readline(500)

#check if valid value can be casted
try:
valueInInt = int(valueRead)
print(valueInInt)
if valueInInt <= 1024:
if valueInInt >= 0:
values.append(valueInInt)
values.pop(0)
drawnow(plotValues)
else:
print("Invalid! negative number")
else:
print("Invalid! too large")
except ValueError:
print("Invalid! cannot cast")

bennguyen
Автор

if I want to take the analog value and print it into a text label in the GUI, which variable do I have to put in the label? I'm very new in these things.

RainbowDashDark
Автор

i need a alternative to drawnow .. not sure why matplot doesnt include this. not availble in anaconda and my ide's can find it.

kurtauerbach
Автор

How did you set y-axis values from 0 to 1200 ??

I tried different example but in my plot on my y-axis it plots value randomly like 50 then 2, 45, 18, 10, 35 ... (on y-axis)

I want it to be from 0 to 50 (for y-axis) like yours
Plz

ssk
Автор

how can i fix this error
SerialException: could not open port 'COM3': PermissionError(13, 'Access is denied.', None, 5)

arbaazkhan
Автор

I modified the code to plot float values (angles from gyroscope), sending data at 10Hz, but there is a very long lag, well over 5 seconds. Any idea how to fix this?

SirArghPirate
Автор

i get this error
ImportError: cannot import name zip_longest

trisharivera
Автор

is it possible to use this code for three potentiometer?

behnampourani
Автор

Good job. Thank you for share the code

hamedpourmohammadi
Автор

Hello, nice real-time data plotting!
Well could you please help me with this error:

pressure = float(dataArray [1])
IndexError: list index out of range

I´ve done a def makeFig and plot it with drawnow
Error only with Raspian on RaspberryPi, but all works on my PC-Win7.
But for my project I have to use RaspPi!
Help much appreciated!!

jomephift