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.
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.
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.
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
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.
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.
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
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?
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!
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.
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.
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
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.
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
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"
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?
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.
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
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
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?
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)
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?
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
@@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.
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?
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
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";
+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 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 !
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. ☺
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.
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.
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
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
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. 👌
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. ☺
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 :)
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. ☺
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.
@@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?
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. :(