Arduino Tutorial on How to read Serial Port Data

preview_player
Показать описание

This is part1 of a 2 part tutorial in this video I will show you how to make a arduino sketch to recieve serial data from the pc and respond to specific commands.

Part 2 will cover how to send commands to the arduino from a python program.
Рекомендации по теме
Комментарии
Автор

Finally I find a video with someone using a variable for high low.

dannyhd
Автор

I used serial.peek() just in case you wanted to check for multiple commands.. I wrote this code for use(before this simplified version) I prefixed different commands with different characters and if you used Serial.read() then the next check wouldnt work... really it all depends how the person writing it prefers to write the code :p

as far as serial.flush goes I didn't want to confuse anyone to as what it was doing also there is mixed info out there whether or not it even works properly.

Dreded
Автор

I need to find a way to capture the oscillation point of a moving object.
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
Автор

is there any way by which i can give it 3 different integers and it can store them and act accordingly ? imagine if i want to move 3 different steppers to 3 different locations.

guardiangamer
Автор

Thanks for the tut.. 2 questions: why did you use serial.peek() == 'c' instead of serial.read() == 'c' ? Also, why not flush the buffer with serial.flush() ?

sosaj
Автор

Dude, excellent tutorial, I have a question for you, I don't know if it's possible but bare with me. I have a machine at my house with an eproom and it has a system in it. I want to play around it. could it be possible if instead of seeing the data on the monitor I can see it on my arduino console?

brolysmash
Автор

Thank you very much for this tutorial! Works like a charm :)

Question: is it possible to print a word instead of a letter? I would like it to print "Lights" instead of "C".

glennfeldt_
Автор

no variable to parse 0 on input, because initial state of diode are 0 and that is defined in "(Serial.available() > 0) "

zlackbiro
Автор

hi sir is it posible to make the arduino listening to the serial value printed not inserted
for example :
Serial.print("on");
if(serial.print="on"){
digitalWrite(led, HIGH);
}
is it possible sir, sorry it was just a simple way to show what I want to do but i'm sure it is not the proper code to command it

francilliasoazara
Автор

Hello, i was hoping you could help me with something, i have my arduino connected to my router through Tx, Rx and Gnd. i have a html file stored on the router and that works with 2 .cgi files. one for ON and one for OFF. the idea is that when one visits the html site on the router, they will get those 2 buttons. Those buttons must turn a led connected to the arduino ON or OFF. im having trouble with the arduino knowing what to do with the commands. any ideas?

sonyshot
Автор

Amazing, so much info in just 4 min, and what the fuck is ACCSII code, didn't know it needs to be learn in order to code for higher level languages

ivanfaye
Автор

using if and while for the same condition is redundant.
a simple
 while (Serial.available() > 0) 
  {
     msg+= char(Serial.read());
   
no if needed

kozage
Автор

Hello.
I tried your code to send char to a lcd display but i get 5 vertical bars at the end of each print.
How can i fix this?

dalewhitmore
Автор

Thanks for this! great tutorial, hope you keep them coming XD

AlexLPD
Автор

I can't clear the buffer... The flush AND your method don't work !! :(

SwainixFPV
Автор

спасиб, тебе, русских туториалов чо-т совсем на горизонте не видно)..

kabanpunk
Автор

man all these people asking for help in the comments, it's on every
arduino video, and it's kinda annoying.

forloop
Автор

I need to find a way to capture the oscillation point of a moving object.
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
join shbcf.ru