Hot answers tagged

9

Here is an analogy for you to help you understand why using the IRQ is a good idea. Imagine you are at a conference. There's hundreds of you in the audience, and you are in a question and answer session with the person on the stage. Maybe their presentation has just come to the end and they're fielding questions from the audience. Lots of people have ...


6

I was able to resolve my issue thanks to Juraj comment. I did : Wire.begin(16, 17); htu21d.begin(Wire);


6

To achieve what you want you probably want to use the "string format time" function strftime (docs). You would write the result in a character buffer, which you can also print directly without having to convert it to String object. So, the following code should work: void printLocalTime() { time_t rawtime; struct tm timeinfo; if(!getLocalTime(&...


6

The String object created as return from IPAddress.toString() as parameter to constructor of NtpClient is temporary. It contains the char array returned by c_str(). NTPClient doesn't copy the string, only stores a reference to it. And the referenced string (char array) doesn't exist at the time the NTPClient wants to use it. class TestClass { public: ...


5

Assuming that each separate hardware device (ESP32?) must run self-contained with both the fundamental parts, and the use-specific parts, then you would do well to separate out the fundamentals into a library, and then include that library in each use-specific sketch. The Adafruit Unified Sensor Driver would be one project that shows this. Each of the ...


5

Since all you have is 2 bare wires, the water simply forms a resistor between them. You can use it as part of a resistive divider, with a fixed resistor between your analog input and +3.3V. The resistance between the wires will change from infinite (dry) to something much lower (wet) and the reading you get from the ADC will depict that. You will need to ...


5

It is very simple to set up a PWM signal at any frequency you desire, with any resolution you desire, provided you don't exceed the maximum 'bandwidth': the frequency multplied by the resolution must be less than half the clock speed of the device. The full explanation with relation to the ESP-IDF is available here. The article explains the intricacies of ...


5

Code using the Arduino Wire library is generally portable between processors, but there are pitfalls to watch for. One that I'm aware of is a difference in the Wire libraries for the ESP32 and ESP8266. The TwoWire::begin() method for the ESP32 has prototype: bool TwoWire::begin(int sdaPin, int sclPin, uint32_t frequency); whereas for the ESP8266 it is: ...


5

The ESP WROOM32 is an ESP32, not an ESP8266. You have PlatformIO configured for an ESP8266, specifically the ESP12e, and there's no way that's going to work. You'll want something more along these lines: [env:espwroom32] platform = espressif32 To choose the board - if you're using a breakout board, you'll need to be more specific about it - what model is it?...


5

I take this to mean that you do not want to have to ask the user of the code to configure a boolean flag. The ESP8266 Arduino package provides -DARDUINO_ARCH_ESP8266 -DESP8266 command-line options these while calling g++. These effectively #define feature test macros as though they were at the beginning of the source code. For ESP32 it does likewise with -...


5

The best way to handle this exception is to identify what's using so much space on the stack and rewrite your code to avoid it. The three most common ways you'd use too much stack space are: large local variables - for instance, declaring a large array as a local variable inside a function, like: #define VERY_LARGE_STRING_LENGTH 8000 void loop() { char ...


4

Not an exhaustive list. Most advantages will be subjective. UECIDE - Wide variety of boards, not only Arduino, better editor and serial monitor, plug-in based modules. PlatformIO (Available as plugin for Atom editor, MS Visual Studio and Eclipse IDE) - Automatic library updating, one ini file that defines project settings and external libraries, making ...


4

I started writing this as a comment, but the more I wrote the more I needed space to complete my thoughts, so here it is as answer. In my opinion, reacting to a user interaction should NOT be put in ISR; consequently the best thing to do is to avoid the interrupt and poll that wire. IMHO interrupts need to be used in very few cases, and only when the ...


4

You should not power a motor from a micro-controller, period, regardless if that is an ATmega or an ESP32. Instead, you need to use a motor driver circuit - this isn't really so much about voltage amplification, as it is about current amplification. The actual I/O output voltage of your ESP32 is likely very close to 3.3v. If you are measuring 1.8v, that is ...


4

The NTP timestamp format doesn't use milliseconds. All timestamps are in seconds, in a 32.32 fixed point format. This means that the fraction field is in units of 2−32 s, or about 233 picoseconds. You can convert that to milliseconds by multiplying by 1000 and dividing by 232. For example: uint32_t frac = (uint32_t) packetBuffer[44] << 24 ...


4

String is included by Arduino.h. Before #include <Arduino.h> String is not defined. Move #include <Arduino.h> to the top of the file or remove it. If you remove it, the Arduino builder adds it.


4

Yes, that's the idea behind bus protocols like i2c. You only require the sensors on i2c to have different bus adresses. A sensor's address usually can be chosen by soldering a jumper (the mpu6050 provides this feature on pin AD0). If you can't avoid an address collision you could use an i2c multiplexer or a microcontroller in between the sensor and the ...


4

When the client sends you a request, you should answer only once. Your root() function attempts to answer twice whenever the request contains the argument “duty”. The client will not handle a duplicate response to a single request. Here is your root() function: void root() { iso(); ser.send(200, "text/html", iso()); // ← first response if (ser....


4

You have several options for controlling the sampling rate. Software only This is the simplest, and the previous answer got it almost right. Here is my take: const SAMPLE_INTERVAL = 500; // 500 microseconds void loop() { static unsigned long last_sample_time; if (micros() - last_sample_time >= SAMPLE_INTERVAL) { // note 1 ...


4

In principle yes (see also comment in update). The voltage is ok (5V), typically USB, and it doesn't differ from the output of a computer USB port. The output current is max 2000 mA, so check if your project (ESP + related hardware powered by this USB), is not exceeding 2000 mA. The ESP needs much less than 2000 mA, so if you didn't have a lot of external ...


4

What's your last error message? no matching function for call to 'PubSubClient::publish(const char [11], String&)' Read the documentation for the publish() method in PubSubClient: int publish (topic, payload) Publishes a string message to the specified topic. Parameters topic - the topic to publish to (const char[]) payload - ...


4

Those boards have an inherent weakness in that they don't provide enough decoupling capacitance for the module. Not all modules are quite the same, and some have more internal decoupling than others (not by design, just due to component tolerances). I have found that unless you provide adequate decoupling of your own some modules work just fine and some don'...


4

Well after I posted this question, I kept googling. Literally hours of googling at this point. Then I stumbled across this example: https://github.com/T-vK/ESP32-BLE-Keyboard I wrote that sketch to my ESP32, paired my iPhone and it immediately starting controlling music playback on my phone. After looking at the code, it's so simple that I'm embarrassed I ...


4

Thanks to @Majenko I was able to find what I was looking for on the internet from this link. When I googled "captive portal" instead of the phrases that I was using I found a lot more examples. This code opens a "captive portal" once I connect to the esp32 access point. #include <WiFi.h> #include <DNSServer.h> const byte ...


4

If you provide a password for you network, it will be encrypted. Thats the point of the password. When you look at the function description in the WifiAP.cpp file of the Wifi class for the ESP32, the description suggests, that it will be encrypted with WPA2, which is currently the standard in Wifi encryption. (Though that can depend on the actual library, ...


4

There are no programmers for ESP32. It only accepts Serial upload over bootloader. Versions of IDE before 1.8.13 displayed programmers for all board support packages, that is why a programmer could be selected. Now only programmers for package of the selected board are available. But programmers are used only with the "Burn bootloader" or "...


4

No. You're way off. If the output can provide 12mA at 3.3V that equates to (P=VI) 39.6mW. Boosting the voltages does not increase the power. Assuming a 100% efficient boost circuit (which does not exist) you would just be boosting to 12V at 39.6mW - which means (I=P/V) 3.3mA. You can't magic more power out of thin air - if you could we'd all have "free ...


4

As this image from Okdo Page on LED Driving shows, there are two ways to drive an LED from a GPIO output pin: In the Active HIGH case, a HIGH output on the GPIO will turn the LED on since that will source current out of the pin and through the LED into ground. In the Active LOW case, a LOW output on the GPIO will sink current from the +V supply into the pin....


4

As @timemage explains in a comment, you cannot pass a capturing lambda to a function that expects a plain pointer to function. There is, however, a way out of this: the Ticker class provides an overload of the attach() method that allows you to provide a parameter of any type to tour callback: template<typename TArg> void attach(float seconds, void (*...


4

Your problem is, that you try to provide a HEX value, but you are actually providing a decimal value. When you just write a whole number like 32, it will be interpreted by the compiler as a decimal number. The decimal number 32 is equal to HEX 20, which is a space character in ASCII. Solution: Write your number as decimal value like this: int i = 0x32; The ...


Only top voted, non community-wiki answers of a minimum length are eligible