Тёмный

Connect And Use Arduino Via Serial Library In C++ Software | Works With Any IDE! 

Learn with Sciengit
Подписаться 349
Просмотров 43 тыс.
50% 1

Опубликовано:

 

22 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 150   
@muneebmuzammal3987
@muneebmuzammal3987 3 года назад
100% Working code! If you got an error in the serial port ("a value of type "const char *" cannot be used to initialize an entity of type "char *"") just do a minor change in code: In your main.cpp the line that you make the pointer to the part, char *port = " ////.//COM3 "; declare it as char port[ ] = " ////.//COM3"; And InshaAllah you're problem will be solved.
@tomasfederico1247
@tomasfederico1247 3 года назад
i love you bro, you saved me
@peterraeth4963
@peterraeth4963 3 года назад
Truly Superior!! Many thanks for this clear example and explanation. Two Subtle Points: Given my Windows 10 setup with Visual Studio 2019 Community IDE, communication between the PC and the UNO is rather slow. It may be possible to use a faster rate than 9600. Did not try that. However, I did add a Sleep(500) line before attempting to receive a response at the PC from the UNO. This relieved what are essentially non-responses. Also found that longer and shorter messages can cause garbage to be displayed at the PC. This came about because I modified UNO's code to deliver a message when an unrecognized response occurred. For this reason, prior to receiving a response at the PC, I filled the output vector with '\0'. That solved the problem with garbage being in that buffer.
@aplacefaraway
@aplacefaraway 4 года назад
It's amazing how many bad examples are out there. But this is the best one I've seen. Great job! You should post this on more forums to help people.
@Sciengit
@Sciengit 4 года назад
Thanks for your kind words.
@rfdave3980
@rfdave3980 3 года назад
This is great. You have shown how to read and write to the serial port. I search and could not find such a valuable tutorial. Thank you Mr. Mustafa
@jeffegg2
@jeffegg2 6 лет назад
char *port = "\\\\.\\COM3"; This is giving me a warning that you can't assign a char* a constant. I changed it to: char commport[] = "\\\\.\\COM6"; char *port = commport; and it accepted this.
@estonia77
@estonia77 5 лет назад
Of course, you wrote char port instead of char *port , so technically you were indeed trying to assign a string constant to a single char.
@Johnybbrown
@Johnybbrown 4 года назад
This was totally helpful for my personal arduino project. I now have communication between C++ and arduino. Works in Code Blocks IDE. Only one depricated line and fixed it from the comments here. Great work
@JoaoF_CS
@JoaoF_CS 5 лет назад
Thanks for this video, it was one of the simplest and easy to follow resources on the topic.
@AshrafulHussainKhan
@AshrafulHussainKhan 2 года назад
As per your introduction "How to process information which Arduino can't. Eg. Camera information". For your example actually I have to keep the PC connected to obstacles avoider and walk along with the device as the processing will happen on the PC. Are you suggesting this? If someone want to use a camera for image processing why don't you think people will not use the host system directly to connect the camera instead of the Arduino there. Anyways, great effort.
@Sciengit
@Sciengit 2 года назад
For example drones tethered to the on ground control station (can be a PC) via a cord. The host system on ground can ask Arduino to trigger the camera and get other on board sensor data. Such info can be dispatched back to the host. Similarly the host can ask servos on the drone to adjust the orientation of the camera or point it towards a certain direction. Such drones are typically used to quickly capture a scene while getting power from the ground as well. No batteries on a drone results in less weight and less thrust. Meaning such drones can be used in surveillance and can stay up for quite a long while.
@rodrigogrego5762
@rodrigogrego5762 2 года назад
Thanks. You are a great programmer, congratulations. From, Brazil.
@AsdfirePL
@AsdfirePL 5 лет назад
Actually works unlike other code thats supposed to work according to the author.
@mistykal
@mistykal 2 года назад
Hi, good tutorial. I able to get something but the string print as some weird character. Did I miss something? Edit: nvm. figured it out. change the baud solve the issue. 115200 -> 9600
@TheMasterScotty
@TheMasterScotty 5 лет назад
Hi, first things first, great Video and nice explanation! But when the commands "ON" and "OFF" come very soon after each other, there is no recognition on the Arduino side, this means the LED doesn´t switch the status. Have you any idea why this could be the case?
@jesustomas6105
@jesustomas6105 5 лет назад
Thanks man, I am actually doing my dissertation and this video has helped me a lot.
@ahmednouman9871
@ahmednouman9871 3 года назад
Does this work if I run it from Unix say Ubuntu and setting the right port number "/dev/tty..." ?
@Sciengit
@Sciengit 3 года назад
Yes it will. You just need to change port. Sorry for late reply but I am really really busy these days.
@Bouncy_Hippo
@Bouncy_Hippo 3 года назад
Hi, thanks so much for this video, its really helpful! What would be the best way to edit the code to read a continuous stream of data like something from an accelerometer? Thanks!
@lamphanvan6049
@lamphanvan6049 2 года назад
Hey. Thank you for excellent video. I want to receive integer value instead string and i have used atoi() to convert from string to integer. However, I met a problem. If we send string "123", it will show on console as "123" , but then if we send string "23", it shows as " 233". How can I display as "23" when previously sent "123". Please help me, thank you very much.
@NoName-mr1lh
@NoName-mr1lh 5 лет назад
Thanks for the video. Id like to write a c++ app to control a commercial radio or test equipment by sending commands over a serial cable or usb with fdti cable. Please can you tell me if I need to include any delays or error checking when sending commands or receiving data from the radio? Thank you.
@Chezburger8
@Chezburger8 4 года назад
Getting a variable 'SerialPort::errors' is uninitialized in the .cpp
@maczajsci7080
@maczajsci7080 4 года назад
Also, unlike many others, the code actually works here
@sodiko100
@sodiko100 4 года назад
Hello, I am having a problem with your code. I've downloaded it from GitHub and opened it in visual studio code and made sure my comport number is correct, it connects successfully but can not control the led. when I send "ON" for the first time nothing happens but it returns on the console a weird output of 2222. I have no idea what that means. Please help
@maczajsci7080
@maczajsci7080 4 года назад
Thank you very much. This is an excellent video which really explains the individual concepts perfectly.
@mauriziobuzzolo3386
@mauriziobuzzolo3386 4 года назад
Do you connect a RS232 or a USB port on pc side ?
@danieltadla1012
@danieltadla1012 6 лет назад
What a fantastic video. You teach very well. How can this be modified to send and receive floats instead of strings?
@Sciengit
@Sciengit 6 лет назад
Daniel Tadla Thanks for your feedback. Do all your calculations and everything in float and cast it to string just before sending.
@aidensmith6277
@aidensmith6277 5 лет назад
char myString[4] = (char*)(&myFloat) char myString[4]... this creates a string with 4 bytes in it ...(char*)... this casts the following pointer into a char pointer ...(&myFloat) this gets the pointer to the float you want to send. Basically, it puts the 4 bytes that make up your float into a string. The receiver receive the float as a string, so you'll have to convert it back.
@huistv2005
@huistv2005 3 года назад
Thanks for the tutorial and code. Can you point me in the right direction on how to read from the arduino using 'readSerialPort'? I want my program to read a string if a button is pressed on the arduinop side. I can see the string already but how to check the stream? thx edit. I found out myself by setting a string object equal to output. Thanks
@mozarellachan5854
@mozarellachan5854 2 года назад
any tutorial on how to read and store data from Arduino into C++ program to be processed?
@Quarkee
@Quarkee 2 года назад
Hey idk if you'll see this but do you happen to know why the data that's sent to the serial buffer *via* the SerialPort header contains a bunch of garbage and extra null characters? Because when I tried to send some other type of data types like numbers e.t.c the Arduino would read a bunch of \0 which messed up the output... *Edit:* I messed up and forgot to change "MAX_DATA_LENGTH" to the size of the data I'm sending. So I just swapped that to "data.size() +1"
@Sciengit
@Sciengit 2 года назад
Hi. Did you try this: forum.arduino.cc/t/how-to-send-numbers-from-one-arduino-to-another-using-serial/97066 ?
@Quarkee
@Quarkee 2 года назад
@@Sciengit no, but I solved it. My bad for not editing the original comment. Nice video though!
@Sciengit
@Sciengit 2 года назад
@@Quarkee great 👍 and thanks for the edit. Others might need it 😄
@levamento
@levamento 6 лет назад
best video i‘ve found to this topic! i like the way you sound when speaking english! 🙊
@Sciengit
@Sciengit 6 лет назад
levamento Thanks 😀
@aquarealtime4408
@aquarealtime4408 6 лет назад
When I try to compile this in MSVS 2013, I get the error: Error 1 error C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators' d:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility 2132 1 PC-Serial-Comms I tried adding in // Try to get rid of the damn C4996 error: #define _SCL_SECURE_NO_WARNINGS #pragma warning(disable:4996) But the error is still there. How to fix?
@harunlisic
@harunlisic 5 лет назад
is there a way to detect whether arduino is connected to computer's USB port or to battery bank, if it's connected to computer's usb port let it RUN the program, else do nothing. ?? something like Serial.available() but more like USB.available() // which doesn't exist.
@Sciengit
@Sciengit 5 лет назад
Hi. I made something of that sort in Python GUI. Here is the link: github.com/ZainUlMustafa/Spectrometer-GUI-Project
@mrwolf2758
@mrwolf2758 5 лет назад
hi thank you for this video but what if i want to make the communication via bluetooth (am new to this so am kind of lost any help will be amazing ) i want to make a c++ app that recieve and send data via bluetooth to or from arduino
@alexspencer8708
@alexspencer8708 3 года назад
Is there any way of speed up the writeSerialPort? I have been using this with openCV to balance a ball on a beam and was wondering if there is a way to speed up the writeSerialPort function to be faster than 1 second otherwise it doesn't send any data help please
@exmachina2600
@exmachina2600 3 года назад
The arduino has a default serial timout of one second. You can change it to a tenth of a second by adding "Serial.setTimeout(10);" to void setup()
@rccar1515
@rccar1515 4 года назад
Great video; thank you! It's the first time that I arrive at accomplishing a serial connection to my Arduino! However I try to send commands to "GRBL" (a motion controller for CNC) and I don't get consistent results. When sending a demand, the first operation seems to be well executed but not the whole "answer" is printed in the terminal. When sending another command apparently there rest fractions of the last command that where shown. WHY?
@tomasfederico1247
@tomasfederico1247 3 года назад
to send commands i recommend you to use PuTTy
@egemenertem3166
@egemenertem3166 Год назад
In the main, try changing cout
@renanbfo3785
@renanbfo3785 6 лет назад
great my dude, it seems every good tutorial i find is made by an indian guy, not sure what this means but thanks for the help anyways
@renanbfo3785
@renanbfo3785 6 лет назад
also i don't get where i say what my command is
@Sciengit
@Sciengit 6 лет назад
We appreciate your feedback.
@phillbon3457
@phillbon3457 4 года назад
​ Sciengit can u attached this to a Xamarin.Forms cross platform app, with buttons?
@phillbon3457
@phillbon3457 4 года назад
Keeping in mind the UI with buttons is built in C#?
@Sciengit
@Sciengit 4 года назад
Hey Phill. My suggestion when you are working to link mobile app with Arduino sensor data is to use some sort of database in between (like Firebase). Arduino will upload data to Firebase and mobile will retrieve data from Firebase. This probably is the easiest, robust, and wireless solution (basically IoT stuff)
@alexjimenez6020
@alexjimenez6020 2 года назад
Thank you Sir! Very helpful video!!
@jesusgarciamartinez8555
@jesusgarciamartinez8555 6 лет назад
Hello, i've a code problem in the .cpp file of Visual Studio. At the line char *port = "\\\\.\\COM3"; It says i cant use a "const char*" value as initialization of a entity type "char*". What can i do?
@Sciengit
@Sciengit 6 лет назад
Replace char *port with char port[]
@manuellonic8952
@manuellonic8952 3 года назад
Error on char *port = "\\\\.\\COM3"; a value od type "const char *" cannot be used to initialize an entity of type "char *" I would appreciate some help here
@KiemPlant
@KiemPlant 2 года назад
I know this is a late response but for anyone having this issue, you can simply cast it to a char* with (char*) char *port = (char*)"\\\\.\\COM3";
@lukewalker6961
@lukewalker6961 2 года назад
@@KiemPlant Thank you!!! this is what i needed
@lukewalker6961
@lukewalker6961 2 года назад
Still doesn’t work but at least I don’t have any compiler errors
@KiemPlant
@KiemPlant 2 года назад
@@lukewalker6961 Yeah the library ended up not working for me either if I recall correctly. My problem wasn't with the COM port but it just didn't function. I eventually found a C# library and used that to make a windows forms app and it worked perfectly for me.
@m.muzammilbabar4375
@m.muzammilbabar4375 4 года назад
Thank you Boy! I got an error on port name. But it worked perfectly fine in "Release Mode".
@michaeldungo2141
@michaeldungo2141 6 лет назад
What if the data is from visual studio consule to arduino? How can I send the data that is not from typing it but data that is from the loop of consule and what code will I use?
@Sciengit
@Sciengit 6 лет назад
Michael Dungo Hi there. You can make an array of strings with instructions ON OFF or something like that. Make a loop and add the message sending and receiving part inside that loop. Now send every element of the array to the Serial Port (Arduino) and get the response back. Do let me know if you got it right. -Zain
@michaeldungo2141
@michaeldungo2141 6 лет назад
Sciengit Do you have sample codes for that? thanks
@Sciengit
@Sciengit 6 лет назад
Michael Dungo Sorry but I don't have it. Try yourself though and keep me updated with what you come up with
@dc9852
@dc9852 2 года назад
Will this serial library work on Linux?
@Sciengit
@Sciengit 2 года назад
Yes. The only thing you need to check is the port name.
@dc9852
@dc9852 2 года назад
@@Sciengit But we are using windows.h to make this library. How will it work in Linux? Are you sure?
@bernd24
@bernd24 5 лет назад
what if i use another BAUD-Rate? can i just change "CBR_9600" to "CBR_115200" in your cpp?
@TheMasterScotty
@TheMasterScotty 5 лет назад
Yes. You have to change it in the Arduino project and in your VisualStudio project.
@teddyhraje5117
@teddyhraje5117 3 года назад
Helo, i have a problem with initializing the port, it gives me this error: a value of type "const char*" cannot be used to initialize an entity of type "char*" My line looks like this: char *port = "\\\\.\\COM3";
@tomasfederico1247
@tomasfederico1247 3 года назад
same here bro, did you find a solution?
@kostor222
@kostor222 6 лет назад
+sciengit For some reason, when sending a command again I get the following: Connection made Enter your command: ON >> ON Enter your command: ON >> ²²²²▌▌▌ How can this be dealt with? Arduino code: void setup() { // put your setup code here, to run once: Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: if (Serial.available() > 0) { String info = Serial.readStringUntil(' '); Serial.println(info); } } Changes I made to original CPP: Using COM5 instead of 3.
@kostor222
@kostor222 6 лет назад
@scuengit
@kostor222
@kostor222 6 лет назад
never mind, solved it
@beginner687
@beginner687 5 лет назад
@@kostor222 How did you solved it?
@kostor222
@kostor222 5 лет назад
@@beginner687 make sure you have stop symbol in the command
@beginner687
@beginner687 5 лет назад
@@kostor222 Sorry I am new to serial communication. Can you please explain to me about what type of command should I have and in what side of code ie (Arduino or C++)? Thanks !
@kolopolo2035
@kolopolo2035 2 года назад
how you can use the data sent from Arduino? I mean that "Led iS OFF" for example to store it?
@Sciengit
@Sciengit 2 года назад
Hey, I know it's pretty late but can you explain what do you mean by storing the result?
@AB-mf3gk
@AB-mf3gk 2 года назад
@@Sciengit To have a file for example which has inputs coming from the Arduino stored in it?
@by2love2020
@by2love2020 5 лет назад
Hi, I having a error on "////.//COM3". Did you know what is the problem?
@_APOGEE
@_APOGEE 5 лет назад
everything is fine.
@kyrillosessamanpey5041
@kyrillosessamanpey5041 5 лет назад
hi, i need link for this package please. I copied the link in the video but it doesn't exist.
@miraldizgrodnii8784
@miraldizgrodnii8784 4 года назад
Thank for your job. Its great!
@jayemersoncruz5369
@jayemersoncruz5369 6 лет назад
I did this but the program shut down immediately, what do you think is the problem? thanks
@Sciengit
@Sciengit 6 лет назад
Jay Emerson Cruz May i know if you are using the same IDE as I am?
@jayemersoncruz5369
@jayemersoncruz5369 6 лет назад
I already made it. It's running. But how can I send data and not char? Please help me.
@jayemersoncruz5369
@jayemersoncruz5369 6 лет назад
I need to send data in a programmable time interval.
@Sciengit
@Sciengit 6 лет назад
Jay Emerson Cruz Does your data means information in another data type like integer, float etc. If yes, you can only send char in serial monitor/console. you will have to cast the information from char to your desired data type in Arduino IDE. Please let me know if I answered your question. ☺
@jayemersoncruz5369
@jayemersoncruz5369 6 лет назад
Sciengit thank you, i get your point. But how can i convert my info(int) into char? I tried to use if statement like if (x=0){ char data = "ON";} but nothings happen. I badly needs your help. And thank you for that.
@NghiaTran-be7gn
@NghiaTran-be7gn 4 года назад
thanks so much. this video so helful
@joseecalderongarnier915
@joseecalderongarnier915 6 лет назад
Is this not same as using FIRMATA?
@Ninjacat9000Ilovebigfloppa
@Ninjacat9000Ilovebigfloppa Год назад
Thank you
@aliefekarakascv1391
@aliefekarakascv1391 5 лет назад
amazing tutorial thank you so much
@-highvoltage4685
@-highvoltage4685 3 года назад
why you have stopped making videos?
@Sciengit
@Sciengit 3 года назад
Interesting question. I started Sciengit as a fun idea while in my engineering university but after graduation I got involved with other products which does not mean Sciengit was gone. In fact I still try to make sure channel is up and website is running fine. However, Sciengit has become a subsidiary of a tech company, Ejaarat.com (which I co-founded). Currently we are raising funds there and trying to set it up for a year now (which might answer the 2 years of not producing any new content). We are hoping to get some funds and allocate some for Sciengit that can allow me to gather its team and start with production again and also making sure Sciengit remains a free platform (the foundations on which I created this in the first place). Hoping for good times.
@peerlessrecords6236
@peerlessrecords6236 2 года назад
doesnt work. cannot convert from const char [9] to char *
@XknotAlpha
@XknotAlpha 6 лет назад
I'm getting an error that says " a value of type void * cannot be used to initialize an entity of type "char *" "I know that this is in reference to what your line[8] is. I don't understand why I'm getting this error. thank you
@Sciengit
@Sciengit 6 лет назад
XknotAlpha Can you tell me which line is causing this error?
@XknotAlpha
@XknotAlpha 6 лет назад
hi i figured it out. Error[1] no longer use #include ............now u must use #include Error[2] in your main.cpp the line that you make the pointer to the part. char* port = " ////.//COM3 "; need to declare as char port[ ] = " ////.//COM3"; Error[3]: after the decleration was made correctly i got an error that said. d_scl_secure_no_warnings so i googled : d_scl_secure_no_warnings visual studio 2013 then got to this SUPER helpful stack overflow link: stackoverflow.com/questions/25046829/what-does-use-d-scl-secure-no-warnings-mean? i followed the steps and now we're in business. thank you for the response I appreciate it. Have an excellent weekend! -M
@Sciengit
@Sciengit 6 лет назад
XknotAlpha Thank you for pointing these out. I still don't know why these problem might be occuring but your solution is another way to put up this code. 👌
@XknotAlpha
@XknotAlpha 6 лет назад
would you like me to e-mail you my main.cpp? or I can just up load and send you a link to the script?
@Sciengit
@Sciengit 6 лет назад
XknotAlpha We would love it if you share us with anything. Email us on: sciengit@gmail.com
@PanPuszekMechanik
@PanPuszekMechanik 7 лет назад
What if arduino connects on another COM? How can I find which COM is currently connected to Arduino?
@Sciengit
@Sciengit 7 лет назад
I3lood There are many ways to check. However, if you are using Windows then watch this video ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-mTbv9dpSEoI.html You need to Google for port name if you are working with Mac or Linux. ☺
@PanPuszekMechanik
@PanPuszekMechanik 7 лет назад
Alright, but if I reconnect Arduino with PC it may change right? And I want create App that talks to Arduino but at first I need to know how to find right COM by code, thanks for advices :)
@Sciengit
@Sciengit 7 лет назад
I3lood Actually, com port name doesn't change if you are using your Arduino with the SAME PC regardless of how many times you reconnect. It will change though if you want to build an app that runs on multiple PCs. For such a purpose, you need to write an additional code that recognizes the port name automatically. I wrote a code for this very purpose in Python but currently not getting time to make a video on that. You can check out my github spectrometer project that has such port name recognizer code integrated, if you want to. ☺
@exmachina2600
@exmachina2600 3 года назад
Does anybody know how to send ints over serial? Need to send coordinates like "X614Y98" to my Arduino.
@Sciengit
@Sciengit 3 года назад
You should send "614,98" in string and on Arduino split the string using ',' which will return you an array of 2 string elements. Simply cast them to int. I always would prefer sending strings over any other data type since it's predictable and less prone to errors on sender side.
@exmachina2600
@exmachina2600 3 года назад
@@Sciengit Wont all of the numbers get converted into nonsense when you convert the string into an array of chars before sending your command over serial?
@vini9598
@vini9598 2 года назад
What does \\\\. \\ do ?
@Sciengit
@Sciengit 2 года назад
Consider it like an escape sequence.
@buddytrainers6007
@buddytrainers6007 5 лет назад
Can i coonect my sms sending device using the same mathedeolgy?
@dronemansk2121
@dronemansk2121 5 лет назад
For some reason, it doesn't let me execute the code...
@Sciengit
@Sciengit 5 лет назад
Please check the comments, I think you must have the same problem as most
@rishabhsstudio1457
@rishabhsstudio1457 3 года назад
awesome bro !!!!!!!
@Sciengit
@Sciengit 3 года назад
Thanks ✌️
@demnyan
@demnyan 4 года назад
Thanks you)))
@tomascarrasco371
@tomascarrasco371 6 лет назад
amazing video ma dude
@楊佑國-g7k
@楊佑國-g7k 3 года назад
I LUV U
@Splatschi
@Splatschi 6 лет назад
So this works for any IDE, I guess?
@Sciengit
@Sciengit 6 лет назад
Yes. C++ syntax is the same for every IDE
@phillbon3457
@phillbon3457 4 года назад
​@@Sciengit can u attached this to a Xamarin.Forms cross platform app, with buttons?
@itsMaxPower159
@itsMaxPower159 6 лет назад
Hello, I have this error that says: (const char [9])"\\\\.\\COM4" a value of this type "const char" cannot be used to initalize an entity of type char*" I tried everything, but I can't get it fixed. :(
@Sciengit
@Sciengit 6 лет назад
Sorry for the late reply, been very busy lately. try char *port = \\\\.\\COM4
@juniqbeatz1323
@juniqbeatz1323 2 года назад
doesn't work at all!
@sadiqsamaila5947
@sadiqsamaila5947 5 лет назад
\\ it's just a comment
@andrez383
@andrez383 3 года назад
//
Далее
USB COM Ports in C++
35:42
Просмотров 33 тыс.
Arduino GUI Part 1   Communications
19:44
Просмотров 155 тыс.
#kikakim
00:17
Просмотров 8 млн
Coding a Web Server in 25 Lines - Computerphile
17:49
Просмотров 340 тыс.
Emulating a CPU in C++ (6502)
52:28
Просмотров 994 тыс.
BEST WAY to make Desktop Applications in C++
26:00
Просмотров 925 тыс.
Arduino Interrupts Tutorial
9:30
Просмотров 295 тыс.
How is this Website so fast!?
13:39
Просмотров 510 тыс.
Vim Tips I Wish I Knew Earlier
23:00
Просмотров 72 тыс.
Writing Code That Runs FAST on a GPU
15:32
Просмотров 563 тыс.