Hello guys, I am trying to do esp8266 12-E model with ultrasonic sensor and running the below code:
#include "thingProperties.h"
// Define the pin connected to the SIG pin of the sensor
#define ULTRASONIC_PIN D7
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
// Wait for a successful connection
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
// Set the ultrasonic pin
pinMode(ULTRASONIC_PIN, OUTPUT);
}
void loop() {
ArduinoCloud.update(); // This function must be called periodically to send and receive data from Arduino IoT Cloud
// Measure distance
long duration;
float distanceValue;
// Send a 10us HIGH pulse to trigger the ultrasonic sensor
pinMode(ULTRASONIC_PIN, OUTPUT);
digitalWrite(ULTRASONIC_PIN, LOW);
delayMicroseconds(2);
digitalWrite(ULTRASONIC_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(ULTRASONIC_PIN, LOW);
// Switch the pin to input mode to read the echo pulse
pinMode(ULTRASONIC_PIN, INPUT);
duration = pulseIn(ULTRASONIC_PIN, HIGH);
// Calculate the distance in centimeters
distanceValue = duration * 0.034 / 2;
// Update the property in the Arduino IoT Cloud
water = distanceValue;
// Print the distance to the Serial Monitor
Serial.print("Distance: ");
Serial.print(distanceValue);
Serial.println(" cm");
// Wait a bit before measuring again
delay(1000); // Adjust the delay as needed
}
/*
Since Water is a READ_WRITE variable, onWaterChange() is
executed every time a new value is received from IoT Cloud.
*/
void onWaterChange() {
// Add your code here to act upon Water change
Serial.print("New value from cloud: ");
Serial.println(water);
}
and getting error below:
Flashing with command:{runtime.tools.esptool.path}/esptool -vv -cd nodemcu -cb 115200 -cp /dev/cu.usbserial-0001 -ca 0x00000 -cf /var/folders/yz/7bmrjzdn03gdvm8dcz5hzw7r0000gn/T/arduino-create-agent1171049788/Untitled_aug02a.bin
Start command: fork/exec {runtime.tools.esptool.path}/esptool: no such file or directory
Hi @raghav_2501. Unfortunately there is currently a bug in Arduino Create Agent that makes it impossible to for macOS users to upload to ESP8266-based boards from Arduino Cloud:
If you have a GitHub account, you can subscribe to that thread to get notifications of any new developments related to this subject:
Hopefully the Arduino Create Agent developers will fix the bug soon. Until then, you should use Arduino IDE instead of Arduino Cloud. The download links for Arduino IDE are listed here:
After installing Arduino IDE on your computer, follow the instructions here to add support to Arduino IDE for your ESP8266 board:
You can use Arduino IDE to develop and upload your Arduino Cloud IoT Thing sketch. Arduino IDE even has a convenient Arduino Cloud sketchbook integration that allows you to open any of the sketches from your Arduino Cloud account in Arduino IDE. You can edit the sketch code in Arduino IDE, upload the sketch to your board, and push any changes you made to the sketch back to your Arduino Cloud account. There is a tutorial for using this Cloud sketchbook feature of Arduino IDE here:
I have an update to share on this subject: The bug has been fixed and the fix is now released in version 1.6.1 of Arduino Cloud Agent. Arduino Cloud Agent will automatically self-update to the new version the next time you use Arduino Cloud while Arduino Cloud Agent is running.
Once the update has been completed, you can upload to ESP8266 boards from Arduino Cloud and the workaround of using Arduino IDE will no longer be necessary.
Please let us know if you still encounter any problems using Arduino Cloud.