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

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

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

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(&...


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 ...


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

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


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 ...


3

Here's a few tips on optimization. for(int index = 0; index <= framesRead; index++) { value = smappioSound.getSampleValue(index); if(index % 2 == 0) { serialBT.print(String(value) + ","); Serial.println(value); } } Doing serialBT.print(String(value) + ","); ...


3

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 ...


3

The better way to do it would be to set a volatile flag in the ISR and handle that in the main loop. This relies on you making sure the main loop never blocks so the flag can be check often. volatile bool isr_happened; void isr(){ isr_happened = true; } void loop(){ if(isr_happened){ //do i2c isr_happened = false; } }


3

I'm not familiar with this board, but according to this schematic: https://wiki.wemos.cc/_media/products:lolin32:sch_lolin32_v1.0.0.pdf U4 (one of the small 6-leg components) connects to IO0 (pin 25) on the ESP-32. The transistor inside U4 combines the RTS and DTR signals (from U6 USB-Serial converter IC, which will be the large IC marked SIL2104) to put ...


3

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 ...


3

Try doubles instead of floats. Your initial value, 34567891.234 needs 35 bits of precision to keep track of the decimals, but floats only have 24 bits pf precision. So to have enough precision to keep track of the difference between 34567891.234 and 34567891.234+1, you need higher precision storage. void setup() { // put your setup code here, to run ...


3

As already stated in comments and Dave X's answer, floats have a limited resolution. That resolution is given by the constant FLT_EPSILON, which is the difference between 1 and the smallest float larger than 1. On any system conformant to IEEE 754, FLT_EPSILON is 2−23, or about 1.19e-7. The implication is that, within the interval [1, 2], the real ...


3

No. It's as simple as that. No. Voice Recognition is a very very complex task. To do it fast and well in a "general" way takes a neural network, or a very powerful PC (note: all common ones now use online resources to do all the work). A voice recognition chip generally is pre-programmed to respond to specific words.


3

If you want to declare multiple variables with the same name inside different case statements, you can enclose the code inside each of them inside curly braces: case 1:{ Code... break;} case 2: ... The curly braces will set the limits for the variables scope to just this case.


3

Assuming you are using a 9V block battery: They don't deliver the current you need for the esp32 to run/create an access point/act as a client. What you can do is connect 6 AA batteries in a row (6*1.5V = 9V) and they will deliver a higher current than the 9V block.


3

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.


3

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....


3

There's a number of things to consider when choosing batteries. First is the capacity. In broad terms, the capacity is, mAh, means "This battery can supply X mA for one hour". So a battery of 1000mAh could supply around 1A (1000mA) for one hour before it goes flat. Simply divide the mAh by your device's mA and you get the time it will run for before it ...


3

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 ...


3

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 - ...


3

ARP isn't generally used the way you described. Per the spec, to resolve an IP address into a MAC address, you broadcast an ARP request for the IP address, and receive a unicast response from the host whose address it is - not a router. It also only resolves a single IP address in one request; it doesn't return the contents of the entire ARP cache. While ...


3

The function you are looking for is strstr(), which takes two strings, and returns a pointer to where the second string appears in the first (or NULL if it doesn't appear). You could use it something like this: void setup() { Serial.begin(15200); Serial.println("Load"); char *p = strstr(payload, "ssid="); char *q = strstr(payload, "pass=")...


2

I had to read until delimiter :D String receive() { String content = ""; content = Serial.readStringUntil('\r'); return content; } Now it is fine. I will also change String to large char array.


2

For example, Eclipse IDE with Sloeber plugin is much better than Arduino IDE. You have all the features of Eclipse (coloring, error highlighting, auto-complete, open declaration ('drill down' to libraries), ...*). And every project has own settings (board settings, port, programmer ...). And the Arduino IDE buttons Upload, Verify, Session Monitor are there ...


2

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 ...


2

The mkspiffs tool creates bin from file system data (or extracts data from bin). SPIFFS bin is uploaded with esptool over USB or with espota over WiFi. It can be uploaded with the sketch binary in one command. Example: esptool.py -p /dev/ttyUSB0 write_flash 0x0 sketch.bin 0x300000 spiffs.bin The IDE plugin adds SPIFFS upload to Arduino IDE Tools menu.


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