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


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

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


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

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

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


4

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

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

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

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

SPIFFS is not implemented for ESP32 yet, and there is no much information about progress. A workaround you can use is a SD card adaptor.


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

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

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


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

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

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


2

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) + ","); ...


2

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


2

The SDK API documentation from Espressif directly notes: uint8_t max_connection Max number of stations allowed to connect in, default 4, max 4 EDIT However, another area of the API documentation (The API Guide) notes: max_connection Currently, ESP32 Wi-Fi supports up to 10 Wi-Fi connections. If max_connection > 10, soft-AP defaults the ...


2

Do different boards analogRead differently? Yes. Your typical Arduino has a 10-bit ADC. That can give values between 0 and 1023 (210-1), with 400 falling just short of half way. The ESP32 has a 12-bit ADC. That gives values between 0 and 4095 (212-1), which means that your 2000 falls, yes, just short of half way. It is not the value from the ADC that is ...


2

Save the patch to a file, put it in the directory holding the library, open a terminal on that directory and type: patch -p1 < patchfile You may have to install the "patch" utility if you don't have it yet. On a Debian-like OS (I don't know for other OSes): sudo apt install patch


2

For getting millisecond resolution out of an RTC, I think the only viable solution is to sync with the 1 Hz square wave output, as suggested by Jot in a comment. Note that, since you are only counting seconds and milliseconds, you probably don't care about hours, minutes, days, months, etc. So you won't use the RTC for timekeeping: only for providing ...


2

Your plan has more flaws. First as Juraj wrote in a comment, you can't dim a switching power supply of the LED bulb. But this would not work as you plan even if you use a classic incandescent light bulb with AC. You can't control it with PWM. AC is dimmed with phase control, which requires a zero crossing detection to turn off power for part of the AC wave.


2

The authors of the ESP32 core didn't bother to create a proper set of compatability shims for the PROGMEM system - chiefly because it's not needed for ESP32 operation. We did for chipKIT, though, and you can grab a copy of ours here and place it in with the core files for the ESP32 in your Arduino installation (you only need the pgmspace.h file, and place ...


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