Cécilia Facca in MATLAB Answers
上次活动时间: 2024-7-29

Hello :) This is my first big project using Arduino components, so I don't really understand everything, that's why I encounter so many difficulties. My goal is to send data from my ultrasonic sensor (HC-SR04) to Thingspeak using an Arduino UNO and a GSM SIM800c. Material : Arduino UNO ; GSM SIM 800c shield (https://www.eagle-robotics.com/accueil/257-shield-sim800c-arduino.html) ; Ultrasonic sensor (HC-SR04) ; Cables for my ultrasonic sensor ; Cable to connect my Arduino to my computer. I want to send data to Thinspeak from everywhere, so I can't use Wifi. I found a solution on google : https://github.com/707amitkumar/Send-Data-on-cloud-using-gsm-800c/blob/main/gsmangthingspeak.txt In order to send data to my channel on thingspeak, I did use the code mentionned on the link and I just changed the part concerning the data to send (because I want to send data from my ultrasonic sensor) : #include <SoftwareSerial.h> SoftwareSerial gprsSerial(7,8); #include <String.h> #include <HCSR04.h> const int trigPin = 2 ; const int echoPin = 3 ; UltraSonicDistanceSensor distanceSensor(trigPin, echoPin) ; void setup() { gprsSerial.begin(9600); // the GPRS baud rate Serial.begin(9600); // the GPRS baud rate delay(1000); } void loop() { float distance = distanceSensor.measureDistanceCm(); Serial.print("Distance = "); Serial.print(distance); Serial.println(" cm"); if (gprsSerial.available()) Serial.write(gprsSerial.read()); gprsSerial.println("AT"); delay(1000); gprsSerial.println("AT+CPIN?"); delay(1000); gprsSerial.println("AT+CREG?"); delay(1000); gprsSerial.println("AT+CGATT?"); delay(1000); gprsSerial.println("AT+CIPSHUT"); delay(1000); gprsSerial.println("AT+CIPSTATUS"); delay(2000); gprsSerial.println("AT+CIPMUX=0"); delay(2000); ShowSerialData(); gprsSerial.println("AT+CSTT=\"tango.lu\"");//start task and setting the APN, delay(1000); ShowSerialData(); gprsSerial.println("AT+CIICR");//bring up wireless connection delay(3000); ShowSerialData(); gprsSerial.println("AT+CIFSR");//get local IP adress delay(2000); ShowSerialData(); gprsSerial.println("AT+CIPSPRT=0"); delay(3000); ShowSerialData(); gprsSerial.println("AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",\"80\"");//start up the connection delay(6000); ShowSerialData(); gprsSerial.println("AT+CIPSEND");//begin send data to remote server delay(4000); ShowSerialData(); String str="GET https://api.thingspeak.com/update?api_key=F2WFEAUL58M062LM&field1=0" + String(distance) ; Serial.println(str); gprsSerial.println(str);//begin send data to remote server delay(4000); ShowSerialData(); gprsSerial.println((char)26);//sending delay(5000); //waitting for reply, important the time is base on the condition of internet gprsSerial.println(); ShowSerialData(); gprsSerial.println("AT+CIPSHUT"); //close the connection delay(100); ShowSerialData(); } void ShowSerialData() { while(gprsSerial.available()!=0) Serial.write(gprsSerial.read()); delay(5000); } When I run this code to my Arduino, I notice 2 problems : The piece of information is "sent" to my Thingspeak Channel but it doesn't match with the data sent from my sensors (It always show "0" on Thingspeak while the sensor sends a positive value : 2. I can notice that my code doesn't run as well as expected because the Serial Monitor dislay this : I really don't kow what to do... And I thank you in advance for any help you may give me. I hope my english is not so bad and you cand understand me :) I wish you a good day, Cécilia.
Hsu Yung-Cheng in Discussions
上次活动时间: 2024-2-23

When I embed Matlab windows into C#, I use C# to call the mouse functions such as drawline() and getpts() which are encapsulated in Matlab's dll, and then the program crashes, how can I solve this problem? ps : The functions that I call in C# can be executed in Matlab. ps : If I don't embed the window into C#, but just let C# call the Matlab function, it can execute the mouse control normally in the window, but once embedded into the C# window, it will crash when execute the mouse command. Encapsulating Matlab's Mouse Control Functions for C# I think I know why. It's because it conflicts with the C# UI thread. So I will try to call it in an asynchronous way I solved this problem by using an asynchronous thread (async). The reason it happens is that it gets stuck with the C# UI thread. matlab c

关于 ThingSpeak

The community for students, researchers, and engineers looking to use MATLAB, Simulink, and ThingSpeak for Internet of Things applications. You can find the latest ThingSpeak news, tutorials to jump-start your next IoT project, and a forum to engage in a discussion on your latest cloud-based project. You can see answers to problems other users have solved and share how you solved a problem.